·
Last changedVersion:
This version passed the hardening gate. Hardening applied 2 targeted changes and preserved all other text. Classified findings before hardening: 1. Classified findings closed: 0. Classified findings remaining: 1. Unclassified scanner findings remaining: 1. Review findings closed: 1. Review findings remaining: 15.
1
1
Expand | File | Group | Subtype | Severity | Status |
|---|---|---|---|---|---|
LICENSE | Excessive Agency & Rogue Autonomy | — | Low | Open |
1 finding
Debug test failures and runtime errors in the PyTorch 2 compiler stack (Dynamo, Inductor, AOTAutograd, FX graphs).
$CONDA_DEFAULT_ENV. Then run python -c "import torch; print(torch.__version__)" to confirm torch is importable and report the version. If the environment is not active or torch cannot be imported, stop and ask the user to activate the correct environment before proceeding.test/dynamo/test_repros.py, test/inductor/test_torchinductor.py, test/export/test_export.py). Avoid test/dynamo/test_misc.py — it is already oversized; find a more specific test file that matches the area of the bug. Use torch.testing._internal.common_utils.TestCase and run_tests. The test must fail before the fix and pass after. Having the test first keeps you grounded — you know exactly what "fixed" looks like before you start exploring the codebase.EnterWorktree to create a worktree checked out at main. Copy the new test file into the worktree and run the test there to confirm it fails on main. If the test passes on main, stop — the test may not be capturing the right bug, or the bug may already be fixed. Exit the worktree with ExitWorktree (action: remove) and return to the working branch before continuing.TORCH_LOGS settingsTORCH_COMPILE_DEBUG=1is_exporting works, also run the existing test_is_exporting export test). Use pytest -k to quickly run related tests by name. The task is not complete until all pass./pr-review skill to review your own changes before presenting them.Use Grep, Glob, and Read directly for code exploration. Do not spawn meta_codesearch agents — they are slow and expensive. The Architectural Knowledge and Key Source Files sections below should give you enough context to know where to look. A targeted Grep for a function name is always faster.
Before reading implementation code, determine the compilation mode. These share code but diverge in important ways:
torch.compile -- Dynamo + Inductor. tx.export=False, no _compiling_state_context().torch.export (strict) -- tx.export=True, _compiling_state_context() active.torch.export (non-strict, the default) -- Uses Dynamo via fullgraph_capture but tx.export may differ from strict. _compiling_state_context() active. Check torch._export.config.use_new_tracer_experimental — it changes which code path is used.Many PT2 bugs come from confusing these two:
is_exporting() → ConstantVariable(True)).torch.compiler._is_exporting_flag.When debugging, add temporary print() statements directly in the source file rather than monkey-patching from outside — dispatch chains make monkey-patching unreliable.
Pick the right diagnostic tool based on the error category:
TORCH_LOGS="+dynamo,graph_breaks,recompiles" python your_script.pyTORCH_COMPILE_DEBUG=1 python your_script.py — creates torch_compile_debug/ with FX graphs, Inductor IR, and generated codeTORCH_LOGS="output_code" python your_script.pyTORCH_TRACE=/path/to/trace python your_script.py then tlparse /path/to/traceTORCHINDUCTOR_COMPILE_THREADS=1 python your_script.pyClassify the failure using the error message and traceback:
| Error Pattern | Category | Jump To |
|---|---|---|
| Graph break | |
| Inductor/backend crash | |
| Recompilation | |
Accuracy mismatch / wrong numerical output | Accuracy | |
| Dynamo bug | |
Segfault or CUDA IMA | Runtime crash | |
Triton assertion / index out of bounds | Triton kernel bug |
Graph breaks split the compiled graph into smaller subgraphs, often causing performance regressions or unexpected behavior.
Diagnosis:
Key files:
torch/_dynamo/exc.py -- Unsupported exception classtorch/_dynamo/variables/ -- where most graph break decisions happenCommon causes:
Fix approach:
torch._dynamo.allow_in_graph or restructuring user codeBackendCompilerFailed means Inductor (or another backend) crashed during compilation.
Diagnosis:
This generates minifier_launcher.py that isolates the minimal failing graph.
Key files:
torch/_dynamo/repro/after_aot.py -- repro/minifier for post-AOT failurestorch/_inductor/ -- the backend itselfFix approach:
TORCH_COMPILE_DEBUG=1) to understand what ops are involvedtorch/_inductor/lowering.py), scheduling issue, or codegen issueExcessive recompilation happens when guards are too specific, causing cache misses.
Diagnosis:
Key config:
torch._dynamo.config.recompile_limit (default: 8)torch._dynamo.config.fail_on_recompile_limit_hit -- set to True to get a hard errorCommon causes:
Fix approach:
torch._dynamo.mark_dynamic() or fix the source of guard instabilityThe compiled model produces different numerical results than eager mode.
Diagnosis:
This compares compiled vs. eager with an fp64 reference and dumps a repro if accuracy fails.
Key utilities:
torch/_dynamo/debug_utils.py -- same_two_models(), backend_accuracy_fails(), cast_to_fp64()torch._dynamo.config.repro_tolerance (default: 1e-3)Fix approach:
InternalTorchDynamoError indicates a bug in Dynamo itself.
Diagnosis:
Key files:
torch/_dynamo/symbolic_convert.py -- bytecode interpretertorch/_dynamo/variables/ -- variable tracking systemtorch/_dynamo/guards.py -- guard generationFix approach:
TORCHDYNAMO_VERBOSE=1TORCHINDUCTOR_COMPILE_THREADS=1 and pdb if neededSegfaults and CUDA illegal memory access errors during execution of compiled code.
Diagnosis (make crash deterministic):
For CUDA IMA, add NaN checks:
For Inductor-level sync debugging:
Fix approach:
PYTORCH_NO_CUDA_MEMORY_CACHING=1 CUDA_LAUNCH_BLOCKING=1TORCH_LOGS="output_code"TORCHINDUCTOR_NAN_ASSERTS=1 to find the first kernel producing bad valuesTriton assertion failures or index-out-of-bounds in generated kernels.
Diagnosis:
Key files:
torch/_inductor/codegen/triton.py -- Triton codegentorch/_inductor/scheduler.py -- kernel fusion decisionsFix approach:
output_code logsTORCH_COMPILE_DEBUG=1) to trace back to the FX op| File | Purpose |
|---|---|
| Exception hierarchy and error formatting |
| Minifier support, accuracy checking, input serialization |
| Repro/minifier for Dynamo-stage failures |
| Repro/minifier for post-AOTAutograd failures |
| Repro/minifier for AOTI failures |
| Dynamo config (repro levels, recompile limits) |
| Torch function handling, tracing state functions |
| HOP tracing (cond, map, etc.) |
| Bytecode interpreter, InstructionTranslator |
| Frame compilation, |
| New export tracer ( |
|
|
| Export pipeline ( |
|
|
|
|
|
|
|
|
| Inductor config (debug flags, trace settings) |
| DebugContext, graph visualization, IR logging |
| All registered log aliases and artifacts |
The minifier reduces a failing graph to the smallest reproduction:
For accuracy issues, use level 4:
Get started with chainctlchainctl skill install public/pytorch/pt2-bug-basher:latest
Bring Chainguard's hardening pipeline to your first-party skills — custom rulesets, automated remediation, full audit trail.
skills.cgr.dev/public/github.com/pytorch/.claude/skills/pt2-bug-basher:latest
BSD-3-Clause
HARDENING.md
LICENSE
SKILL.md