/usr/local/lib64/python3.6/site-packages/torch/nn/qat/modules/__pycache__
Edit: /usr/local/lib64/python3.6/site-packages/torch/nn/qat/modules/__pycache__/linear.cpython-36.pyc (2511B)
3
Eg @ s@ d dl Z d dljZd dljjZd dlmZ G dd dejZdS ) N)
LinearReLUc sJ e Zd ZdZejZd
dd fdd
Zdd Ze d d
Z
dd Z ZS )Lineara
A linear module attached with FakeQuantize modules for weight,
used for quantization aware training.
We adopt the same interface as `torch.nn.Linear`, please see
https://pytorch.org/docs/stable/nn.html#torch.nn.Linear
for documentation.
Similar to `torch.nn.Linear`, with FakeQuantize modules initialized to
default.
Attributes:
weight: fake quant module for weight
TN)returnc sB ||d}t j|||f| |s*td|| _|j|d| _d S )N)devicedtypez'qconfig must be provided for QAT module)factory_kwargs)super__init__AssertionErrorqconfigweightweight_fake_quant)selfin_featuresout_featuresbiasr r r r ) __class__ G/usr/local/lib64/python3.6/site-packages/torch/nn/qat/modules/linear.pyr s
zLinear.__init__c C s t j|| j| j| jS )N)Flinearr
r r )r inputr r r forward s zLinear.forwardc C s t || jks(td| j d | jj t|ds:td|jsHtdt |tkr\|d }|j}| |j|j|j dk |d}|j
|_
|j |_ |S ) zCreate a qat module from a float module or qparams_dict
Args: `mod` a float module, either produced by torch.quantization utilities
or directly from user
z qat.z.from_float only works for r z,Input float module must have qconfig definedz,Input float module must have a valid qconfigr N)r r )type
_FLOAT_MODULEr
__name__hasattrr r r r r r )clsmodr Z
qat_linearr r r
from_float" s zLinear.from_floatc C s\ t jj| j| j| jd k }t jj| jj |_| jd k rLt jj| jj |_|j | j
|S )N)torchnnr r r r Parameterr detachZtrainZtraining)r r r r r to_float6 s
zLinear.to_float)TNNN)
r
__module____qualname____doc__r! r r r r classmethodr r$
__classcell__r r )r r r s r ) r Ztorch.nnr! Ztorch.nn.functionalZ
functionalr Ztorch.nn.intrinsicr r r r r r
s