Shortcuts

torch.compiler.is_compiling

torch.compiler.is_compiling()[source]

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

Note that there are 2 other related flags that should deprecated eventually:
  • torch._dynamo.external_utils.is_compiling()

  • torch._utils.is_compiling()

Example:

>>> def forward(self, x):
>>>     if not torch.compiler.is_compiling():
>>>        ...logic that is not needed in a compiled/traced graph...
>>>
>>>     ...rest of the function...
Return type

bool

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources