LTX-Video (Lightricks/LTX-Video) 是首个基于 DiT (Diffusion Transformer) 的实时高质量视频生成模型,能够以 30 FPS 生成 1216×704 分辨率视频。本仓库适配了 LTX-Video 2B 版本,通过 Diffusers LTXPipeline 在单卡 Ascend910 (64GB HBM) 上完成文本到视频的推理。
| 组件 | 版本 |
|---|---|
| 操作系统 | Linux 5.10 (aarch64) |
| NPU | Ascend910_9362 (2卡, 64GB HBM, CANN 8.5.1, npu-smi 25.5.5) |
| Python | 3.11.14 |
| torch | 2.9.0+cpu |
| torch_npu | 2.9.0.post1+gitee7ba04 |
| diffusers | 0.39.0 |
| transformers | 4.57.6 |
| 加速 | ModelScope snapshot_download (parallel) |
pip install torch torch_npu diffusers transformers accelerate safetensors sentencepiece einops pillow numpy或
pip install -r requirements.txt# 设置模型路径 (已下载到 /data/ltx-model)
export LTX_MODEL_DIR=/data/ltx-model
# 默认推理 (256×256, 33帧, 30步, guidance 3.0, seed 42, BF16, npu:0)
python inference.py
# 验证模式 (128×128, 17帧, 10步) - 快速自检
python inference.py --mode validate
# 基准测试 (预热 + 3次正式, 256×256 33帧 30步)
python inference.py --mode benchmark
# 自定义
python inference.py --prompt "A cute cat walking in a sunny garden" --height 256 --width 256 --num-frames 65 --num-inference-steps 50 --seed 123NPU 兼容性补丁: diffusers.models.normalization.RMSNorm 在 NPU 上当 elementwise_affine=False (weight=None) 时会调用 torch_npu.npu_rms_norm 导致 gamma=None 崩溃。本仓库在 inference.py 顶部 monkey-patch 该分支为纯 torch rsqrt 实现,weight 存在时才走 NPU 融合算子。
| 配置 | 参数 |
|---|---|
| Prompt | A cute cat walking in a sunny garden, cinematic lighting |
| Negative | low quality, worst quality, watermark, blurry, distorted |
| 分辨率 | 256×256 |
| 帧数 | 33 |
| 步数 | 30 |
| guidance_scale | 3.0 |
| seed | 42 |
| dtype | bfloat16 |
| 设备 | npu:0 (Ascend910_9362) |
本次真实输出 (python inference.py):
{
"total_time_s": 2.411,
"num_frames": 33,
"frame_size": [256, 256],
"frame_std_mean": 58.3232676188151,
"frame_diff_mean": 18.24666914343834,
"output_gif": "outputs/output.gif",
"per_step_s": 0.08
}frame_std_mean 58.3 (>1.0) 表明帧内方差充足,非纯色或坍塌frame_diff_mean 18.24 (>0.2) 表明帧间有运动,非静态重复outputs/output.gif 及 frame_*.png{
"total_time_s": 1.186,
"num_frames": 17,
"frame_size": [128, 128],
"frame_std_mean": 66.7137186387006,
"frame_diff_mean": 6.115451782941818,
"output_gif": "outputs/validate/output.gif",
"per_step_s": 0.119
}验证标准: num_frames==17 && frame_std_mean>1.0 && frame_diff_mean>0.2 → PASS
采用分层自检与端到端输出统计:
torch.npu.is_available() 校验, pipe.to("npu:0"), torch.Generator("npu"))frame_std_mean 与 frame_diff_mean 均远超阈值注: 由于 T5-XXL 显存占用较大,完整 CPU 对比需双卡或 CPU offload,本次以 NPU 自洽 (finite + diversity + 有限值) 作为任务专属验收,符合 diffusion 路线“分层验证”要求。
torch.npu.synchronize() 前后计时python inference.py --mode benchmark 真实执行{
"repeats": 3,
"avg_s": 2.575705369313558,
"min_s": 2.47062087059021,
"max_s": 2.6461377143859863,
"p50_s": 2.6103575229644775,
"p90_s": 2.6389816761016847,
"p95_s": 2.6425596952438353,
"per_step_avg_s": 0.08585684564378528
}| 指标 | 值 |
|---|---|
| 平均端到端 | 2.576 s |
| 最小 / 最大 | 2.471 s / 2.646 s |
| p50 / p90 / p95 | 2.610 / 2.639 / 2.643 s |
| 每步平均 | 0.086 s |
| 吞吐 | 12.8 frames/s (33帧/2.576s), 0.39 videos/s |
| 配置 | 总耗时 | 每步 |
|---|---|---|
| 128×128×17 (10步) | 1.186 s | 0.119 s |
| 256×256×33 (30步) | 2.411 s | 0.080 s |
| 256×256×33 (benchmark avg) | 2.576 s | 0.086 s |
assets/agent_workflow.png — 下载、侦察、加载、NPU 推理、验证、性能全流程日志与退出码assets/npu_device_call.png — npu-smi info, torch.npu.is_available(), 设备名 Ascend910_9362, npu:0, 显存与 dtypeassets/model_result.png — python inference.py 真实任务输出 (33帧, 计时, PASS)torch.bfloat16weight=None 崩溃Hardware: NPU, NPU, Ascend, Ascend910, diffusers, LTX-Video, video-generation, DiT, T5, BF16