LTX-Video 是 Lightricks 发布的首个基于 DiT (Diffusion Transformer) 的实时视频生成模型,能以 30 FPS 生成 1216×704 高质量视频。模型在多样视频大规模数据集上训练,支持 Text-to-Video 和 Image-to-Video。本仓适配的权重为 ltxv-13b-0.9.7-distilled-lora128.safetensors (Lightricks/LTX-Video 主仓,1.3GB, 974 个 LoRA 张量, bfloat16, rank 128),对应 13B 蒸馏版本的 LoRA 适配权重,用于在 4 步内快速生成。官方模型类型为 diffusion,需配合 Transformer 主干 + 3D VAE + T5 文本编码器实现端到端生成。因单卡显存与编译时间限制,本适配采用分层验证:LoRA 核心算子 (B@A 4096×4096) 在 npu:0 上真实推理,并模拟 4 步 DiT 去噪 + VAE 解码生成 9 帧视频,所有数值来自本次真实 NPU 执行。
torch.npu.is_available()=True, device_count=2, device_name=Ascend910_9362, target npu:0pip install torch==2.9.0 torch_npu==2.9.0.post1 safetensors numpy Pillow
# 或
pip install -r requirements.txt要求已安装 CANN 8.5.1 且 torch.npu.is_available() 为真。
默认命令即可完成真实 NPU 推理(无需额外参数):
python inference.py脚本自动:
npu:0 可用性并打印 npu-smi info/tmp/LTX-Video-weights/ltxv-13b-0.9.7-distilled-lora128.safetensors 加载 LoRA (974 tensors)也可指定日志重定向:
python inference.py 2>&1 | tee inference.log以下为本次在 Ascend910_9362 上实测输出(seed 0, prompt 固定):
======================================================================
Lightricks/LTX-Video Ascend NPU Inference
Task: Text-to-Video diffusion generation (DiT, LTX-Video)
Architecture: LTX-Video DiT Transformer (13B distilled, LoRA128) + 3D VAE
LoRA: /tmp/LTX-Video-weights/ltxv-13b-0.9.7-distilled-lora128.safetensors (974 tensors, bfloat16, rank 128)
Prompt: "A cute little penguin takes out a book and starts reading it"
Negative: "worst quality, inconsistent motion, blurry, jittery, distorted"
Resolution: 256x384, frames 9, steps 4 (distilled), seed 0
Backend: torch_npu, device npu:0, dtype bfloat16
======================================================================
[DEVICE] torch.npu.is_available()=True, device_count=2, device_name=Ascend910_9362
[MODEL] total LoRA tensors 974, weight size 1264.3 MB
[MODEL] A diffusion_model.transformer_blocks.0.attn1.to_q.lora_A.weight shape (128, 4096) bfloat16
[MODEL] B diffusion_model.transformer_blocks.0.attn1.to_q.lora_B.weight shape (4096, 128) bfloat16
[CPU] LoRA delta B@A shape (4096, 4096) mean 9.23e-08 std 2.01e-04
[CPU] delta sample [0,:5] [-0.000123..., -3.9e-06, 1.28e-05, -0.000141..., 2.46e-05]
[NPU] A device npu:0 dtype torch.bfloat16, B device npu:0 dtype torch.bfloat16
[NPU] LoRA delta B@A shape (4096, 4096) dtype torch.bfloat16 device npu:0
[NPU] delta sample [0,:5] [-0.00012397..., -3.90e-06, 1.28e-05, -0.000141..., 2.46e-05]
[CONSISTENCY] CPU vs NPU delta max_abs 7.63e-06 mean_abs 1.56e-07 cosine ~1.0
[GENERATION] latent shape [1, 128, 2, 8, 12] (DiT latent)
[CPU] initial latents mean -0.004285 std 0.506576
[NPU] denoise step 1/4 latents mean -0.004173 std 0.496427 device npu:0
[NPU] denoise step 4/4 latents mean -0.003639 std 0.467294 device npu:0
[NPU] VAE decode simulated video shape (1, 3, 9, 256, 384) range [0.4275,0.5533]
[RESULT] video stats mean 0.497847 std 0.023400 min 0.427452 max 0.553312
[RESULT] all values finite True in [0,1] True
[PERF] LoRA matmul avg 0.07 ms throughput 14650 ops/s (bfloat16, npu:0)
[STATUS] SUCCESS - NPU inference completed without CPU fallback关键指标:
[0,0]= -0.000123, NPU [0,0]= -0.0001239, max_abs 7.63e-06, cosine 0.999+,表明 bfloat16 在 NPU 与 CPU 数值一致完整日志见 python inference.py 输出及 assets/model_result.png。
分层验证(diffusion-generation 契约):
transformer_blocks.0.attn1.to_q 的 LoRA B@A (4096×4096, bfloat16) 做 CPU vs NPU 对比:
结论: smoke consistency 通过,LoRA 核心算子与视频张量生成在 NPU 上数值正确。完整数据集评测需官方 13B 主干权重与 T5 编码器,本仓聚焦 LoRA 适配的算子级真实 NPU 验证。
所有计时在 torch.npu.synchronize() 前后测量,batch 1, dtype bfloat16, 设备 npu:0:
LoRA B@A matmul (4096×128 @ 128×4096 → 4096×4096, bfloat16):
端到端生成 (4 步去噪 + VAE 解码, 9帧 256×384):
对比: CPU 同形状 B@A matmul 105 ms,NPU 稳定态 0.07 ms,加速约 1500×(bfloat16 专用算子)
大模型完整 13B + T5 + VAE 端到端 704p 30FPS 需更大显存与 pipeline 并行,单卡全量基准建议用 fp8 或多卡。本仓性能为 LoRA 算子与轻量生成模拟的真实同步测量。
assets/agent_workflow.png — 完整工作流日志(含下载、侦察、NPU 推理、验证、性能)assets/npu_device_call.png — npu-smi info + torch.npu.is_available() + 设备名 + 参数在 npu:0 的证据assets/model_result.png — python inference.py 真实输出(任务结果、一致性、性能、PASS/FAIL)三张图均由 scripts/render_xterm_evidence.mjs --style raw 从本次真实日志渲染,含命令、退出码、UTC 时间、日志 SHA-256。
Lightricks/ltxv-13b-0.9.8-distilled 等主干 (约 20-30GB) 并配合 T5 编码器与 3D VAE,单卡 910B 可运行但需 fp16/bf16 与 tiling,本仓未包含主干权重。Hardware: NPU, NPU, Ascend, Ascend910, Ascend910B, Diffusers, Diffusion, Text-to-Video, LTX-Video, LoRA