本文档重点介绍与 LTX-Video 模型相关的信息,代码库可在此处获取。
LTX-Video 是首个基于 DiT 架构的实时视频生成模型,能够以高于观看速率的速度生成 1216×704 分辨率、30 FPS 的高质量视频。该模型通过大规模多样化视频数据集训练,可生成包含真实丰富内容的高分辨率视频。
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
| 名称 | 说明 | inference.py 配置 | ComfyUI 工作流(推荐) |
|---|---|---|---|
| ltxv-13b-0.9.8-dev | 最高质量,需要更多显存 | ltxv-13b-0.9.8-dev.yaml | ltxv-13b-i2v-base.json |
| ltxv-13b-0.9.8-mix | 在同一多尺度渲染工作流中混合 ltxv-13b-dev 与 ltxv-13b-distilled,实现速度与质量平衡 | 不适用 | ltxv-13b-i2v-mixed-multiscale.json |
| ltxv-13b-0.9.8-distilled | 速度更快,显存占用更低,相较 13b 版本略有质量损失。适合快速迭代 | ltxv-13b-0.9.8-distilled.yaml | ltxv-13b-dist-i2v-base.json |
| ltxv-2b-0.9.8-distilled | 小型模型,相较 13b 蒸馏版略有质量损失。适合低显存环境 | ltxv-2b-0.9.8-distilled.yaml | 不适用 |
| ltxv-13b-0.9.8-fp8 | ltxv-13b 的量化版本 | ltxv-13b-0.9.8-dev-fp8.yaml | ltxv-13b-i2v-base-fp8.json |
| ltxv-13b-0.9.8-distilled-fp8 | ltxv-13b-distilled 的量化版本 | ltxv-13b-0.9.8-distilled-fp8.yaml | ltxv-13b-dist-i2v-base-fp8.json |
| ltxv-2b-0.9.8-distilled-fp8 | ltxv-2b-distilled 的量化版本 | ltxv-2b-0.9.8-distilled-fp8.yaml | 不适用 |
| ltxv-2b-0.9.6 | 质量良好,显存需求低于 ltxv-13b | ltxv-2b-0.9.6-dev.yaml | ltxvideo-i2v.json |
| ltxv-2b-0.9.6-distilled | 速度提升 15 倍,支持实时生成,所需步数更少,无需 STG/CFG | ltxv-2b-0.9.6-distilled.yaml | ltxvideo-i2v-distilled.json |
您可在许可协议允许的范围内使用本模型:
青绿色的海浪拍打着岸边黝黑嶙峋的岩石,激起白色泡沫飞溅空中。画面以亮蓝色海水与近乎漆黑的岩石形成的强烈对比为主导。海水呈现清澈的青绿色,浪尖点缀着白色泡沫。岩石暗黑尖锐,表面覆盖着斑驳的青苔。海岸线排列着茂密的绿色植被,包括树木与灌木。背景处是覆盖着密林的连绵山丘。天空多云,光线昏暗。可通过以下链接立即体验模型:
如需在ComfyUI中使用本模型,请遵循专属ComfyUI代码库的指引。
代码库已在Python 3.10.5、CUDA 12.2环境下测试通过,支持PyTorch >= 2.1.2版本。
git clone https://github.com/Lightricks/LTX-Video.git
cd LTX-Video
# create env
python -m venv env
source env/bin/activate
python -m pip install -e .
$$inference-script$$
要使用我们的模型,请遵循 inference.py 中的推理代码:
python inference.py --prompt "PROMPT" --input_image_path IMAGE_PATH --height HEIGHT --width WIDTH --num_frames NUM_FRAMES --seed SEED --pipeline_config configs/ltxv-13b-0.9.8-distilled.yaml您现在可以根据一组图像和/或短视频片段生成视频。 只需提供所需图像或视频片段的路径列表,并指定它们在生成视频中的目标帧编号。您还可以为每个条件项指定条件强度(默认值:1.0)。
python inference.py --prompt "PROMPT" --conditioning_media_paths IMAGE_OR_VIDEO_PATH_1 IMAGE_OR_VIDEO_PATH_2 --conditioning_start_frames TARGET_FRAME_1 TARGET_FRAME_2 --height HEIGHT --width WIDTH --num_frames NUM_FRAMES --seed SEED --pipeline_config configs/ltxv-13b-0.9.8-distilled.yamlLTX Video 与用于图像生成视频的 Diffusers Python 库 兼容。
在尝试以下示例前,请确保已安装 diffusers。
pip install -U git+https://github.com/huggingface/diffusers现在,您可以运行以下示例(请注意,上采样阶段是可选的,但建议执行):
import torch
from diffusers import LTXConditionPipeline, LTXLatentUpsamplePipeline
from diffusers.pipelines.ltx.pipeline_ltx_condition import LTXVideoCondition
from diffusers.utils import export_to_video, load_image, load_video
pipe = LTXConditionPipeline.from_pretrained("Lightricks/LTX-Video-0.9.8-dev", torch_dtype=torch.bfloat16)
pipe_upsample = LTXLatentUpsamplePipeline.from_pretrained("Lightricks/ltxv-spatial-upscaler-0.9.8", vae=pipe.vae, torch_dtype=torch.bfloat16)
pipe.to("cuda")
pipe_upsample.to("cuda")
pipe.vae.enable_tiling()
def round_to_nearest_resolution_acceptable_by_vae(height, width):
height = height - (height % pipe.vae_spatial_compression_ratio)
width = width - (width % pipe.vae_spatial_compression_ratio)
return height, width
image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/penguin.png")
video = load_video(export_to_video([image])) # compress the image using video compression as the model was trained on videos
condition1 = LTXVideoCondition(video=video, frame_index=0)
prompt = "A cute little penguin takes out a book and starts reading it"
negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"
expected_height, expected_width = 480, 832
downscale_factor = 2 / 3
num_frames = 96
# Part 1. Generate video at smaller resolution
downscaled_height, downscaled_width = int(expected_height * downscale_factor), int(expected_width * downscale_factor)
downscaled_height, downscaled_width = round_to_nearest_resolution_acceptable_by_vae(downscaled_height, downscaled_width)
latents = pipe(
conditions=[condition1],
prompt=prompt,
negative_prompt=negative_prompt,
width=downscaled_width,
height=downscaled_height,
num_frames=num_frames,
num_inference_steps=30,
generator=torch.Generator().manual_seed(0),
output_type="latent",
).frames
# Part 2. Upscale generated video using latent upsampler with fewer inference steps
# The available latent upsampler upscales the height/width by 2x
upscaled_height, upscaled_width = downscaled_height * 2, downscaled_width * 2
upscaled_latents = pipe_upsample(
latents=latents,
output_type="latent"
).frames
# Part 3. Denoise the upscaled video with few steps to improve texture (optional, but recommended)
video = pipe(
conditions=[condition1],
prompt=prompt,
negative_prompt=negative_prompt,
width=upscaled_width,
height=upscaled_height,
num_frames=num_frames,
denoise_strength=0.4, # Effectively, 4 inference steps out of 10
num_inference_steps=10,
latents=upscaled_latents,
decode_timestep=0.05,
image_cond_noise_scale=0.025,
generator=torch.Generator().manual_seed(0),
output_type="pil",
).frames[0]
# Part 4. Downscale the video to the expected resolution
video = [frame.resize((expected_width, expected_height)) for frame in video]
export_to_video(video, "output.mp4", fps=24)import torch
from diffusers import LTXConditionPipeline, LTXLatentUpsamplePipeline
from diffusers.pipelines.ltx.pipeline_ltx_condition import LTXVideoCondition
from diffusers.utils import export_to_video, load_video
pipe = LTXConditionPipeline.from_pretrained("Lightricks/LTX-Video-0.9.8-dev", torch_dtype=torch.bfloat16)
pipe_upsample = LTXLatentUpsamplePipeline.from_pretrained("Lightricks/ltxv-spatial-upscaler-0.9.8", vae=pipe.vae, torch_dtype=torch.bfloat16)
pipe.to("cuda")
pipe_upsample.to("cuda")
pipe.vae.enable_tiling()
def round_to_nearest_resolution_acceptable_by_vae(height, width):
height = height - (height % pipe.vae_spatial_compression_ratio)
width = width - (width % pipe.vae_spatial_compression_ratio)
return height, width
video = load_video(
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cosmos/cosmos-video2world-input-vid.mp4"
)[:21] # Use only the first 21 frames as conditioning
condition1 = LTXVideoCondition(video=video, frame_index=0)
prompt = "The video depicts a winding mountain road covered in snow, with a single vehicle traveling along it. The road is flanked by steep, rocky cliffs and sparse vegetation. The landscape is characterized by rugged terrain and a river visible in the distance. The scene captures the solitude and beauty of a winter drive through a mountainous region."
negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"
expected_height, expected_width = 768, 1152
downscale_factor = 2 / 3
num_frames = 161
# Part 1. Generate video at smaller resolution
downscaled_height, downscaled_width = int(expected_height * downscale_factor), int(expected_width * downscale_factor)
downscaled_height, downscaled_width = round_to_nearest_resolution_acceptable_by_vae(downscaled_height, downscaled_width)
latents = pipe(
conditions=[condition1],
prompt=prompt,
negative_prompt=negative_prompt,
width=downscaled_width,
height=downscaled_height,
num_frames=num_frames,
num_inference_steps=30,
generator=torch.Generator().manual_seed(0),
output_type="latent",
).frames
# Part 2. Upscale generated video using latent upsampler with fewer inference steps
# The available latent upsampler upscales the height/width by 2x
upscaled_height, upscaled_width = downscaled_height * 2, downscaled_width * 2
upscaled_latents = pipe_upsample(
latents=latents,
output_type="latent"
).frames
# Part 3. Denoise the upscaled video with few steps to improve texture (optional, but recommended)
video = pipe(
conditions=[condition1],
prompt=prompt,
negative_prompt=negative_prompt,
width=upscaled_width,
height=upscaled_height,
num_frames=num_frames,
denoise_strength=0.4, # Effectively, 4 inference steps out of 10
num_inference_steps=10,
latents=upscaled_latents,
decode_timestep=0.05,
image_cond_noise_scale=0.025,
generator=torch.Generator().manual_seed(0),
output_type="pil",
).frames[0]
# Part 4. Downscale the video to the expected resolution
video = [frame.resize((expected_width, expected_height)) for frame in video]
export_to_video(video, "output.mp4", fps=24)如需了解更多信息,请查阅官方文档。
Diffusers 还支持通过 from_single_file() 方法直接从原始 LTX 检查点加载。查看本节内容以获取更多信息。