ObserverBase#
- class torch.ao.quantization.observer.ObserverBase(dtype, is_dynamic=False)[源代码]#
基础观察者模块。任何观察者实现都应继承自此类。
具体观察者应遵循相同的 API。在 forward 中,它们将更新观察到的 Tensor 的统计信息。并且它们应该提供一个 calculate_qparams 函数,该函数根据收集到的统计信息计算量化参数。
- 参数
dtype – dtype argument to the quantize node needed to implement the reference model spec.
is_dynamic (bool) – 指示观察者是否为动态量化的占位符
量化 (或静态) –
- 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() >>> # wait 50 >>> foo_instance2 = foo_builder() >>> id(foo_instance1.creation_time) == id(foo_instance2.creation_time) False