快捷方式

IntxFakeQuantizeConfig

class torchao.quantization.qat.IntxFakeQuantizeConfig(dtype: Union[dtype, TorchAODType], granularity: Optional[Union[Granularity, str]] = None, mapping_type: Optional[MappingType] = None, scale_precision: dtype = torch.float32, zero_point_precision: dtype = torch.int32, zero_point_domain: ZeroPointDomain = ZeroPointDomain.INT, is_dynamic: bool = True, range_learning: bool = False, eps: Optional[float] = None, *, group_size: Optional[int] = None, is_symmetric: Optional[bool] = None)[源代码]

用于伪量化权重或激活的配置,目标是高达 torch.int8 的整数数据类型。

参数:
  • dtype – 伪量化期间模拟的数据类型,例如 torch.int8。对于早于 2.6 的 PyTorch 版本,您可以使用 TorchAODType 来表示 torch.int1 到 torch.int7,例如 TorchAODType.INT4。

  • granularity

    比例和零点的粒度,例如 PerGroup(32)。我们也支持以下字符串

    1. ’per_token’: 等同于 PerToken()

    2. ’per_channel’: 等同于 PerAxis(0)

    3. ’per_group’: 等同于 PerGroup(group_size),必须与单独的 group_size 关键字参数结合使用

      与单独的 group_size 关键字参数结合使用,或者,只需设置 group_size 关键字参数,并将此字段留空。

  • mapping_type – 是否使用对称(默认)或非对称量化。或者,设置 is_symmetric (bool) 并将此字段留空。

  • scale_precision – 比例数据类型(默认为 torch.fp32)

  • zero_point_precision – 零点数据类型(默认为 torch.int32)

  • zero_point_domain – 零点是整数(默认)还是浮点域

  • is_dynamic – 是否使用动态(默认)或静态比例和零点

  • range_learning (prototype) – 是否在训练期间学习比例和零点(默认 false),与 is_dynamic 不兼容。

关键字参数:
  • group_size – 每个组在每组伪量化中的大小,可以代替 granularity 设置

  • is_symmetric – 是否使用对称或非对称量化,可以代替 mapping_type 设置

使用示例

# Per token asymmetric quantization
IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
IntxFakeQuantizeConfig(torch.int8, PerToken(), MappingType.ASYMMETRIC)

# Per channel symmetric quantization
IntxFakeQuantizeConfig(torch.int4, "per_channel")
IntxFakeQuantizeConfig(torch.int4, "per_channel", is_symmetric=True)
IntxFakeQuantizeConfig(torch.int4, PerAxis(0), MappingType.SYMMETRIC)

# Per group symmetric quantization
IntxFakeQuantizeConfig(torch.int4, group_size=32)
IntxFakeQuantizeConfig(torch.int4, group_size=32, is_symmetric=True)
IntxFakeQuantizeConfig(torch.int4, "per_group", group_size=32, is_symmetric=True)
IntxFakeQuantizeConfig(torch.int4, PerGroup(32), MappingType.SYMMETRIC)
property group_size: int

如果是每组粒度,则返回组大小。否则,会引发错误。

property is_symmetric: bool

如果映射类型是对称的,则返回 True,否则返回 False(非对称)。

文档

访问全面的 PyTorch 开发者文档

查看文档

教程

为初学者和高级开发者提供深入的教程

查看教程

资源

查找开发资源并让您的问题得到解答

查看资源