ObserverBase¶
- 类 torch.ao.quantization.observer.ObserverBase(dtype, is_dynamic=False)[source][source] ¶
基础观察器模块。任何观察器实现都应从此类派生。
混合观察者应遵循相同的 API。在正向中,它们将更新观察到的张量的统计信息。并且它们应提供一个计算量化参数的 calculate_qparams 函数,该函数根据收集到的统计信息进行计算。
- 参数:
dtype - 量化节点需要的 dtype 参数,以实现参考模型规范。
is_dynamic (布尔值) – 表示观察者是否为动态量化的占位符的指示器
量化(或静态)–
- 类方法 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