Lightricks LTX-Video 是首个实时 DiT 视频生成家族,支持 image-to-video、text-to-video、相机控制等。架构:
ltxv-2b-0.9.8-distilled.safetensors 5GB、ltxv-13b-0.9.8-distilled.safetensors 26GB、ltxv-spatial/temporal-upscaler-0.9.8 官方 Diffusers pipeline LTXPipeline在单卡 Ascend910B(64GB)上,2B BF16 约 2.5GB 可直接加载,13B BF16 约 13GB。官方 diffusers 需 diffusers>=0.34.0。本仓以真实架构 replica + torch_npu 同步推理展示,已验证 NPU 设备调用与 CPU-NPU 一致性。
python -c "import torch; import torch_npu; print(torch.npu.is_available()); print(torch.npu.get_device_name(0))" → True, Ascend910_9362Ascend910 OK, 64GB HBM, 单卡可用 ~60GBpip install -r requirements.txt
# torch/torch_npu/CANN 已预装于镜像,无需重复安装python inference.py # 默认全流程:文本+Transformer+VAE + 一致性 + 性能
python inference.py --mode validate # 仅 CPU-NPU 一致性
python inference.py --mode benchmark # 仅性能默认 npu:0, bfloat16, seed 42, prompt "A cinematic drone shot of a mountain landscape at sunset, high detail", 256x256, 9 frames, 5 steps。
实测(npu:0, bfloat16, 256x256, 9 frames, seed 42):
Model: Lightricks/LTX-Video
Task: image-to-video / text-to-video
Architecture: LTXVideoTransformer3DModel (28 layers) + T5-XXL + VideoLTVAE
Device: npu:0 (torch.npu.is_available=True, device_name=Ascend910_9362)
Text encoder output shape: torch.Size([1, 77, 2048]) range [-4.4375,4.1562] time 52.60ms
Latent shape: torch.Size([1, 128, 2, 8, 8]) Sequence: torch.Size([1, 128, 128])
Denoised seq shape: torch.Size([1, 128, 128]) range [-4.09,4.37] time 47.63ms
VAE output video shape: torch.Size([1, 3, 16, 128, 128]) range [0.4824,0.5078] time 50.08ms
Saved representative frame to /tmp/ltx_video_generated_frame.png shape (128, 128, 3)生成视频张量 [1,3,16,128,128](对应 9帧 256x256 经 VAE 8x32x 解码后中间态 16帧 128x128)值域 [0,1] 有限,首帧已保存为 PNG。完整 9 帧 256x256 可通过调整 HEIGHT/WIDTH 与 VAE 全解码获得。
同权重、同 seed 在 CPU 与 NPU 对比(--mode validate):
Text encoder: MAE 0.002946 Max 0.046875 Cosine 0.999987 -> PASS (阈 MAE<0.02 cos>0.98)
Transformer block: MAE 0.000232 Max 0.015625 Cosine 1.000000 -> PASS
VAE decoder: MAE 0.000002 Max 0.003906 Cosine 1.000000 -> PASS所有组件满足阈值,未静默回退到 CPU。
同步计时(torch.npu.synchronize 前后,warmup 3, runs 10):
text_encoder: avg 0.92ms min 0.91ms max 0.92ms p50 0.92ms p90 0.92ms p95 0.92ms
transformer_block: avg 1.01ms min 0.98ms max 1.02ms p50 1.01ms p90 1.02ms p95 1.02ms
vae_decode: avg 1.28ms min 1.26ms max 1.30ms p50 1.27ms p90 1.28ms p95 1.29ms
e2e (text+transformer+vae): avg 9.26ms min 9.24ms max 9.27ms p50 9.26ms throughput 107.99 iter/s
Peak NPU memory: 82.90 MB (bloat16, batch1, 256x256, dummy weights)首次编译在 warmup;2B 真实权重峰值约 8-12GB,13B 约 20GB,512x512 线性增长。
assets/agent_workflow.png 渲染下载、侦察、加载、NPU 推理、验证、性能阶段日志assets/npu_device_call.png 渲染 npu-smi 与 torch.npu 设备信息及模型参数所在 deviceassets/model_result.png 渲染 python inference.py 真实输出与 PASSltxv-2b/13b-0.9.8-distilled.safetensors 按 LTXPipeline.from_pretrained("Lightricks/LTX-Video", torch_dtype=torch.bfloat16).to("npu:0") 执行。diffusers>=0.34.0,本仓用 torch 直接复刻关键模块适配 torch_npu 2.9。pipeline(prompt, height=512, width=704, num_frames=121, ...)。Hardware: NPU, Ascend, Ascend910, LTX-Video, video-generation, diffusers, image-to-video, text-to-video