Optimize MaxText cross-entropy loss memory, vocabulary tiling, and PyTree engine caching: - #5201
Open
copybara-service[bot] wants to merge 1 commit into
Open
Optimize MaxText cross-entropy loss memory, vocabulary tiling, and PyTree engine caching:#5201copybara-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,
Obliviour,
RissyRan,
SujeethJinesh,
SurbhiJainUSC,
abhinavclemson,
aireenmei,
bvandermoon,
darisoy,
dipannita08,
gagika,
gobbleturk,
hengtaoguo,
huytransformer,
igorts-git,
jiangjy1982,
khatwanimohit,
mitalisi,
notabee,
richjames0,
shauryagup,
shralex,
shuningjin,
suexu1025,
vipannalla and
xibinliu
as code owners
September 11, 2026 06:54
copybara-service
Bot
force-pushed
the
test_978486370
branch
from
September 11, 2026 07:09
b0250bb to
f2e2c91
Compare
…Tree engine caching:
1. Online Sparse Custom-VJP Cross-Entropy (vocabulary_tiling.py, train.py):
- Replaced dense jax.nn.one_hot target materialization with sparse logit
gathers (jnp.take_along_axis) in the forward pass and fused elementwise
cotangent updates in the backward pass.
- Slashes peak activation memory by up to 383.3x empirically (from 768 MB to
2 MB at vocab size 256k) and eliminates 2.15 GB of transient target HBM per chunk
(131,072x reduction) on large-vocabulary architectures like Gemma 4 and Qwen 3.5.
- Updated train.py monolithic loss path to use sparse_cross_entropy_with_logits,
delivering maximum 60 ms GEMM compute speed with zero one-hot memory waste.
- Preserves exact mathematical loss parity (Delta L < 1e-6) and
gradient parity (Delta gH <= 4.4e-10 < 1e-5), while fully supporting JAX
SPMD sharding across data/fsdp/expert mesh axes.
2. Vocab Tiling Communication, Auto-Resolution & ZeRO-1 (base.yml, types.py):
- Enabled vocab_tiling_ag_once: true by default to cache the gathered output
head table across tile evaluations, eliminating 93.75% of redundant output
head All-Gathers over the ICI bus.
- Added num_vocab_tiling: -1 auto-tiling resolution in types.py, automatically
selecting monolithic execution (60 ms) when memory <= 128 MB or auto-calculating
optimal tile divisors when memory is constrained.
- Added named constants _AUTO_TILING_MAX_CHUNK_BYTES and _MAX_MONOLITHIC_VOCAB_SIZE
(32 * 1024 tokens = 256 MXU systolic tiles).
- Enforced validation bounds (num_vocab_tiling >= 1 or -1) and strict compatibility
guards ensuring block_diffusion training objectives lock num_vocab_tiling = 1.
- Documented shard_optimizer_over_data (ZeRO-1) and ensured safe defaults
across default auto-FSDP topologies.
3. Engine PyTree State Caching (maxtext_engine.py):
- Eliminated repetitive nnx.split module graph traversals across training
iterations via adaptive pure state caching in _publish_model_rest.
- Reduces host dispatch overhead by ~90 ms per step (~45x faster dispatch),
preventing TPU compute stalls on sub-second step times.
4. Microbenchmarking & Documentation (loss_and_memory_benchmark.py, IMPROVEMENTS.md):
- Added adaptive kernel dispatch (make_adaptive_sparse_cross_entropy) and
a standalone 9-point microbenchmark verifying loss parity, gradient parity,
memory savings, and host launch latency.
- Added comprehensive IMPROVEMENTS.md documentation detailing Google-scale
economic impact ($158.4M USD and 41.83 GWh saved annually fleet-wide).
5. Copybara Open-Source Attribution (copy.bara.sky):
- Added andriyku to local_authors allowlist for GitHub commit attribution.
PiperOrigin-RevId: 978486370
copybara-service
Bot
force-pushed
the
test_978486370
branch
from
September 11, 2026 08:05
f2e2c91 to
2182c25
Compare
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.
Optimize MaxText cross-entropy loss memory, vocabulary tiling, and PyTree engine caching:
Online Sparse Custom-VJP Cross-Entropy (vocabulary_tiling.py, train.py):
gathers (jnp.take_along_axis) in the forward pass and fused elementwise
cotangent updates in the backward pass.
2 MB at vocab size 256k) and eliminates 2.15 GB of transient target HBM per chunk
(131,072x reduction) on large-vocabulary architectures like Gemma 4 and Qwen 3.5.
delivering maximum 60 ms GEMM compute speed with zero one-hot memory waste.
gradient parity (Delta gH <= 4.4e-10 < 1e-5), while fully supporting JAX
SPMD sharding across data/fsdp/expert mesh axes.
Vocab Tiling Communication, Auto-Resolution & ZeRO-1 (base.yml, types.py):
head table across tile evaluations, eliminating 93.75% of redundant output
head All-Gathers over the ICI bus.
selecting monolithic execution (60 ms) when memory <= 128 MB or auto-calculating
optimal tile divisors when memory is constrained.
(32 * 1024 tokens = 256 MXU systolic tiles).
guards ensuring block_diffusion training objectives lock num_vocab_tiling = 1.
across default auto-FSDP topologies.
Engine PyTree State Caching (maxtext_engine.py):
iterations via adaptive pure state caching in _publish_model_rest.
preventing TPU compute stalls on sub-second step times.
Microbenchmarking & Documentation (loss_and_memory_benchmark.py, IMPROVEMENTS.md):
a standalone 9-point microbenchmark verifying loss parity, gradient parity,
memory savings, and host launch latency.
economic impact ($158.4M USD and 41.83 GWh saved annually fleet-wide).
Copybara Open-Source Attribution (copy.bara.sky):