Skip to content

fix(cache): key compiled artifacts on the fx graph and input placements - #88

Closed
cennn wants to merge 1 commit into
mainfrom
fix/cache-key-graph-signature
Closed

cennn wants to merge 1 commit into
mainfrom
fix/cache-key-graph-signature

Conversation

@cennn

@cennn cennn commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Problem

The magi cache key (MagiBackend._init_cache) only hashed the compile/inductor configs, the compiler manager and the traced source files. Changing DTensor placements alone (e.g. SimpleFSDP fully_shard -> replicate on a 1-rank mesh, athena commit 2fb95f5b) leaves all of them unchanged, so the old artifact was silently reused. On 400B 8xH200 the stale graph kept issuing 1-rank AllGathers (served by NCCL as DtoD copies): 474 GB / 223 ms per request, fully exposed, until the cache dir was removed by hand.

Fix

Add compute_graph_hash(graph, example_inputs) to the key: graph.code plus each input's dtype, DTensor placements and mesh shape.

Tests

tests/feature_tests/cache/test_placement_cache_key.py (1 GPU, toy SimpleFSDP MLP):

  • test_bug_reproduced_without_fix: with the graph hash disabled, a replicate run after a fully_shard run in the same cache root compiles 0 times (reuses the stale artifact).
  • test_bug_fixed_placement_change_recompiles: with the fix, the placement change recompiles, and rerunning the same placements still hits the cache.

The magi cache key only hashed configs and traced source files. Changing DTensor placements (SimpleFSDP fully_shard -> replicate on a 1-rank mesh) leaves both unchanged, so the old artifact - still issuing the AllGathers - was silently reused. Add compute_graph_hash(graph.code + per-input dtype/placements/mesh shape) to the key.
@cennn

cennn commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #89 (rebased the still-useful parts onto current main). Closing this PR.

@cennn cennn closed this Oct 14, 2026
jiahy0825 pushed a commit that referenced this pull request Oct 15, 2026
…split graphs (#89)

* fix: cache key on graph+placements, AOT JIT fallback, skip FSDP overlap on split graphs

Unmerged remnants of #88 / #86 / #84 / #79, rebased onto current main:

- Cache key includes graph.code and DTensor placements. Changing SimpleFSDP
  fully_shard -> replicate used to reuse the old artifact (1-rank AllGathers
  served as DtoD copies).
- AOT compile failures fall back to JIT so MAGI_COMPILE_AOT=1 can stay
  process-wide (VAE AOT, SimpleFSDP DiT JIT).
- enable_fsdp no longer runs fullgraph overlap when disable_graph_split is
  False (VAE in a monolithic FSDP process). #79's restart-analysis half
  already landed as #75.
- Timing bench dim 128->1024 so launch jitter does not flake max/min < 1.2
  on B300/H100.

* fix(cache): hash input placements only, not graph.code

Restart-analysis retraces with different FX node names, so including graph.code
in the magi cache key made the second pass miss the first-pass directory
(test_assert_cache_hit_succeeds_with_restart_analysis / test_restart_analysis_cache
on pt212). DTensor fully_shard vs replicate is still distinguished by the input
placement signature.

* fix(cache): hash only DTensor placements so restart-analysis still hits

* fix(aot): do not swallow AssertionError/OOM when AOT falls back to JIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant