Add MaxText mHC-lite Pallas/Mosaic TPU kernel and profiling benchmarks. - #4834
Open
copybara-service[bot] wants to merge 1 commit into
Open
Add MaxText mHC-lite Pallas/Mosaic TPU kernel and profiling benchmarks.#4834copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
copybara-service
Bot
requested review from
A9isha,
NuojCheng,
RissyRan,
SurbhiJainUSC,
abhinavclemson,
aireenmei,
bvandermoon,
darisoy,
dipannita08,
gagika,
gobbleturk,
hengtaoguo,
huytransformer,
igorts-git,
jiangjy1982,
khatwanimohit,
parambole,
richjames0,
shralex,
shuningjin,
vipannalla and
xibinliu
as code owners
August 11, 2026 16:48
copybara-service
Bot
force-pushed
the
test_958551188
branch
2 times, most recently
from
August 11, 2026 20:45
3100589 to
7f2a1e7
Compare
PiperOrigin-RevId: 958551188
copybara-service
Bot
force-pushed
the
test_958551188
branch
from
August 11, 2026 20:46
7f2a1e7 to
3551b54
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Add MaxText mHC-lite Pallas/Mosaic TPU kernel and profiling benchmarks.
This change implements the Manifold Constrained Hyper-Connections (mHC-lite) algorithm in MaxText using Pallas. Instead of a single monolithic kernel, the implementation is split into a pipeline of three forward kernels and three custom VJP backward kernels. This design allows the wrapped model branch (Attn + MoE) to run in between.
Algorithmic Step-by-Step
1. Forward Pass
_coeff_fwd)x, folded projection weightsphi(fuses RMSNorm scale and projection matrices), gate parameters, and permutation matrices.xusingphi.xin HBM).h_pre(input gate) andh_post(output gate).residualpermutation matrix.h_pre(passed to Kernel 2),h_postandresidual(saved in context for Kernel 3)._pre_apply_fwd)x,h_pre.h_pretoxand sums across the streams dimension, collapsing it.layer_inputof shape(tokens, embedding)which is passed to the wrapped model branch.layer_inputto producelayer_output._post_apply_fwd)x,layer_output,h_post,residual.xusing the blendedresidualmatrix.layer_outputbyh_post.(tokens, streams, embedding).2. Backward Pass (Custom VJP)
_post_apply_bwd)x,layer_output,h_post,residual, and the incoming gradientd_output.d_layer_output(sent to wrapped block backward) and cotangentsd_x_post,d_h_post,d_residual(passed to pre-branch backward).d_layer_input._pre_apply_bwd)x,h_pre,d_layer_input, andd_x_post(accumulated gradient from post-branch).pre_applyto getd_x_preandd_h_pre.d_x_acc = d_x_pre + d_x_post.d_h_preand accumulatedd_x_acc._coeff_bwd)x,phi, parameters, permutations, cotangents (d_h_pre,d_h_post,d_residual), andd_x_acc.mhc_coeffsforward pass internally to regenerate intermediate activations (gates, logits, softmax weights), saving HBM read/write traffic.mhc_coeffsto get gradients forx(d_x_coeff),phi, and parameters.d_x = d_x_coeff + d_x_acc.d_x,d_phi, and parameter gradients.d_phito individual projection gradients using JAX.Rematerialization (Remat) Behavior
The MHC-lite kernel implementation is fully compatible with JAX rematerialization (checkpointing).
presavesx(shape[B, S, K, D]),phi, andh_pre;postsavesx,layer_output,h_post, andresidual.contextcontainingh_postandresidual, and thelayer_output) are discarded during the forward pass.prekernel runs again to recreate thecontext, the wrapped branch runs again to recreatelayer_output, andpostkernel runs again.contextis not explicitly named for selective checkpointing policies (likeminimal_with_context), meaning it will be recomputed rather than saved when using such policies.Numerical Verification against MaxText Baseline Layer
ManifoldConstrainedHyperConnectionswithuse_mhc_pallas_kernel=False).out, input gradientgrad_x, weight gradientgrad_W, and 10 primal parameter gradients:grad_norm_scale,grad_pre_alpha,grad_pre_bias,grad_pre_scale,grad_post_alpha,grad_post_bias,grad_post_scale,grad_res_alpha,grad_res_bias,grad_res_scale).> 99.9%cosine similarity (cos_sim >= 0.999) and bounded elementwise difference in bfloat16 across multiple test shapes ((b=2, s=4096, k=4, d=3072)).Hardware Benchmarks & Optimal Block Configurations
1. TPU v6 (Trillium / Ghostlite)
fwd_bs = 256,bwd_bs = 256(batch=2, sequence=4096, streams=4, embedding=3072):8.866 msper stepfwd=256, bwd=256):4.511 msper step (1.97x speedup)2. TPU v7 (Ironwood / Ghostfish)
fwd_bs = 256,bwd_bs = 128(batch=2, sequence=4096, streams=4, embedding=3072):6.481 msper step |968.58 MBHBM usage |52.00 MBVMEM usage.fwd=256, bwd=128):4.514 msper step (1.44x speedup) |381.01 MBHBM usage (2.54x HBM traffic reduction) |63.94 MBVMEM usage.