Repository navigation
feat(pdd): Qwen-Image 2.1 PDD training with a LoRA student from SGLang rollouts - #386
Open
niehen6174 wants to merge 3 commits into
Open
niehen6174 wants to merge 3 commits into
niehen6174 wants to merge 3 commits into
Conversation
…GLang rollouts Parallel Decoding Distillation (`--loss-type pdd`): SGLang rolls out an 8-step student whose output layer is 32 interval heads, the FSDP actor trains it against the frozen teacher's midpoint velocity, and weight sync closes the loop. - Rollout: the `pdd_qwen_image21` patch group steps all 32 intervals with one DiT forward per 4-interval block (heads cached), so the trajectory carries every interval's start state; the trainer never re-simulates the trajectory. - Training: each trajectory expands into eight block-ordered updates (loss-hub train-input hook). Update j recomputes the heads from the rollout state at block j; the prepare hook hands the actor a `teacher_solver`, so the teacher's midpoint solve from the rollout's sampled-interval state runs in the actor like any other teacher forward. - LoRA student: adapters on the backbone, heads trained in full. The model-transform hook (`--custom-train-model-transform-path`) now runs after LoRA so the heads it adds stay trainable; LoRA checkpoints keep them, and LoRA weight sync pushes them as plain weights after the adapter. The engine applies the adapter unmerged (merging into BF16 weights rounds a small update away). - Generic: `--fsdp-param-dtype`; an explicit global batch size is allowed when a train-input hook defines the per-step samples; the LR schedule counts num_rollout x num_steps_per_rollout optimizer steps. Docs: docs/developer/pdd.md. Tests: CPU loss/rollout/integration tests, FSDP one/two-rank parity against an unsharded reference, and an SGLang closed-loop smoke.
…tants with the rollout patch This PR ships Qwen-Image 2.1 only, so the per-family/per-stream abstraction had a single user: - Remove PDDFamily/PDD_FAMILIES. Qwen's grid and student time input become plain helpers (pdd_grid, model_time) and its scope is checked directly in validate_pdd_args. - Rollout trajectories are one [33, S, C] tensor instead of a dict of streams; the loss hook and teacher_mean_velocity work on a single latent tensor. This also removes per-stream metric names that were not in the metrics SCHEMA. - The SGLang patch reads the interval count, block size, resolution and token count from the same constants the argument validation uses.
… GPU smoke - One tests/fast/distillation/test_pdd.py replaces three files: interval math, teacher target, engine cached-head steps, timestep matching, trajectory validation, the LoRA student (meta init, trainable and checkpointed parameters), arguments, and the eight-update loop against an independent reference. - Drop the FSDP one/two-rank parity worker: the SGLang smoke already trains the LoRA student through one-rank FSDP and checks every interval of the next rollout, and FSDP sharding itself is covered by the existing FSDP tests. - Remove pdd_loss, which only the tests used; the loss hook composes teacher_mean_velocity and interval_loss directly.
niehen6174
requested review from
Rockdu,
guapisolo and
zhihengy
as code owners
November 16, 2026 02:08
This branch has not been deployed
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.
What
Parallel Decoding Distillation (PDD) for Qwen-Image 2.1 t2i, trained online from SGLang rollouts with a LoRA student (
--loss-type pdd).The student's output layer becomes 32 interval heads. One DiT forward per 4-interval block predicts all four intervals, so an 8-forward rollout covers the 32-interval trajectory. Each update regresses one sampled head on the frozen teacher's midpoint velocity.
How
pdd_qwen_image21patch group keeps the native DiT and replaces onlyproj_outwith the live heads.PreparedBatch.teacher_solver, so the actor runs the teacher's midpoint solve from the rollout's state at the sampled interval, the same way it runs any other teacher forward.--custom-train-model-transform-pathnow runs after LoRA is applied, so the parameters it adds stay trainable.--sglang-lora-merge-mode dynamic). Merging a small update into BF16 weights rounds most of it away and drifts from the trainer.--fsdp-param-dtype(defaults to--diffusion-forward-dtype).--global-batch-sizeis accepted when a train-input hook defines the samples per optimizer step.train_iters = num_rollout * num_steps_per_rollout. This equals the old formula whenever the global batch size is derived.PreparedBatch.teacher_solver, which defaults toNone.iter_hf_trained_weights(), which yields nothing unless non-LoRA parameters are trainable.Design and recipe:
docs/developer/pdd.md. MiniMax H3 (video and audio heads) will follow in a separate PR.Validation
tests/fast/distillation/test_pdd.py(CPU): interval math, the detached midpoint teacher target, the engine's cached-head interval steps, timestep matching, trajectory validation, the LoRA student's trainable and checkpointed parameters, argument validation, and eight block updates from rollout states against an independent optimizer loop.tests/fast-gpu/backends/sglang_diffusion_utils/test_pdd_sglang_loop.py: a tiny Qwen-Image 2.1 through SGLang's native stages and one-rank FSDP with a LoRA student. It runs one rollout, eight updates and a sync, then checks every interval of the next rollout against the trainer within 0.5%. Passed.tests/fast-gpu/test_lora_weight_sync.py: passed.tests/fastpasses, except media tests that also fail onmainon the same host (environment).By rollout 1400 the LoRA student is within 0.003 LPIPS / SSIM of the full-param prototype, scores higher on MUSIQ and CLIPIQA and slightly lower on Q-Align. Rollout 1400 → 1600 changes are within the noise of 64 prompts.
Moved from #365 (same commits) so that the MiniMax H3 PR can stack on this branch.