You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Behavior of ``torch.compile`` with Nested Modules and Function Calls
161
+
#
162
+
# When you use ``torch.compile``, the compiler will try to recursively inline
163
+
# and compile every function call inside the target function or module.
164
+
#
165
+
# This includes:
166
+
#
167
+
# - **Nested function calls:** All functions called within the decorated or compiled function will also be compiled.
168
+
#
169
+
# - **Nested modules:** If a ``torch.nn.Module`` is compiled, all sub-modules and functions within the module are also compiled.
170
+
#
171
+
# **Best Practices:**
172
+
#
173
+
# 1. **Modular Testing:** Test individual functions and modules with ``torch.compile``
174
+
# before integrating them into larger models to isolate potential issues.
175
+
#
176
+
# 2. **Disable Compilation Selectively:** If certain functions or sub-modules
177
+
# cannot be handled by `torch.compile`, use the `torch.compiler.disable` context
178
+
# managers to recursively exclude them from compilation.
179
+
#
180
+
# 3. **Compile Leaf Functions First:** In complex models with multiple nested
181
+
# functions and modules, start by compiling the leaf functions or modules first.
182
+
# For more information see `TorchDynamo APIs for fine-grained tracing <https://pytorch.org/docs/stable/torch.compiler_fine_grain_apis.html>`__.
0 commit comments