Skip to content

[TRTLLM-14287][feat] Qwen Image CFG parallelism support - #16384

Merged
yibinl-nvidia merged 9 commits into
NVIDIA:mainfrom
yibinl-nvidia:qwen-image-cfg-parallel
Jul 30, 2026
Merged

[TRTLLM-14287][feat] Qwen Image CFG parallelism support#16384
yibinl-nvidia merged 9 commits into
NVIDIA:mainfrom
yibinl-nvidia:qwen-image-cfg-parallel

Conversation

@yibinl-nvidia

@yibinl-nvidia yibinl-nvidia commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added distributed CFG parallel generation for Qwen-Image pipelines.
    • Improved true classifier-free guidance with norm-based noise rescaling.
    • Added support for flexible negative prompt inputs, including validation for batch sizes.
  • Bug Fixes

    • Improved guidance behavior when negative prompts are omitted.
  • Tests

    • Added coverage for prompt handling, distributed CFG state, input selection, and guidance calculations.

Description

CFG=1 CFG=2
qwen_cfg1_negative_prompt_direct_output qwen_cfg2_negative_prompt_direct_output

Measured with explicit negative_prompt="", 1328x1328, 50 steps.

Case GPUs Generation time
CFG=1 true CFG, positive + negative serial 1 16.22s
CFG=2 CFG parallel 2 8.51s

CFG=2 is about 1.91x faster. LPIPS is 0.00000000.

Test Coverage

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Qwen-Image CFG parallel generation

Layer / File(s) Summary
CFG helper and state contracts
tensorrt_llm/_torch/visual_gen/models/qwen_image/pipeline_qwen_image.py
Adds helpers for negative-prompt normalization, rank-specific CFG inputs, true-CFG rescaling, and distributed CFG state validation.
Forward CFG parallel denoising
tensorrt_llm/_torch/visual_gen/models/qwen_image/pipeline_qwen_image.py
Updates CFG setup and denoising to gather per-rank predictions and combine them, while retaining the non-parallel path.
CFG helper validation
tests/unittest/_torch/visual_gen/test_qwen_image_registry.py
Tests prompt normalization, CFG state selection, rank-based inputs, and true-CFG results.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant QwenImagePipeline
  participant CFGRanks
  participant Transformer
  participant DistributedGroup
  QwenImagePipeline->>CFGRanks: select rank-specific embeddings
  CFGRanks->>Transformer: execute denoising
  Transformer-->>CFGRanks: local noise prediction
  CFGRanks->>DistributedGroup: all_gather predictions
  DistributedGroup-->>QwenImagePipeline: gathered predictions
  QwenImagePipeline->>QwenImagePipeline: apply true CFG rescaling
Loading

Suggested reviewers: karljang, luyiyun1021, chienchunhung

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description has a summary and checklist, but the Test Coverage section is empty. Add a Test Coverage section with the tests that cover CFG parallelism and briefly explain the issue and solution.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title matches the main change and follows the required ticket/type format.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
tensorrt_llm/_torch/visual_gen/models/qwen_image/pipeline_qwen_image.py (1)

429-429: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Loosely-typed cfg_pg return value.

The return type is annotated Tuple[bool, int, int, object], but visual_gen_mapping.cfg_group returns Optional[ProcessGroup] (per tensorrt_llm/_torch/visual_gen/mapping.py). Using object loses that type information for callers.

