[maxtext] Add block-diffusion pre-training - #4776
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for block-diffusion pre-training within MaxText. It adds configuration options, input pipeline transformations (including token corruption and padding adjustments), and updates the pre-training loss function to handle target-aligned block-diffusion losses and explicit loss masking. It also hardens gradient accumulation against division-by-zero errors when total weights are zero, and adds comprehensive unit tests for the new functionality. There are no review comments, so I have no feedback to provide.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
hengtaoguo
left a comment
There was a problem hiding this comment.
Thanks for adding the extensive test coverage. Please make sure to resolve the failing tests in CI before merging.
Wire the block-diffusion primitives into the opt-in text pre-training path. HF batches keep clean same-position targets, corrupt valid tokens per block, and carry separate corruption and loss masks. The loss aligns logits according to the configured model contract and normalizes only supervised positions. Causal LM remains the default; packing, SFT, DPO, MTP, vocabulary tiling, and multimodal input fail validation for this initial scope. Test Plan: - corruption adapter and nonzero-pad metadata tests - Linen and NNX loss-mask tests - objective/config compatibility tests - positive-weight causal and zero-weight native gradient-accumulation tests
dc9f37a to
aadaaa8
Compare
Motivation
With block-diffusion primitives and block-causal attention available, MaxText
needs a focused pre-training integration before any completion fine-tuning,
rollout, distillation, replay, or RL behavior is introduced.
Dependencies
This change follows and depends on:
It has no Tunix dependency.
Scope
This PR adds only:
training_objective=block_diffusionconfiguration;corruption masks, and target-loss masks;
positions.
It does not add SFT, DPO, rollout, serving, distillation, replay, or RL.
Training contract
The supported model contracts are:
same_positionlogits with anall_maskedcanvas; andshiftedlogits with aseed_and_maskcanvas.Each nonempty eligible block keeps at least one supervised position. Clean
targets and segmentation metadata remain separate from the corrupted inputs.
Loss is normalized over
targets_loss_maskpositions only. Packing, SFT,DPO, MTP, vocabulary tiling, audio, multimodal input, and non-Hugging-Face
pipelines fail validation for this initial scope.
Compatibility
training_objective=causal_lmremains the default. Its next-token datatransform, segmentation-based loss mask, and autoregressive attention path are
unchanged.
The shared gradient-accumulation helper guards a zero total-weight denominator
only for the block-diffusion objective. The causal branch retains its original
operations, including the upstream Tunix accumulation-step divisor. Focused
regression tests verify both accumulation modes against the direct full-batch
loss and gradients.
Tests
The audited current-main replay passed:
The gate covers block-diffusion primitives, dense and TPU mask construction,
configuration, Hugging Face objective selection, padding and corruption,
Linen and NNX loss masks, causal-loss fallback, shaped batches, context
parallel metadata, and positive- and zero-weight gradient accumulation.
Three pre-existing Hugging Face iterator integration tests are deselected in
the local CPU gate because they require live
datasets.load_datasetaccess.The new objective-transform tests in that module pass independently.
All reachable changed production statements and branches are covered by this
gate: 122/122 executable lines and 70/70 branches. The one excluded clause is
the objective-specific packing error, which cannot execute because the
block-diffusion attention validation above it necessarily rejects packing
first.
With the CI JAX/libtpu toolchain, normalized optimized HLO for DeepSeek3,
Llama3 8B, and Qwen3 1.7B is byte-identical to the public PR parent. The
feature therefore requires no reference-HLO changes.
Pyink, Pylint, Python compilation, and
git diff --checkare also required bythe guarded publisher.
Checklist
Design document:
https://docs.google.com/document/d/1N7KcCoAIErB2CV9EJ2G1u_mdN-AQgqwNUYSvM0mtqMI/edit