Repository navigation
[graph_trainer] Add full recompute memory policy - #3429
Conversation
ac01726 to
a0667a3
Compare
| and torch.Tag.nondeterministic_seeded in node.target.tags | ||
| ): | ||
| return CheckpointPolicy.MUST_SAVE | ||
| return CheckpointPolicy.PREFER_RECOMPUTE |
There was a problem hiding this comment.
Should this be MUST_RECOMPUTE? Can there be a situation where a PREFER_RECOMPUTE gets promoted to MUST_SAVE?
There was a problem hiding this comment.
in current graphtrainer impl, prefer_x == must_x, these is actually no different between these two.
but I agree, must_* is better than prefer_. I should use must_ in all cases.
a0667a3 to
2237830
Compare
|
Ok I tried this on DeepSeek V3 671B and 64x4 GB200 (on pytorch commit: pytorch/pytorch@090b49d, note latest pytorch is hanging right now). Still seeing OOM for PP=1,EP=64,Local BS=8,FSDP=256 compared to eager which doesn't OOM with full AC. |
|
After disabling the boundary saves, I still see OOM, but much lower memory request at the point of OOM: Probably the rest of the MUST_SAVEs. |
Add a "full" memory policy that marks all ops as PREFER_RECOMPUTE, saving only layer boundary outputs (and RNG ops like dropout whose random state cannot be replayed, and higher-order ops like flex_attention/inductor_compiled_code whose GraphModule subgraph arguments cannot be duplicated by node_copy). This mirrors eager mode's full AC (checkpoint_wrapper with no context_fn). ## Llama3 8B benchmarks (8×H100, 20 steps, c4_test) ### FSDP4 + TP2 | Metric | default | full | Delta | |--------------|-----------------|-----------------|-----------| | Peak memory | 30.92 GiB (33%) | 20.70 GiB (22%) | **-33.0%** | | TPS (step20) | 6,607 | 5,933 | -10.2% | | MFU (step20) | 38.69% | 34.74% | -10.2% | ### FSDP8 + TP1 | Metric | default | full | Delta | |--------------|-----------------|-----------------|-----------| | Peak memory | 52.44 GiB (55%) | 32.07 GiB (34%) | **-38.8%** | | TPS (step20) | 7,890 | 7,006 | -11.2% | | MFU (step20) | 46.20% | 41.02% | -11.2% | ## DeepSeek-v3 16B benchmarks (8×H100, FSDP8+EP8, 20 steps, c4_test) | Metric | default | full | Delta | |--------------|-----------------|-----------------|-----------| | Peak memory | 84.78 GiB (89%) | 52.02 GiB (55%) | **-38.6%** | | TPS (step20) | 8,325 | 7,444 | -10.6% | | MFU (step20) | 15.24% | 13.63% | -10.6% | Usage: --compile.memory_policy full
3d9b9f0 to
35a635d
Compare
The `full` policy previously force-saved flex_attention (and all HOPs) on the assumption that node_copy couldn't duplicate HOPs with GraphModule subgraph args. This made `full` keep one attention activation per layer that eager full AC recomputes for free — the main memory gap behind the DeepSeek-V3 671B OOM. Root cause: node_copy *can* duplicate flex_attention. The real blocker is regional_inductor, which partitions each flex node together with its score_mod/mask_mod get_attr subgraphs. When remat duplicated the flex node, original and duplicate shared those get_attr nodes; a shared get_attr can only live in one partition, so the other flex received the subgraph as a raw GraphModule arg and failed to compile. Fix: - memory_policy: drop the HOP MUST_SAVE workaround so flex is recomputed. RNG ops are still saved (the remat pass can't replay RNG state, unlike eager's preserve_rng_state). - selective_activation_remat: give each recompute duplicate private copies of its subgraph (GraphModule) get_attr inputs, keeping each flex region self-contained for regional_inductor. Plain-tensor get_attrs stay shared. Also fix the SAC per-layer log: compute the summary after the boundary pass so boundary-forced saves are reflected per layer, and label the recompute column RECOMPUTE (it covers both PREFER_ and MUST_RECOMPUTE) instead of the misleading PREFER_RECOMPUTE. Validation (DeepSeek-V3 flex debugmodel, 8xH100 FSDP8): full vs default produce identical loss/grad_norm every step; peak memory 2.88 -> 1.46 GiB (-49%). Bitwise-identical to eager across llama3/deepseek-v3/qwen3 flex debug models. New CPU unit tests cover the get_attr duplication and the full-policy RNG-save / flex-recompute mapping.
35a635d to
7faef1e
Compare
|
@syed-ahmed the latest commit now recomputes flex_attn, whose output tensor is about 1GB per layer, and was saved in the earlier impl. I think it now matches eager FullAC impl. I am landing this, will iterator on it if you see more OOM issues. |
…no ezpz replay Pulled 2 commits from upstream/main (04a3098..27aa490, merge commit 45a2b25): - 27aa490 [graph_trainer] Add full recompute memory policy (pytorch#3429) - 051562e [graph_trainer] Re-enable DSv3 eager bitwise deterministic tests (pytorch#3482) Both entirely inside torchtitan/experiments/graph_trainer/. Zero ezpz code or doc changes triggered. No conflicts. Tree clean. Documents both commits in upstream-sync.md and adds a one-paragraph journal note pointing at the sync entry.
…oE) (#3484) ## Summary `test_eager_self_deterministic` baselines for **Llama3 FlexAttention**, **Qwen3 MoE**, and **Qwen3 MoE FlexAttention** drifted after upstream PyTorch nightly numerics changes — the same class of drift #3432/#3482 already handled for DSv3. The H100.8 CI was red on these three. This is the **pure-eager path** (base `Trainer`, no compile/trace): - Loss strings are **unchanged** → low-order numeric drift, not a real break. - `test_aot_fx_trace_vs_eager` still passes → the trace path stays bitwise-identical to eager; only the absolute `model_hash`/`grad_hash` baselines were stale. ## How the new hashes were obtained - **Qwen3 MoE** / **Qwen3 MoE FlexAttn**: regenerated on a local H100 and verified **bitwise-equal to the CI nightly (cu130)** `model_hash`, so their `grad_hash` is authoritative. - **Llama3 FlexAttn**: local (CUDA 12.8) diverges from CI (cu130) for this flex path, so both hashes were taken from the CI run. ## Validation GraphTrainer 8-GPU H100 CI green on this branch: bitwise suite **21 passed, 3 skipped** (the 3 skips are the pre-existing FlexAttn-precompile tests). Loss strings untouched. > Note (separate issue): one earlier run on this branch hit a **flaky** `qwen3_moe` FSDP+TP+EP all-to-all crash (`RuntimeError: Split sizes doesn't match total dim 0 size`) — intermittent, unrelated to this test-only change (the prior main run on #3429 passed that flavor and failed only on these same stale hashes). Worth a separate look.
Summary
"full"memory policy for graph_trainer that marks all ops asPREFER_RECOMPUTE, saving only layer boundary outputs, RNG ops (dropout), and higher-order ops (flex_attention, inductor_compiled_code whose GraphModule subgraph arguments can't be duplicated by node_copy). This mirrors eager mode's_apply_full_ac(checkpoint_wrapperwith nocontext_fn).--compile.memory_policy fullLlama3 8B benchmarks (8×H100, 20 steps, c4_test)
FSDP4 + TP2
defaultfullFSDP8 + TP1
defaultfullDeepSeek-v3 16B benchmarks (8×H100, FSDP8+EP8, 20 steps, c4_test)
defaultfullTest plan
TestFullMemoryPolicy(4 unit tests): all ops marked recompute, save ops also recomputed, layer boundaries forced to MUST_SAVE, same-layer nodes all recomputedTestApplySACPass(8 existing tests): no regressionstest_llama3_debugmodel_full_ac_saves_memory_vs_default: full uses less peak memory than defaulttest_llama3_debugmodel_full_ac_numerics_match_eager: bitwise-identical loss and grads vs eager full ACtest_llama3_debugmodel_peak_memory_matches_eager_selective_ac: existing test still passes