Skip to content

fix(trainer-rank): price dense CP2 recompute and no-grad waves from traced stages - #1090

Open
bradhilton wants to merge 12 commits into
mainfrom
dalinar/dense-cp2-explicit-floor
Open

bradhilton wants to merge 12 commits into
mainfrom
dalinar/dense-cp2-explicit-floor

Conversation

@bradhilton

@bradhilton bradhilton commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Agent: Dalinar

Problem

The planner over-prices dense Qwen3.8-27B at CP2 by 41–46% on gradient waves and up to 119% on multi-group no-grad waves, so admission rejects waves that fit. The cause is that main prices a CP2 gradient wave with every boundary on the busiest rank's rows, one incoming gradient per boundary, and a per-packed-token floor. That same floor also over-prices no-grad waves.

Behavior

The change applies only to a covered dense model at TP1/CP2/PP1 with a full/uniform/1 checkpointed decoder. The gate checks the decoder, its final norm, and each decoder layer with all its descendants:

  • the decoder and everything it holds match one structural template of the real Qwen3.8-27B decoder: each module's exact class has exactly its child slots, each holding only the classes the real model builds there. The decoder is a TransformerBlock with an optional TE RMSNorm final norm; each layer is a TransformerLayer with identity (fused) norms, an identity cross attention and an IdentityFuncOp cross-attention BDA; GDN holds its TE projections (optionally behind ART's LoRA), conv1d and TE norm; attention holds its TE projections (optionally behind ART's LoRA), ART's CP or CP1 core attention and optional TE q/k norms; LoRA's only child is its slot dict. Any other module or slot, such as a Sequential or a stock MLP as a norm, or an extra child, falls back;
  • each layer runs its class forward untouched or behind ART's GDN-island wrapper, which changes layouts around that forward; each mixer runs its class forward untouched or behind ART's prefix-tree wrapper, which runs ART's GDN operator when tree IDs are present and the class forward otherwise;
  • the mixer is exactly SelfAttention, Qwen3VLSelfAttention or GatedDeltaNet, and only GDN may carry the prefix-tree wrapper and only a TE norm ART's empty-safe wrapper;
  • the MLP is the fused, bias-free BF16 SwiGLU, wrapped by ART's FC1/FC2 LoRA with ranks up to 256;
  • none of those modules has a forward, forward-pre, backward or backward-pre hook, or a cudagraph_manager; PyTorch's global module hooks are empty, and ART's GDN trace hooks are not installed;
  • no walked module holds a plain (non-module) callable except ART's validated forward wrapper and delegate and allowlisted (class, attribute) pairs with their stock values (the layer's BDAs and grad context, GDN's and the MLP's SiLU, Transformer Engine's RNG tracker getter on row-parallel linears, and the decoder's CPU-offload sync function, which runs only with CPU offloading, rejected by the gate);
  • for layouts: ART's CP core attention with no softmax offset, and GDN island markers.

