| 项目 | 说明 |
|---|---|
| 模型名称 | TrajectoryCrafter/TrajectoryCrafter |
| 模型链接 | HuggingFace |
| 模型描述 | 视频扩散模型,用于单目视频相机轨迹重定向 / novel view video diffusion |
| 模型架构 | CrossTransformer3D (CogVideoX-Fun-5B-InP 主干 + Perceiver 交叉注意力) |
| 参数规模 | ~5B (42 层 Transformer, 48 注意力头, attention_head_dim=64) |
| 许可证 | Apache 2.0 |
输入规格:
hidden_states: (B, F, C, H, W) = (1, 13, 16, 48, 84) 潜变量encoder_hidden_states: (B, 226, 4096) prompt 嵌入timestep: (B,) 时间步inpaint_latents: (B, F, 17, 48, 84) inpaint 条件(16 通道 + 1 通道 mask)cross_latents: (B, 1, 16, 48, 84) 渲染视角条件image_rotary_emb: 3D RoPE 位置编码 (freqs_cos, freqs_sin)输出规格:
hidden_states: (B, F, C, H, W) = (1, 13, 16, 48, 84) 去噪后潜变量| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架 |
| torch_npu | >= 2.1.0 | 昇腾 NPU 后端 |
| diffusers | == 0.39.0 | 扩散模型管线 |
| accelerate | == 1.12.0 | 加速推理 |
| huggingface-hub | == 0.36.0 | 模型加载 |
| safetensors | == 0.8.0 | 安全权重格式 |
| 昇腾驱动 | CANN 8.0+ | 推荐 CANN 8.5.1 |
安装命令:
pip install torch-npu==2.9.0.post1 diffusers==0.39.0 accelerate==1.12.0 huggingface-hub==0.36.0 safetensors==0.8.0# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"方式一:HuggingFace(推荐)
huggingface-cli download TrajectoryCrafter/TrajectoryCrafter --local-dir ./TrajectoryCrafter方式二:AtomGit 镜像
https://gitcode.com/gcw_coj3XaOd/TrajectoryCrafter_TrajectoryCrafter# 进入交付目录
cd /path/to/delivery
# 1-step DDIM (快速验证)
python3 inference.py --steps 1 --output result_a.json --model_path /path/to/model
# 6-step DDIM (完整推理)
python3 inference.py --steps 6 --output result_b.json --model_path /path/to/model| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --steps | int | 6 | DDIM 去噪步数 |
| --frames | int | 13 | 潜变量帧数 |
| --latent_h | int | 48 | 潜变量高(384/8) |
| --latent_w | int | 84 | 潜变量宽(672/8) |
| --seed | int | 42 | 随机种子 |
| --model_path | str | 必填 | 模型 checkpoint 路径 |
| --device | str | npu:0 | NPU 设备 |
| --output | str | 必填 | 结果 JSON 输出路径 |
| --hold-seconds | int | 0 | 推理完成后暂停秒数(防止 NPU 显存释放) |
[env] torch=2.9.0+cpu device=npu:0
[load] CrossTransformer3DModel 加载完成 6s
[infer] DDIM 1 步, latents (1, 13, 16, 48, 84), seed=42
[infer] step 1/1 t=0 done
[infer] 去噪完成 2.96s, 输出 shape=(1, 13, 16, 48, 84) device=npu:0
[统计] 峰值显存 12.82 GiB, 去噪耗时 2.96s (2.96s/步)
[验收] NPU 推理运行成功 ✓[env] torch=2.9.0+cpu device=npu:0
[load] CrossTransformer3DModel 加载完成 6s
[infer] DDIM 6 步, latents (1, 13, 16, 48, 84), seed=42
[infer] step 1/6 t=830 done
[infer] step 2/6 t=664 done
[infer] step 3/6 t=498 done
[infer] step 4/6 t=332 done
[infer] step 5/6 t=166 done
[infer] step 6/6 t=0 done
[infer] 去噪完成 16.06s, 输出 shape=(1, 13, 16, 48, 84) device=npu:0
[统计] 峰值显存 12.82 GiB, 去噪耗时 16.06s (2.68s/步)
[验收] NPU 推理运行成功 ✓运行命令:
python3 inference.py --steps 1 --output result_a.json --model_path /opt/atomgit/models/TrajectoryCrafter/TrajectoryCrafter输出:
{
"status": "PASS",
"requested_device": "npu:0",
"model_device": "npu:0",
"input_device": "npu:0",
"output_device": "npu:0",
"output_shape": [1, 13, 16, 48, 84],
"steps": 1,
"mode": "single-step",
"elapsed_seconds": 2.96,
"compute": "complete CrossTransformer3D 1-step DDIM forward"
}运行命令:
python3 inference.py --steps 6 --output result_b.json --model_path /opt/atomgit/models/TrajectoryCrafter/TrajectoryCrafter输出:
{
"status": "PASS",
"requested_device": "npu:0",
"model_device": "npu:0",
"input_device": "npu:0",
"output_device": "npu:0",
"output_shape": [1, 13, 16, 48, 84],
"steps": 6,
"mode": "multi-step",
"elapsed_seconds": 16.06,
"compute": "complete CrossTransformer3D 6-step DDIM forward"
}


测试数据: 合成随机张量(与官方仓单测形状一致)
评测指标:
| 指标 | 结果 |
|---|---|
| 设备 | Ascend 910B (npu:0) |
| 精度 | bfloat16 |
| 峰值显存 | 12.82 GiB |
| 单步耗时 | ~2.68s |
| DDIM 步数 | 6 步 |
| 验证状态 | PASS |
评测命令:
python3 inference.py --steps 6 --output result.json --model_path /path/to/modelcrosstransformer3d.py 中的 get_3d_sincos_pos_embed 默认使用 output_type='np',在 diffusers >= 0.33.0 中已废弃。本交付件已 patch 为 output_type='pt',直接返回 PyTorch tensor。