Skip to content

[TRTLLM-12133][fix] refactor VisualGen examples - #13298

Closed
o-stoner wants to merge 6 commits into
NVIDIA:mainfrom
o-stoner:user/o-stoner/visual-gen-refactor-examples
Closed

[TRTLLM-12133][fix] refactor VisualGen examples#13298
o-stoner wants to merge 6 commits into
NVIDIA:mainfrom
o-stoner:user/o-stoner/visual-gen-refactor-examples

Conversation

@o-stoner

@o-stoner o-stoner commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Refactor
    • Consolidated visual generation example scripts by delegating CLI argument parsing and configuration management to shared utilities.
    • Unified configuration handling for cache, quantization, attention backend, and optimization settings across examples.
    • Added new utility module providing reusable configuration helpers for visual generation examples.

Description

Cache-DiT integration resulted in many redundant functions across pipeline example files (Wan, LTX-2, FLUX.2). For example, the _cache_dit_config_from_args() helper is repeated across all example scripts. In this PR, we extract these redundant example functions found into a shared example utility. Additionally, we enable a missing FA4 attention backend for LTX-2 in the example scripts.

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)

  • 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.

@o-stoner

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #44817 [ run ] triggered by Bot. Commit: 46f0b59 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #44817 [ run ] completed with state SUCCESS. Commit: 46f0b59
/LLM/main/L0_MergeRequest_PR pipeline #35165 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

Link to invocation

@o-stoner

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #45001 [ run ] triggered by Bot. Commit: 59c4125 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #45001 [ run ] completed with state SUCCESS. Commit: 59c4125
/LLM/main/L0_MergeRequest_PR pipeline #35320 completed with status: 'SUCCESS'

CI Report

Link to invocation

@o-stoner
o-stoner force-pushed the user/o-stoner/visual-gen-refactor-examples branch from 59c4125 to 9b08bd5 Compare April 23, 2026 02:27

@zhenhuaw-me zhenhuaw-me left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer standalone per-model examples, i.e., no shared utils across examples, but since we are switching to new style example. Should be fine to have this fix in short term.


"""Shared argparse helpers for visual-generation example scripts."""

from tensorrt_llm._torch.visual_gen.config import CacheDiTConfig, TeaCacheConfig

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is one of the reasons that why I want to switch to the new style example - keep CLI interface and dict/yaml config synced is painful...

@o-stoner

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@o-stoner
o-stoner marked this pull request as ready for review April 24, 2026 22:51
@o-stoner
o-stoner requested review from a team as code owners April 24, 2026 22:51
@o-stoner
o-stoner requested review from chang-l and venkywonka April 24, 2026 22:51
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #45454 [ run ] triggered by Bot. Commit: 3927b61 Link to invocation

@coderabbitai

coderabbitai Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

A refactoring that centralizes CLI argument registration and configuration building for cache, quantization, attention backend, and optimization settings across visual generation examples into new shared utilities, removing duplicate code from four example scripts.

Changes

Cohort / File(s) Summary
New Shared Utilities
tensorrt_llm/_torch/visual_gen/example_utils.py, tensorrt_llm/_torch/visual_gen/utils.py
Added new helper module with reusable CLI argument registration functions (add_cache_args, add_cache_dit_args, add_quant_args, add_attention_backend_args, add_optimization_args) and config builders (build_cache_config, build_cache_dit_config, build_teacache_config). Also added linear_type_to_quant_config utility for quantization mapping.
Example Scripts Refactored
examples/visual_gen/visual_gen_flux.py, visual_gen_ltx2.py, visual_gen_wan_i2v.py, visual_gen_wan_t2v.py
Replaced inline CLI argument definitions and local helper functions with calls to shared utilities. Each script now delegates cache, quantization, attention backend, and optimization argument registration to centralized functions, removing duplicate code.
Test Update
tests/integration/defs/examples/test_visual_gen.py
Removed local _linear_type_to_quant_config mapping and updated test functions to use the imported linear_type_to_quant_config from the shared utilities module.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: refactoring VisualGen examples to extract redundant helper functions into shared utilities.
Description check ✅ Passed The description section explains the issue (redundant functions across example scripts) and solution (extracting into shared utility), but Test Coverage section is blank and should have been populated.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@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.

🧹 Nitpick comments (2)
tensorrt_llm/_torch/visual_gen/example_utils.py (1)

159-169: Consider a more specific return type annotation.

The return type could be more precise to aid type checking.

Suggested improvement
-def build_cache_config(args) -> dict:
+def build_cache_config(args) -> dict[str, CacheDiTConfig | TeaCacheConfig]:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tensorrt_llm/_torch/visual_gen/example_utils.py` around lines 159 - 169, The
function build_cache_config currently uses a broad return type of dict; change
its signature to a more specific type such as Dict[str, Any] (or Mapping[str,
Any]) to improve type checking and IDE hints, and update the import from typing
accordingly; ensure the signature for build_cache_config(args) -> Dict[str, Any]
(or -> Mapping[str, Any]) and keep the returned keys compatible with
VisualGenArgs by referencing the same "cache" key produced by
build_cache_dit_config and build_teacache_config.
tensorrt_llm/_torch/visual_gen/utils.py (1)

38-45: Add return type annotation.

Per coding guidelines, Python functions should always have return type annotations.

Suggested fix
-def linear_type_to_quant_config(linear_type: str):
+def linear_type_to_quant_config(linear_type: str) -> dict | None:
     """Map a --linear_type CLI shortcut to a quant_config dict for VisualGenArgs."""
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tensorrt_llm/_torch/visual_gen/utils.py` around lines 38 - 45, The function
linear_type_to_quant_config lacks a return type annotation; update its signature
to include an explicit return type (e.g. -> Optional[Dict[str, Any]]) and add
the required typing imports (Optional, Dict, Any) if not already present so the
mapping return value or None is correctly typed; keep the function body
unchanged and ensure the annotation references the same function name
linear_type_to_quant_config.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tensorrt_llm/_torch/visual_gen/example_utils.py`:
- Around line 159-169: The function build_cache_config currently uses a broad
return type of dict; change its signature to a more specific type such as
Dict[str, Any] (or Mapping[str, Any]) to improve type checking and IDE hints,
and update the import from typing accordingly; ensure the signature for
build_cache_config(args) -> Dict[str, Any] (or -> Mapping[str, Any]) and keep
the returned keys compatible with VisualGenArgs by referencing the same "cache"
key produced by build_cache_dit_config and build_teacache_config.

In `@tensorrt_llm/_torch/visual_gen/utils.py`:
- Around line 38-45: The function linear_type_to_quant_config lacks a return
type annotation; update its signature to include an explicit return type (e.g.
-> Optional[Dict[str, Any]]) and add the required typing imports (Optional,
Dict, Any) if not already present so the mapping return value or None is
correctly typed; keep the function body unchanged and ensure the annotation
references the same function name linear_type_to_quant_config.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: baf7511f-bb55-4b60-8896-b43d2a50c8d9

📥 Commits

Reviewing files that changed from the base of the PR and between 23ff7d5 and 3927b61.

📒 Files selected for processing (7)
  • examples/visual_gen/visual_gen_flux.py
  • examples/visual_gen/visual_gen_ltx2.py
  • examples/visual_gen/visual_gen_wan_i2v.py
  • examples/visual_gen/visual_gen_wan_t2v.py
  • tensorrt_llm/_torch/visual_gen/example_utils.py
  • tensorrt_llm/_torch/visual_gen/utils.py
  • tests/integration/defs/examples/test_visual_gen.py

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #45454 [ run ] completed with state SUCCESS. Commit: 3927b61
/LLM/main/L0_MergeRequest_PR pipeline #35686 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

Link to invocation

@o-stoner
o-stoner force-pushed the user/o-stoner/visual-gen-refactor-examples branch 2 times, most recently from 49521dc to 5bdbec3 Compare May 4, 2026 20:29
@o-stoner

o-stoner commented May 4, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast --add-multi-gpu-test

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #46685 [ run ] triggered by Bot. Commit: 5bdbec3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #46685 [ run ] completed with state SUCCESS. Commit: 5bdbec3
/LLM/main/L0_MergeRequest_PR pipeline #36724 completed with status: 'SUCCESS'

CI Report

Link to invocation

o-stoner added 4 commits May 12, 2026 16:57
Signed-off-by: Olivia Stoner <245287810+o-stoner@users.noreply.github.com>
Signed-off-by: Olivia Stoner <245287810+o-stoner@users.noreply.github.com>
Signed-off-by: Olivia Stoner <245287810+o-stoner@users.noreply.github.com>
Signed-off-by: Olivia Stoner <245287810+o-stoner@users.noreply.github.com>
@o-stoner
o-stoner force-pushed the user/o-stoner/visual-gen-refactor-examples branch from 1d6c144 to def1d59 Compare May 13, 2026 00:29
@o-stoner

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast --add-multi-gpu-test

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #48054 [ run ] triggered by Bot. Commit: def1d59 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #48054 [ run ] completed with state SUCCESS. Commit: def1d59
/LLM/main/L0_MergeRequest_PR pipeline #37888 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

o-stoner added 2 commits May 13, 2026 16:17
Signed-off-by: Olivia Stoner <245287810+o-stoner@users.noreply.github.com>
Signed-off-by: o-stoner <245287810+o-stoner@users.noreply.github.com>
@o-stoner

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast --add-multi-gpu-test

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #48252 [ run ] triggered by Bot. Commit: f121734 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #48252 [ run ] completed with state SUCCESS. Commit: f121734
/LLM/main/L0_MergeRequest_PR pipeline #38067 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

Link to invocation

@o-stoner

o-stoner commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

These examples scripts being refactored have been updated/removed in #14632; closing.

@o-stoner o-stoner closed this Jun 8, 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.

3 participants