ObserverBase¶
- class torch.ao.quantization.observer.ObserverBase(dtype, is_dynamic=False)[來源][來源]¶
基礎觀察者模組。任何觀察者實作都應由此類別衍生。
具體觀察者應遵循相同的 API。在 forward 中,它們將更新觀察到的張量的統計資訊。並且它們應提供一個 calculate_qparams 函數,該函數可計算給定收集的統計資訊的量化參數。
- 參數
dtype – quantize 節點的 dtype 引數,需要實作參考模型規格。
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