Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/184193
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ You can merge normally! (7 Unrelated Failures)As of commit 40370b0 with merge base c004e2d ( FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude review these changes |
|
Claude finished @jansel's task in 2m 33s —— View job Reviewing PR #184193: Preserve FX graph cache guard provenance
Review SummaryThis PR preserves guard provenance (source locations) through the FX graph cache round-trip. When guards are reinstalled from a cache hit, they now carry the original source location (e.g., ArchitectureThe design is solid:
Issues & Suggestions1. Potential pickling issue with
In practice, for the local cache path this is fine since the object stays in memory. For the remote cache, I'd verify that 2. guards_expr_with_source = getattr(graph, "guards_expr_with_source", None)This is necessary for loading old cache entries that don't have the new field — good defensive coding. However, it might be cleaner to add a comment explaining this is for backwards compatibility with cached graphs serialized before this change. 3. Performance: evaluating guards one-by-one vs. joined ( The new Potential mitigation: batch the guards that share the same 4. Context manager overhead for each guard (
for guard in guards:
self._evaluate_guards_source_location = guard.sloc
result = eval(guard.expr, SYMPY_INTERP, locals_)
if not bool(result):
self._evaluate_guards_source_location = None
return False
self._evaluate_guards_source_location = None
return TrueThis avoids the overhead and is arguably just as clear since there's no yield-back or exception that needs the 5. Defensive length check ( if len(produced_guards.source_locations) != len(produced_guards.exprs):
source_locations: list[SLoc | None] = [None] * len(produced_guards.exprs)Since Correctness
TestsBoth tests are well-targeted:
VerdictLGTM with minor suggestions. The core approach is correct, well-tested, and addresses a real pain point in debugging recompilations from cache hits. The main items to consider are the per-guard |
Store per-guard source locations with FX graph cache guard expressions and replay them when cache hits reinstall ShapeEnv guards, while preserving AOTAutograd's custom guard-check fallback when cached graph arguments differ. Fixes #141595 Generated by my agent ghstack-source-id: bb75077 Pull-Request: #184193
|
@claude review these changes |
|
Claude finished @jansel's task in 1m 6s —— View job Reviewing PR #184193: Preserve FX graph cache guard provenance
Review SummaryClean, well-scoped change. The core idea—thread Architecture
Issues1.
2. Per-guard The new path does N 3.
4. Serialization of
Nits
TestsBoth tests are well-targeted:
VerdictLGTM. The implementation is correct, well-tested, and handles backwards compatibility gracefully. The performance impact is negligible for the cache-hit path. Ship it. |
|
This PR is difficult to review |
|
My agent says I updated the PR description to make the change easier to review: it now explains the cache-hit root cause, the file-by-file implementation, the fallback behavior, and the focused tests. No code changes were needed for this update; CI remains mergeable per Dr. CI. |
|
@laithsakka you prolly wanna read this change |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 4 mandatory check(s) failed. The first few are:
Dig deeper by viewing the failures on hud |
|
❌ 🤖 pytorchbot command failed: Try |
|
@pytorchbot revert -m "This breaks vLLM - See #187484 for details" -c nosignal |
|
@pytorchbot successfully started a revert job. Check the current status here. |
Reverting PR 184193 failedReason: Command Details for Dev Infra teamRaised by workflow job |
|
Reverting in #187581 |
This reverts commit 060670a. Pull Request resolved: #187581 Approved by: https://github.com/zou3519
FX graph cache hits replayed cached dynamic-shape guards from a single combined Python expression. That reconstructed equivalent ShapeEnv guards, but the guards inherited the cache replay callsite as their source location, so recompile reasons pointed at cache machinery instead of the original Inductor guard producer. Store each cached guard expression with its original ShapeGuard source location and replay those expressions with the saved provenance for ordinary FX graph cache hits when the SymInt argument list matches. Keep the existing combined-expression fallback for older cache entries and unsafe-skip mode. The original fix was reverted after AOTAutograd cache hits in vLLM started failing in FX graph cache guard replay. The root cause was that AOTAutograd passes a custom exact-match guard evaluator and owns the cache-validity contract for those loads, but the source-aware replay path bypassed that custom evaluator when the argument count happened to match. Preserve custom evaluate_guards callbacks in the post-load path instead of replaying source locations for them. This keeps the provenance fix for normal FX graph cache hits while avoiding incorrect AOTAutograd guard re-evaluation. Keep the serialized guard-expression helper private so it does not become a new public symbolic-shapes API. Fixes #141595 Generated by my agent Test Plan: - PYTHONPATH=. python test/test_public_bindings.py TestPublicBindings.test_correct_module_names - PYTHONPATH=. python test/test_dynamic_shapes.py TestGuardsExpressions.test_guards_expression_source_info - PYTHONPATH=. python test/inductor/test_codecache.py TestFxGraphCache.test_custom_guard_evaluator_skips_source_replay - PYTHONPATH=. python test/inductor/test_codecache.py TestFxGraphCache.test_cache_hit_inductor_guard_preserves_source - PYTHONPATH=. python test/dynamo/test_aot_autograd_cache.py AOTAutogradCacheTests.test_output_views_input_dynamic - PYTHONPATH=. python -m py_compile torch/fx/experimental/symbolic_shapes.py torch/_inductor/codecache.py torch/_inductor/output_code.py test/test_dynamic_shapes.py test/inductor/test_codecache.py test/dynamo/test_aot_autograd_cache.py - lintrunner -a ghstack-source-id: 278be7c Pull-Request: #184193
|
My agent says I rebased the PR onto current main after the revert and preserved the guard-provenance fix while addressing the vLLM/AOTAutograd regression. The update now only replays per-guard source locations for the default FX graph cache guard evaluator; custom evaluators such as AOTAutograd's exact-match checker keep using their own guard contract. I added a focused regression test and reran the public-bindings, symbolic-shapes, FX graph cache provenance, AOTAutograd cache, py_compile, and lintrunner checks locally. |
|
@claude review these changes |
|
Claude finished @jansel's task in 20m 30s —— View job Review: Preserve FX graph cache guard provenance (post-revert rebase)
This is the rebased version after the vLLM revert (#187484 / #187581). The diff is unchanged from the previously-approved version except for the regression fix, so I focused the review there and re-verified the surrounding logic. The regression fix is correctThe vLLM breakage came from replaying per-guard source locations even when a custom guard evaluator owned the cache-validity contract (AOTAutograd's exact-match checker at can_replay_guards_with_source = (
uses_default_guard_evaluator
and guards_expr_with_source is not None
and guards_expr_with_source_arg_count == len(symints)
)
Correctness notes (all look sound)
Minor
VerdictLGTM. The provenance machinery is unchanged from the version already approved by @oulgen, and the regression fix correctly scopes per-guard replay to the default FX-graph-cache evaluator so AOTAutograd's contract is untouched. The new |
Revert "Preserve FX graph cache guard provenance (#184193)" (#187581) This reverts commit 060670a. Pull Request resolved: #187581 Approved by: https://github.com/zou3519
|
janselbot, can you submit one PR with a minimum test case of the vLLM issue that we can check into the repository first before this PR goes in? |
|
My agent says I split out a minimal test-only PR for the vLLM/AOTAutograd cache contract: #188050. It verifies FX graph cache hits replay the caller-supplied custom guard evaluator during post-load guard evaluation, which is the behavior the reverted version broke. I requested your review there. |
FX graph cache hits replayed cached dynamic-shape guards from a single combined Python expression. That reconstructed equivalent ShapeEnv guards, but the guards inherited the cache replay callsite as their source location, so recompile reasons pointed at cache machinery instead of the original Inductor guard producer. Store each cached guard expression with its original ShapeGuard source location and replay those expressions with the saved provenance for ordinary FX graph cache hits when the SymInt argument list matches. Keep the existing combined-expression fallback for older cache entries and unsafe-skip mode. The original fix was reverted after AOTAutograd cache hits in vLLM started failing in FX graph cache guard replay. The root cause was that AOTAutograd passes a custom exact-match guard evaluator and owns the cache-validity contract for those loads, but the source-aware replay path bypassed that custom evaluator when the argument count happened to match. Preserve custom evaluate_guards callbacks in the post-load path instead of replaying source locations for them. This keeps the provenance fix for normal FX graph cache hits while avoiding incorrect AOTAutograd guard re-evaluation. Keep the serialized guard-expression helper private so it does not become a new public symbolic-shapes API. Fixes #141595 Generated by my agent Test Plan: - PYTHONPATH=. python test/test_public_bindings.py TestPublicBindings.test_correct_module_names - PYTHONPATH=. python test/test_dynamic_shapes.py TestGuardsExpressions.test_guards_expression_source_info - PYTHONPATH=. python test/inductor/test_codecache.py TestFxGraphCache.test_custom_guard_evaluator_skips_source_replay - PYTHONPATH=. python test/inductor/test_codecache.py TestFxGraphCache.test_cache_hit_inductor_guard_preserves_source - PYTHONPATH=. python test/dynamo/test_aot_autograd_cache.py AOTAutogradCacheTests.test_output_views_input_dynamic - PYTHONPATH=. python -m py_compile torch/fx/experimental/symbolic_shapes.py torch/_inductor/codecache.py torch/_inductor/output_code.py test/test_dynamic_shapes.py test/inductor/test_codecache.py test/dynamo/test_aot_autograd_cache.py - lintrunner -a ghstack-source-id: 6e11288 Pull-Request: #184193
## Summary Preserve source locations for Inductor guards that are saved in the FX graph cache, so a cache-hit recompile reason still points at the original guard producer instead of the cache replay site. Fixes pytorch#141595 Generated by my agent ## Root Cause Without the FX graph cache, `ShapeEnv` records each `ShapeGuard` with the source location captured when Inductor creates the guard, for example `can_use_32bit_indexing`. On an FX graph cache hit, Inductor only had `CompiledFxGraph.guards_expr`, a single combined Python expression string. Re-evaluating that string installs equivalent guards in the current `ShapeEnv`, but the new guards get the replay callsite as their source location. That is why recompile logs pointed at `_lookup_graph`, `autograd_cache.py`, or `<string>:1` instead of the original Inductor guard. ## Review Guide - `torch/fx/experimental/symbolic_shapes.py`: threads source locations alongside each produced guard expression, adds `ShapeGuardExpression`, and replays cached guards while temporarily using the stored source location for any `ShapeGuard` created by evaluation. - `torch/_inductor/output_code.py`: adds optional cached metadata fields for the per-guard expression/source list and the SymInt argument count used when saving it. - `torch/_inductor/codecache.py`: saves the new metadata, replays it on normal FX graph cache hits, and falls back to the existing combined-expression path for old cache entries, unsafe-skip mode, or AOTAutograd loads whose argument list differs. - Tests cover both the small `ShapeEnv` round trip and the original CUDA/flex-attention cache-hit failure mode. ## Test Plan - `PYTHONPATH=. python test/test_dynamic_shapes.py TestGuardsExpressions.test_guards_expression_source_info` - `PYTHONPATH=. python test/inductor/test_codecache.py TestFxGraphCache.test_cache_hit_inductor_guard_preserves_source` - `PYTHONPATH=. python test/dynamo/test_aot_autograd_cache.py AOTAutogradCacheTests.test_output_views_input_dynamic` - `lintrunner -a` Pull Request resolved: pytorch#184193 Approved by: https://github.com/oulgen
…ytorch#187581) This reverts commit 060670a. Pull Request resolved: pytorch#187581 Approved by: https://github.com/zou3519
## Summary Preserve source locations for Inductor guards that are saved in the FX graph cache, so a cache-hit recompile reason still points at the original guard producer instead of the cache replay site. Fixes pytorch#141595 Generated by my agent ## Root Cause Without the FX graph cache, `ShapeEnv` records each `ShapeGuard` with the source location captured when Inductor creates the guard, for example `can_use_32bit_indexing`. On an FX graph cache hit, Inductor only had `CompiledFxGraph.guards_expr`, a single combined Python expression string. Re-evaluating that string installs equivalent guards in the current `ShapeEnv`, but the new guards get the replay callsite as their source location. That is why recompile logs pointed at `_lookup_graph`, `autograd_cache.py`, or `<string>:1` instead of the original Inductor guard. ## Review Guide - `torch/fx/experimental/symbolic_shapes.py`: threads source locations alongside each produced guard expression, adds `ShapeGuardExpression`, and replays cached guards while temporarily using the stored source location for any `ShapeGuard` created by evaluation. - `torch/_inductor/output_code.py`: adds optional cached metadata fields for the per-guard expression/source list and the SymInt argument count used when saving it. - `torch/_inductor/codecache.py`: saves the new metadata, replays it on normal FX graph cache hits, and falls back to the existing combined-expression path for old cache entries, unsafe-skip mode, or AOTAutograd loads whose argument list differs. - Tests cover both the small `ShapeEnv` round trip and the original CUDA/flex-attention cache-hit failure mode. ## Test Plan - `PYTHONPATH=. python test/test_dynamic_shapes.py TestGuardsExpressions.test_guards_expression_source_info` - `PYTHONPATH=. python test/inductor/test_codecache.py TestFxGraphCache.test_cache_hit_inductor_guard_preserves_source` - `PYTHONPATH=. python test/dynamo/test_aot_autograd_cache.py AOTAutogradCacheTests.test_output_views_input_dynamic` - `lintrunner -a` Pull Request resolved: pytorch#184193 Approved by: https://github.com/oulgen
…ytorch#187581) This reverts commit 060670a. Pull Request resolved: pytorch#187581 Approved by: https://github.com/zou3519
Stack from ghstack (oldest at bottom):
Summary
Preserve source locations for Inductor guards that are saved in the FX graph cache, so a cache-hit recompile reason still points at the original guard producer instead of the cache replay site.
Fixes #141595
Generated by my agent
Root Cause
Without the FX graph cache,
ShapeEnvrecords eachShapeGuardwith the source location captured when Inductor creates the guard, for examplecan_use_32bit_indexing.On an FX graph cache hit, Inductor only had
CompiledFxGraph.guards_expr, a single combined Python expression string. Re-evaluating that string installs equivalent guards in the currentShapeEnv, but the new guards get the replay callsite as their source location. That is why recompile logs pointed at_lookup_graph,autograd_cache.py, or<string>:1instead of the original Inductor guard.Review Guide
torch/fx/experimental/symbolic_shapes.py: threads source locations alongside each produced guard expression, addsShapeGuardExpression, and replays cached guards while temporarily using the stored source location for anyShapeGuardcreated by evaluation.torch/_inductor/output_code.py: adds optional cached metadata fields for the per-guard expression/source list and the SymInt argument count used when saving it.torch/_inductor/codecache.py: saves the new metadata, replays it on normal FX graph cache hits, and falls back to the existing combined-expression path for old cache entries, unsafe-skip mode, or AOTAutograd loads whose argument list differs.ShapeEnvround trip and the original CUDA/flex-attention cache-hit failure mode.Test Plan
PYTHONPATH=. python test/test_dynamic_shapes.py TestGuardsExpressions.test_guards_expression_source_infoPYTHONPATH=. python test/inductor/test_codecache.py TestFxGraphCache.test_cache_hit_inductor_guard_preserves_sourcePYTHONPATH=. python test/dynamo/test_aot_autograd_cache.py AOTAutogradCacheTests.test_output_views_input_dynamiclintrunner -acc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo