[TRTLLM-14287][feat] Qwen Image CFG parallelism support - #16384
Conversation
📝 WalkthroughWalkthroughChangesQwen-Image CFG parallel generation
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
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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 valueLoosely-typed
cfg_pgreturn value.The return type is annotated
Tuple[bool, int, int, object], butvisual_gen_mapping.cfg_groupreturnsOptional[ProcessGroup](pertensorrt_llm/_torch/visual_gen/mapping.py). Usingobjectloses 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 winInsufficient coverage:
_cfg_parallel_state's error/fallback branches are untested.Only the
do_true_cfg=True/Falsehappy paths (cfg_size=2,dist.is_initialized()==True) are tested. Missing:
cfg_size != 2withdo_true_cfg=True→ should raiseValueError.dist.is_initialized() == Falsewithdo_true_cfg=True,cfg_size==2→ should raiseRuntimeError.visual_gen_mappingisNone/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_gatherpath, so coverage here is worth adding intest_qwen_image_registry.pybefore 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
📒 Files selected for processing (2)
tensorrt_llm/_torch/visual_gen/models/qwen_image/pipeline_qwen_image.pytests/unittest/_torch/visual_gen/test_qwen_image_registry.py
8a4db36 to
0971712
Compare
|
/bot run |
|
PR_Github #59274 [ run ] triggered by Bot. Commit: |
|
PR_Github #59274 [ run ] completed with state
|
0971712 to
903f4df
Compare
|
/bot run |
|
PR_Github #59288 [ run ] triggered by Bot. Commit: |
|
/bot kill |
|
PR_Github #59293 [ kill ] triggered by Bot. Commit: |
|
PR_Github #59288 [ run ] completed with state |
|
PR_Github #59293 [ kill ] completed with state |
|
/bot run |
1 similar comment
|
/bot run |
|
PR_Github #59294 [ run ] triggered by Bot. Commit: |
|
PR_Github #59294 [ run ] completed with state |
|
PR_Github #62310 [ run ] triggered by Bot. Commit: |
|
PR_Github #62310 [ run ] completed with state
|
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>
3f4ae7b to
7ed9254
Compare
|
/bot run |
|
PR_Github #62654 [ run ] triggered by Bot. Commit: |
|
PR_Github #62654 [ run ] completed with state
|
|
/bot run |
|
PR_Github #62677 [ run ] triggered by Bot. Commit: |
|
PR_Github #62677 [ run ] completed with state
|
Signed-off-by: Yibin Li <109242046+yibinl-nvidia@users.noreply.github.com>
|
/bot run |
|
PR_Github #62791 [ run ] triggered by Bot. Commit: |
|
PR_Github #62791 [ run ] completed with state
|
|
/bot run |
|
PR_Github #62806 [ run ] triggered by Bot. Commit: |
|
PR_Github #62806 [ run ] completed with state |
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Description
Measured with explicit negative_prompt="", 1328x1328, 50 steps.
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-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin 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.