Skip to content

[maxtext] Add block-diffusion CFT and SFT - #4891

Open
ethannnnnn wants to merge 1 commit into
AI-Hypercomputer:mainfrom
ethannnnnn:block-diffusion-maxtext-v2-pr4-cft-sft
Open

[maxtext] Add block-diffusion CFT and SFT#4891
ethannnnnn wants to merge 1 commit into
AI-Hypercomputer:mainfrom
ethannnnnn:block-diffusion-maxtext-v2-pr4-cft-sft

Conversation

@ethannnnnn

Copy link
Copy Markdown
Collaborator

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:

  • 333 passed, 76 platform skips, 3 documented HF integration deselections, 163 subtests
  • Pyink clean and Pylint 10.00/10
  • compileall, Yamllint, and git diff --check pass

Description

Start with a short description of what the PR does and how this is a change from
the past.

The rest of the description includes relevant details and context, examples:

  • why is this change being made,
  • the problem being solved and any relevant context,
  • why this is a good solution,
  • some information about the specific implementation,
  • shortcomings of the solution and possible future improvements.

If the change fixes a bug or a Github issue, please include a link, e.g.,:
FIXES: b/123456
FIXES: #123456

You can also provide a comma-separated list. If you don't want to close a bug but
simply to reference it, use BUGS, e.g.:
BUGS: b/123456

Notice 1: Once all tests pass, the "pull ready" label will automatically be assigned.
This label is used for administrative purposes. Please do not add it manually.

Notice 2: For external contributions, our settings currently require an approval from a MaxText maintainer to trigger CI tests.

Tests

Please describe how you tested this change, and include any instructions and/or
commands to reproduce.

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request integrates target-aligned block-diffusion Supervised Fine-Tuning (SFT) with Tunix. It updates configuration types, data processing pipelines, and training hooks to support block-diffusion SFT, including handling of completion-only masking and preaveraged evaluation losses. Additionally, a new adapter module diffusion_sft.py is introduced to interface MaxText with Tunix's diffusion SFT. Feedback on the changes highlights a performance concern in the newly added adapter, where eager validation via np.asarray on JAX arrays could trigger device-to-host transfers and degrade training throughput.

Comment on lines +42 to +48
def _concrete_numpy(value):
"""Returns a host view only when eager validation is safe."""
if isinstance(value, jax.core.Tracer):
return None
if isinstance(value, jax.Array) and not value.is_fully_addressable:
return None
return np.asarray(value)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Calling np.asarray on JAX arrays inside _concrete_numpy on every training step triggers device-to-host transfers and host-device synchronization, which can severely degrade training throughput. Consider disabling these eager validations by default in production, or only running them on the first step, or gating them behind a debug configuration flag.

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/maxtext/integration/tunix/diffusion_sft.py 81.57% 7 Missing and 7 partials ⚠️
src/maxtext/input_pipeline/input_pipeline_utils.py 86.66% 3 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

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
@ethannnnnn
ethannnnnn force-pushed the block-diffusion-maxtext-v2-pr4-cft-sft branch from 6957f93 to cd571e1 Compare August 18, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants