Skip to content

Price the recomputed layer's attention or GDN activations in the checkpoint floor - #963

Draft
bradhilton wants to merge 12 commits into
mainfrom
dalinar/recompute-mixer-floor
Draft

bradhilton wants to merge 12 commits into
mainfrom
dalinar/recompute-mixer-floor

Conversation

@bradhilton

@bradhilton bradhilton commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #949. This makes TrainerRank's cold memory estimate count what is actually live at the backward peak under full one-layer recompute. The expert-parallel routing allowance also now depends on the EP size.

What changes:

  • Recomputed mixer. The recomputed layer's attention or GDN activations stay live beside its MoE stage, and the estimate now counts them. Leaving them out under-predicted CP2/EP1 by 23%.
  • Incoming gradient. When every layer is a MoE layer whose expert stage, FC1 included, the estimate prices, it charges the one incoming gradient live at the peak, not one per layer. The old charge over-counted about 17 GB on the random-weight 40-layer run and 8.4 GB on the real-data one. Other models keep the old charge, which also covers recompute work the estimate doesn't price.
  • Items the old charge hid. These are now priced: the recomputed layer's residual and norm rows, a sixth GDN value tensor, the shared expert's FC1/GLU outputs, router and permutation state, and Transformer Engine's cuBLAS workspaces (first call only).
  • HybridEP dispatch. HybridEP keeps one dispatched copy of each routed row, not two. It dispatches the whole EP group's tokens, so when the EP group is the CP group, routed rows are now priced on the group's even share, not on the busiest CP rank's rows. For example, on a real-data CP2 batch one rank held 52,480 rows, but each rank's even share of routed tokens was 48,397.
  • EP routing allowance. It was a flat 1.5 and is now 1.4 / 1.6 / 2.0 at EP2 / 4 / 8. The values come from a forward-only routing measurement on 3.5M tokens of real retail trajectories. In 200k-token batches the worst layer reached up to 1.22 / 1.40 / 1.62 with pretrained weights and 1.24 / 1.41 / 1.61 with a trained policy; a small rollout sample reached 1.95 at EP8, close to its 2.0 allowance. The old flat 1.5 was too low for EP8. EP4 and EP8 have no memory runs.

Raw estimate vs measured PyTorch peak on the most-loaded rank, Qwen3.6-35B-A3B on two H200s. Random-weight runs use 194,753 tokens. Real-data runs use about 206k tokens of real retail agent trajectories (97k after prefix sharing).

case before (cold) after (cold / warm)
CP1 +2.1% +0.5% / +15.9% ¹
CP2/EP1 −23% (under) +0.3% / +6.8% ¹
EP2/CP2, random weights, 8 layers +38.5% +26.5% / +23.6%
EP2/CP2, random weights, 40 layers not run +19.7% / +17.5%
EP2/CP2, pretrained, real data, 40 layers not run +18.2% / +19.2%
EP2/CP2, trained policy (059, step 225), real data, 40 layers not run +18.3% / +19.4%

¹ Measured on an earlier commit of this PR. The later changes don't alter the estimates for these two configurations.

In the pretrained EP2 cold case, the estimate is 26.81 GB against a 22.67 GB PyTorch peak. 1.05 GB of that estimate is HybridEP's communication buffer, which lives outside PyTorch, so the PyTorch peak can't show it. Leaving it out, the estimate is +13.6%. The GPU's memory outside PyTorch grew 2.76 GB during that call; the estimate prices only the HybridEP buffer part of that.

Limitation. EP2 is still well above the 10% target. With this formula and allowance, on these measured workloads, most of the remaining gap is the routing allowance: 1.4 is priced, while the layer at the peak saw about 1.0. The allowance covers the worst imbalance measured: 1.16 to 1.24 per layer on real data, and about 1.35 inferred from one production run. A cold estimate can't know which layer will be imbalanced, and these routing samples bound only what was measured, not all possible routing. Warm calls could price the routing they have already seen; that is a separate proposal.

Testing: all trainer-rank unit tests pass. The table's runs are on local H200s.

🤖 Generated with Claude Code

@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation September 25, 2026 06:42 — with GitHub Actions Failure
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation September 25, 2026 07:09 — with GitHub Actions Failure
@bradhilton
bradhilton deployed to trainer-rank-gpu-validation September 25, 2026 07:20 — with GitHub Actions Active
@bradhilton
bradhilton force-pushed the dalinar/recompute-mixer-floor branch from 1ffff5e to 4b3d1e0 Compare September 25, 2026 15:47
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation September 25, 2026 15:47 — with GitHub Actions Failure
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation September 25, 2026 15:55 — with GitHub Actions Failure
@bradhilton
bradhilton deployed to trainer-rank-gpu-validation September 25, 2026 15:59 — with GitHub Actions Active
bradhilton and others added 8 commits September 25, 2026 17:17
…kpoint floor

