| name | pytorch-dynamo |
| description | Expert guidance for PyTorch Dynamo (torch.compile) development and debugging. Covers symbolic execution, VariableTracker system, pytree integration, guard failures, guard generation, FakeTensors, SymInts, symbolic shapes, dynamic shapes, C++ ATen ops, .size() vs .sym_size(), .numel() vs .sym_numel(), and bytecode tracing. |
PyTorch Dynamo Expert
Expert guidance for working with PyTorch's Dynamo compilation system (torch.compile).
Quick Start
Working with torch.compile? Start here:
Working with pytree operations? See pytree-integration.md
Writing C++ ATen ops for dynamic shapes? See GUARD.md
What is Dynamo?
Dynamo is PyTorch's JIT compiler that intercepts Python bytecode execution to trace and optimize PyTorch models. It powers torch.compile().
Core idea: Intercept Python frame execution โ Symbolically execute bytecode โ Generate FX graph โ Compile with backend
When to Use This Skill
Activate when:
- Implementing Dynamo features or fixes (VariableTracker, opcode handlers, etc.)
- Understanding Dynamo internals (symbolic execution, guards, bytecode)
- Developing new PyTorch compilation support
- Writing tests in
test/dynamo/
For user-level debugging (graph breaks, TORCH_LOGS, FX graphs): Use compile-trace-dynamo skill instead.
This skill is for Dynamo contributors implementing/fixing Dynamo code.
Implementation Workflow
When implementing a Dynamo feature or fixing an internal issue:
- Understand the requirement - What behavior needs to change?
- Locate the code - Use ARCHITECTURE.md to find relevant files
- Write a test - Add failing test BEFORE implementing (
test/dynamo/)
- Implement - Follow patterns in COMMON-PATTERNS.md
- Debug - Use DEBUGGING-GUIDE.md for implementation-level debugging
- Verify - Run new test + related existing tests
- Review - Check that implementation follows development principles
Implementation Quick Reference
Core Concepts (30-Second Version)
Frame Interception
Dynamo installs a custom frame evaluation hook to intercept Python execution.
File: torch/_dynamo/eval_frame.py
Symbolic Execution
Instead of executing Python bytecode normally, Dynamo executes it symbolically using InstructionTranslator.
File: torch/_dynamo/symbolic_convert.py
Variable Tracking
Python objects are represented as VariableTracker subclasses during symbolic execution.
Directory: torch/_dynamo/variables/
Guard System
Guards ensure compiled code only runs when assumptions hold (e.g., tensor shapes, types).
Files: guards.py, guard_failures.py
Graph Generation
Symbolic execution produces an FX GraphModule that backends can optimize.
File: output_graph.py
Common Tasks
Debug a Compilation Error
- Create minimal repro
- Enable logging:
torch._logging.set_logs(dynamo=logging.INFO, bytecode=True)
- Follow workflow in DEBUGGING-GUIDE.md
Add Support for a New Type
- Create
MyTypeVariable in torch/_dynamo/variables/
- Update
VariableBuilder to recognize it
- See COMMON-PATTERNS.md
Fix a pytree Integration Bug
- Understand fast-path optimization in PYTREE-INTEGRATION.md
- Check
call_tree_map_branch() implementation
- Ensure both explicit and implicit registration checks
Key Files Quick Map
torch/_dynamo/
โโโ eval_frame.py # Frame interception entry point
โโโ convert_frame.py # Decides whether to trace
โโโ symbolic_convert.py # InstructionTranslator (main bytecode interpreter)
โโโ output_graph.py # Graph builder
โโโ guards.py # Guard system
โโโ variables/
โ โโโ base.py # VariableTracker base class
โ โโโ tensor.py # TensorVariable
โ โโโ lists.py # List/Tuple/NamedTuple variables
โ โโโ dicts.py # Dict variables
โ โโโ functions.py # Function variables (includes tree_map fast-path)
โ โโโ user_defined.py # UserDefinedObjectVariable (custom classes)
โโโ polyfills/
โโโ pytree.py # PyTree polyfills for tracing
Progressive Disclosure
Development Principles
- Respect the architecture - Don't create parallel systems
- Guard everything - Never bypass the guard system
- Use existing abstractions - Don't invent new Dynamo APIs
- Maintain consistency - VariableTrackers should behave uniformly
- Place logic correctly - Opcode handlers belong in specific places
See ARCHITECTURE.md for details.
Getting Help
Compilation error? โ DEBUGGING-GUIDE.md
Guard failure? โ DEBUGGING-GUIDE.md
Adding feature? โ COMMON-PATTERNS.md
PyTree issue? โ PYTREE-INTEGRATION.md
C++ ATen ops & guards? โ GUARD.md
Need quick command? โ QUICK-REFERENCE.md