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}, >> )