Files
pytorch/docs/source/torch.compiler_api.md
T
angelayi c48c6913b5 [torch.compile] Add torch.compiler.set_default_backend (#178944)
Addresses https://github.com/pytorch/pytorch/issues/178930

Allow overriding the default torch.compile backend globally so that out-of-tree backend authors don't need to pass `backend=` at every call site. Follows the same pattern as `torch.set_default_dtype` and `torch.set_default_device`. Explicit `backend= arguments to torch.compile still take precedence.

Usage:

```python
import torch

torch.compiler.set_default_backend("my_custom_backend")
compiled_model = torch.compile(model)  # uses "my_custom_backend"

torch.compiler.set_default_backend(None)
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/178944
Approved by: https://github.com/anijain2305, https://github.com/williamwen42, https://github.com/mlazos
2026-04-20 21:45:18 +00:00

856 B

.. currentmodule:: torch.compiler
.. automodule:: torch.compiler

(torch.compiler_api)=

torch.compiler API reference

For a quick overview of torch.compiler, see {ref}torch.compiler_overview.

.. autosummary::
    :toctree: generated
    :nosignatures:

     compile
     reset
     allow_in_graph
     substitute_in_graph
     assume_constant_result
     list_backends
     disable
     set_default_backend
     get_default_backend
     set_stance
     set_enable_guard_collectives
     cudagraph_mark_step_begin
     is_compiling
     is_dynamo_compiling
     is_exporting
     keep_portable_guards_unsafe
     skip_guard_on_inbuilt_nn_modules_unsafe
     skip_guard_on_all_nn_modules_unsafe
     keep_tensor_guards_unsafe
     skip_guard_on_globals_unsafe
     skip_all_guards_unsafe
     nested_compile_region