W3cubDocs

/PyTorch 2.9

torch.compiler.keep_tensor_guards_unsafe

torch.compiler.keep_tensor_guards_unsafe(guard_entries, keep_parameters=False) [source]

A common function to keep tensor guards on all tensors. This is unsafe to use by default. But if you don’t expect any changes in the model code, you can just keep the tensor guards.

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

© 2025, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://docs.pytorch.org/docs/2.9/generated/torch.compiler.keep_tensor_guards_unsafe.html