[maxtext] Add block-diffusion training primitives - #4737
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
hengtaoguo
left a comment
There was a problem hiding this comment.
Thanks for the feature contribution!
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
ae57764 to
ce55a8e
Compare
shralex
left a comment
There was a problem hiding this comment.
Since block diffusion deviates significantly from the standard autoregressive (AR) pipeline (introducing concepts like canvas_policy, seed_and_mask, and target_alignment), future contributors would greatly benefit from a README.md in the src/maxtext/diffusion/block_diffusion/ directory.
You could include the following in the README or module-level docstring:
Literature Links: Link to the Block Diffusion (https://arxiv.org/abs/2503.09573 ?) paper so readers understand the theoretical backing.
Terminology definitions: Briefly explain the core concepts implemented in this PR:
Canvas: The fixed-length sequence of token slots being refined via denoising.
Logit Alignment (same_position vs shifted): Explain how logits map to targets, as standard causal AR models shift targets by 1, whereas diffusion models might align them directly.
Corruption / Masking: Explain that corrupt_tokens handles the forward noising process by masking valid tokens independently within each bounded bidirectional block.
Adding this context will make the codebase much more approachable for anyone maintaining the diffusion or speculative decoding pipelines in MaxText!
Introduce model-independent block corruption and target-alignment utilities under `maxtext.diffusion.block_diffusion`. The module supports the explicit `same_position/all_masked` and `shifted/seed_and_mask` contracts, guarantees supervision for every nonempty eligible block, and keeps padded positions untouched. Test Plan: - `python -m pytest -q tests/unit/block_diffusion_test.py`
ce55a8e to
8da87c0
Compare
|
Thanks for the documentation suggestion. I added |
|
@hengtaoguo @shralex Thanks for the approvals! All required checks are green and the PR is pull-ready. GitHub prevents me from merging into protected main. Could one of you please squash-merge it or enable auto-merge? |
Motivation
MaxText needs small, model-independent primitives for discrete block-diffusion
training before attention, input-pipeline, trainer, or post-training support is
introduced.
Scope
This PR adds only:
maxtext.diffusion.block_diffusion;same_positionandshiftedlogits; andIt does not change configuration, attention, model execution, training loops,
serving, SFT, distillation, or RL.
Design
The corruption API consumes clean tokens, an explicit eligibility mask, a
logical block size, and one of two declared model contracts:
same_positionwith anall_maskedcanvas; orshiftedwith aseed_and_maskcanvas.Each nonempty eligible block is guaranteed to retain at least one supervised
position. Padding remains untouched. Target alignment follows logical token
positions, including reordered physical layouts, instead of assuming that
array index equals sequence position.
Compatibility
There is no behavior change for existing MaxText training or inference paths.
The new package is not activated by any configuration in this PR.
Tests
python -m pytest -q tests/unit/block_diffusion_test.pyThe tests cover partial blocks, per-block noise sampling, deterministic RNG,
all-invalid rows, seeded anchors, mask/loss provenance, reordered logical
positions, padding, and invalid contracts and shapes.
Current clean-head result:
13 passed,5 subtests passed; Pyink, compileall,and
git diff --checkalso pass.Checklist
Follow-ups
Block-causal attention and pre-training integration will be proposed only after
this primitive contract is reviewed and landed. CFT/SFT, OPD, exact replay,
and RL remain separate later changes.
Design document:
https://docs.google.com/document/d/1N7KcCoAIErB2CV9EJ2G1u_mdN-AQgqwNUYSvM0mtqMI/edit