Skip to content

[None][feat] Cosmos3 video-to-video (V2V) generation - #16155

Open
ishovkun wants to merge 48 commits into
NVIDIA:mainfrom
ishovkun:cosmos_v2v
Open

[None][feat] Cosmos3 video-to-video (V2V) generation#16155
ishovkun wants to merge 48 commits into
NVIDIA:mainfrom
ishovkun:cosmos_v2v

Conversation

@ishovkun

@ishovkun ishovkun commented Jul 8, 2026

Copy link
Copy Markdown

Dev Engineer Review

  • Added Cosmos3 offline video-to-video (V2V) generation by conditioning on a reference video payload, including request→pipeline wiring for:
    • video (reference bytes)
    • condition_video_latent_indexes
    • condition_video_keep
    • flow_shift
  • Implemented conditioning-window computation and V2V latent preparation/conditioning in the Cosmos3 pipeline, plus “pinning” of clean conditioning latents during the denoise loop when V2V conditioning is active.
  • Strengthened Cosmos3 request/schema validation and defaults:
    • use_system_prompt is now tri-state (None = model decides; CLI supports --no-use_system_prompt)
    • condition_video_latent_indexes normalization/validation (integer, non-empty, non-negative)
    • condition_video_keep restricted to first/last
    • output_type validated, and preflight rejects invalid modality combinations (e.g., image+video together; V2V only for video outputs)
  • Added worker-side media decoding for V2V references:
    • NVDEC via PyNvVideoCodec with a fixed conditioning window
    • decode-frame limiting via TRTLLM_MAX_REFERENCE_DECODE_FRAMES / DEFAULT_MAX_REFERENCE_DECODE_FRAMES (default 7200; 0 disables)
    • client vs capacity error classification and distributed synchronization to avoid deadlocks when some ranks fail
  • Extended the OpenAI-style “videos” API input handling:
    • input_reference now supports image or video payloads using content/container sniffing (not filename/MIME)
    • undecodable/unrecognized references are rejected as HTTP 400
    • capacity decode failures map to HTTP 503 via a dedicated endpoint handler using VisualGenCapacityError
    • num_frames upper bound now uses shared MAX_VIDEO_FRAMES
  • Added Cosmos3 action-generation groundwork (transformer/output plumbing):
    • action token RoPE offset support, DomainAwareLinear, action injection/packing into transformer forward, and new optional action inputs/outputs
    • output conversion now propagates action tensors and metadata (mode/domain/dim)
    • forward-time validation for action/audio incompatibility and missing action-module initialization
    • Follow-up recommended: verify end-to-end request routing, action-generation modes/presets, and API parameter wiring (not fully evidenced in the provided excerpts).
  • Consistency check: Cosmos3 system prompt constants include an intentional “give” typo—verify whether this is a known/intentional value and consistent with expected prompt behavior.

QA Engineer Review

Test code changes (files outside tests/integration/test_lists/)

  • tests/unittest/_torch/visual_gen/test_cosmos3_pipeline.py

    • Added/expanded: scheduler configuration assertions (flow-shift + use_karras_sigmas), V2V conditioning defaults/normalization tests (incl. error cases), flow-shift propagation override, modality rejection (image+video; V2V with output_type="image"), and prompt/tokenization role behavior (new system-prompt-default variant).
    • Coverage in tests/integration/test_lists/: not listed in the updated CI test-db entry provided (needs follow-up).
    • Verdict: needs follow-up.
  • tests/unittest/_torch/visual_gen/test_trtllm_serve_endpoints.py

    • Added/expanded: MP4 multipart input_reference success routing to params.extra_params["video"]; invalid non-media input_reference returns HTTP 400; adjusted multipart image reference naming expectation.
    • Coverage in tests/integration/test_lists/: not listed in provided update (needs follow-up).
    • Verdict: needs follow-up.
  • tests/unittest/_torch/visual_gen/test_visual_gen_utils.py

    • Added/expanded: parse_visual_gen_params routing for base64/multipart MP4+AVI→extra_params["video"], JPEG→params.image, undecodable/malformed base64 rejection with cleanup, and media probing/sniffing unit tests.
    • Coverage in tests/integration/test_lists/: not listed in provided update (needs follow-up).
    • Verdict: needs follow-up.
  • tests/unittest/_torch/visual_gen/test_media_decode.py

    • Added: resize/center-crop parity tests; lanczos tap behavior; import isolation ensuring PyNvVideoCodec not eagerly loaded; distributed synchronization convergence tests; decode limit parsing (0 disables) and GPU-gated correctness/perf for decoding window behavior.
    • Coverage in tests/integration/test_lists/: Yes (unittest/_torch/visual_gen/test_media_decode.py added).
    • Verdict: sufficient for the updated test-db scope.
  • tests/unittest/_torch/visual_gen/test_visual_gen_params.py

    • Added: extra-param validator execution semantics (including deterministic client errors), validator TypeError→ValueError conversion, and pickling round-trip for validator functions in COSMOS3_EXTRA_SPECS.
    • Coverage in tests/integration/test_lists/: not listed in provided update (needs follow-up).
    • Verdict: needs follow-up.
  • tests/unittest/visual_gen/test_output.py

    • Added: single-prompt error routing based on worker error_type, including mapping "capacity"VisualGenCapacityError, plus batch behavior ensuring errors populate per-item without raising.
    • Coverage in tests/integration/test_lists/: not listed in provided update (needs follow-up).
    • Verdict: needs follow-up.

Integration test code changes

  • tests/integration/defs/examples/visual_gen/test_visual_gen.py
    • Added: test_cosmos3_nano_v2v_lpips_against_golden (CUDA-gated) covering V2V LPIPS comparison using an input video payload.
    • Coverage in tests/integration/test_lists/: Yes (examples/visual_gen/test_visual_gen.py::test_cosmos3_nano_v2v_lpips_against_golden added).
    • Verdict: sufficient for the updated test-db scope.

Test-list changes

  • tests/integration/test_lists/test-db/l0_b200.yml
    • Added:
      • unittest/_torch/visual_gen/test_media_decode.py
      • examples/visual_gen/test_visual_gen.py::test_cosmos3_nano_v2v_lpips_against_golden (TIMEOUT (10))
  • Verdict: needs follow-up (other modified unittest coverage is not reflected in the provided updated test-db entry).
    </final_summary>

Description

Adds video-conditioned generation (V2V) for Cosmos3, offline and via the
OpenAI-style videos API, plus the action-generation groundwork it builds on.

  • Pipeline: pinned condition latents (default indexes [0,1] = first 5
    input frames), velocity masking + post-step re-injection of clean latents,
    flow_shift=10.0 with Karras sigmas forced off (restored per request),
    condition_frame_indexes_vision / condition_video_keep request params,
    shared video decode utils (.mp4/.avi file, frame directory, image, PIL
    list). Mode selection is implicit: a video input without an action mode runs
    V2V. Faithful to the vllm-omni reference implementation.
  • Serving: input_reference on the videos API is now classified by
    decoding its content (PIL-readable → image/I2V, PyAV-readable video stream →
    video/V2V); filename and content-type are ignored. Video uploads route to
    the same pipeline entry as the offline path; undecodable content returns
    HTTP 400; base64-JSON video references work. Image-reference behavior is
    byte-identical to before. No request-schema changes (input_reference
    type/default untouched — api-compatible).
  • Action generation (policy / forward_dynamics / inverse_dynamics),
    embodiment domain presets, action_fps — included because V2V structurally
    reuses this machinery (VAE video encode, --video_path CLI, video
    normalize helpers extracted into shared utils.py).
  • Docs: Cosmos3 example README (V2V mode + media I/O dependencies), serve
    README (input_reference semantics, V2V curl, Cosmos3 extra_params),
    prompts/v2v.json. No media assets ship with the repo — examples point at
    the checkpoint's own assets/; test videos are synthesized with PyAV/PIL.
  • New dependency: av (PyAV) in requirements.txt — video reference
    decode (torchvision read_video backend) and serve-side classification.

Validated on Cosmos3-Nano (1x B200): offline and served V2V outputs pin the
conditioning frames (frame-0 pixel MAE ≈ 2 vs ≈ 18 different-frame scale) and
diverge afterwards; I2V upload path regression-checked; garbage upload returns
a clean 400.

The default system prompt intentionally says "a give prompt" — it matches the
model's training data; please do not "fix" it in review.

Test Coverage

  • tests/unittest/_torch/visual_gen/test_cosmos3_pipeline.py -k v2v
    checkpoint-gated GPU suite (skips without DIFFUSION_MODEL_PATH_COSMOS3 /
    LLM_MODELS_ROOT): V2V smoke, condition_video_keep="last" behavioral test
    (dark-head/bright-tail input → output must track the tail), audio+V2V smoke,
    conditioning-param normalization, flow-shift request path,
    _prepare_latents_v2v values.
  • tests/unittest/_torch/visual_gen/test_visual_gen_utils.py — CPU:
    content-classifier and routing units (mp4 upload → extra_params["video"],
    base64 mp4, JPEG → image, undecodable → 400 + temp-file cleanup).
  • tests/unittest/_torch/visual_gen/test_trtllm_serve_endpoints.py — CPU,
    mock generator: multipart video reference → V2V routing with .mp4 suffix;
    undecodable reference → HTTP 400; existing image-reference tests cover the
    I2V regression.
  • tests/unittest/_torch/visual_gen/test_cosmos3_action.py and
    multi_gpu/test_cosmos3_transformer_parallel.py — action-generation
    coverage from the underlying commits.

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.

@ishovkun

ishovkun commented Jul 8, 2026

Copy link
Copy Markdown
Author

/bot run

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 9ee52845-b24e-47e5-bb0e-63b6fddd5c7d

📥 Commits

Reviewing files that changed from the base of the PR and between 9cf90e6 and e8eeada.

📒 Files selected for processing (1)
  • tests/unittest/visual_gen/test_output.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/unittest/visual_gen/test_output.py

Walkthrough

Cosmos3 gains V2V reference-video conditioning, action-modality support, NVDEC decoding, content-based media routing, classified failures, expanded outputs, CLI examples, documentation, and unit/integration coverage.

Changes

Cosmos3 V2V and action generation

