[maxtext] Add generalized block-diffusion CFT and SFT#4587
Open
ethannnnnn wants to merge 2 commits into
Open
Conversation
Add block_diffusion as a default-off attention type with one namespaced block-size setting. Resolve it in the shared attention layer so ordinary global layers need no model-name dispatch while explicit specialized attention remains intact. Implement matching dense, Splash, Tokamax, packed-sequence, and load-balanced context-parallel masks. Preserve the autoregressive path and support partial final blocks. Tests: attention 42 passed/37 skipped; config 18 passed plus 21 subtests; Tokamax 3 passed; pyink, yamllint, git diff --check.
Add a model-agnostic block-diffusion training objective without changing the causal LM default. The data pipeline emits separate validity, completion, corruption, and loss masks, supports same-position/all-masked and shifted/seeded canvases, and preserves those fields through context-parallel reordering and shaped batches. Align model logits to physical targets in a shared scoring utility and consume explicit loss weights in Linen, NNX, native gradient accumulation, and the Tunix SFT adapter. The adapter composes the stock Tunix PeftTrainer and its LossOutput contract, including denominator-aware accumulation and evaluation; the existing MaxText AR trainer path remains unchanged. Tests cover partial blocks, prompt protection, deterministic corruption, alignment after sequence reordering, strict mask requirements, zero-weight gradients, causal no-regression, weighted accumulation/evaluation acceptance, and SFT adapter validation. Test Plan: - 196 passed, 14 skipped, 3 deselected; 66 subtests passed in focused MaxText unit suite - 11 passed in Tunix-backed post-training SFT suite - Pylint 10.00/10 on new scoring and loss/GA tests - Pyink, yamllint, codespell, pycompile, and git diff checks pass
ethannnnnn
requested review from
RissyRan,
SurbhiJainUSC,
aireenmei,
darisoy,
igorts-git,
jiangjy1982,
parambole,
richjames0,
shralex,
shuningjin and
suexu1025
as code owners
July 23, 2026 22:44
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
ethannnnnn
requested review from
A9isha,
NuojCheng,
abhinavclemson,
bvandermoon,
dipannita08,
gagika,
gobbleturk,
hengtaoguo,
huytransformer,
khatwanimohit,
vipannalla and
xibinliu
as code owners
July 23, 2026 22:44
|
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. |
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.
Motivation
Block-diffusion CFT/SFT needs one explicit definition of target alignment, completion scope, corruption, and loss weights. Reusing segmentation fields for these different meanings can leak clean targets or bias training.
Scope
block_diffusiontraining objective while retainingcausal_lmas the default.same_position/all_maskedandshifted/seed_and_maskmodel contracts.Design
Targets remain physically unshifted. A shared scoring utility maps model logits to physical targets according to the configured alignment. Corruption samples independently per eligible block, protects prompts and padding, guarantees progress, and handles partial blocks.
completion_mask,corruption_mask, andtargets_loss_maskremain separate through shaped batches and context-parallel reordering. Loss normalization uses the sum of active weights, including under gradient accumulation; an all-zero batch returns finite zero loss and zero gradients.The Tunix-backed diffusion SFT entry point constructs the stock Tunix
PeftTrainerand configures it throughconfigure_diffusion_sft, a raw-batch adapter, and a target-aligned logits function. MaxText's existing causal-SFT compatibility subclass remains on the causal path only; diffusion does not depend on that overridden train step.Compatibility
The causal pipeline keeps its existing trainer selection, next-token shift, segmentation-derived mask, configuration defaults, and checkpoint shape. Diffusion refuses missing explicit masks instead of guessing. Through the paired Tunix weighted-reduction dependency, the Tunix-backed path supports denominator-aware gradient accumulation and evaluation instead of averaging independently normalized microbatches.
Extensibility
The objective is selected by stable configuration rather than a model name. Additional models can implement one of the declared alignment/canvas contracts or add a new validated contract without changing trainer ownership.
Tests
git diff --checkpassed.Known limitations
The Tunix-backed SFT path does not support optimizer-state host offload because the underlying
PeftTrainerdoes not provide that execution mode. Native MaxText SFT remains available for the same diffusion objective.Stack
Depends on the preceding upstream PR: #4586
Cross-repository dependency: google/tunix#1745 (
block-diffusion-tunix-pr3-sftat8dc0dd39951a).MaxText block-diffusion design document