Full one-layer recompute replays a layer with gradients, so its mixer's
saved activations stay live beside that layer's MoE stage. The checkpoint
floor priced boundaries and the MoE stage only, which left context-parallel
runs short: Qwen3.6-35B-A3B at CP2 peaked 9-11 GB above the floor on the
most loaded rank. Price the larger of the model's attention and GDN mixers
per recomputed row, with context-parallel stage buffers and GDN exchange
copies, from allocator traces at CP1 and CP2.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Price GDN from its saved tensors (norm output, q/k with fp32 l2norm copies,
v, z, segment-layout tensors, gated norm and the chunk decay matrix) instead
of a ratio fit, and its context-parallel exchanges from hidden and value
widths rather than the key width. Divide CP attention extras by TP like the
retained widths, and say CP above 2 reuses the CP2 allowance.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The l2-normalized q and k are expanded to the value heads before they are
saved, so their width follows value_heads * key_head_dim, not twice the key
width. Qwen3.6 is unchanged; geometries with more value than key heads were
under-priced.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The EP1 all-to-all holds its permuted copy and the exchanged rows at the
expert stage; HybridEP permutes while it dispatches and returns one tensor.
A Qwen3.6 CP2/EP2 allocator trace holds exactly one routed H-wide input
beside the FC1 and FC2 stage tensors (9,728 features per routed row), where
the planner charged two (11,776).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…pendent

Backward recomputes the last layer first, so the checkpoint floor's peak meets
every saved boundary but only the one incoming gradient. Where the MoE stage
is priced, charge that gradient instead of one per boundary (39 hidden rows
per token too many at 40 layers), and price what the old allowance was
silently covering, all from Qwen3.6-35B-A3B allocator traces:

- the recomputed layer's residual and pre-MLP norm output (2H per row);
- GDN's sixth value-width tensor (the projected q/k/v includes v);
- the shared expert's saved FC1 gate/up and GLU outputs;
- router scores and map plus the dispatcher's row-id map (EP1) or probability
  copy and handle (HybridEP);
- TE's cuBLAS workspaces, as growth until its GEMMs allocate them.

Without a priced MoE stage the per-boundary allowance stays: it also covers
dense MLP and other recompute work the floor does not price.

The EP>1 routed-row allowance becomes EP-dependent (1.4, 1.6, 2.0 at EP2, 4,
8), from pretrained Qwen3.6 routing of 3.5M tokens of retail agent
trajectories (worst layer 1.21, 1.41, 1.63) and one production EP2 run (1.35).
Routed rows are no longer rounded up to whole rows.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton force-pushed the dalinar/recompute-mixer-floor branch from 2b54d0c to c59a692 Compare September 25, 2026 18:50
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation September 25, 2026 18:51 — with GitHub Actions Failure
@bradhilton
bradhilton deployed to trainer-rank-gpu-validation September 25, 2026 19:03 — with GitHub Actions Active
HybridEP dispatches the whole EP group's rows. When that group is this
rank's CP group, a balanced rank receives the group's rows over EP, not
the busiest CP rank's share: a CP2/EP2 real-data trace put 52,480 rows on
one rank while each layer dispatched exactly 8 x 96,794 pairs across both.
Price only the routed part (and its converted stages) on that share; the
shared expert, mixer and boundaries stay on local rows.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation September 25, 2026 20:12 — with GitHub Actions Failure
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation September 25, 2026 20:14 — with GitHub Actions Failure
Charge only the one incoming gradient when every decoder layer is a priced
MoE layer that encloses its FC1 stage, for each gradient group's slot. A
positive FC2-only coefficient, dense layers or a slot that reprices to zero
keep one gradient per boundary, which also covers unpriced recompute work.

Count an empty CP rank's padding row in the EP group's total: dispatch runs
at least one row per rank, and that row is routed too.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton deployed to trainer-rank-gpu-validation September 25, 2026 20:48 — with GitHub Actions Active
A layer counts as enclosed only if its FC1 converted stages are priced too,
unless FC1 has no adapter or the selected slot has no FC1 tensors. A slot
with FC1 adapters but no FC2 adapter prices FC2 rows from the original
metadata yet skips the whole converted-stage block, so it now keeps one
gradient per boundary. A slot's walk must enclose as many layers as the
constructor's, which already matched every decoder layer.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation September 25, 2026 21:08 — with GitHub Actions Error
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
trainer-rank-gpu-validation — ae10b7e0 Deployed Sep 25, 2026 by bradhilton via Run on 2x H200 #723
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