[maxtext] Export exact stochastic denoising traces#4590
Open
ethannnnnn wants to merge 5 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
Add a model-independent low-confidence block rollout that consumes target- aligned logits. It supports the two public model contracts, logical-position block boundaries after context-parallel reordering, heterogeneous batches, partial final blocks, confidence-threshold commits, and forced-argmax progress. The initial OPD scope validates a single contiguous completion suffix so clean future turns cannot leak through bidirectional intra-block attention. Shifted rollouts also require logical position zero to remain prompt context. Test Plan: - 7 passed in tests/unit/diffusion_denoise_test.py, including jax.jit execution - Pylint 10.00/10 - Pyink, pycompile, and git diff checks pass
Add a default-off student-rollout distillation source that prepares fresh block-diffusion rollouts in MaxText and delegates the weighted prepared loss to Tunix. Keep completion, corruption, validity, and loss ownership explicit; score clean generated tokens with a causal teacher; and exclude positions after model-specific stop tokens. Canonicalize multi-turn examples around the final assistant span. Earlier turns become prompt context, while any later conversation turns are truncated from tokens and both input/target segmentation before rollout. Rows without a completion span or prompt still fail closed, so the teacher and student cannot observe future context. Make resume fail closed. Persist the tokenizer, model, objective, optimizer, data-stream, topology, and stop-token contract; replay deterministic HF input before global device placement; reject early exhaustion and incompatible standard-distillation checkpoints. Honor each decoder family's native sharding mode and limit OPD to one inflight computation to control dense-logit memory. The existing dataset-driven distillation path remains the default and lazily avoids the new Tunix diffusion APIs. Test plan: - 209 passed, 14 skipped, 3 deselected, 69 subtests in the focused MaxText suite - 26 passed, 25 skipped, 22 subtests against the paired Tunix OPD head - 4 standard checkpoint restore tests passed through unittest - 45 focused MaxText OPD/input-pipeline tests and 21 subtests passed - Pyink 24.10.1, Ruff, Pylint 10/10, and git diff --check
Extend the low-confidence block denoiser with a stochastic, per-row rollout that records the sampled token, action step, and action log probability for every completion position. The trace keeps the full fixed-horizon denoising schedule even after a visible EOS, isolates RNG streams between batch rows, excludes the mask token from sampling, and forces progress when no token clears the confidence threshold. Existing deterministic generation remains unchanged. This trace is the minimal model-independent contract needed to replay the same diffusion actions under live, reference, and old policies during policy optimization. Test Plan: - pytest tests/unit/diffusion_denoise_test.py - included in the 83-test focused diffusion-RL suite - Pyink, Pylint, py_compile, and git diff --check
ethannnnnn
requested review from
SurbhiJainUSC,
aireenmei,
darisoy,
richjames0 and
shralex
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
NuojCheng,
RissyRan,
bvandermoon,
gagika,
gobbleturk,
huytransformer,
igorts-git,
jiangjy1982,
parambole,
shuningjin,
suexu1025 and
xibinliu
as code owners
July 23, 2026 22:44
ethannnnnn
requested review from
A9isha,
abhinavclemson,
dipannita08,
hengtaoguo,
khatwanimohit and
vipannalla
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
Diffusion policy optimization must replay the actions that were actually sampled. A final token sequence alone does not identify the intermediate canvas or denoising step that produced each action.
Scope
Design
The trace records each action against its pre-commit state. Sampling excludes the mask token, applies the configured temperature, and uses forced argmax only to guarantee progress when the confidence threshold commits nothing. Per-row keys prevent extra denoising work in one batch row from advancing another row's random stream.
RNG normalization derives the scalar key shape from the JAX key dtype instead of assuming a legacy
uint32[2]representation. The rollout accepts typed and legacy scalar keys or one key per row, and key selection preserves any implementation-specific trailing dimensions. This supports boththreefry2x32andunsafe_rbgunder JIT without changing sampled-action semantics.Visible output truncation is deliberately separate from policy data: reward text may stop at EOS, while the policy trace retains every scheduled action needed for exact replay.
Compatibility
The existing deterministic rollout and its public wrapper remain unchanged when no RNG is supplied. Existing legacy-key callers continue to work, while typed-key callers no longer depend on one concrete key layout. No trainer or RL algorithm is selected by this PR.
Extensibility
The trace is model independent and can be scored by live, reference, and old policies through a separate adapter. It can also support future grouped/native scoring optimizations without changing sampled-action semantics.
Tests
tests/unit/diffusion_denoise_test.pycovers stochastic traces, row-independent RNG, EOS/full-trace separation, forced progress, and mask exclusion.threefry2x32andunsafe_rbgimplementations.git diff --checkpassed.Known limitations
This records a fixed old sampling schedule. It does not claim an unbiased estimator over alternative denoising schedules, and it does not add a TPU-optimized grouped replay kernel.
Stack
Depends on the preceding upstream PR: #4589
MaxText block-diffusion design document