🔧 Suggested type fix
-    def _cfg_parallel_state(self, do_true_cfg: bool) -> Tuple[bool, int, int, object]:
+    def _cfg_parallel_state(
+        self, do_true_cfg: bool
+    ) -> Tuple[bool, int, int, Optional[ProcessGroup]]:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/visual_gen/models/qwen_image/pipeline_qwen_image.py` at
line 429, Update the return annotation of the method producing do_cfg_parallel,
cfg_size, cfg_rank, and cfg_pg to use Optional[ProcessGroup] for cfg_pg instead
of object, matching visual_gen_mapping.cfg_group and preserving the nullable
process-group type for callers.
tests/unittest/_torch/visual_gen/test_qwen_image_registry.py (1)

123-135: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Insufficient coverage: _cfg_parallel_state's error/fallback branches are untested.

Only the do_true_cfg=True/False happy paths (cfg_size=2, dist.is_initialized()==True) are tested. Missing:

  • cfg_size != 2 with do_true_cfg=True → should raise ValueError.
  • dist.is_initialized() == False with do_true_cfg=True, cfg_size==2 → should raise RuntimeError.
  • visual_gen_mapping is None/falsy → defaults (cfg_size=1, cfg_rank=0, cfg_pg=None).

These are exactly the guard-rails that prevent a misconfigured or partially-initialized distributed setup from silently entering the CFG-parallel all_gather path, so coverage here is worth adding in test_qwen_image_registry.py before merge.

As per path instructions, tests/** changes should be reviewed with attention to coverage sufficiency: "Keep feedback actionable: suggest concrete list file names and whether coverage is sufficient, insufficient, or needs follow-up outside the PR."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unittest/_torch/visual_gen/test_qwen_image_registry.py` around lines
123 - 135, Expand test_qwen_image_cfg_parallel_state to cover
_cfg_parallel_state guard branches: assert ValueError when do_true_cfg=True with
cfg_size not equal to 2, assert RuntimeError when do_true_cfg=True and
dist.is_initialized() is false with cfg_size=2, and verify a falsy
visual_gen_mapping returns (1, 0, None). Keep the existing happy-path assertions
unchanged.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tensorrt_llm/_torch/visual_gen/models/qwen_image/pipeline_qwen_image.py`:
- Around line 413-429: Update _cfg_parallel_state to emit a one-time warning
when cfg_size is greater than one while do_true_cfg is disabled, indicating that
CFG-parallel ranks will redundantly compute the same path. Update _run_warmup to
use a true_cfg_scale greater than 1.0 whenever CFG parallelism is configured, so
the CFG input selection and all_gather path is exercised during warmup; preserve
the existing scale for non-parallel configurations.

---

Nitpick comments:
In `@tensorrt_llm/_torch/visual_gen/models/qwen_image/pipeline_qwen_image.py`:
- Line 429: Update the return annotation of the method producing
do_cfg_parallel, cfg_size, cfg_rank, and cfg_pg to use Optional[ProcessGroup]
for cfg_pg instead of object, matching visual_gen_mapping.cfg_group and
preserving the nullable process-group type for callers.

In `@tests/unittest/_torch/visual_gen/test_qwen_image_registry.py`:
- Around line 123-135: Expand test_qwen_image_cfg_parallel_state to cover
_cfg_parallel_state guard branches: assert ValueError when do_true_cfg=True with
cfg_size not equal to 2, assert RuntimeError when do_true_cfg=True and
dist.is_initialized() is false with cfg_size=2, and verify a falsy
visual_gen_mapping returns (1, 0, None). Keep the existing happy-path assertions
unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b510b144-103b-427a-a64d-df323f3fddd9

📥 Commits

Reviewing files that changed from the base of the PR and between 725d9a1 and b79f692.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/visual_gen/models/qwen_image/pipeline_qwen_image.py
  • tests/unittest/_torch/visual_gen/test_qwen_image_registry.py

Comment thread tensorrt_llm/_torch/visual_gen/models/qwen_image/pipeline_qwen_image.py Outdated
@yibinl-nvidia
yibinl-nvidia force-pushed the qwen-image-cfg-parallel branch from 8a4db36 to 0971712 Compare July 14, 2026 20:38
@yibinl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59274 [ run ] triggered by Bot. Commit: 0971712 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59274 [ run ] completed with state SUCCESS. Commit: 0971712
/LLM/main/L0_MergeRequest_PR pipeline #47762 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@yibinl-nvidia yibinl-nvidia changed the title [None][feat] qwen image true CFG parallelism support [TRTLLM-14287][feat] qwen image true CFG parallelism support Jul 14, 2026
@yibinl-nvidia
yibinl-nvidia force-pushed the qwen-image-cfg-parallel branch from 0971712 to 903f4df Compare July 14, 2026 22:06
@yibinl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59288 [ run ] triggered by Bot. Commit: 903f4df Link to invocation

@yibinl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot kill

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59293 [ kill ] triggered by Bot. Commit: aade012 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59288 [ run ] completed with state ABORTED. Commit: 903f4df

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59293 [ kill ] completed with state SUCCESS. Commit: aade012
Successfully killed previous jobs for commit aade012

Link to invocation

@yibinl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

1 similar comment
@yibinl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59294 [ run ] triggered by Bot. Commit: aade012 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59294 [ run ] completed with state SUCCESS. Commit: aade012
/LLM/main/L0_MergeRequest_PR pipeline #47780 completed with status: 'SUCCESS'

CI Report

Link to invocation

Comment thread tensorrt_llm/_torch/visual_gen/models/qwen_image/pipeline_qwen_image.py Outdated
@yibinl-nvidia yibinl-nvidia changed the title [TRTLLM-14287][feat] qwen image true CFG parallelism support [TRTLLM-14287][feat] Qwen Image CFG parallelism support Jul 16, 2026
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62310 [ run ] triggered by Bot. Commit: 3f4ae7b Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62310 [ run ] completed with state FAILURE. Commit: 3f4ae7b
/LLM/main/L0_MergeRequest_PR pipeline #50479 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@chang-l chang-l self-assigned this Jul 29, 2026
Signed-off-by: yibinl-nvidia <109242046+yibinl-nvidia@users.noreply.github.com>
Signed-off-by: yibinl-nvidia <109242046+yibinl-nvidia@users.noreply.github.com>
Signed-off-by: yibinl-nvidia <109242046+yibinl-nvidia@users.noreply.github.com>
Signed-off-by: yibinl-nvidia <109242046+yibinl-nvidia@users.noreply.github.com>
Signed-off-by: yibinl-nvidia <109242046+yibinl-nvidia@users.noreply.github.com>
Signed-off-by: yibinl-nvidia <109242046+yibinl-nvidia@users.noreply.github.com>
Signed-off-by: yibinl-nvidia <109242046+yibinl-nvidia@users.noreply.github.com>
Signed-off-by: Yibin Li <109242046+yibinl-nvidia@users.noreply.github.com>
@yibinl-nvidia
yibinl-nvidia force-pushed the qwen-image-cfg-parallel branch from 3f4ae7b to 7ed9254 Compare July 30, 2026 02:25
@yibinl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62654 [ run ] triggered by Bot. Commit: 7ed9254 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62654 [ run ] completed with state SUCCESS. Commit: 7ed9254
/LLM/main/L0_MergeRequest_PR pipeline #50794 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@yibinl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62677 [ run ] triggered by Bot. Commit: 7ed9254 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62677 [ run ] completed with state SUCCESS. Commit: 7ed9254
/LLM/main/L0_MergeRequest_PR pipeline #50817 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

Signed-off-by: Yibin Li <109242046+yibinl-nvidia@users.noreply.github.com>
@yibinl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62791 [ run ] triggered by Bot. Commit: 9bce31b Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62791 [ run ] completed with state FAILURE. Commit: 9bce31b
/LLM/main/L0_MergeRequest_PR pipeline #50919 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@yibinl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62806 [ run ] triggered by Bot. Commit: 9bce31b Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62806 [ run ] completed with state SUCCESS. Commit: 9bce31b
/LLM/main/L0_MergeRequest_PR pipeline #50931 completed with status: 'SUCCESS'

CI Report

Link to invocation

@yibinl-nvidia
yibinl-nvidia merged commit c083da6 into NVIDIA:main Jul 30, 2026
7 checks passed
@yibinl-nvidia
yibinl-nvidia deleted the qwen-image-cfg-parallel branch July 31, 2026 22:54
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.

4 participants