Skip to content

[TRTLLM-11804][feat] Mechanical refactoring VisualGen API#12807

Open
zhenhuaw-me wants to merge 1 commit intoNVIDIA:mainfrom
zhenhuaw-me:update-api-step1
Open

[TRTLLM-11804][feat] Mechanical refactoring VisualGen API#12807
zhenhuaw-me wants to merge 1 commit intoNVIDIA:mainfrom
zhenhuaw-me:update-api-step1

Conversation

@zhenhuaw-me
Copy link
Copy Markdown
Member

@zhenhuaw-me zhenhuaw-me commented Apr 7, 2026

  • Move VisualGenArgs to public visual_gen/args.py; remove to_dict()/from_dict()
  • Rename VisualGen constructor params: model_path→model, diffusion_args→args
  • Add VisualGenError exception class; replace bare RuntimeError raises
  • Rename DiffusionGenerationResult→VisualGenResult; add done property and result_sync()
  • Fix req_counter thread safety with itertools.count()
  • Export VisualGenArgs, VisualGenError, VisualGenResult from public init.py files
  • Update all callers: serve, bench, examples, tests

Summary by CodeRabbit

  • Breaking Changes

    • Updated VisualGen constructor parameters: use model and args instead of model_path and diffusion_args.
  • New Features

    • Introduced VisualGenError exception for improved error handling in visual generation tasks.
    • Added VisualGenResult with a new result_sync() method for synchronous result retrieval and a done property for checking completion status.

Description

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.

# from tensorrt_llm.visual_gen.args import VisualGenArgs
# from tensorrt_llm.visual_gen import VisualGenArgs
# from tensorrt_llm import VisualGenArgs
from tensorrt_llm._torch.visual_gen.config import VisualGenArgs
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note for reviewers: VisualGenArgs needs more work to refactor, so not moved here in this PR.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2026

📝 Walkthrough

Walkthrough

The pull request refactors the VisualGen API by renaming constructor parameters (model_pathmodel, diffusion_argsargs), introducing new public exception and result types (VisualGenError, VisualGenResult), removing serialization methods from VisualGenArgs, and reorganizing public API imports throughout the tensorrt_llm package.

Changes

Cohort / File(s) Summary
Example Visual Generation Scripts
examples/visual_gen/quickstart_example.py, 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
Updated VisualGen constructor calls to use new parameter names: model (instead of model_path) and args (instead of diffusion_args).
Core VisualGen Implementation
tensorrt_llm/visual_gen/visual_gen.py
Refactored constructor signature (model/args parameters), introduced VisualGenError exception and VisualGenResult result type (replacing DiffusionGenerationResult), added done property and result_sync() method to result type, updated error handling to raise VisualGenError on generation failures, changed request counter from manual to itertools.count().
Configuration and Serialization
tensorrt_llm/_torch/visual_gen/config.py
Removed to_dict() and from_dict() methods from VisualGenArgs class; retained to_mapping() and from_yaml() methods.
Public API Exports
tensorrt_llm/__init__.py, tensorrt_llm/visual_gen/__init__.py
Reorganized imports: changed VisualGenArgs source path, added VisualGenError and VisualGenResult to public exports in both modules.
Public Args Module
tensorrt_llm/visual_gen/args.py
New module providing canonical public import path for VisualGenArgs with re-export via __all__.
Infrastructure and Serve
tensorrt_llm/commands/serve.py, tensorrt_llm/bench/benchmark/visual_gen.py
Updated VisualGen instantiation calls to use new constructor parameters; updated attribute access in serve.py from diffusion_args to args.
Tests
tests/integration/defs/examples/test_visual_gen.py, tests/unittest/_torch/visual_gen/test_visual_gen_args.py
Updated test fixtures and construction calls to reflect new parameter names; replaced from_dict() usage with direct keyword expansion; updated mocked attributes (model_pathmodel, diffusion_argsargs, req_counter_req_counter).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description lists specific changes but lacks explanation of why these changes were made or their business impact. Required sections like 'Description', 'Test Coverage', and PR Checklist are incomplete. Add a 'Description' section explaining the motivation and benefits of the refactoring, document which tests validate these changes under 'Test Coverage', and ensure all PR Checklist items are properly reviewed before submission.
Docstring Coverage ⚠️ Warning Docstring coverage is 44.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: a mechanical refactoring of the VisualGen API with parameter renames and structural improvements.

✏️ 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

36-36: Sort __all__ for consistency with linter rules.

Static analysis flags that __all__ is not sorted. Consider applying isort-style sorting:

-__all__ = ["VisualGen", "VisualGenParams", "MediaOutput", "VisualGenError", "VisualGenResult"]
+__all__ = ["MediaOutput", "VisualGen", "VisualGenError", "VisualGenParams", "VisualGenResult"]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tensorrt_llm/visual_gen/visual_gen.py` at line 36, The __all__ export list is
unsorted; update the __all__ declaration so its entries are in sorted
(isort-style) alphabetical order to satisfy the linter. Locate the __all__
assignment (containing "VisualGen", "VisualGenParams", "MediaOutput",
"VisualGenError", "VisualGenResult") and reorder the items alphabetically (by
name) while preserving the same symbols and string formatting.
tensorrt_llm/visual_gen/__init__.py (1)

18-25: Sort __all__ for consistency.

Static analysis flags the unsorted __all__. Consider alphabetical ordering:

♻️ Proposed fix
 __all__ = [
-    "VisualGen",
-    "VisualGenArgs",
-    "VisualGenError",
-    "VisualGenParams",
-    "VisualGenResult",
     "MediaOutput",
+    "VisualGen",
+    "VisualGenArgs",
+    "VisualGenError",
+    "VisualGenParams",
+    "VisualGenResult",
 ]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tensorrt_llm/visual_gen/__init__.py` around lines 18 - 25, The __all__ list
is unsorted; update it to be alphabetically ordered to satisfy static analysis.
Locate the __all__ definition in tensorrt_llm.visual_gen.__init__ and reorder
the exported symbols (VisualGen, VisualGenArgs, VisualGenError, VisualGenParams,
VisualGenResult, MediaOutput) into alphabetical order so the list is stable and
passes linting.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tensorrt_llm/__init__.py`:
- Around line 135-136: The import line importing VisualGen, VisualGenArgs,
VisualGenError, VisualGenParams, VisualGenResult from .visual_gen incorrectly
includes a stale "# noqa: F811 (VisualGenArgs already imported above)" comment;
remove that inline noqa comment so the import reads normally without the F811
suppression. Locate the import statement that references
VisualGen/VisualGenArgs/VisualGenError/VisualGenParams/VisualGenResult and
delete only the trailing noqa comment text.

In `@tensorrt_llm/visual_gen/visual_gen.py`:
- Around line 428-434: result_sync calls result() via
asyncio.run_coroutine_threadsafe but if timeout expires await_responses can
return None causing result() to access response.error_msg and raise
AttributeError; update result_sync/result to check for a None response from
await_responses (or from result()) and handle it explicitly (e.g., raise a
TimeoutError or return a clear error object/string) instead of dereferencing
response.error_msg—look at the result_sync, result, and await_responses paths
and add a None-check and appropriate error handling/raise when response is None.

---

Nitpick comments:
In `@tensorrt_llm/visual_gen/__init__.py`:
- Around line 18-25: The __all__ list is unsorted; update it to be
alphabetically ordered to satisfy static analysis. Locate the __all__ definition
in tensorrt_llm.visual_gen.__init__ and reorder the exported symbols (VisualGen,
VisualGenArgs, VisualGenError, VisualGenParams, VisualGenResult, MediaOutput)
into alphabetical order so the list is stable and passes linting.

In `@tensorrt_llm/visual_gen/visual_gen.py`:
- Line 36: The __all__ export list is unsorted; update the __all__ declaration
so its entries are in sorted (isort-style) alphabetical order to satisfy the
linter. Locate the __all__ assignment (containing "VisualGen",
"VisualGenParams", "MediaOutput", "VisualGenError", "VisualGenResult") and
reorder the items alphabetically (by name) while preserving the same symbols and
string formatting.
🪄 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: Pro

Run ID: 623e7db0-2bac-4882-8242-b86aa7664351

📥 Commits

Reviewing files that changed from the base of the PR and between ace1338 and 718eca3.

📒 Files selected for processing (14)
  • examples/visual_gen/quickstart_example.py
  • 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/__init__.py
  • tensorrt_llm/_torch/visual_gen/config.py
  • tensorrt_llm/bench/benchmark/visual_gen.py
  • tensorrt_llm/commands/serve.py
  • tensorrt_llm/visual_gen/__init__.py
  • tensorrt_llm/visual_gen/args.py
  • tensorrt_llm/visual_gen/visual_gen.py
  • tests/integration/defs/examples/test_visual_gen.py
  • tests/unittest/_torch/visual_gen/test_visual_gen_args.py
💤 Files with no reviewable changes (1)
  • tensorrt_llm/_torch/visual_gen/config.py

@zhenhuaw-me
Copy link
Copy Markdown
Member Author

/bot run

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #42245 [ run ] triggered by Bot. Commit: ff3ab43 Link to invocation

- Move VisualGenArgs to public visual_gen/args.py; remove to_dict()/from_dict()
- Rename VisualGen constructor params: model_path→model, diffusion_args→args
- Add VisualGenError exception class; replace bare RuntimeError raises
- Rename DiffusionGenerationResult→VisualGenResult; add done property and result_sync()
- Fix req_counter thread safety with itertools.count()
- Export VisualGenArgs, VisualGenError, VisualGenResult from public __init__.py files
- Update all callers: serve, bench, examples, tests

Signed-off-by: Zhenhua Wang <zhenhuaw@nvidia.com>
@zhenhuaw-me
Copy link
Copy Markdown
Member Author

/bot run

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #42281 [ run ] triggered by Bot. Commit: 7bb6074 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Collaborator

@QiJune QiJune left a comment

Choose a reason for hiding this comment

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

LGTM

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.

3 participants