HuggingFace镜像/LTX-Video
模型介绍
文件和版本
分析

LTX-Video 模型卡片

本文档重点介绍与 LTX-Video 模型相关的信息,代码库可在此处获取。

LTX-Video 是首个基于 DiT 架构的实时视频生成模型,能够以高于观看速率的速度生成 1216×704 分辨率、30 FPS 的高质量视频。该模型通过大规模多样化视频数据集训练,可生成包含真实丰富内容的高分辨率视频。

预告片

图像生成视频示例

示例1示例2示例3
示例4示例5示例6
示例7示例8示例9

模型与工作流

名称说明inference.py 配置ComfyUI 工作流(推荐)
ltxv-13b-0.9.8-dev最高质量,需要更多显存ltxv-13b-0.9.8-dev.yamlltxv-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.yamlltxv-13b-dist-i2v-base.json
ltxv-2b-0.9.8-distilled小型模型,相较 13b 蒸馏版略有质量损失。适合低显存环境ltxv-2b-0.9.8-distilled.yaml不适用
ltxv-13b-0.9.8-fp8ltxv-13b 的量化版本ltxv-13b-0.9.8-dev-fp8.yamlltxv-13b-i2v-base-fp8.json
ltxv-13b-0.9.8-distilled-fp8ltxv-13b-distilled 的量化版本ltxv-13b-0.9.8-distilled-fp8.yamlltxv-13b-dist-i2v-base-fp8.json
ltxv-2b-0.9.8-distilled-fp8ltxv-2b-distilled 的量化版本ltxv-2b-0.9.8-distilled-fp8.yaml不适用
ltxv-2b-0.9.6质量良好,显存需求低于 ltxv-13bltxv-2b-0.9.6-dev.yamlltxvideo-i2v.json
ltxv-2b-0.9.6-distilled速度提升 15 倍,支持实时生成,所需步数更少,无需 STG/CFGltxv-2b-0.9.6-distilled.yamlltxvideo-i2v-distilled.json

模型详情

  • 开发机构: Lightricks
  • 模型类型: 基于扩散技术的图像生成视频模型
  • 支持语言: 英语

使用指南

直接使用

您可在许可协议允许的范围内使用本模型:

  • 2B 版本 0.9:许可协议
  • 2B 版本 0.9.1 许可协议
  • 2B 版本 0.9.5 许可协议
  • 2B 版本 0.9.6-dev 许可协议
  • 2B 版本 0.9.6-distilled 许可协议
  • 13B 版本 0.9.7-dev 许可协议
  • 13B 版本 0.9.7-dev-fp8 许可协议
  • 13B 版本 0.9.7-distilled 许可协议
  • 13B 版本 0.9.7-distilled-fp8 许可协议
  • 13B 版本 0.9.7-distilled-lora128 许可协议
  • 13B 版本 0.9.7-ICLoRA Depth 许可协议
  • 13B 版本 0.9.7-ICLoRA Pose 许可协议
  • 13B 版本 0.9.7-ICLoRA Canny 许可协议
  • 时序超分版本 0.9.7 许可协议
  • 空间超分版本 0.9.7 许可协议
  • 13B 版本 0.9.8-dev 许可协议
  • 13B 版本 0.9.8-dev-fp8 许可协议
  • 13B 版本 0.9.8-distilled 许可协议
  • 13B 版本 0.9.8-distilled-fp8 许可协议
  • 2B 版本 0.9.8-distilled 许可协议
  • 2B 版本 0.9.8-distilled-fp8 许可协议
  • 13B 版本 0.9.8-ICLoRA detailer 许可协议
  • 时序超分版本 0.9.8 许可协议
  • 空间超分版本 0.9.8 许可协议

通用提示:

  • 模型适用于分辨率可被32整除、帧数可被8整除再加1(例如257)的情况。若分辨率或帧数不符合要求,输入将被填充-1后再裁剪至目标分辨率和帧数。
  • 模型在分辨率低于720×1280且帧数少于257时表现最佳。
  • 提示词需使用英文。描述越详尽效果越好,优质提示词示例:青绿色的海浪拍打着岸边黝黑嶙峋的岩石,激起白色泡沫飞溅空中。画面以亮蓝色海水与近乎漆黑的岩石形成的强烈对比为主导。海水呈现清澈的青绿色,浪尖点缀着白色泡沫。岩石暗黑尖锐,表面覆盖着斑驳的青苔。海岸线排列着茂密的绿色植被,包括树木与灌木。背景处是覆盖着密林的连绵山丘。天空多云,光线昏暗。

在线演示

可通过以下链接立即体验模型:

  • LTX-Studio 图像生成视频(13B混合版)
  • LTX-Studio 图像生成视频(13B蒸馏版)
  • Fal.ai 图像生成视频(13B完整版)
  • Fal.ai 图像生成视频(13B蒸馏版)
  • Replicate 图像生成视频

ComfyUI

如需在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.yaml

Diffusers 🧨

LTX 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 检查点加载。查看本节内容以获取更多信息。

局限性

  • 该模型并非设计用于也无法提供事实性信息
  • 作为统计模型,此检查点可能放大现有的社会偏见
  • 模型可能无法完美生成与提示词完全匹配的视频
  • 提示词遵循效果受提示风格影响显著