pytorch/torch/_dynamo/backends/inductor.py
Raymond Li 21c2565f35 Document dynamo (#146736)
Many files in dynamo are currently lacking file/module-level documentation, which makes it hard to know what they do at a glance and without digging into the code. This fixes that.

Note: documentation was AI-generated and could be incorrect, please review carefully.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/146736
Approved by: https://github.com/jansel, https://github.com/StrongerXi, https://github.com/anijain2305, https://github.com/zou3519
2025-02-13 00:02:21 +00:00

24 lines
761 B
Python

# mypy: ignore-errors
"""
This module provides the TorchInductor backend integration for TorchDynamo.
TorchInductor is a compiler backend that generates optimized code for both CPU and GPU.
This module lazily imports and registers the TorchInductor compiler to avoid loading it
into memory when it is not being used. This helps reduce memory overhead when using
other backends.
The inductor backend can be used with torch.compile():
model = torch.compile(model, backend="inductor")
"""
from torch._dynamo import register_backend
@register_backend
def inductor(*args, **kwargs):
# do import here to avoid loading inductor into memory when it is not used
from torch._inductor.compile_fx import compile_fx
return compile_fx(*args, **kwargs)