评价此页

torch.compiler.skip_guard_on_all_nn_modules_unsafe#

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

一个常用的函数,用于跳过对所有nn.Module的guard,包括用户自定义的和内置的nn.Module(例如torch.nn.Linear)。此函数默认不安全。但对于大多数torch.compile用户而言,模型代码不会修改nn.Module的属性。通过使用此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}, >> )