ObserverBase¶
- class torch.ao.quantization.observer.ObserverBase(dtype, is_dynamic=False)[source][source]¶
基础 observer 模块。任何 observer 实现都应派生自此类别。
具体的 observer 应遵循相同的 API。在 forward 方法中,它们会更新被观察 Tensor 的统计信息。并且它们应该提供一个 calculate_qparams 函数,该函数根据收集到的统计信息计算量化参数。
- 参数
dtype – quantize 节点的 dtype 参数,实现参考模型规范所需。
is_dynamic (bool) – 指示该 observer 是否为动态量化的占位符
或静态量化
- classmethod with_args(**kwargs)[source]¶
允许创建类工厂的包装器。
当需要创建具有相同构造函数参数但不同实例的类时,这会很有用。可与 _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)[source]¶
允许创建需要在构造时调用的类工厂参数的包装器。
当需要创建具有相同构造函数参数但不同实例,且这些参数只能在构造时计算的类时,这会很有用。可与 _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() >>> # wait 50 >>> foo_instance2 = foo_builder() >>> id(foo_instance1.creation_time) == id(foo_instance2.creation_time) False