評價此頁

torch.compiler API 參考#

創建於: 2023 年 6 月 02 日 | 最後更新於: 2025 年 6 月 22 日

有關 torch.compiler 的快速概述,請參閱 torch.compiler

compile

有關此函式的引數的詳細資訊,請參閱 torch.compile()

reset

此函式清除所有編譯快取,並將系統恢復到初始狀態。

allow_in_graph

指示編譯器前端(Dynamo)跳過對函式的符號自省,而是在遇到函式時直接將其寫入圖。

substitute_in_graph

為某個函式(通常是 C 擴充套件中的 C 函式)註冊一個 polyfill 處理程式,在將原始函式內聯到圖中時用於替換原始函式。

assume_constant_result

此函式用於標記一個函式 fn 具有常量結果。

list_backends

返回可傳遞給 torch.compile(..., backend="name") 的有效字串。

disable

此函式提供了一個裝飾器,用於停用函式上的編譯。

set_stance

設定編譯器的當前姿態(stance)。

set_enable_guard_collectives

在 guard 評估 *期間* 啟用 collectives 的使用,以跨程序同步行為。

cudagraph_mark_step_begin

指示推理或訓練的新迭代即將開始。

is_compiling

指示圖是否作為 torch.compile() 或 torch.export() 的一部分執行/跟蹤。

is_dynamo_compiling

指示圖是否透過 TorchDynamo 進行了追蹤。

is_exporting

指示當前是否處於匯出狀態。

skip_guard_on_inbuilt_nn_modules_unsafe

一個通用函式,用於跳過對內建 nn 模組(如 torch.nn.Linear)的 guard。

skip_guard_on_all_nn_modules_unsafe

一個通用函式,用於跳過對所有 nn 模組的 guard,包括使用者定義的和內建的 nn 模組(如 torch.nn.Linear)。

keep_tensor_guards_unsafe

一個通用函式,用於保留對所有張量的 tensor guard。

skip_guard_on_globals_unsafe

一個通用函式,用於跳過對所有全域性變數的 guard。

nested_compile_region

指示 ``torch.compile`` 標記的操作集合構成一個巢狀編譯區域(通常在完整模型中重複出現),其程式碼可以編譯一次並安全重用。