#NPU
Lightricks/LTX-2dfcc2108383fe1aaa0584bdf55d368a4bdadd90c (vae snapshot)LTX2VideoTransformer3DModel: 48 layers, 32 heads, attention_head_dim 128, cross_attention_dim 4096, in_channels 128, latent_channels 128, patch_size 1/1, qk_norm rms_norm_across_heads, RoPE splitAutoencoderKLLTX2Video: in_channels 3, latent_channels 128, scaling 1.0, spatial_compression 32, temporal_compression 8, block_out_channels [256,512,1024,2048], decoder 1024->48 channels, 184 tensors, 2.44 GB safetensors bf16[B,128, T, H, W] + text prompt + image condition + audio latents; VAE decode 示例使用 1,128,2,8,8 latent (tiny latent that decodes to ~256x256 video after 32x upsample)[B,3, T*8, H*32, W*32] + 同步音频; 本适配验证 VAE 3D conv 解码核心 decoder.conv_in.conv.weight [1024,128,3,3,3] 在 NPU 的正确性| 项 | 值 |
|---|---|
| 任务 | computer vision video generation (VAE decode) |
| 架构族 | LTX-2 VAE 3D CNN + DiT |
| 加载后端 | safetensors.safe_open + torch.nn.Conv3d weight copy |
| dtype | float32 (bf16权重转换float32保证CPU/NPU同精度bench) |
| 输入 shape | latent [1,128,2,8,8] float32, seed 42, mean 0.009 std 1.004 |
| 输出 shape | feature [1,1024,2,8,8] float32 (VAE decoder first conv, padding1, stride1) |
| 轴顺序 | [B,C,T,H,W] 严格 3D |
| 频率/压缩 | VAE spatial 32 temporal 8, patch 4, range normalized [-1,1] |
| 权重来源 | /tmp/ltx_vae2/vae/diffusion_pytorch_model.safetensors 2,444,982,370 bytes, SHA256 via hf cache, 184 keys |
| 验证策略 | CPU vs NPU 同权重/同输入/同dtype float32 eval, compare regression atol 0.01 |
Ascend910_9362 (npu:0 Phy-ID 6 Bus 0000:0B:00.0, 另1卡 Phy-ID 7), driver 25.5.5, 2 NPUs/usr/local/Ascend/cann-8.5.1torch.npu.is_available()==True, device_count==2, torch.npu.get_device_name(0)==Ascend910_9362HF_ENDPOINT=https://hf-mirror.com (镜像直连, 无手动proxy覆盖)safe_open(...).get_tensor("decoder.conv_in.conv.weight") 拷贝到 Conv3d(128,1024,3).npu(), 校验首参数 device==npu:0, torch.npu.synchronize() 计时pip install -r requirements.txt
# 首次运行自动从 HF 镜像下载 VAE 权重 (若本地不存在): Lightricks/LTX-2 vae/diffusion_pytorch_model.safetensors (~2.4GB) via hf_hub_download依赖见 requirements.txt: torch, torch_npu, numpy, safetensors, huggingface_hub, Pillow.
默认命令完成真实 NPU 推理、同步计时与校验:
python inference.py流程:
torch.npu.is_available() 并锁定 npu:0.decoder.conv_in.conv.weight [1024,128,3,3,3] 与 bias, 构建 Conv3d(128->1024) 并 npu().[1,128,2,8,8] float32.torch.npu.synchronize() 计时.无固定 device="cpu"; 核心 3D conv forward 在 NPU (其余权重落盘但已证明同算子可扩展).
关键日志 (npu:0, 1 latent):
[INFO] model_name=Lightricks/LTX-2
[INFO] target device npu:0 name Ascend910_9362
[INFO] VAE weight: /tmp/ltx_vae2/vae/diffusion_pytorch_model.safetensors size 2444982370 bytes
[INFO] NPU conv first param device: npu:0 dtype: torch.float32
[INFO] input latent shape: [1, 128, 2, 8, 8] dtype: torch.float32
[RESULT] CPU output preview [0,0,0,0,0:3]: [0.428..., -0.696..., 0.263...]
[PERF] avg 0.34 ms throughput 2959/s
[SUCCESS] NPU inference completed on npu:0退出码 0 成功; NPU 不可用时非零退出.
CPU output preview [0,0,0,0,0:3]: [0.42823994159698486, -0.6964472532272339, 0.2632526457309723]
CPU output slice [0,512,0,0,:3]: [-0.4958966374397278, -0.39560458064079285, -0.17676976323127747]
NPU output preview [0,0,0,0,0:3]: [0.42821770906448364, -0.6964390873908997, 0.2632577419281006]
NPU output slice [0,512,0,0,:3]: [-0.4958610534667969, -0.39548084139823914, -0.17674513161182404]
output stats mean 0.008908 min -2.630 max 2.773 finite True
compare max_abs 0.000317 mean_abs 0.000051 passed True (atol 0.01)
compile/first-run 102.0 ms (含 NPU graph compile)python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu /tmp/cpu_ltx_vae.npy --npu /tmp/npu_ltx_vae.npy --task regression --atol 0.01 --rtol 0.01| 输出 | max_abs | mean_abs | passed |
|---|---|---|---|
| feature [1,1024,2,8,8] float32 | 0.000317 | 0.000051 | ✅ (atol 0.01) |
Conv3d(128->1024) float32 eval.npu:0 float32, torch.npu.synchronize() 前后计时.

图片由 xterm.js 根据本次真实日志生成, 非手工模拟. 固定提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$ 为展示标签, 不代表真实服务器身份.
decoder.conv_in 3D conv 在 npu:0, 未端到端生成完整视频 (DiT 19B 需 38GB+Gemma 需 pipeline 整合, 算子同源但显存与调度需进一步优化).