评价此页

AffineQuantizedObserverBase#

class torch.ao.quantization.observer.AffineQuantizedObserverBase(mapping_type, target_dtype, granularity, quant_min=None, quant_max=None, eps=None, scale_dtype=None, zero_point_dtype=None, preserve_zero=True, zero_point_domain=ZeroPointDomain.INT, **kwargs)[源代码]#

仿射量化(pytorch/ao)的观察器模块

参数
  • block_size (granularity and) – 量化的粒度,必须至少指定一个,如果都指定了,则 block_size 优先。当前支持的粒度类型为 PerTensorPerAxis

  • args (other) – 请参阅 :class:torchao.dtypes.AffineQuantizedTensor

abstract calculate_qparams()[源代码]#

根据观察器模块中的统计信息计算量化参数,并返回 scale 和 zero_point Tensor 的元组。

返回类型

tuple[torch.Tensor, torch.Tensor]

convert(model, observer_node)[源代码]#

将图中的观察器节点转换为其量化表示。

参数
  • model (GraphModule) – 要在其中转换观察器节点的图模块。

  • observer_node (Node) – 要转换的观察器节点。

abstract forward(input)[源代码]#

forward 函数应接收输入张量,更新内部统计信息,并返回原始输入张量。

返回类型

张量

classmethod with_args(**kwargs)[源代码]#

允许创建类工厂的包装器。

当需要创建具有相同构造函数参数但实例不同的类时,这可能很有用。可以与 _callable_args 一起使用。

示例

>>> Foo.with_args = classmethod(_with_args)
>>> foo_builder = Foo.with_args(a=3, b=4).with_args(answer=42)
>>> foo_instance1 = foo_builder()
>>> foo_instance2 = foo_builder()
>>> id(foo_instance1) == id(foo_instance2)
False