• 文档 >
  • 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

返回一个新张量,其中 input 的数据在每个通道上使用 scalezero_pointquant_minquant_max 进行伪量化,跨由 axis 指定的通道。

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(张量)- 量化尺度,每个通道在 torch.float32

  • zero_point(张量)- 量化 zero_point,每个通道在 torch.int32torch.halftorch.float32

  • axis(int32)- 通道轴

  • quant_min(int64)- 量化域的下界

  • quant_max(int64)- 量化域的上界

返回值:

一个新的按通道 fake_quantized torch.float32 张量

返回类型:

张量

示例:

>>> 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]]])

© 版权所有 PyTorch 贡献者。

使用 Sphinx 构建,并使用 Read the Docs 提供的主题。

文档

PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

查找开发资源并获得您的疑问解答

查看资源