[tunix] Add target-aligned diffusion SFT adapter - #1891
Open
ethannnnnn wants to merge 1 commit into
Open
Conversation
ethannnnnn
requested review from
abheesht17,
hgao327,
jiangyangmu,
lc5211,
s-noghabi,
sizhit2,
tianshub and
wang2yn84
as code owners
August 14, 2026 16:18
4 tasks
ethannnnnn
added a commit
to ethannnnnn/maxtext
that referenced
this pull request
Aug 18, 2026
Extend the opt-in block-diffusion objective from pre-training to text CFT and completion-only SFT. Preserve clean targets and role-derived completion eligibility through the Hugging Face pipeline, then corrupt only the configured supervision scope. Reject assistant-to-user transitions within one bidirectional diffusion block to prevent future-prompt leakage. Adapt prepared batches to the target-aligned Tunix diffusion contract, retain explicit weighted loss, treat diffusion evaluation as preaveraged, and disable NNX graph caching only for diffusion internal metrics. The causal SFT path remains the default. Draft dependency: temporarily pin the immutable google/tunix#1891 contributor-fork head so CI can exercise the integration. Replace it with the upstream Tunix SHA before marking the PR ready. Test Plan: - 343 passed, 76 platform skips, 3 documented HF integration deselections, 163 subtests - Tunix adapter has 100% statement and branch coverage - Pyink clean and Pylint 10.00/10 - compileall, Yamllint, and git diff --check pass
Provide a typed PeftTrainer adapter for canonical diffusion batches and target-aligned score functions. Compute weighted float32 cross entropy without autoregressive shifting, sanitize inactive targets, and preserve zero-weight numerical safety. Tests: diffusion contract and SFT suites; full PeftTrainer regression suite; pyink, pylint, py_compile, and diff checks.
ethannnnnn
force-pushed
the
block-diffusion-tunix-v2-pr5-sft
branch
from
August 19, 2026 21:41
0ab812a to
bd8092a
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.
Motivation
Tunix now has model-agnostic diffusion batch and logits contracts, but
PeftTrainerstill needs a small adapter and a target-aligned supervised lossbefore those contracts can be used for diffusion CFT or SFT. Autoregressive
loss helpers cannot be reused because they shift targets by one token.
Scope
This PR adds only the diffusion SFT integration layer:
DiffusionTokenBatch;DiffusionLogitsFnthrough the public diffusioncontract;
target_ids;PeftTrainer; andvalues cannot contaminate the loss or gradient.
It does not add a model implementation, tokenizer, dataset recipe,
distillation objective, rollout path, or RL trainer.
Dependencies
This PR depends on the contracts merged in #1832 and the fractional and
zero-denominator gradient behavior merged in #1833. Both dependencies are
verified against
mainby the guarded publisher before the patch is replayed.It does not depend on #1850 or the optional OPD track.
Compatibility
The existing autoregressive
PeftTrainerpath is unchanged. Users opt in bycalling
configure_diffusion_sftwith their batch adapter and target-alignedlogits function. CFT and SFT use the same objective; the external adapter
chooses which target positions and weights are active.
Tests
The focused suite covers trainer wiring, same-position alignment, float32
metrics, zero-weight numerical safety and zero gradients, jitted gradients,
microbatch equivalence, and shape rejection. The guarded publisher also runs
full
PeftTrainerregression tests, Pyink, scoped error/fatal Pylint, Pythoncompilation, and
git diff --check.Design document:
https://docs.google.com/document/d/1Xe-98ScS2RSH29AdhTdc9tO4WHQG5wCbFkJA3gmIUZQ/edit