評價此頁

torch.compiler.skip_guard_on_inbuilt_nn_modules_unsafe#

torch.compiler.skip_guard_on_inbuilt_nn_modules_unsafe(guard_entries)[source]#

一個常見的函式,用於跳過對內建 nn 模組(如 torch.nn.Linear)的 guard。此函式預設不安全。但對於大多數 torch.compile 使用者而言,模型程式碼不會修改內建 nn 模組的屬性。他們可以透過使用此 API 來減少 guard 延遲開銷。

要使用此 API,請在呼叫 torch.compile 時使用 guard_filter_fn 引數。

>> opt_mod = torch.compile( >> mod, >> options={“guard_filter_fn”: torch.compiler.skip_guard_on_all_nn_modules_unsafe}, >> )