Rate this Page

torch.compiler API reference#

Created On: Jun 02, 2023 | Last Updated On: Apr 24, 2026

For a quick overview of torch.compiler, see torch.compiler.

compile

See torch.compile() for details on the arguments for this function.

reset

Reset the in-process compiler state.

allow_in_graph

Tells the compiler frontend (Dynamo) to skip symbolic introspection of the function and instead directly write it to the graph when encountered.

substitute_in_graph

Register a polyfill handler for a function, usually a C function from the C extension, to be used in place of the original function when inlining the original function in the graph.

assume_constant_result

This function is used to mark a function fn as having a constant result.

list_backends

Return valid strings that can be passed to torch.compile(..., backend="name").

disable

This function provides a decorator to disable compilation on a function.

set_default_backend

Set the default backend for torch.compile when no backend argument is specified.

get_default_backend

Return the current default backend for torch.compile.

set_stance

Set the current stance of the compiler.

set_enable_guard_collectives

Enables use of collectives during guard evaluation to synchronize behavior across ranks.

cudagraph_mark_step_begin

Indicates that a new iteration of inference or training is about to begin.

is_compiling

Indicates whether a graph is executed/traced as part of torch.compile() or torch.export().

is_dynamo_compiling

Indicates whether a graph is traced via TorchDynamo.

is_exporting

Indicated whether we're under exporting.

keep_portable_guards_unsafe

A common function to only keep guards that can be used in both Python and non-Python environments.

skip_guard_on_inbuilt_nn_modules_unsafe

A common function to skip guards on the inbuilt nn modules like torch.nn.Linear.

skip_guard_on_all_nn_modules_unsafe

A common function to skip guards on all nn modules, both user defined as well inbuilt nn modules (like torch.nn.Linear).

keep_tensor_guards_unsafe

A common function to keep tensor guards on all tensors.

skip_guard_on_globals_unsafe

A common function to skip guards on all globals.

skip_all_guards_unsafe

A function for skipping all guards on a compiled function.

nested_compile_region

Tells ``torch.compile`` that the marked set of operations forms a nested compile region (which is often repeated in the full model) whose code can be compiled once and safely reused.

load_cache_artifacts

Hot loads cache artifacts that were previously serialized via save_cache_artifacts

load_compiled_function

Load an aot-compiled function from a file.

save_cache_artifacts

Serializes all the cache artifacts that were created during the compilation

wrap_numpy

Decorator that turns a function from np.ndarrays to np.ndarrays into a function from torch.Tensors to torch.Tensors.