Skip to content

Price dense recompute by its traced stage and one input gradient - #986

Draft
bradhilton wants to merge 6 commits into
dalinar/cp-layout-recompute-floorfrom
dalinar/dense-recompute-floor
Draft

bradhilton wants to merge 6 commits into
dalinar/cp-layout-recompute-floorfrom
dalinar/dense-recompute-floor

Conversation

@bradhilton

@bradhilton bradhilton commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

For dense models TrainerRank charges one input gradient per saved layer boundary, on top of the boundaries themselves. It also prices several no-grad groups as if they ran at once. On dense Qwen3.8-27B at CP2 this over-prices gradient waves by about 40% and multi-group no-grad waves by up to about 2.5x. In q062 the planner refused a wider wave in 242 of 269 decisions.

Allocator traces of dense Qwen3.8-27B at CP2 (random init, reproducing q062's shapes exactly) show:

  • the recomputed layer's peak holds one input gradient;
  • its MLP FC1 stage holds the base output, the LoRA output and their sum, plus one F-wide tensor: 7F per row;
  • a no-grad group holds 6F + 6H per row, and groups run one after another.

What changes (dense models at CP2 only, gated)

  • Structural gate. _dense_mlp_recompute_bytes_per_token returns the per-row gradient stage and no-grad transient only when every decoder layer matches the traced execution:

    • the TE layer-norm FC1 and row-parallel FC2 with their LoRA wrappers;
    • the fused SwiGLU that Megatron Bridge's Qwen3.5 providers configure, with no clamp or offset; BF16; no bias or FP8/FP4; TP1/PP1; no sequence parallelism or CUDA graphs;
    • LoRA ranks up to 256, rechecked per active slot;
    • the checkpoint floor's own decoder conditions (full/uniform/1 recompute in training), so a discount always carries its TE workspace growth;
    • Megatron TransformerLayer with exactly the traced mixer types: SelfAttention, Bridge's Qwen3VLSelfAttention or GatedDeltaNet;
    • nothing the layer runs, the mixer's children included, has hooks or forward overrides besides ART's own GDN layer, mixer and empty-safe norm wrappers, which must still call the class's forward (through Dynamo's compile wrapper, as in training);
    • every adapter in the layer, the mixer's too, is an exact LoRA that selects its tensors the way execution does, with every adapter's rank priced.

    The traced model is a GDN/attention hybrid. A pure-attention dense model with the same MLP passes the gate on extrapolated widths.

    Anything else returns 0 and keeps today's pricing.

  • Eligibility. Decided once over all of a wave's slots, so one unsupported slot keeps both allowances.

  • Gradient groups. Priced with the recomputed mixer, residual and norm, and the MLP stage. The stage also carries one more FC1 triplet (6F) for the early-run recompile residue seen in q062. The gradient is one row of H instead of one per boundary. This applies to both the busiest-rank floor and Price CP2 recompute per rank on each layer type's layout #978's per-layout floor, plus TE workspace growth (no-grad-only waves included).

  • No-grad groups. Charged their 6F + 6H transient, including beside retained gradient boundaries in mixed waves.

  • Multi-group no-grad waves. Priced at the largest group's own rows at that width, and at least its share of today's per-token floor. A single no-grad group also gains its per-row transient from the checkpoint floor, which is conservative. That share falls as another group's rows grow, so the split planner's lower bound keeps only the largest group's rows.

  • Not changed. CP1, CP>2, TP>1, MoE, the 1.10 factor and learned profiles.

Before/after (q062, 269 real waves held out from the trace fit)

  • Gradient waves: the floor alone is never under an observed peak (min +8.1%). The median raw error moves only from +40.9% to +35.8%, because the always-on recompile allowance keeps cold waves safe without a profile.
  • No-grad waves: median from +137% to +32%, never under.

Testing: 65 new unit tests cover the gate (43 structural negatives, including a compiled delegate, the Qwen attention class, mixer children and adapters, and LoRA selector overrides), named slots through the real slot lookup, per-slot ranks and mixed-slot fallback, the checkpoint-floor conditions, the split lower bound, one gradient, both floors, the no-grad transient in mixed waves, unequal group ratios and the CP2-only scope. Replay of older reports stays compatible. The trainer-rank suite passes.

