Shortcuts

torch.compile

torch.compile(model=None, *, fullgraph=False, dynamic=False, backend='inductor', mode=None, options=None, disable=False)[source]

Optimizes given model/function using TorchDynamo and specified backend.

Parameters:
  • model (Callable) – Module/function to optimize

  • fullgraph (bool) – Whether it is ok to break model into several subgraphs

  • dynamic (bool) – Use dynamic shape tracing

  • backend (str or Callable) – backend to be used

  • mode (str) – Can be either “default”, “reduce-overhead” or “max-autotune”

  • options (dict) – A dictionary of options to pass to the backend.

  • disable (bool) – Turn torch.compile() into a no-op for testing

Return type:

Callable

Example:

@torch.compile(options={"matmul-padding": True}, fullgraph=True)
def foo(x):
    return torch.sin(x) + torch.cos(x)

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