Optional block-diffusion support for Qwen3 (attention + masked-diffusion SFT + on-policy distillation + RL rollout)#4516
Open
ethannnnnn wants to merge 4 commits into
Conversation
…ze/mask_id) for Fast_dLLM/Diffusion-GR2
…FT (Fast_dLLM/Diffusion-GR2)
…e rollout + committed-position forward-KL)
…red diffusion per-token logprob (TraceRL) for GRPO/DAPO
ethannnnnn
requested review from
A9isha,
NuojCheng,
RissyRan,
SurbhiJainUSC,
abhinavclemson,
aireenmei,
bvandermoon,
darisoy,
dipannita08,
gagika,
gobbleturk,
hengtaoguo,
huytransformer,
igorts-git,
jiangjy1982,
khatwanimohit,
parambole,
richjames0,
shralex,
shuningjin,
suexu1025,
vipannalla and
xibinliu
as code owners
July 17, 2026 04:14
|
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.
Summary
Adds optional block-diffusion (masked-diffusion / discrete-diffusion) support for the Qwen3 family across the full lifecycle: the attention pattern, a masked-diffusion SFT objective, on-policy distillation from an AR teacher, and an RL rollout. Block-diffusion LMs (Fast-dLLM, BD3-LM) attend bidirectionally within a fixed block and causally across blocks, and generate by iterative denoising. Everything is gated (default off); autoregressive paths are unchanged. Conversion is weight-preserving — only the attention pattern, objective, and decode change.
This branch spans four logical pieces; happy to split into a stacked series if that's easier to review.
1. Block-diffusion attention
AttentionType.BLOCK_DIFFUSION(common/common_types.py): bidirectional within a block ofbd_size, causal across blocks ((i // bd) >= (j // bd)).generate_attention_maskand aBlockDiffusionMask(splash_attention_mask._ComputableMask)set as the base mask on the splash path (layers/attention_op.py).enable_block_diffusion/bd_size/mask_id(configs/types.py,configs/base.yml) with a validator;bd_sizethreaded intoAttentionOp; wired on the Qwen3 attention module (models/qwen3.py), covering dense + MoE decoder layers.2. Masked-diffusion SFT data transform
BlockDiffusionMasking(input_pipeline/input_pipeline_utils.py): per-block noising — draw a masking ratio per block, replace response tokens withmask_idin the inputs, keep targets aligned (not shifted), and set the loss mask (targets_segmentation) only at masked positions. Wired into the HF preprocessing pipeline, gated, replacing the AR shift.targets_segmentation != 0.3. On-policy distillation (OPD)
trainers/post_train/distillation/diffusion_generate.py: a JAX block-diffusion generation helper (innerwhile_loopdenoise + outerfori_loopacross blocks), a shared per-token diffusion log-prob, and the commit rule.train_distill.py: the student generates on-policy understop_gradient(outsidevalue_and_grad, like the frozen teacher); the existing forward-KL distillation loss is reused, applied only at committed positions. Gated byopd_on_policy.4. RL rollout (GRPO/DAPO)
integration/vllm/maxtext_diffusion_rollout.py:MaxTextDiffusionRollout(a plainBaseRollout, since block-diffusion decode is not autoregressive) whosegenerate()denoises and whoseget_per_token_logps()uses the shared diffusion log-prob.trainers/post_train/rl/train_rl.py, gated byrl_diffusion_rollout. The GRPO loss's new-policy log-prob is supplied via a pluggable hook so the same diffusion log-prob function backs both the rollout (old policy) and the loss (new policy), keeping the importance ratio consistent.Back-compat / gating
All four pieces gated (
enable_block_diffusion,opd_on_policy,rl_diffusion_rollout, default off). No AR path changes.Testing (CPU)
_ComputableMask) vs a reference, config validator, and a tiny end-to-end Qwen3 forward confirming weight-preservation and that the flag is wired (38 tests incl. regressions).mask_idset, targets aligned, loss-mask correct, determinism, AR path unchanged (8 tests).jax.gradcheck confirming generation is stop-gradient (16 tests).Limitations / follow-ups
Draft pending TPU validation.