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