評價此頁

Linear#

class torch.ao.nn.quantized.Linear(in_features, out_features, bias_=True, dtype=torch.qint8)[原始碼]#

一個量化的線性模組,輸入和輸出均為量化張量。我們採用了與 torch.nn.Linear 相同的介面,請參閱 https://pytorch.com.tw/docs/stable/nn.html#torch.nn.Linear 獲取文件。

Linear 類似,屬性將在模組建立時被隨機初始化,稍後會被覆蓋。

變數
  • weight (Tensor) – 模組的非學習型量化權重,形狀為 (out_features,in_features)(\text{out\_features}, \text{in\_features})

  • bias (Tensor) – 模組的非學習型偏置,形狀為 (out_features)(\text{out\_features})。如果 biasTrue,則值初始化為零。

  • scale – 輸出量化張量的 scale 引數,型別:double

  • zero_point – 輸出量化張量的 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, use_precomputed_fake_quant=False)[原始碼]#

從觀察到的浮點模組建立量化模組。

引數
  • mod (Module) – 一個浮點模組,由 torch.ao.quantization 工具生成或使用者提供

  • use_precomputed_fake_quant (bool) – 如果為 True,則模組將重用預計算的 fake quant 模組的 min/max 值。

classmethod from_reference(ref_qlinear, output_scale, output_zero_point)[原始碼]#

從參考量化模組建立(fbgemm/qnnpack)量化模組。

引數
  • ref_qlinear (Module) – 一個參考量化線性模組,可以由 torch.ao.quantization 工具生成,也可以由使用者提供。

  • output_scale (float) – 輸出張量的 scale。

  • output_zero_point (int) – 輸出張量的 zero point。