Repository navigation
fix(trainer-rank): price dense CP2 recompute and no-grad waves from traced stages - #1090
Open
bradhilton wants to merge 12 commits into
Open
bradhilton wants to merge 12 commits into
bradhilton wants to merge 12 commits into
Conversation
…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
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
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
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
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
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
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
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
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
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
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
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
deployed
to
trainer-rank-gpu-validation
October 3, 2026 13:21 — with
GitHub Actions
Active
bradhilton
marked this pull request as ready for review
October 3, 2026 14:00
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
TransformerBlockwith an optional TERMSNormfinal norm; each layer is aTransformerLayerwith identity (fused) norms, an identity cross attention and anIdentityFuncOpcross-attention BDA; GDN holds its TE projections (optionally behind ART's LoRA),conv1dand 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 aSequentialor a stock MLP as a norm, or an extra child, falls back;SelfAttention,Qwen3VLSelfAttentionorGatedDeltaNet, and only GDN may carry the prefix-tree wrapper and only a TE norm ART's empty-safe wrapper;cudagraph_manager; PyTorch's global module hooks are empty, and ART's GDN trace hooks are not installed;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.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.
852cf9d36, whose plain-callable inventory matched the allowlist. The structural template added since was derived from source.1d4bf0f2) has the same peaks on the shared gradient calls and shows no recompile leftover.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_checkplans.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
IdentityOp(qk_layernorm off), and any other structure outside the template, keep main's pricing.🤖 Generated with Claude Code