Modules outside the decoder are not checked, such as the embedding, the output head and the rotary cache. The gate covers what supported layer specs, model config and ART features can reach, not runtime monkeypatching such as replacing _compiled_call_impl, overriding __call__ in subclasses, class-level patching of Megatron methods, or parameter-level gradient hooks.

  • Gradient waves are priced on each CP rank's own layouts, which come from the same planning bundle the executor runs. For each rank the price covers:
    • each layer's saved input, in that layer's layout;
    • the recomputed layer's mixer, residual, norm output and FC1 stage (7F + H/4 + 2R);
    • one incoming gradient;
    • adapter gradients against that rank's own boundaries;
    • the rank's GDN recurrent states: an initial and a final state per executed segment, plus each parent state imported from the other rank, counted from the executor's GDN decision and state exchange. This bounds the retained state inventory (2 × executed + imported), not every temporary buffer: the state exchange's send/receive buffers and the native CP scan workspaces are not priced separately.
  • No-grad waves are priced at the largest group's rows × (6F + 4.25H + 2R), with the same per-rank GDN states. This shares fix(trainer-rank): preserve dense no-grad floors beside adapter backward peaks #1067's CP1 formula; CP1 pricing is unchanged.
  • TE workspace growth is charged beside the larger of the decoder stage and the head, until this device's ordinary GEMM workspace exists.
  • Everything else is unchanged: MoE, CP1, CP4, the TP×SP floor (fix(trainer-rank): price TP2/TP4 sequence-parallel recompute term by term #1075), uncovered dense models and mixed gradient/no-grad waves keep main's pricing.
  • Replay capture refuses these plans with dense_runtime_facts_unsupported, and the facts version stays 3. CUDA-admitted plans are already non-replayable under feat: add versioned trainer graphs and logical-rank APIs #925.

Validation

Raw logged price (÷ 1.1) vs observed peak on Qwen3.8-27B CP2, from G3v: this branch on GPU with real model wiring and G3's calls.

  • The gate accepted the real model at 852cf9d36, whose plain-callable inventory matched the allowlist. The structural template added since was derived from source.
  • All 7 peaks are byte-identical to G3.
  • A (pretrained weights at revision 1d4bf0f2) has the same peaks on the shared gradient calls and shows no recompile leftover.
  • The CPU fixture reproduces every logged price byte-for-byte on both ranks.
Call main this branch (busiest rank)
grad 23,251, process-cold +44.9% +1.2%
grad 23,251, warm, first +46.1% +2.3%
grad 23,251, warm, second +46.1% +1.1%
grad 34,999, unprofiled +42.9% +1.3%
grad 69,999, unprofiled +40.7% +1.4%
no-grad 47,103 +5.7% +1.0%
no-grad 2 × 23,999 +119.2% +1.0%

On the two warm calls, main's existing profile path sets the busiest rank's price, not this change:

  • After a call, a rank's profile is seeded from that call's whole peak per token.

  • The profile path adds 6,144 B per logical row and one GDN segment state on top.

  • The other rank prices both warm calls at +0.7%.

  • GDN states: none of these calls moves with the GDN state term. Each is one sequence, so one segment per rank adds 6.4 MB to a GDN stage that does not bind. On 64 short requests (64 × 256 tokens), 32 segments per rank add 205 MB raw: gradient 9.10 GB (main 12.59 GB), no-grad 2.28 GB (main 2.68 GB).

  • Pricing elsewhere unchanged: a CPU sweep of 939 cases matches main byte-for-byte. It covers MoE (EP1, EP2), dense away from TP1/CP2, the TP2 and TP4 SP floor, TP2/CP2, and real _plan_cost / _memory_check plans.

  • Tests: the new dense and CP-executor tests fail on main and pass here.

  • Suite: the CPU trainer-rank suite has the same failures and skips as main.

  • Checks: ruff and ty match main, and both new test files are in the Megatron lane.

Limits

🤖 Generated with Claude Code

…raced stages

A covered dense model (every decoder layer the traced gated MLP, TP1/CP2/PP1, full/uniform/1) is now priced on each CP rank's own layouts for gradient waves: boundaries in each layer input's layout, the recomputed layer's mixer ((H + 5q + 5kv)x2 beside the executor's retained records, or the GDN width), residual, norm output and FC1 stage ((7F + H/4 + 2R)x2), one incoming gradient, per-rank adapter gradients and TE workspace growth only while the process is cold. No-grad waves at CP2 price the largest group's rows at (6F + 4.25H + 2R)x2, sharing #1067's CP1 form, instead of the per-packed-token floor. Split lower bounds use even-share minimum layouts.

Qwen3.8-27B CP2 (random-init G3 and pretrained A): raw +0.7% to +1.4% on every call against main's +40.7% to +119.2%. MoE, CP1, CP4, the TP x SP floor (#1075), uncovered dense and mixed waves keep main's pricing (927-case CPU sweep, byte-identical). Replay capture refuses these plans; the runtime facts version stays 3.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton deployed to trainer-rank-gpu-validation October 3, 2026 08:10 — with GitHub Actions Active
…p TE growth beside the peak

Review fixes on the dense CP2 floor (Sol, r1):

- Each CP rank's GDN layer now holds its segments' recurrent states (_gdn_segment_layer_bytes, as the TP x SP floor charges them), counted from the same GDN execution decision the executor runs: the rank's own segments plus every chained one. No-grad waves are priced on the same per-rank layouts, so they get the states too.

- The coverage walk requires every executed module's class forward to come from the traced packages and rejects instance overrides of class methods (such as _forward_mlp). No-grad pricing now passes the same layout gate as gradient waves (ART's CP attention, no softmax offset, GDN islands).

- TE workspace growth checks this device's ordinary GEMM entry in TE's (device, overlap, grouped) cache instead of any entry.

- TE growth sits beside the larger of the decoder stage and the head instead of inside the decoder stage, for gradient and no-grad waves.

The dense floor is computed once per subforward; the checkpoint floor and the replay rank keep main's signatures. None of the 17 measured Qwen3.8-27B calls moves (single sequences: one segment per rank, 6.4 MB on a stage that does not bind).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation October 3, 2026 08:46 — with GitHub Actions Error
…lable in the dense gate

