-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[None][feat] Add LTX-2 visual generation example #14976
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
Open
yibinl-nvidia
wants to merge
4
commits into
NVIDIA:main
Choose a base branch
from
yibinl-nvidia:dev-yibinl-ltx2-example-investigation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+153
−1
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2022-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. | ||
|
|
||
| # 1-GPU LTX-2 text-to-video with audio. | ||
| # Shared by offline examples (--visual_gen_args) and trtllm-serve. | ||
| quant_config: | ||
| quant_algo: NVFP4 | ||
| dynamic: true | ||
| attention_config: | ||
| backend: VANILLA | ||
| parallel_config: | ||
| cfg_size: 1 | ||
| ulysses_size: 1 | ||
| cuda_graph_config: | ||
| enable: false |
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,27 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2022-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. | ||
|
|
||
| # 1-GPU LTX-2 text-to-video with audio. | ||
| # Shared by offline examples (--visual_gen_args) and trtllm-serve. | ||
| quant_config: | ||
| quant_algo: FP8_BLOCK_SCALES | ||
| dynamic: true | ||
| attention_config: | ||
| backend: VANILLA | ||
| parallel_config: | ||
| cfg_size: 1 | ||
| ulysses_size: 1 | ||
| cuda_graph_config: | ||
| enable: false |
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,97 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-FileCopyrightText: Copyright (c) 2022-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. | ||
| """LTX-2 Text-to-Video generation with audio. | ||
| Usage: | ||
| python ltx2.py | ||
| python ltx2.py --visual_gen_args ../configs/ltx2.yaml | ||
| """ | ||
|
|
||
| import argparse | ||
|
|
||
| from tensorrt_llm import VisualGen, VisualGenArgs | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description="LTX-2 Text-to-Video example") | ||
| parser.add_argument( | ||
| "--model", | ||
| type=str, | ||
| default="Lightricks/LTX-2", | ||
| help="Model path or HuggingFace Hub ID", | ||
| ) | ||
| parser.add_argument( | ||
| "--visual_gen_args", | ||
| "--extra_visual_gen_options", | ||
| dest="visual_gen_args", | ||
| type=str, | ||
| default=None, | ||
| help="Path to YAML config (same as trtllm-serve --visual_gen_args)", | ||
| ) | ||
| parser.add_argument( | ||
| "--text_encoder_path", | ||
| type=str, | ||
| default=None, | ||
| help=( | ||
| "Gemma3 text encoder path. Overrides pipeline_config.text_encoder_path " | ||
| "from --visual_gen_args when set." | ||
| ), | ||
| ) | ||
| parser.add_argument( | ||
| "--output_path", | ||
| type=str, | ||
| default="ltx2_t2v_output.mp4", | ||
| help="Path to save the output video", | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| # LTX-2 requires pipeline_config.text_encoder_path for the Gemma3 text | ||
| # encoder. The YAML path is preferred for production configs; the default | ||
| # below keeps this script runnable as a minimal offline example. | ||
| extra_args = ( | ||
| VisualGenArgs.from_yaml(args.visual_gen_args) if args.visual_gen_args else VisualGenArgs() | ||
| ) | ||
| text_encoder_path = args.text_encoder_path | ||
| if text_encoder_path is None and not args.visual_gen_args: | ||
| text_encoder_path = "google/gemma-3-12b-it" | ||
| if text_encoder_path is not None: | ||
| extra_args.pipeline_config = { | ||
| **extra_args.pipeline_config, | ||
| "text_encoder_path": text_encoder_path, | ||
| } | ||
| visual_gen = VisualGen(model=args.model, args=extra_args) | ||
|
|
||
| # --- Model-specific: T2V request construction --- | ||
| # Start from LTX-2 defaults and override the main request shape explicitly. | ||
| params = visual_gen.default_params | ||
| params.height = 512 | ||
| params.width = 768 | ||
| params.num_frames = 121 | ||
| params.frame_rate = 24.0 | ||
| params.num_inference_steps = 40 | ||
| params.guidance_scale = 4.0 | ||
|
|
||
| output = visual_gen.generate( | ||
| inputs="A cinematic shot of a cat walking through a field of flowers", | ||
| params=params, | ||
| ) | ||
|
|
||
| output.save(args.output_path) | ||
| print(f"Saved: {args.output_path}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
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.