On dense Qwen3.8-27B compiled as in training, the gate is active on the real model, including its walk over each layer's children. The GPU results below come from the previous revision, whose widths were 0.06% lower. On 2×H200 (CP2, random init), held-out single waves:

  • gradient waves of 35k and 70k tokens: +28% raw;
  • a two-group no-grad wave: +13% (main's formula: +119%).

None is under. On q062-shaped batches, #986 packs 10 waves where main needs 11, but runs no faster. The binding limit is the ~36 GB of free memory, not the estimate.

Stacked on #978 (itself on #963); none of the stack is merged, so review in that order.

🤖 Generated with Claude Code

For dense models TrainerRank charged one input gradient per saved
boundary, which on dense Qwen3.8-27B at CP2 over-prices gradient waves by
about 40%. Allocator traces show the recomputed layer's peak holds one
input gradient and an MLP FC1 stage of 7F per row: the base output, the
LoRA output and their sum, plus one F-wide tensor.

When every decoder layer is the exact supported gated MLP, up to CP2,
price that stage beside the recomputed mixer in both checkpoint floors and
charge one gradient. Above CP2, or for any other structure, the
per-boundary allowance stays.

No-grad groups run one after another, so a CP2 multi-group no-grad wave's
static floor now counts only the largest group's share of packed tokens.
Single-group pricing is unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation September 26, 2026 08:21 — with GitHub Actions Failure
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation September 26, 2026 08:30 — with GitHub Actions Failure
Review follow-ups:
- A no-grad group in a covered dense model is charged its traced 6F + 6H
  transient per row, including beside retained gradient boundaries in
  mixed waves, instead of 4H.
- Multi-group no-grad waves price the largest group's own rows at that
  width, and at least its share of the per-token floor, instead of
  converting through the wave's average packed-to-row ratio.
- The gradient stage adds one more FC1 triplet (6F) for the early-run
  recompile residue seen in q062, so cold waves need no learned profile.
- Only at CP2, where it was traced. TE workspace growth is charged for
  dense too.
- The gate requires the traced fused-norm FC1, the unfused SwiGLU config,
  no hooks or overrides on the decoder, layers, mixers or MLP besides ART's
  GDN wrappers, the trainer's hidden size, and LoRA ranks up to 256,
  rechecked per active slot.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation September 26, 2026 08:43 — with GitHub Actions Failure
Round-2 review follow-ups:
- The one-gradient decision uses the same slots as the floor, so an
  unsupported slot in any group keeps both allowances.
- No-grad-only waves charge TE workspace growth too.
- The gate requires Megatron's TransformerLayer, attention or GDN mixers
  whose class forward is the base one, and ART's GDN wrappers delegating
  to that class forward.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation September 26, 2026 08:57 — with GitHub Actions Failure
Training compile replaces each layer's _art_gdn_island_physical_forward
with torch.compile's wrapper, so the gate rejected every layer of the
compiled model it was traced on. Judge the callable Dynamo wraps.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation September 26, 2026 09:03 — with GitHub Actions Failure
The traced Qwen3.8-27B run uses Megatron Bridge's Qwen3VLSelfAttention
(which overrides forward) and Bridge's fused SwiGLU
(bias_activation_fusion=True), so the gate rejected every layer of it.
Accept exactly the traced mixer types and the fused activation.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton deployed to trainer-rank-gpu-validation September 26, 2026 09:13 — with GitHub Actions Active
The gate now walks every module under each decoder layer, not just the MLP:
- no hooks or instance forwards except ART's GDN layer, mixer and
  empty-safe norm wrappers, which must delegate to the class forward;
- every adapter, including the mixer's, is an exact LoRA with no
  selector override, within the rank limit;
- every adapter's rank term is priced.

Dense widths now require the checkpoint floor's own decoder conditions, so
the multi-group no-grad discount always keeps its TE workspace growth.

The split planner's optimistic lower bound drops the largest group's
share of the per-token floor. That share shrinks as another group's rows
grow, so it could exceed the exact cost and prune a feasible split.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation September 26, 2026 10:10 — with GitHub Actions Failure
@bradhilton
bradhilton deployed to trainer-rank-gpu-validation September 26, 2026 10:30 — with GitHub Actions Active
@bradhilton
bradhilton marked this pull request as ready for review September 26, 2026 15:46
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation September 26, 2026 15:46 — with GitHub Actions Failure
@bradhilton
bradhilton marked this pull request as draft September 26, 2026 16:08

This branch had an error being deployed

1 failed deployment
trainer-rank-gpu-validation — da1294df Deployed Sep 26, 2026 by bradhilton via Run on 2x H200 #765
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