Shortcuts

线性

class torch.ao.nn.quantized.Linear(in_features, out_features, bias_=True, dtype=torch.qint8)[源代码]

一个使用量化张量作为输入和输出的量化线性模块。 我们采用了与torch.nn.Linear相同的接口,请参阅 https://pytorch.org/docs/stable/nn.html#torch.nn.Linear获取文档。

类似于Linear,属性将在模块创建时随机初始化,并将在之后被覆盖

Variables
  • weight (Tensor) – 模块的不可学习的量化权重,形状为 (out_features,in_features)(\text{out\_features}, \text{in\_features})

  • 偏置 (张量) – 模块的不可学习偏置,形状为 (out_features)(\text{out\_features})。 如果 biasTrue,则值初始化为零。

  • scalescale 参数,输出量化张量的参数,类型:double

  • zero_point零点参数用于输出量化张量,类型:long

示例:

>>> m = nn.quantized.Linear(20, 30)
>>> input = torch.randn(128, 20)
>>> input = torch.quantize_per_tensor(input, 1.0, 0, torch.quint8)
>>> output = m(input)
>>> print(output.size())
torch.Size([128, 30])
classmethod from_float(mod)[源代码]

从观察到的浮点模块创建一个量化模块

Parameters

mod (模块) – 一个浮点模块,由 torch.ao.quantization 工具生成或由用户提供

classmethod from_reference(ref_qlinear, output_scale, output_zero_point)[源代码]

从参考量化模块创建一个(fbgemm/qnnpack)量化模块

Parameters
  • ref_qlinear (模块) – 一个参考量化线性模块,由 torch.ao.quantization 工具生成或由用户提供

  • output_scale (float) – 输出张量的缩放比例

  • output_zero_point (int) – 输出张量的零点

优云智算