ObserverBase¶
- class torch.ao.quantization.observer.ObserverBase(dtype, is_dynamic=False)[源代码]¶
基础观察者模块。 任何观察者实现都应该继承自此类。
具体的观察者应遵循相同的API。在前向传播中,它们将更新被观察张量的统计数据。并且它们应提供一个calculate_qparams函数,该函数根据收集的统计数据计算量化参数。
- Parameters
dtype – 实现参考模型规范所需的quantize节点的dtype参数。
is_dynamic – 指示观察者是否为动态量化的占位符的标志
量化(或静态)——
- 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
- classmethod with_callable_args(**kwargs)¶
包装器,允许创建需要在构造时调用的类工厂参数。
当需要创建具有相同构造函数参数但不同实例的类,并且这些参数仅应在构造时计算时,这可能会很有用。可以与_with_args结合使用
示例:
>>> Foo.with_callable_args = classmethod(_with_callable_args) >>> Foo.with_args = classmethod(_with_args) >>> foo_builder = Foo.with_callable_args(cur_time=get_time_func).with_args(name="dan") >>> foo_instance1 = foo_builder() >>> # 等待 50 >>> foo_instance2 = foo_builder() >>> id(foo_instance1.creation_time) == id(foo_instance2.creation_time) False