-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[TRTLLM-14268][feat] Cosmos3 Transfer (control-video conditioning) #16394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
8efa9c0
Intial version of Cosmos3 Trasnfer
bastefaniak c2f5e2d
Fix transfer transformer calling convention and use OpenCV-backed med…
ishovkun 44b00bd
Default use_system_prompt off for transfer requests
ishovkun 7f8ab45
Add Cosmos3 transfer unit tests ported from vllm-omni
ishovkun ac35bcb
Add transfer example surface: extra_params flag, ball-control generat…
ishovkun 01f6406
Fill transfer extra-param descriptions and tidy imports
ishovkun 5353b7a
Fix import order and trailing whitespace in cosmos3 pipeline
ishovkun f1f5d1e
Add `find_closest_target_size` for Cosmos3 transfer resolution
ishovkun 7cb24d5
Replace PyAV with OpenCV for video dimension probing in Cosmos3 transfer
ishovkun eeb9ccf
Fix line length and formatting in Cosmos3 transfer module
ishovkun f655fb8
Fix pre-commit formatting issues in Cosmos3 files
ishovkun 1650e95
Refactor Cosmos3 transfer helpers and consolidate constants
ishovkun 8a350bf
Add unit tests for Cosmos3 transfer media-conversion helpers
ishovkun ad6cc5f
Carry Cosmos3 transfer control media as encoded bytes
ishovkun ab393b7
Drop the PyAV dependency from the ball-control generator
ishovkun 8c48dd1
Accept inline base64 media for bytes-typed extra params
ishovkun bede20c
Stop the Cosmos3 transfer branch skipping shared pipeline machinery
ishovkun 8c735e6
Read source dimensions through the declared decoder, not OpenCV
ishovkun 4ad477c
Generate Cosmos3 transfer controls on the GPU
ishovkun 6cf5efd
Bound Cosmos3 control preprocessing by a frame window
ishovkun 5ba802e
Validate Cosmos3 transfer extra params at preflight
ishovkun ced154e
Size Cosmos3 output to the source aspect worker-side
ishovkun 6a69022
Follow the source frame rate when the caller sets none
ishovkun 9484408
Address review findings on the Cosmos3 transfer branch
ishovkun 72e78ab
Harden the control resize kernels for direct callers
ishovkun 19008ff
Close out the remaining example and serving-doc review notes
ishovkun 1c1b9d5
Apply the reviewer nitpicks that still hold
ishovkun 9316978
Follow the source frame rate on the transfer path too
ishovkun 391030b
Reject strided inputs in the control kernels
ishovkun c456fbe
Name the kernel guard for what it validates
ishovkun 372aa2b
Read windowed clips in place in the edge control path
ishovkun 06d4e71
Merge remote-tracking branch 'upstream/main' into cosmos3_control
ishovkun dda103f
Merge remote-tracking branch 'upstream/main' into cosmos3_control
ishovkun 5134453
Restore imports dropped by the upstream merge
ishovkun b0517d0
Merge remote-tracking branch 'upstream/main' into cosmos3_control
ishovkun 829f4fc
[None][fix] Restore transfer's scheduler setup and apply its guidance…
ishovkun 173eeb7
[None][fix] Drop transfer's unreachable extra_params frame lookups
ishovkun 73de920
[None][fix] Size transfer output by the longest control hint
ishovkun 37e70f4
[None][fix] Stream transfer chunks to host instead of stacking them o…
ishovkun 4f0485e
[None][doc] Document the model_fields_set contract and transfer's chu…
ishovkun 23e8b86
Merge remote-tracking branch 'upstream/main' into cosmos3_control
ishovkun ef3f53b
Merge remote-tracking branch 'upstream/main' into cosmos3_control
ishovkun 475cd9a
Merge remote-tracking branch 'upstream/main' into cosmos3_control
ishovkun eccc039
[None][ci] Restore the two Ray disagg tp2 waivers removed by #17632
ishovkun 95a6fce
Merge remote-tracking branch 'upstream/main' into cosmos3_control
ishovkun 52c4286
Merge remote-tracking branch 'upstream/main' into cosmos3_control
ishovkun 0825886
Merge remote-tracking branch 'upstream/main' into cosmos3_control
ishovkun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
examples/visual_gen/models/cosmos3/generate_bouncing_ball_control.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| r"""Generate a synthetic edge-map control video: a ball bouncing off walls. | ||
|
|
||
| Draws white outlines on black — a room border plus a ball following simple | ||
| elastic-bounce physics — which is exactly what the Cosmos3 transfer ``edge`` | ||
| hint expects. No media assets required: the control is 30 lines of math, and | ||
| transfer turns it into a photorealistic video whose subject follows the | ||
| physics frame by frame. | ||
|
|
||
| Generate the control, then run transfer with it: | ||
|
|
||
| python generate_bouncing_ball_control.py --out_dir ./ball_control | ||
|
|
||
| python cosmos3.py --model nvidia/Cosmos3-Nano \ | ||
| --visual_gen_args ../../configs/cosmos3-nano-1gpu.yaml \ | ||
| --prompt "A photorealistic beach ball with colorful panels bouncing \ | ||
| between the walls of an enclosed room, studio lighting." \ | ||
| --extra_params '{"edge": "./ball_control/control.mp4"}' \ | ||
| --output_path cosmos3_bouncing_ball.mp4 | ||
|
|
||
| Tip: keep synthetic controls edge-style. The ``blur`` hint expects the low | ||
| frequencies of natural video; flat synthetic color fields are far from its | ||
| training distribution and degrade generation quality. | ||
| """ | ||
|
|
||
| import argparse | ||
| from pathlib import Path | ||
|
|
||
| import numpy as np | ||
| import PIL.Image | ||
| import PIL.ImageDraw | ||
| import torch | ||
|
|
||
|
|
||
| def parse_args() -> argparse.Namespace: | ||
| parser = argparse.ArgumentParser(description="Bouncing-ball edge-control generator") | ||
| parser.add_argument("--out_dir", default="./ball_control") | ||
| parser.add_argument("--width", type=int, default=1280) | ||
| parser.add_argument("--height", type=int, default=720) | ||
| parser.add_argument("--num_frames", type=int, default=49) | ||
| parser.add_argument("--fps", type=int, default=24) | ||
| parser.add_argument("--radius", type=int, default=90) | ||
| parser.add_argument("--wall_inset", type=int, default=10, help="Room border inset in px") | ||
| parser.add_argument("--line_width", type=int, default=6) | ||
| parser.add_argument("--start", type=float, nargs=2, default=(300.0, 250.0)) | ||
| parser.add_argument( | ||
| "--velocity", | ||
| type=float, | ||
| nargs=2, | ||
| default=(26.0, 19.0), | ||
| help="px/frame; the defaults bounce a few times over 49 frames", | ||
| ) | ||
| parser.add_argument( | ||
| "--save_frames", action="store_true", help="Also write the individual PNG frames" | ||
| ) | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| def draw_frame(args: argparse.Namespace, x: float, y: float) -> PIL.Image.Image: | ||
| image = PIL.Image.new("RGB", (args.width, args.height), (0, 0, 0)) | ||
| draw = PIL.ImageDraw.Draw(image) | ||
| inset, r = args.wall_inset, args.radius | ||
| draw.rectangle( | ||
| [inset, inset, args.width - inset, args.height - inset], | ||
| outline=(255, 255, 255), | ||
| width=args.line_width, | ||
| ) | ||
| draw.ellipse([x - r, y - r, x + r, y + r], outline=(255, 255, 255), width=args.line_width) | ||
| return image | ||
|
|
||
|
|
||
| def main() -> None: | ||
| args = parse_args() | ||
| out_dir = Path(args.out_dir) | ||
| out_dir.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| lo_x, hi_x = args.wall_inset + args.radius, args.width - args.wall_inset - args.radius | ||
| lo_y, hi_y = args.wall_inset + args.radius, args.height - args.wall_inset - args.radius | ||
| x, y = args.start | ||
| vx, vy = args.velocity | ||
|
|
||
| frames = [] | ||
| for i in range(args.num_frames): | ||
| frame = draw_frame(args, x, y) | ||
| frames.append(frame) | ||
| if args.save_frames: | ||
| frame.save(out_dir / f"frame_{i:03d}.png") | ||
| x, y = x + vx, y + vy | ||
| if x < lo_x or x > hi_x: | ||
| vx = -vx | ||
| x = max(lo_x, min(x, hi_x)) | ||
| if y < lo_y or y > hi_y: | ||
| vy = -vy | ||
| y = max(lo_y, min(y, hi_y)) | ||
|
|
||
| # Same encoder the pipeline saves its outputs through, so this needs | ||
| # nothing installed beyond what running a generation already needs. | ||
| from tensorrt_llm.media.encoding import save_video | ||
|
|
||
| video_path = out_dir / "control.mp4" | ||
| clip = torch.from_numpy(np.stack([np.asarray(frame) for frame in frames])) | ||
| save_video(clip, video_path, frame_rate=args.fps) | ||
|
|
||
| print( | ||
| f"Wrote {video_path}" + (f" and {args.num_frames} PNG frames" if args.save_frames else "") | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.