Skip to content

feat(qwen image): dmd2 preprocess fixes - #3593

Open
linnanwang wants to merge 3 commits into
jingyu-ml/dmd2-qwen-image-trainerfrom
linnanw/feat/qwen-image-dmd2-preprocess-fixes
Open

feat(qwen image): dmd2 preprocess fixes#3593
linnanwang wants to merge 3 commits into
jingyu-ml/dmd2-qwen-image-trainerfrom
linnanw/feat/qwen-image-dmd2-preprocess-fixes

Conversation

@linnanwang

@linnanwang linnanwang commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a masking bug in Qwen-Image preprocessing, adds multi-node sharded
preprocessing, and adds a DMD2 inference sampler + diffusers export tool —
closing the data-preprocessing-through-inference gaps around this PR's DMD2
Qwen-Image distillation recipe.

Changelog

  • fix(diffusion): thread the real prompt_embeds_mask from Qwen-Image's
    encode_prompt through the processor, TextToImageDataset, and
    collate_fn_production, instead of synthesizing a mask from the raw
    (possibly already-padded) embedding length — the synthesized fallback is
    wrong whenever encode_prompt pads to a fixed max_sequence_length.
  • feat(diffusion): add --shard_idx/--shard_count to
    tools/diffusion/preprocessing_multiprocess.py's image subcommand for
    multi-node/multi-job preprocessing sweeps, with rank-namespaced metadata
    files so concurrent jobs sharing one output_dir don't collide. Default
    single-job output is unchanged.
  • feat(diffusion): add tools/diffusion/inference_dmd2_qwen_image.py
    (QwenImageDMDInferencePipeline) — a bit-aligned single/multi-step
    rectified-flow sampler for DMD2-trained Qwen-Image students, matching the
    training-time math in ModelOpt's fastgen, with optional inference-time
    CFG and EMA-shadow overlay.
  • feat(diffusion): add tools/diffusion/export_diffusers_pipeline.py to
    assemble a consolidated transformer checkpoint + base pipeline components
    into a full QwenImagePipeline.from_pretrained-loadable directory
    (symlink by default, --copy for portability).
  • test: 17 new unit tests covering the mask fix, sharded preprocessing, the
    sampler's schedule-resolution logic, and the export tool — all CPU-only,
    no GPU/ModelOpt/diffusers required to run.

Before your PR is "Ready for review"

Pre checks:

Additional Information

  • Builds on / targets feat(diffusion): integrate DMD2 into the native trainer #3298 directly rather than main, since it extends
    the DMD2 recipe that PR introduces.
  • The sampler and export tool depend only on diffusers/torch, not on
    ModelOpt, so they work independent of the pinned fastgen branch.
  • pre-commit/ruff could not be run in the environment that authored
    these commits (no pre-commit/uv reachable there) — please run
    pre-commit run locally before merging to confirm formatting/lint.

The Qwen-Image processor discarded the attention mask returned by
encode_prompt, so downstream collation had to synthesize one from the raw
embedding length -- wrong whenever encode_prompt pads to a fixed
max_sequence_length, since padded positions would be marked as real tokens.
Thread the real mask through processor -> dataset -> collate instead, with
the old length-derived fallback kept for caches preprocessed before this fix.

Signed-off-by: linnan wang <linnanw@nvidia.com>
The preprocessing CLI had no way to split a large image set across multiple
jobs/nodes without them clobbering each other's metadata files in a shared
output_dir. Add --shard_idx/--shard_count so each rank processes
image_files[shard_idx::shard_count] and writes rank-namespaced metadata
shard/index files; default single-job output is unchanged.

Signed-off-by: linnan wang <linnanw@nvidia.com>
The DMD2 recipe could train a student but Automodel had no way to sample
from or deploy the result: a DMD2 student is trained on the rectified-flow
identity, not the noise-prediction loss a stock diffusers scheduler expects,
so it can't be sampled with standard scheduler stepping. Add
QwenImageDMDInferencePipeline (bit-aligned single/multi-step RF sampler,
optional CFG and EMA overlay) and export_diffusers_pipeline (assembles a
consolidated transformer checkpoint + base pipeline components into a full
QwenImagePipeline.from_pretrained-loadable dir). Both depend only on
diffusers/torch, not on ModelOpt, so they work independent of the pinned
fastgen branch's availability.

Signed-off-by: linnan wang <linnanw@nvidia.com>
@linnanwang
linnanwang requested a review from a team as a code owner August 20, 2026 04:10
@copy-pr-bot

copy-pr-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@akoumpa akoumpa changed the title Linnanw/feat/qwen image dmd2 preprocess fixes feat(qwen image): dmd2 preprocess fixes Aug 20, 2026
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