快捷方式

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

文件

訪問 PyTorch 的完整開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得疑問解答

檢視資源