Repository navigation
Conversation
…UNED_FLAGS TRAINER_TUNED_FLAGS=true now also passes custom_mesh_and_rule=cp-as-ep-dense-no-cp (from AI-Hypercomputer/maxtext#5783, on top of AI-Hypercomputer/maxtext#5758) after the recipe's default custom_mesh_and_rule=cp-as-ep. MaxText keeps the last value of a repeated key, so when TRAINER_TUNED_FLAGS=true the trainer uses cp-as-ep-dense-no-cp: the dense weights (attention and shared-expert projections, the MoE router and the shared-expert gate; logical axes embed, embed_attn, q_lora, kv_lora) are sharded 64-way over fsdp x expert instead of 256-way over fsdp x context x expert and replicated over context, so their all-gathers run in four groups of 64 devices that do not cross context ranks. Their gradients are still reduce-scattered over all 256 devices and then all-gathered over context. The GDN projections (embed_gdn), routed experts, embeddings and activations stay sharded as under cp-as-ep. When TRAINER_TUNED_FLAGS=false (the default), the recipe's output is byte-identical to #2913. Bench (AI-Hypercomputer/maxtext#5701 driver, Qwen3.5-397B-A17B, 128 TPU v7x, mesh fsdp 32 x context 4 x expert 2, ragged_buffer_factor 2.75, 9 micro-batches per step, mean of steps 1 to 4, regular micro-batch = median of micro-batches 3 to 9, 0 tokens dropped in all 45 micro-batch audits): - cp-as-ep (AI-Hypercomputer/maxtext#5758 at 20c877aa1 + #2913 at bee6353): 82.200, 82.158, 82.111 and 82.269 s/step across four runs in three pods (o275x-prf-l3-prof, o275x-prf-l3-r, o275x-prfc-l3, o275x-prf-roll4c-prof; mean 82.185 s/step = 3,588 tokens/s/chip; regular micro-batch 8.942-8.959 s). - cp-as-ep-dense-no-cp (adding AI-Hypercomputer/maxtext#5783 at 20c93dc4f and custom_mesh_and_rule=cp-as-ep-dense-no-cp): 81.261 and 81.245 s/step across two pods (o275x-l2-l3-prof in parambole-bl2-v14 and parambole-bl2r-v14; two-pod mean 81.253 s/step = 3,630 tokens/s/chip, -0.93 s/step; regular micro-batch 8.838 s, -110 ms/mb). - Numerics (loss gates off, random advantages, 3 steps, against two reference runs nxref/nxref2 whose gradient norms differ by 1.92e-5 relative): PASS 6/6 in both pods (nxl2 in parambole-bl2-v14 and parambole-bl2r-v14). Loss is 0.0304453575 in all 3 steps (identical to cp-as-ep's nxprf-l3 to all 10 logged digits); step-0 gradient norm relative diff is 4.58e-6 (pod 1) and 2.22e-5 (pod 2) against reference (tolerance 2e-3), and within 1.4e-4 of nxprf-l3. - Memory (AOT compile at the 128-chip cell under --xla_tpu_max_hbm_size_mib=84992): fwd_bwd HBM usage is 81.05 GiB vs 78.28 GiB with cp-as-ep (train-kernel device peak 109.04 vs 104.46 GiB); both TPU pods ran all 5 steps without OOM.
Rohan-Bierneni
pushed a commit
to Rohan-Bierneni/tunix
that referenced
this pull request
Oct 16, 2026
…UNED_FLAGS Cherry-picked from google#2940 (2cfa895), companion to AI-Hypercomputer/maxtext#5783 (20c93dc4f), which AI-Hypercomputer/maxtext#5721 now carries in place of its earlier 2-line cp-as-ep.yml edit. TRAINER_TUNED_FLAGS=true now also passes custom_mesh_and_rule=cp-as-ep-dense-no-cp after the recipe's default custom_mesh_and_rule=cp-as-ep (MaxText keeps the last value of a repeated key): the dense weights (attention and shared-expert projections, the MoE router and the shared-expert gate) are sharded over fsdp x expert and replicated over context, their gradients reduce-scattered over every device and then all-gathered over context (linears.route_dense_weight_grad); the GDN projections (embed_gdn), routed experts, embeddings and activations stay as under cp-as-ep. TRAINER_TUNED_FLAGS=false renders as before. 128 TPU v7x (maxtext#5701 bench, from google#2940): 82.185 -> 81.253 s/step (3,588 -> 3,630 tok/s/chip), numerics PASS 6/6. Moves requirements/maxtext_requirements.txt to AI-Hypercomputer/maxtext#5721 at d66a82096.
This branch has not been 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.
Draft — stacked on #2913 (
parambole/rl-trainer-4600atbee63532f), companion to AI-Hypercomputer/maxtext#5783 (20c93dc4fon AI-Hypercomputer/maxtext#5758).Summary
Adds
custom_mesh_and_rule=cp-as-ep-dense-no-cp(defined in AI-Hypercomputer/maxtext#5783) to theTRAINER_TUNED_FLAGS=trueblock oftunix/experimental/examples/recipes/mlperf_397b_256_v7x.sh, after the recipe's defaultcustom_mesh_and_rule=cp-as-ep.TRAINER_TUNED_FLAGS=false(the default): Every rendered manifest and flag string is byte-identical to Qwen3.5-397B RL trainer on 128 v7x: pad-first sequence packing, fused sharded log-prob head VJP, and the tuned trainer recipe #2913 (custom_mesh_and_rule=cp-as-ep).TRAINER_TUNED_FLAGS=true: MaxText keeps the last value of a repeated key, so the trainer selectscp-as-ep-dense-no-cp. Undercp-as-ep-dense-no-cp, the dense weights (attentionq/k/v/out, shared-expertwi_0/wi_1/woandgate, and the frozen MoE router; logical axesembed,embed_attn,q_lora,kv_lora) are sharded 64-way overfsdp x expertinstead of 256-way overfsdp x context x expertand replicated acrosscontext=4. Their forward and backward weight all-gathers run in four disjoint 64-device groups without crossing context ranks, while their gradients are still reduce-scattered over all 256 devices and then all-gathered overcontext. The GDN projections (embed_gdn), routed experts, embeddings, and activations remain sharded identically tocp-as-ep.Results on 128 TPU v7x Chips (Qwen3.5-397B-A17B RL Trainer Bench)
Setup: AI-Hypercomputer/maxtext#5701 bench driver, 128 TPU v7x chips (256 devices, mesh
fsdp=32 x context=4 x expert=2), 9 micro-batches per optimizer step (294,912 tokens / step/chip),ragged_buffer_factor=2.75with dropless fallback,0dropped tokens across all 45 micro-batch audits per timing run. Step time is the mean of steps 1–4; regular micro-batch time is the median of micro-batches 3–9.custom_mesh_and_rules/step, Steps 1–4)s/mb)tok/s/chipreg / ruler)num_readout.py)20c877aa1+bee63532fcp-as-ep(256-way dense weights)bprf-v14,bl3-v14,bslow-v14)82.200,82.158,82.111,82.269(mean82.185 s)8.942–8.959 s3,588/3,655nxprf-l3: loss2.69e-7, logp1.87e-6, last-mb5.70e-6, ent5.07e-7,grad_norm1.11e-4vs tol2e-3)cp-as-ep-dense-no-cp)20c93dc4f+ this PRcp-as-ep-dense-no-cp(64-way dense weights)parambole-bl2-v14,parambole-bl2r-v14)81.261 s(Pod 1),81.245 s(Pod 2; step 281.231 s) (mean81.253 s,-0.932 s/step)8.838 s(-110 ms/mb)3,630/3,698(+42 tok/s/chip)nxl2Pod 1N3=4.58e-6,nxl2rPod 2N3=2.22e-5vs replicate spread1.92e-5, tol2e-3;loss = 0.0304453575bit-identical at all 3 steps)Memory (128-Chip AOT & Runtime)
--xla_tpu_max_hbm_size_mib=84992):fwd_bwdHBM usage is81.05 GiBundercp-as-ep-dense-no-cpvs78.28 GiBundercp-as-ep(+2.77 GiB; train-kernel device peak109.04 GiBvs104.46 GiB).xprof get_kpi_metrics): Peak HBM is87.66 GiB(bl2-v14/bl2r-v14) vs84.79 GiB(bprf-v14). Both pods completed all 5 steps cleanly without OOM.Testing
tests/experimental/examples/deepswe_dist/mlperf_submission_launcher_test.py): 41/41 passed (0skipped). Verifies:TRAINER_TUNED_FLAGS=truesetscustom_mesh_and_rule=cp-as-ep-dense-no-cpon the trainer JobSet while leaving the other five renders byte-identical.TRAINER_TUNED_FLAGS=false(default) and the other397b_v7xrecipes keepcustom_mesh_and_rule=cp-as-epand do not passcp-as-ep-dense-no-cp.bash -n tunix/experimental/examples/recipes/mlperf_397b_256_v7x.sh(rc=0),git diff --check(rc=0).