• 文件 >
  • torch >
  • torch.fake_quantize_per_channel_affine
快捷方式

torch.fake_quantize_per_channel_affine

torch.fake_quantize_per_channel_affine(input, scale, zero_point, axis, quant_min, quant_max) Tensor

傳回一個新的 Tensor,其資料來自 input,並使用 scalezero_pointquant_minquant_max,針對由 axis 指定的通道進行 fake quantized (偽量化)。

output=(min(quant_max,max(quant_min,std::nearby_int(input/scale)+zero_point))zero_point)×scale\text{output} = ( min( \text{quant\_max}, max( \text{quant\_min}, \text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point} ) ) - \text{zero\_point} ) \times \text{scale}
參數
  • input (Tensor) – 輸入值,格式為 torch.float32

  • scale (Tensor) – 量化比例,每個通道的格式為 torch.float32

  • zero_point (Tensor) – 量化零點,每個通道的格式為 torch.int32torch.halftorch.float32

  • axis (int32) – 通道軸

  • quant_min (int64) – 量化範圍的下限

  • quant_max (int64) – 量化範圍的上限

傳回

一個新的每個通道進行 fake_quantized (偽量化) 的 torch.float32 Tensor

傳回類型

Tensor

範例

>>> x = torch.randn(2, 2, 2)
>>> x
tensor([[[-0.2525, -0.0466],
         [ 0.3491, -0.2168]],

        [[-0.5906,  1.6258],
         [ 0.6444, -0.0542]]])
>>> scales = (torch.randn(2) + 1) * 0.05
>>> scales
tensor([0.0475, 0.0486])
>>> zero_points = torch.zeros(2).to(torch.int32)
>>> zero_points
tensor([0, 0])
>>> torch.fake_quantize_per_channel_affine(x, scales, zero_points, 1, 0, 255)
tensor([[[0.0000, 0.0000],
         [0.3405, 0.0000]],

        [[0.0000, 1.6134],
        [0.6323, 0.0000]]])

文件

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources