捷徑

torch.compiler.set_stance

torch.compiler.set_stance(stance='default', *, skip_guard_eval_unsafe=False, force_backend=None)[source][source]

設定編譯器的目前姿態。可以用作函式、上下文管理器或裝飾器。請勿在 torch.compile 區域內使用此函式 - 否則會引發錯誤。

@torch.compile
def foo(x):
    ...

@torch.compiler.set_stance("force_eager")
def bar():
    # will not be compiled
    foo(...)

bar()

with torch.compiler.set_stance("force_eager"):
    # will also not be compiled
    foo(...)

torch.compiler.set_stance("force_eager")
# will also not be compiled
foo(...)
torch.compiler.set_stance("default")

# will be compiled
foo(...)
參數
  • stance (str) –

    要設定編譯器的姿態。有效值為

    • ”default”: 預設姿態,用於正常編譯。

    • ”force_eager”: 忽略所有 torch.compile 指令。

    • ”eager_on_recompile”:當需要重新編譯時,立即執行程式碼。 如果存在適用於輸入的快取編譯程式碼,它仍然會被使用。

    • ”fail_on_recompile”:當重新編譯函式時,引發錯誤。

  • skip_guard_eval_unsafe

    一個僅執行區分性防護的標誌。 注意 - 此標誌不安全,僅應在您的設定滿足以下條件時使用。

    torch.compile 使用防護系統來支援重新編譯,並選擇在執行時要運行的編譯產物。 這些防護雖然有效率,但會增加一些開銷,這可能會影響您需要針對最小防護處理時間進行優化的場景中的效能。 此 API 允許您停用防護評估,前提是您已使用足夠多樣的輸入來預熱編譯模型。 這種假設意味著,在預熱階段之後,不再需要進一步的重新編譯。 如果此假設失敗,則存在靜默產生不正確結果的風險(因此 API 名稱中包含“unsafe”一詞)。

  • force_backend – 如果 stance 是 “default”,則可以使用此引數強制 torch.compile 使用特定的後端。 否則,會引發錯誤。

文件

存取 PyTorch 的完整開發者文件

檢視文件

教學

取得初學者和進階開發者的深入教學

檢視教學

資源

尋找開發資源並獲得您問題的解答

檢視資源