The coverage walk rejected only function and bound-method instance overrides, so a functools.partial or a callable object assigned to an executed helper such as _forward_mlp passed (Schulman, TEAM review of #1090). Reject any callable instance attribute that shadows a callable of the module's class, except forward and the validated ART delegate. No traced class (Megatron layer, attention, MLP, GDN, TE linears and norms, ART LoRA wrappers, ART CP core attention, Bridge's Qwen3VLSelfAttention) assigns such an attribute in its own or its bases' source.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation October 3, 2026 09:13 — with GitHub Actions Error
…nd walk the final norm

Review fixes on #1090 (Sol, r2):

- A CP rank's GDN layer can hold an initial and a final state per executed segment (its own and every chained one) and each parent state imported from another rank. The layouts now count that inventory per rank, with the imports derived exactly as the executor's state exchange (_build_tree_state_exchanges_by_depth) builds them, and charge half a _gdn_segment_layer_bytes per state. Single sequences (the measured calls) are unchanged: two states per rank as before.

- The coverage walk now includes decoder.final_layernorm, under the same class-origin, instance-override and hook checks (ART's empty-safe norm wrapper allowed), as Megatron runs it after the layers.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation October 3, 2026 09:33 — with GitHub Actions Error
…dd callables

TransformerLayer holds its self-attention and MLP bias-dropout-add factories and their grad context as plain instance attributes, which the module walk and the class-callable check never see (Sol, r3). Require the traced spec's objects by identity: Megatron's get_bias_dropout_add for self_attn_bda and mlp_bda, torch.enable_grad for bias_dropout_add_exec_handler, and an IdentityFuncOp module for cross_attn_bda. Any replacement falls back to main's pricing. The Qwen3.5 block spec ART builds (get_transformer_block_with_experimental_attention_variant_spec) assigns exactly these to every attention and GDN layer, and build_module returns the factory itself.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton deployed to trainer-rank-gpu-validation October 3, 2026 10:02 — with GitHub Actions Active
Sol, r4. The coverage walk now also requires:

- GDN's act_fn to be SiLU (identity), as the MLP activation already is, and its in_proj to be a registered module; the layer's cross_attention to be the stock IdentityOp module;

- no module backward or backward-pre hooks, empty PyTorch global module hook dicts, and no ART GDN trace token-uid callbacks;

- no cudagraph_manager on any covered module (Megatron's CUDA-graph dispatch);

- no TEFusedResidualRMSNorm, whose fused implementation sits outside the walk; Qwen3.5's specs never build it.

Each is reachable through layer specs, transformer config or ART features; anything else falls back to main's pricing. By source, ART's Qwen3.5 construction path registers no module hooks on the decoder (Megatron DDP's forward-pre hooks need overlapped parameter gathers; ART's head-selection hooks sit on the model and output layer), so no stock hook is allowlisted.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation October 3, 2026 10:46 — with GitHub Actions Error
… gate

The gate excluded TEFusedResidualRMSNorm by exact type, so a subclass inheriting its forward and hidden fused implementation passed. Exclude by isinstance, test a subclass, and read GDN's in_proj through getattr so ty accepts the optional mixer.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation October 3, 2026 10:58 — with GitHub Actions Error
A layer spec can fill GatedDeltaNet's out_norm and out_proj with functions, which run outside the module walk. The dense gate now requires registered modules in in_proj, out_norm and out_proj.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton deployed to trainer-rank-gpu-validation October 3, 2026 11:02 — with GitHub Actions Active
… calls

Megatron's build_module accepts function specs, so any slot a layer, its mixer or its MLP calls directly (attention's linear_proj, GDN's projections and norm) could hold a function outside the module walk. The dense gate now rejects any plain callable on those three except the identity-checked BDA, grad context and activations, and ART's forward wrapper and delegate.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton deployed to trainer-rank-gpu-validation October 3, 2026 11:30 — with GitHub Actions Active
…odule

The dense gate scanned plain callables only on the layer, mixer and MLP, so
a norm builder returning a stock torch.nn or Megatron module with a
configured callback (TransformerEncoderLayer's activation, an MLP's
activation_func) kept the reduced price. Every module the gate walks (the
decoder, each layer and its descendants, the final norm and its
descendants) now holds no plain callable beyond ART's validated wrapper and
delegate and an exact-type allowlist with stock values: the layer's BDAs
and grad context, GDN's and the MLP's SiLU, Transformer Engine's RNG
tracker getter on row-parallel linears, and the decoder's unused
CPU-offload sync function.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation October 3, 2026 12:43 — with GitHub Actions Error
…ilds

A configured norm builder could return a stock nn.Sequential of a frozen
Linear and SiLU: every forward came from torch.nn, with no callable or hook,
so the gate accepted it while autograd retained its activations beyond the
priced allowance. The same held for any untyped module slot. Every module
the gate walks (the decoder, each layer and its descendants, the final norm
and its descendants) must now have an exact class from the real Qwen3.8-27B
decoder. This subsumes the TEFusedResidualRMSNorm exclusion, the traced-
package forward check and the exact-LoRA check, which are removed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation October 3, 2026 13:08 — with GitHub Actions Error
The class allowlist bounded which classes ran, not where: a stock MLP or a
TE linear returned by a norm builder, or an extra child, kept the reduced
price. The gate now matches the decoder recursively against one template of
the real Qwen3.8-27B decoder: each exact class with exactly its child slots
and the classes each slot allows (untargeted adapters, q/k norms and the
final norm as explicit optional slots), each module behind only its own
class's ART wrapper. This replaces the class allowlist, the traced() walk,
the MLP site checks, the layer, mixer, cross-attention and BDA type checks,
and the BDA, GDN activation and MLP activation identity checks that the
template and the stock-callable rule now cover.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton deployed to trainer-rank-gpu-validation October 3, 2026 13:21 — with GitHub Actions Active
@bradhilton
bradhilton marked this pull request as ready for review October 3, 2026 14:00

This branch was successfully deployed

1 active deployment
trainer-rank-gpu-validation — 9539e87e Deployed Oct 3, 2026 by bradhilton via Run on 2x H200 #1182
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