Layer / File(s) Summary
Generation and media contracts
tensorrt_llm/_torch/visual_gen/models/cosmos3/defaults.py, tensorrt_llm/inputs/media_io.py, tensorrt_llm/visual_gen/*, tensorrt_llm/_torch/visual_gen/output.py
Adds V2V validators, media classification, byte validation, classified errors, and action output metadata.
Reference media routing and worker decoding
tensorrt_llm/serve/visual_gen_utils.py, tensorrt_llm/_torch/visual_gen/media_decode.py, tensorrt_llm/serve/openai_video_routes.py
Routes image/video references by content, decodes conditioning windows through NVDEC, synchronizes worker failures, and returns capacity failures as HTTP 503.
Cosmos3 V2V pipeline execution
tensorrt_llm/_torch/visual_gen/models/cosmos3/pipeline_cosmos3.py
Passes V2V parameters through inference, prepares conditioned latents, applies request scheduler settings, and pins clean reference latents during denoising.
Action transformer modality
tensorrt_llm/_torch/visual_gen/models/cosmos3/transformer_cosmos3.py
Adds action embeddings, domain-aware projections, positional encoding, token injection, decoding, validation, and checkpoint loading.
Examples and validation
examples/visual_gen/models/cosmos3/*, examples/visual_gen/serve/README.md, tests/unittest/_torch/visual_gen/*, tests/integration/defs/examples/visual_gen/*
Adds V2V examples and documentation plus media-decoding, serving, scheduler, prompt, and LPIPS coverage.
Repository and dependency support
requirements.txt, .gitignore
Adds PyNvVideoCodec and ignores editor/planning paths.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

  • NVIDIA/TensorRT-LLM#12922: Extends the VisualGenParams and extra_params validation infrastructure used by the Cosmos3 V2V validators.

Suggested reviewers: laikhtewari, yiqingy0, mikeiovine, jieli-matrix, cascade812

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant VisualGenServe
  participant Cosmos3Pipeline
  participant NVDEC
  participant Transformer
  Client->>VisualGenServe: submit image or video reference
  VisualGenServe->>VisualGenServe: classify and validate payload
  VisualGenServe->>Cosmos3Pipeline: pass V2V video bytes
  Cosmos3Pipeline->>NVDEC: decode conditioning window
  NVDEC-->>Cosmos3Pipeline: resized RGB frames
  Cosmos3Pipeline->>Transformer: denoise video and optional action streams
  Transformer-->>Cosmos3Pipeline: video, audio, or action outputs
  Cosmos3Pipeline-->>Client: visual generation response
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.83% 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 is concise and accurately summarizes the main change: Cosmos3 V2V generation.
Description check ✅ Passed The description includes the required Description, Test Coverage, and PR Checklist sections and is detailed enough.
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.
✨ 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: 3

🧹 Nitpick comments (8)
tensorrt_llm/_torch/visual_gen/pipeline.py (1)

1183-1188: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Hoist inspect.signature() out of the per-step loop.

post_step_fn's arity never changes across denoising steps, so recomputing inspect.signature() on every iteration is unnecessary reflection overhead in the hot path. Compute it once before the loop.

♻️ Proposed fix
+        post_step_takes_extra = (
+            post_step_fn is not None and len(inspect.signature(post_step_fn).parameters) >= 2
+        )
+
         for i, t in enumerate(timesteps):
             ...
             if post_step_fn is not None:
-                sig = inspect.signature(post_step_fn)
-                if len(sig.parameters) >= 2:
+                if post_step_takes_extra:
                     latents, extra_stream_latents = post_step_fn(latents, extra_stream_latents)
                 else:
                     latents = post_step_fn(latents)

As per coding guidelines, "Avoid using reflection when functionality can be easily achieved without reflection."

🤖 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/pipeline.py` around lines 1183 - 1188, The
denoising loop in the pipeline hot path recomputes post_step_fn arity with
inspect.signature() on every step, which is unnecessary reflection overhead.
Move the signature inspection for post_step_fn out of the per-step loop in the
pipeline logic, cache the parameter count once before iterating, and reuse that
result inside the loop when deciding whether to call post_step_fn with one or
two arguments.

Source: Coding guidelines

tensorrt_llm/_torch/visual_gen/models/cosmos3/utils.py (2)

17-57: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add docstrings to the public helper functions.

pil_to_rgb, decode_video_file, and normalize_video_input_path have no docstrings, while normalize_video_input does. Since none of these are underscore-prefixed, they're part of this module's public interface and should be documented (Google style), similar to normalize_video_input.

As per coding guidelines, "For interfaces that may be used outside a file, prefer docstrings over comments."

🤖 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/cosmos3/utils.py` around lines 17 - 57,
The public helper functions pil_to_rgb, decode_video_file, and
normalize_video_input_path are missing docstrings, unlike normalize_video_input.
Add Google-style docstrings to each function that describe its purpose,
arguments, return values, and raised errors as applicable, keeping the
documentation consistent with the module’s existing public API style.

Source: Coding guidelines


8-9: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use modern typing style (list[...], X | None) instead of typing.List/typing.Optional.

This is a new file, so it's a good opportunity to follow the guideline directly rather than mixing legacy typing conventions.

♻️ Proposed fix
-from typing import Any, List, Optional
+from typing import Any

-def decode_video_file(path: Path, max_frames: Optional[int] = None) -> List[PIL.Image.Image]:
+def decode_video_file(path: Path, max_frames: int | None = None) -> list[PIL.Image.Image]:

-def normalize_video_input_path(path: Path, max_frames: Optional[int] = None) -> List[Any]:
+def normalize_video_input_path(path: Path, max_frames: int | None = None) -> list[Any]:

-def normalize_video_input(video: Any, max_frames: Optional[int] = None) -> List[Any]:
+def normalize_video_input(video: Any, max_frames: int | None = None) -> list[Any]:

As per coding guidelines, "Prefer built-in types list, dict, and tuple to the legacy typing.List, typing.Dict, and typing.Tuple... use the | syntax instead of typing.Union."

Also applies to: 17-76

🤖 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/cosmos3/utils.py` around lines 8 - 9,
The type hints in this new module still use legacy typing imports, so update the
imports and annotations in utils.py to the modern built-in style. Replace
typing.List and typing.Optional with list[...] and ... | None throughout the
file, and adjust any affected function signatures or class attributes so symbols
like the module imports and any typed helpers in this file consistently follow
the new guideline.

Source: Coding guidelines

tests/unittest/_torch/visual_gen/test_cosmos3_transformer.py (1)

400-536: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Good happy-path coverage; consider adding negative-path tests for the action modality.

Structural and forward-pass coverage (presence/absence of action heads, noisy mask, multiframe) is solid. Coverage is currently insufficient for boundary/error conditions on the new action inputs — e.g. action_domain_ids values >= NUM_DOMAINS, or action_latents with a mismatched action_dim. If these error paths aren't already covered in test_cosmos3_action.py (not included in this review batch), consider adding them there or here.

As per path instructions, "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_cosmos3_transformer.py` around lines
400 - 536, Coverage for the new action modality is insufficient because there
are no negative-path tests for invalid action inputs. Add focused assertions in
TestCosmos3Action (or follow up in test_cosmos3_action.py if that is the
intended home) for cases like action_domain_ids at or above NUM_DOMAINS and
action_latents with the wrong action_dim, using Cosmos3VFMTransformer and the
existing action_model_config fixture to locate the behavior quickly.

Source: Path instructions

tests/unittest/_torch/visual_gen/test_cosmos3_pipeline.py (1)

776-909: 🚀 Performance & Scalability | 🔵 Trivial

Coverage gap: resolve_domain_action_config/canonical_domain_preset_key are only exercised via GPU-gated integration tests.

TestCosmos3Action is marked @pytest.mark.integration + @pytest.mark.high_cuda_memory, so it won't run in typical CI. The branching logic in defaults.py (alias resolution, ambiguous domain_idNone fallback, mismatch-warning generation, num_frames = action_chunk_size + 1 derivation) is pure Python with no GPU dependency, yet has no equivalent fast unit test path here (unlike TestCosmos3V2VConditioningParams, which does cover its pure-Python counterparts without GPU marks).

Coverage assessment: insufficient for non-GPU CI on this specific logic. Suggest adding a tests/unittest/_torch/visual_gen/test_cosmos3_defaults.py (or a similarly-marker-free test class in this file) that directly unit-tests canonical_domain_preset_key (including the ambiguous-domain_id-returns-None case and alias mapping) and resolve_domain_action_config (mismatch-warning content, num_frames fallback derivation), independent of cosmos3_pipeline/checkpoint fixtures.

Do you want me to draft this unit test module?

🤖 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_cosmos3_pipeline.py` around lines 776 -
909, The pure-Python domain action config logic is only covered by GPU-gated
integration tests, so add a fast unit test path for the defaults helpers. Create
a marker-free test module (or a non-integration class in this area) that
directly exercises canonical_domain_preset_key and resolve_domain_action_config,
including alias mapping, ambiguous domain_id returning None, mismatch-warning
text, and the num_frames fallback derived from action_chunk_size + 1. Keep the
tests independent of cosmos3_pipeline and checkpoint fixtures so they run in
normal CI.
tests/unittest/_torch/visual_gen/test_trtllm_serve_endpoints.py (1)

845-902: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add coverage for base64-JSON video input_reference.

New tests cover multipart video upload (routes to extra_params["video"]) and undecodable multipart content (400), but the PR objectives call out base64-JSON video references as a supported path, which isn't exercised here (only multipart is tested for video). Recommend adding a test_sync_video_generation_json_with_video_reference (or similar) that posts input_reference as a base64-encoded string in the JSON body and asserts the same extra_params["video"] routing.

🤖 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_trtllm_serve_endpoints.py` around lines
845 - 902, The current video reference tests only cover multipart upload and the
rejection path, but they miss the supported base64-JSON `input_reference` flow.
Add a new test alongside
`test_sync_video_generation_multipart_with_video_reference` that posts
`input_reference` as a base64-encoded video in the JSON body, then verify the
request is accepted and that
`video_client.mock_gen.last_params.extra_params["video"]` is populated (matching
the same routing asserted in the multipart test).

Source: Path instructions

tests/unittest/_torch/visual_gen/test_cosmos3_action.py (1)

154-183: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add coverage for inverse_dynamics and the missing-source error path in action_reference_image.

Current tests only cover forward_dynamics and policy selection order. action_reference_image's inverse_dynamics branch (video preferred over image) and its ValueError guard when neither image nor video is provided are untested. Coverage is insufficient for this function; recommend adding these two cases to test_cosmos3_action.py.

🤖 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_cosmos3_action.py` around lines 154 -
183, Add tests for the missing `action_reference_image` paths in
`TestActionReferenceImage`: cover `inverse_dynamics` to verify it prefers
`video` over `image`, and add a case asserting the `ValueError` raised when both
sources are absent. Keep the new tests alongside the existing
`test_forward_dynamics_accepts_mp4_on_image_path` and
`test_policy_prefers_image_path_over_video` cases so the branch behavior in
`action_reference_image` is fully covered.

Source: Path instructions

tensorrt_llm/_torch/visual_gen/models/cosmos3/action.py (1)

82-109: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add Google-style docstrings to public helper functions, especially prepare_action_latents.

Most module-level functions here (e.g. normalize_action_resolution, normalize_action_mode, prepare_action_latents) lack docstrings despite being imported and used outside this file (tests, presumably pipeline_cosmos3.py). prepare_action_latents in particular has non-obvious parameters (raw_action_dim vs action_dim, action_chunk_size) that would benefit from documentation.

Based on coding guidelines: "For interfaces used outside a file, prefer docstrings over comments... Externally called functions should have docstrings, and their arguments should be documented."

Also applies to: 325-333

🤖 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/cosmos3/action.py` around lines 82 -
109, Add Google-style docstrings to the public helper functions in this module,
including normalize_action_resolution, normalize_action_mode, and especially
prepare_action_latents. Document each function’s purpose, arguments, and return
values so externally used interfaces are clear, with special attention to the
non-obvious parameters in prepare_action_latents such as raw_action_dim,
action_dim, and action_chunk_size.

Source: Coding guidelines

🤖 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/cosmos3/action.py`:
- Around line 325-376: The in-place zeroing in prepare_action_latents can mutate
caller-owned input when clean_action still shares storage with action_input.
Update the prepare_action_latents flow so the tensor is cloned before any
in-place writes, especially before clean_action[:, :, raw_action_dim:] = 0,
while preserving the existing shape/device/dtype handling and the raw_action_dim
logic.
- Around line 267-298: action_reference_image() does not handle URI-based image
references, so http(s):// and data: strings are incorrectly treated as local
paths. Update the string branch in action_reference_image() to detect URI inputs
and pass them through the same URI-aware loading path used elsewhere before
falling back to filesystem/path or normalize_video_input(), while preserving the
existing PIL.Image and inverse_dynamics behavior.

In `@tensorrt_llm/serve/visual_gen_utils.py`:
- Around line 196-202: The temporary reference-file write path in
visual_gen_utils.py needs explicit failure handling and cleanup; wrap the base64
decode and file write logic used for request.input_reference in the same
try/finally flow that handles tmp_path so malformed data or write errors are
converted into a clean validation-style error instead of bubbling up, and ensure
tmp_path is deleted on every failure path. Locate the reference handling block
around request.input_reference, base64.b64decode, shutil.copyfileobj, and the
cleanup logic for tmp_path, and make sure both string and file-object inputs
share the same safe cleanup behavior.

---

Nitpick comments:
In `@tensorrt_llm/_torch/visual_gen/models/cosmos3/action.py`:
- Around line 82-109: Add Google-style docstrings to the public helper functions
in this module, including normalize_action_resolution, normalize_action_mode,
and especially prepare_action_latents. Document each function’s purpose,
arguments, and return values so externally used interfaces are clear, with
special attention to the non-obvious parameters in prepare_action_latents such
as raw_action_dim, action_dim, and action_chunk_size.

In `@tensorrt_llm/_torch/visual_gen/models/cosmos3/utils.py`:
- Around line 17-57: The public helper functions pil_to_rgb, decode_video_file,
and normalize_video_input_path are missing docstrings, unlike
normalize_video_input. Add Google-style docstrings to each function that
describe its purpose, arguments, return values, and raised errors as applicable,
keeping the documentation consistent with the module’s existing public API
style.
- Around line 8-9: The type hints in this new module still use legacy typing
imports, so update the imports and annotations in utils.py to the modern
built-in style. Replace typing.List and typing.Optional with list[...] and ... |
None throughout the file, and adjust any affected function signatures or class
attributes so symbols like the module imports and any typed helpers in this file
consistently follow the new guideline.

In `@tensorrt_llm/_torch/visual_gen/pipeline.py`:
- Around line 1183-1188: The denoising loop in the pipeline hot path recomputes
post_step_fn arity with inspect.signature() on every step, which is unnecessary
reflection overhead. Move the signature inspection for post_step_fn out of the
per-step loop in the pipeline logic, cache the parameter count once before
iterating, and reuse that result inside the loop when deciding whether to call
post_step_fn with one or two arguments.

In `@tests/unittest/_torch/visual_gen/test_cosmos3_action.py`:
- Around line 154-183: Add tests for the missing `action_reference_image` paths
in `TestActionReferenceImage`: cover `inverse_dynamics` to verify it prefers
`video` over `image`, and add a case asserting the `ValueError` raised when both
sources are absent. Keep the new tests alongside the existing
`test_forward_dynamics_accepts_mp4_on_image_path` and
`test_policy_prefers_image_path_over_video` cases so the branch behavior in
`action_reference_image` is fully covered.

In `@tests/unittest/_torch/visual_gen/test_cosmos3_pipeline.py`:
- Around line 776-909: The pure-Python domain action config logic is only
covered by GPU-gated integration tests, so add a fast unit test path for the
defaults helpers. Create a marker-free test module (or a non-integration class
in this area) that directly exercises canonical_domain_preset_key and
resolve_domain_action_config, including alias mapping, ambiguous domain_id
returning None, mismatch-warning text, and the num_frames fallback derived from
action_chunk_size + 1. Keep the tests independent of cosmos3_pipeline and
checkpoint fixtures so they run in normal CI.

In `@tests/unittest/_torch/visual_gen/test_cosmos3_transformer.py`:
- Around line 400-536: Coverage for the new action modality is insufficient
because there are no negative-path tests for invalid action inputs. Add focused
assertions in TestCosmos3Action (or follow up in test_cosmos3_action.py if that
is the intended home) for cases like action_domain_ids at or above NUM_DOMAINS
and action_latents with the wrong action_dim, using Cosmos3VFMTransformer and
the existing action_model_config fixture to locate the behavior quickly.

In `@tests/unittest/_torch/visual_gen/test_trtllm_serve_endpoints.py`:
- Around line 845-902: The current video reference tests only cover multipart
upload and the rejection path, but they miss the supported base64-JSON
`input_reference` flow. Add a new test alongside
`test_sync_video_generation_multipart_with_video_reference` that posts
`input_reference` as a base64-encoded video in the JSON body, then verify the
request is accepted and that
`video_client.mock_gen.last_params.extra_params["video"]` is populated (matching
the same routing asserted in the multipart test).
🪄 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: fffe0e58-286c-43b2-a067-78b9ec05bb3c

📥 Commits

Reviewing files that changed from the base of the PR and between 4cd00bb and 143cbe2.

📒 Files selected for processing (24)
  • examples/visual_gen/models/cosmos3/README.md
  • examples/visual_gen/models/cosmos3/cosmos3.py
  • examples/visual_gen/models/cosmos3/prompts/action_forward_dynamics.json
  • examples/visual_gen/models/cosmos3/prompts/action_inverse_dynamics.json
  • examples/visual_gen/models/cosmos3/prompts/action_policy.json
  • examples/visual_gen/models/cosmos3/prompts/v2v.json
  • examples/visual_gen/serve/README.md
  • requirements.txt
  • tensorrt_llm/_torch/visual_gen/models/cosmos3/action.py
  • tensorrt_llm/_torch/visual_gen/models/cosmos3/defaults.py
  • tensorrt_llm/_torch/visual_gen/models/cosmos3/pipeline_cosmos3.py
  • tensorrt_llm/_torch/visual_gen/models/cosmos3/transformer_cosmos3.py
  • tensorrt_llm/_torch/visual_gen/models/cosmos3/utils.py
  • tensorrt_llm/_torch/visual_gen/output.py
  • tensorrt_llm/_torch/visual_gen/pipeline.py
  • tensorrt_llm/serve/openai_protocol.py
  • tensorrt_llm/serve/visual_gen_utils.py
  • tensorrt_llm/visual_gen/output.py
  • tests/unittest/_torch/visual_gen/multi_gpu/test_cosmos3_transformer_parallel.py
  • tests/unittest/_torch/visual_gen/test_cosmos3_action.py
  • tests/unittest/_torch/visual_gen/test_cosmos3_pipeline.py
  • tests/unittest/_torch/visual_gen/test_cosmos3_transformer.py
  • tests/unittest/_torch/visual_gen/test_trtllm_serve_endpoints.py
  • tests/unittest/_torch/visual_gen/test_visual_gen_utils.py

Comment thread tensorrt_llm/_torch/visual_gen/models/cosmos3/action.py Outdated
Comment thread tensorrt_llm/_torch/visual_gen/models/cosmos3/action.py Outdated
Comment thread tensorrt_llm/serve/visual_gen_utils.py Outdated
@2ez4bz

2ez4bz commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58510 [ run ] triggered by Bot. Commit: b89f4b6 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@ishovkun

Copy link
Copy Markdown
Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58699 [ run ] triggered by Bot. Commit: fc07560 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58699 [ run ] completed with state FAILURE. Commit: fc07560
/LLM/main/L0_MergeRequest_PR pipeline #47284 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

@ishovkun

Copy link
Copy Markdown
Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58706 [ run ] triggered by Bot. Commit: d5efd0a Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@ishovkun

Copy link
Copy Markdown
Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58736 [ run ] triggered by Bot. Commit: 8e7c102 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58736 [ run ] completed with state SUCCESS. Commit: 8e7c102
/LLM/main/L0_MergeRequest_PR pipeline #47319 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

@ishovkun

Copy link
Copy Markdown
Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58996 [ run ] triggered by Bot. Commit: 8e7c102 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58996 [ run ] completed with state SUCCESS. Commit: 8e7c102
/LLM/main/L0_MergeRequest_PR pipeline #47526 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

@ishovkun

Copy link
Copy Markdown
Author

/bot run

ishovkun added 7 commits July 27, 2026 14:36
- Make `is_decodable_image_file` strict (calls `image.load()`) so
  truncated files are rejected at classification, matching the bytes
  probe behavior
- Add `TestMediaFileProbes` with a truncated-PNG test covering the
  file-path probe
- Add AVI/MJPEG as a documented second container/codec pair: new
  `_avi_bytes` helper, `test_multipart_avi_reference_routes_to_video`,
  and `test_avi_mjpeg_bytes_decode`
- Update `VideoGenerationRequest.input_reference` docstring and
  `examples/visual_gen/serve/README.md` to enumerate tested formats

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
Each worker rank demuxes encoded video bytes from memory and decodes the
V2V conditioning window on NVDEC: forward-only feed, preallocated ring at
the request's target resolution (keep=first stops early, keep=last rings
to EOS), emitted-frame work limit (TRTLLM_MAX_REFERENCE_DECODE_FRAMES),
local-tap Lanczos resize with bounded PIL parity, client/capacity error
classes, and an all-rank CPU/gloo status protocol so a rank-local decode
failure cannot hang healthy ranks in model collectives.

PyNvVideoCodec becomes a declared, pinned dependency (compliance approval
recorded, covering the bundled FFmpeg demux libraries); the import stays
function-local so importing tensorrt_llm never loads the driver-linked
module. Checked-in H.264 fixtures (MP4 + AVI, forced B-frames, per-frame
index patterns, provenance in README) drive the direct tests.

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
The serve boundary now classifies input_reference by magic bytes (PNG,
JPEG, MP4 ftyp, AVI RIFF) — routing only, never acceptance: images still
require a full PIL decode at the boundary, while video payloads pass
through as untouched encoded bytes for the workers' NVDEC to decode. This
removes every OpenCV import and probe from the VisualGen path (cv2 cannot
be declared in requirements) along with the boundary video decoders and
the decoded-size budget. Base64 decodes strictly; payload size is
deliberately not part of the request-validity contract (body limits are
deployment policy). Format contract documented accordingly: PNG/JPEG
images; H.264 in MP4/AVI decode-tested; the rest best-effort per the
GPU's decoder capabilities.

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
DiffusionResponse carries an error_type so worker-side failures keep
their class over the wire: client errors (unusable reference content,
conditioning bounds, decode-work limit) surface as HTTP 400 and as
ValueError from VisualGen.generate() — uniform with coordinator preflight
— while capacity failures (allocation/OOM for a valid request) surface as
HTTP 503 and RuntimeError. Ambiguous NVDEC decoder-init failures and
everything unclassified stay 500. No new public exception class.

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
extra_params['video'] now carries encoded MP4/AVI bytes only, decoded
per rank inside forward(): conditioning indexes are bound-checked against
the output latent length before any window math, the decoded frames are
freed as soon as the VAE has encoded them, and per-rank prepare outcomes
converge through the status protocol before any model collective.

The interim tensor form and everything that existed to ship it are
removed: the tensor/tensor_or_bytes type-map entries, the coordinator
crop reducer, the ExtraParamSchema.reducer hook and
reduce_visual_gen_params plumbing, and cosmos3/utils.py (orphaned).
Smokes drive the production bytes path via the checked-in fixture —
keep=last is now exercised through the real NVDEC decode.

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
--video_path reads the file's bytes straight into extra_params['video'];
each worker decodes the conditioning window on NVDEC. Docs updated for
the NVDEC path (no OpenCV install step, MP4/AVI files).

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
The synthesized-tensor reference died with the tensor intake; the gate
now conditions on a 2.7 KB checked-in H.264 clip (same moving-block
content, provenance in test_data/README.md — decoded YUV is normative
per spec, and the YUV->RGB conversion is this stack's, so the decode is
stable for this path). Golden frame regenerated once for the codec-lossy
conditioning pixels. Registers test_media_decode.py in l0_b200.

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
@ishovkun

Copy link
Copy Markdown
Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62004 [ run ] triggered by Bot. Commit: 73eefa3 Link to invocation

@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/inputs/media_io.py (1)

358-372: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Missing parameter type annotations on new media-classification helpers. All three new functions omit the bytes type hint on their sole input parameter, while sibling new functions added in this same PR (e.g. media_decode.py's decode_video_reference_window, _read) are fully annotated.

  • tensorrt_llm/inputs/media_io.py#L358-L372: annotate sniff_media_kind(data: bytes) -> Optional[str].
  • tensorrt_llm/inputs/media_io.py#L374-L389: annotate is_decodable_image_bytes(data: bytes) -> bool.
  • tensorrt_llm/_torch/visual_gen/models/cosmos3/defaults.py#L93-L101: annotate _validate_video_reference(video: bytes) -> None.

As per coding guidelines, "Annotate every function, use None for non-returning functions, avoid Any and unnecessary type ignores... use precise Callable types."

🤖 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/inputs/media_io.py` around lines 358 - 372, Annotate the three
media helpers with precise parameter and return types: update sniff_media_kind
in tensorrt_llm/inputs/media_io.py lines 358-372 to accept bytes, update
is_decodable_image_bytes in tensorrt_llm/inputs/media_io.py lines 374-389 to
accept bytes and return bool, and update _validate_video_reference in
tensorrt_llm/_torch/visual_gen/models/cosmos3/defaults.py lines 93-101 to accept
bytes and return None.

Source: Coding guidelines

tensorrt_llm/serve/visual_gen_utils.py (1)

87-101: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Annotate the reference parameter.

reference is untyped; the two supported shapes are a base64 str and a multipart upload exposing .file. As per coding guidelines ("Annotate every function ... prefer built-in generic types and |"), give it an explicit union (e.g. str | UploadFile).

🤖 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/serve/visual_gen_utils.py` around lines 87 - 101, Update the
`_read_reference_payload` parameter annotation to explicitly accept the two
supported input shapes: a base64 `str` or the project’s multipart upload type
exposing `.file` (for example, `UploadFile`). Keep the return type and existing
decoding/read behavior unchanged.

Source: Coding guidelines

🤖 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/visual_gen/visual_gen.py`:
- Around line 166-185: Update the class and aresult() docstrings to document
ValueError for client failures, VisualGenCapacityError for capacity failures,
and RuntimeError for other single-prompt failures, matching _resolved_value().
Add regression tests covering each of these error types.

---

Nitpick comments:
In `@tensorrt_llm/inputs/media_io.py`:
- Around line 358-372: Annotate the three media helpers with precise parameter
and return types: update sniff_media_kind in tensorrt_llm/inputs/media_io.py
lines 358-372 to accept bytes, update is_decodable_image_bytes in
tensorrt_llm/inputs/media_io.py lines 374-389 to accept bytes and return bool,
and update _validate_video_reference in
tensorrt_llm/_torch/visual_gen/models/cosmos3/defaults.py lines 93-101 to accept
bytes and return None.

In `@tensorrt_llm/serve/visual_gen_utils.py`:
- Around line 87-101: Update the `_read_reference_payload` parameter annotation
to explicitly accept the two supported input shapes: a base64 `str` or the
project’s multipart upload type exposing `.file` (for example, `UploadFile`).
Keep the return type and existing decoding/read behavior 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: 1535fd51-79dd-47db-8842-73e68483c197

📥 Commits

Reviewing files that changed from the base of the PR and between d69513f and 73eefa3.

⛔ Files ignored due to path filters (4)
  • tests/integration/defs/examples/visual_gen/golden/visual_gen_lpips/visual_gen_lpips_golden_media.zip is excluded by !**/*.zip
  • tests/integration/defs/examples/visual_gen/test_data/cosmos3_v2v_lpips_reference.mp4 is excluded by !**/*.mp4
  • tests/unittest/_torch/visual_gen/test_data/cosmos3_v2v_ref_9f_bframes.avi is excluded by !**/*.avi
  • tests/unittest/_torch/visual_gen/test_data/cosmos3_v2v_ref_9f_bframes.mp4 is excluded by !**/*.mp4
📒 Files selected for processing (24)
  • examples/visual_gen/models/cosmos3/README.md
  • examples/visual_gen/models/cosmos3/cosmos3.py
  • examples/visual_gen/serve/README.md
  • requirements.txt
  • tensorrt_llm/_torch/visual_gen/executor.py
  • tensorrt_llm/_torch/visual_gen/media_decode.py
  • tensorrt_llm/_torch/visual_gen/models/cosmos3/defaults.py
  • tensorrt_llm/_torch/visual_gen/models/cosmos3/pipeline_cosmos3.py
  • tensorrt_llm/_torch/visual_gen/pipeline.py
  • tensorrt_llm/inputs/media_io.py
  • tensorrt_llm/serve/openai_protocol.py
  • tensorrt_llm/serve/openai_video_routes.py
  • tensorrt_llm/serve/visual_gen_utils.py
  • tensorrt_llm/visual_gen/params.py
  • tensorrt_llm/visual_gen/visual_gen.py
  • tests/integration/defs/examples/visual_gen/test_data/README.md
  • tests/integration/defs/examples/visual_gen/test_visual_gen.py
  • tests/integration/test_lists/test-db/l0_b200.yml
  • tests/unittest/_torch/visual_gen/test_cosmos3_pipeline.py
  • tests/unittest/_torch/visual_gen/test_data/README.md
  • tests/unittest/_torch/visual_gen/test_media_decode.py
  • tests/unittest/_torch/visual_gen/test_trtllm_serve_endpoints.py
  • tests/unittest/_torch/visual_gen/test_visual_gen_params.py
  • tests/unittest/_torch/visual_gen/test_visual_gen_utils.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tensorrt_llm/serve/openai_protocol.py

Comment on lines 166 to +185
def _resolved_value(self):
# For single prompts, surface engine-side failure as
# ``RuntimeError``. Request-parameter validation is enforced
# synchronously at :meth:`VisualGen.generate_async` entry, so
# anything reaching this point is by definition a runtime
# failure from ``pipeline.infer()``. For batches, return the
# list as-is so callers iterate per-item ``error``.
# For single prompts, surface engine-side failure typed by class:
# worker-classified client errors (unusable reference content,
# conditioning bounds) raise ``ValueError`` — uniform with the
# synchronous parameter validation at ``generate_async`` entry —
# and capacity failures raise ``RuntimeError``
# (``VisualGenCapacityError``), like any unclassified runtime
# failure. For batches, return the list as-is so callers iterate
# per-item ``error``.
if self._batch_size is None and isinstance(self._resolved, VisualGenOutput):
if self._resolved.error is not None:
raise RuntimeError(f"Generation failed: {self._resolved.error}")
message = f"Generation failed: {self._resolved.error}"
error_type = getattr(self, "_error_type", None)
if error_type == "client":
raise ValueError(message)
if error_type == "capacity":
from tensorrt_llm._torch.visual_gen.media_decode import VisualGenCapacityError

raise VisualGenCapacityError(message)
raise RuntimeError(message)

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Update the documented exception contract.

This now raises ValueError for client failures and VisualGenCapacityError for capacity failures, while the class and aresult() docstrings still promise RuntimeError for all single-prompt failures (Lines [54] and [94]). Update those docstrings and add regression coverage for each error type.

🤖 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/visual_gen/visual_gen.py` around lines 166 - 185, Update the
class and aresult() docstrings to document ValueError for client failures,
VisualGenCapacityError for capacity failures, and RuntimeError for other
single-prompt failures, matching _resolved_value(). Add regression tests
covering each of these error types.

The class and aresult() docstrings promised RuntimeError for any
single-prompt failure, but _resolved_value() raises by failure class:
ValueError for client errors, VisualGenCapacityError for capacity, and
RuntimeError only when unclassified. ValueError is not a RuntimeError
subclass, so a caller following the docs would miss client failures
entirely.

Adds regression tests over all three classes plus the batch path (which
keeps Option B semantics and never raises). They assert the exact type:
VisualGenCapacityError subclasses RuntimeError, so a plain
pytest.raises(RuntimeError) would pass for a capacity failure and leave
the 400-vs-503 distinction the routes depend on untested.

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
@ishovkun

Copy link
Copy Markdown
Author

/bot run --disable-fail-fast

@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

🤖 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 `@tests/unittest/visual_gen/test_output.py`:
- Around line 830-842: Parameterize
test_batch_failure_never_raises_regardless_of_error_class over error_type values
"client", "capacity", and None. Pass each value into DiffusionResponse while
preserving the existing assertions that batch results contain per-item errors
and do not raise.
🪄 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: 729a412e-5bc2-4b42-a56c-4c08827d1edc

📥 Commits

Reviewing files that changed from the base of the PR and between 73eefa3 and 9cf90e6.

📒 Files selected for processing (2)
  • tensorrt_llm/visual_gen/visual_gen.py
  • tests/unittest/visual_gen/test_output.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tensorrt_llm/visual_gen/visual_gen.py

Comment thread tests/unittest/visual_gen/test_output.py Outdated
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62009 [ run ] triggered by Bot. Commit: 9cf90e6 Link to invocation

The test asserted Option B semantics 'regardless of error class' while
only exercising the client class; run it over client, capacity, and
unclassified so the name matches what it covers.

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
@ishovkun

Copy link
Copy Markdown
Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62004 [ run ] completed with state ABORTED. Commit: 73eefa3

Link to invocation

@ishovkun

Copy link
Copy Markdown
Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62015 [ run ] triggered by Bot. Commit: e8eeada Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62016 [ run ] triggered by Bot. Commit: e8eeada Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62009 [ run ] completed with state ABORTED. Commit: 9cf90e6

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62015 [ run ] completed with state ABORTED. Commit: e8eeada

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62016 [ run ] completed with state FAILURE. Commit: e8eeada
/LLM/main/L0_MergeRequest_PR pipeline #50203 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

@ishovkun

Copy link
Copy Markdown
Author

/bot -h

@github-actions

Copy link
Copy Markdown

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental) --high-priority]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Supports wildcard * for pattern matching (e.g., "*PerfSanity*" matches all stages containing PerfSanity). Examples: "A10-PyTorch-1, xxx", "PerfSanity". The patterns "*", "*Post-Merge*", and "*PerfSanity*", including equivalent escaped or repeated-star forms and their use in comma-separated lists, require the ci: post-merge approved PR label. Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline. Requires the ci: post-merge approved PR label applied by an active member of NVIDIA/trt-llm-ci-approvers. The approval label remains in place when new commits are pushed.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Supports wildcard * for pattern matching. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx", --extra-stage "Post-Merge". The patterns "*", "*Post-Merge*", and "*PerfSanity*", including equivalent escaped or repeated-star forms and their use in comma-separated lists, require the ci: post-merge approved PR label.

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

--high-priority (OPTIONAL) : Run the pipeline with high priority. This option is restricted to authorized users only and will route the job to a high-priority queue.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

@ishovkun

Copy link
Copy Markdown
Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62106 [ run ] triggered by Bot. Commit: e8eeada Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@ishovkun

Copy link
Copy Markdown
Author

CI status for e8eeada — pipeline #50287, run with --disable-fail-fast so no stage was aborted early. 1 failure, unrelated to this PR.

The failure: DGX_B200-8_GPUs-PyTorch-3 · accuracy/test_llm_api_pytorch.py::TestDeepSeekV4Pro::test_gsm8k_full_accuracy

Why it is unrelated:

  • This PR touches only _torch/visual_gen/, visual_gen/, inputs/media_io.py, serve/, and their tests — no DeepSeek, accuracy, or llm_api_pytorch code.
  • Its sibling TestDeepSeekV4ProDSpark::test_gsm8k_dep8_megamoe_deepgemm is already waived on the same platform under https://nvbugs/6506920 — same GSM8K-accuracy family, same DGX_B200.
  • The one dependency this PR adds (PyNvVideoCodec) declares no transitive dependencies, so it cannot perturb the DeepSeek/NCCL stack.
  • It failed on an 8-GPU stage; this PR only registers single-GPU B200 pre-merge entries.

This PR's tests passed. unittest/_torch/visual_gen/test_media_decode.py, test_visual_gen_params.py, and test_visual_gen_utils.py all ran green on B200. These stages were aborted by fail-fast in the previous pipeline, so they genuinely re-ran here rather than being skipped by artifact reuse. The V2V LPIPS gate is a post_merge entry and therefore runs after merge; it passes locally on this commit.

Also note the previous pipeline's failure — test_moe_comm.py::TestMoEComm::test_nccl_ep_cuda_graph_replay_uses_updated_routing — did not reproduce here; it passed on this run.

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.

9 participants