Skip to content

feat(pdd): Qwen-Image 2.1 PDD training with a LoRA student from SGLang rollouts - #365

Closed
niehen6174 wants to merge 3 commits into
radixark:mainfrom
niehen6174:pdd-sglang-rollout
Closed

niehen6174 wants to merge 3 commits into
radixark:mainfrom
niehen6174:pdd-sglang-rollout

Conversation

@niehen6174

@niehen6174 niehen6174 commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • Rollout. The pdd_qwen_image21 patch group keeps the native DiT and replaces only proj_out with the live heads.
    • The engine steps all 32 intervals: the first interval of each block runs the DiT and caches the heads, and the other three step on the cache.
    • The trajectory therefore returns every interval's start state, 33 states in all.
  • Training.
    • A loss-hub train-input hook expands each trajectory into eight block-ordered updates.
    • Update j recomputes the heads from the rollout state at block j.
    • The prepare hook returns a 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.
    • No trajectory is re-simulated in the trainer.
  • LoRA student.
    • LoRA adapters train on the backbone; the heads train in full.
    • --custom-train-model-transform-path now runs after LoRA is applied, so the parameters it adds stay trainable.
    • LoRA checkpoints keep those parameters.
    • LoRA weight sync pushes them as plain weights after the adapter.
    • The engine applies the adapter unmerged (--sglang-lora-merge-mode dynamic). Merging a small update into BF16 weights rounds most of it away and drifts from the trainer.
  • Generic changes (no effect on other losses):
    • --fsdp-param-dtype (defaults to --diffusion-forward-dtype).
    • An explicit --global-batch-size is 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 to None.
    • 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.
    • 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.
    • The rest of tests/fast passes, except media tests that also fail on main on the same host (environment).
  • Long run on 2 × H200, colocated: LoRA r64/α128, lr 2e-5, batch 8, 1600 rollouts, about 65 s per rollout.
    • Block-0 trainer-vs-engine relative error stays at 0.55–0.95% for the whole run.
    • The mean interval loss falls from 0.038 to about 0.017.
  • Quality on 64 development prompts. The noise, conditions and 8-step grid are the same for every row. LPIPS and SSIM are measured against the 40-step teacher. The full-param row is an earlier prototype (full-parameter student, lr 5e-7), not a same-config comparison.
method LPIPS ↓ SSIM ↑ MUSIQ CLIPIQA NIMA Q-Align quality Q-Align aesthetic
teacher, 40 steps 0 1 72.72 0.704 5.554 4.659 3.893
base model, 8 steps 0.416 0.698 63.06 0.647 5.447 3.834 3.738
full-param PDD, rollout 1600 (earlier prototype) 0.297 0.755 72.51 0.694 5.481 4.647 3.877
LoRA PDD, rollout 400 0.320 0.737 72.71 0.688 5.479 4.632 3.839
LoRA PDD, rollout 1000 0.324 0.730 73.11 0.700 5.441 4.633 3.824
LoRA PDD, rollout 1400 0.300 0.752 72.79 0.707 5.490 4.627 3.865
LoRA PDD, rollout 1600 0.310 0.745 72.82 0.704 5.565 4.606 3.837

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.

  • Samples, 10 of the 64 prompts, 8 DiT forwards for every column except the teacher.

PDD Qwen-Image 2.1 samples 1-5
PDD Qwen-Image 2.1 samples 6-10

@niehen6174
niehen6174 changed the base branch from main to dmd2/02b-train-input-hook November 10, 2026 05:03
@zhihengy
zhihengy force-pushed the dmd2/02b-train-input-hook branch 2 times, most recently from cd303eb to 77dedd4 Compare November 11, 2026 08:18
@Rockdu
Rockdu force-pushed the dmd2/02b-train-input-hook branch from 77dedd4 to d8e53e5 Compare November 11, 2026 15:43
…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.
@niehen6174
niehen6174 changed the base branch from dmd2/02b-train-input-hook to main November 13, 2026 11:31
@niehen6174 niehen6174 changed the title feat(pdd): add Qwen-Image 2.1 PDD training from SGLang rollouts feat(pdd): Qwen-Image 2.1 PDD training with a LoRA student from SGLang rollouts Nov 13, 2026
…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

Copy link
Copy Markdown
Collaborator Author

Moved to #386 (same commits, pushed to a branch on this repo) so that the MiniMax H3 PDD PR can stack on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant