評價此頁

torch.compiler.skip_guard_on_all_nn_modules_unsafe#

torch.compiler.skip_guard_on_all_nn_modules_unsafe(guard_entries)[原始碼]#

一個通用的函式,用於跳過對所有 nn 模組的 guard(保護),包括使用者定義的和內建的 nn 模組(例如 torch.nn.Linear)。預設情況下使用此函式是不安全的。但對於大多數 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}, >> )