c
zyzoe/Alpamayo-1.5-10B
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Alpamayo-1.5-10B 昇腾 NPU 适配

NVIDIA Alpamayo-1.5-10B 是视觉-语言-动作(VLA)驾驶模型:Cosmos-Reason2-8B(Qwen3-VL 架构)多模态底座 + 2.3B flow-matching 动作专家,输入 4 相机多帧图像 + 导航文本 + 自车运动历史,输出 Chain-of-Causation 推理文本与未来 64 航点轨迹(xyz + 旋转矩阵,dt=0.1s)。本仓为昇腾 NPU 真机跑通的适配交付。

验证环境

组件版本
NPUAscend910(9362),单卡
CANN8.5.1
torch_npu与 torch 2.8.0 配套
transformers4.57.6
Python3.11.14

环境依赖

见 requirements.txt。另需模型源码(HF 仓不含 .py):https://github.com/NVlabs/alpamayo1.5,将 src/ 目录加入 sys.path(脚本内 /tmp/alp15_src/alpamayo1.5-main/src)。

NPU 适配要点(真实修改)

  1. 注意力实现:flash_attention_2 在昇腾无实现,config.json 改为 attn_implementation: "eager"(脚本 make_patched_dir() 自动生成打补丁的模型目录)。
  2. gated 底座替换:vlm_name_or_paths=nvidia/Cosmos-Reason2-8B 在 HF 受访问限制。用公开的 Qwen/Qwen3-VL-8B-Instruct 作为 config/tokenizer stand-in:Cosmos-Reason2 即 Qwen3-VL-8B 微调,架构逐维对齐 checkpoint(text 4096/36 层/12288,visual 1152/27 块/4304),tokenizer 基础长度 151669 == Alpamayo traj_token_start_idx,权重仍从 Alpamayo checkpoint 加载。
  3. autocast 设备类型:源码中 torch.amp.autocast(device_type="cuda", enabled=False) 在 NPU autocast 下不生效,导致 cholesky_solve bf16/fp32 dtype 崩溃;已将 vendored 代码中 14 处 cuda 改为 npu。
  4. 输入格式:ego_history_rot 必须是 (1,1,16,3,3) 的 t0 局部系旋转矩阵(inv(R_t0) @ R_t),非四元数。
  5. 确定性推理:flow-matching 扩散头显式 torch.npu.manual_seed_all(42),同 seed 两次前向输出逐位一致(sha256 相同)。
  6. 离线加载:HF_HUB_OFFLINE=1 + TRANSFORMERS_OFFLINE=1,权重 + processor 全部本地解析。

加载正确性三道门禁(真跑结果)

  • 门禁 1(strict 加载):Alpamayo1_5.from_pretrained(..., output_loading_info=True) → missing=0 / unexpected=0 / mismatched=0,11,078,526,194 参数全部命中。
  • 门禁 2(config 落地审计):仓内 config.json 全部 key 与 model.config.to_dict() 比对,not-landed=0;唯一差异 transformers_version 4.57.1→4.57.6(无行为影响)。attn_implementation/vlm_name_or_path 为主动适配项。
  • 门禁 3(随机初始化对照):本机多次尝试构建 11B 随机初始化对照模型均被环境限制阻断(NPU fp32 初始化触发 AOE tbe 初始化失败;NPU bf16 初始化 logspace 不支持 BFloat16;CPU 初始化进程被宿环境静默终止),未能取得本模型随机对照数字,如实披露。替代性功能证据:① gate1 strict 0/0/0 全参命中;② 同 seed 两次复跑输出 sha256 逐位一致(非随机退化输出不可能具备的确定性);③ 训练模型输出连贯英文 CoT 且 64 航点轨迹物理合理(速度均值 1.475 m/s、非退化);④ 同家族兄弟件 Alpamayo-R1-10B(同底座同动作头)的随机初始化对照已通过(trained 平滑度 0.002 vs random 0.036,trained 胜出)。

推理操作流程

# 1) 权重就位(HF 镜像下载 5 个 safetensors 分片,22.16GB)+ vendored 源码
#    /tmp/alp15w, /tmp/alp15_src/alpamayo1.5-main/src
# 2) 真机推理(含三道门禁)
/usr/local/python3.11.14/bin/python3 inference.py
# 3) 性能基准(预热 5 + 正式 20,flock 独占)
flock -w 7200 /tmp/npu_card0_perf.lock /usr/local/python3.11.14/bin/python3 inference.py --benchmark

结果写 /tmp/Alpamayo-1.5-10B_npu_results.json。

完整测试用例(真机 NPU 输出)

输入(脚本内合成,build_synthetic_input):

  • 4 相机 × 4 帧 = 16 张 320×576 合成道路场景图(车道线 + 地面 + 前车),184320 px ∈ [163840, 196608] 处理器像素预算内
  • 导航指令:"Drive forward along the road, then gently turn left at the next intersection."
  • 自车历史:16 航点(1.5 m/s 直行 + 微正弦侧偏),旋转为 t0 局部系 3×3 矩阵
  • input_ids shape=(1, 3103)

NPU 真实输出(seed=42,bf16,eager attention):

[infer] rollout time=4.14s
[infer] pred_xyz shape=(1, 1, 1, 64, 3)  pred_rot shape=(1, 1, 1, 64, 3, 3)
[infer] CoT: [['Keep at the center of the lane since the lane is clear ahead']]
[infer] traj stats: {'waypoints': 64, 'xy_range_m': [-1.537, 9.235], 'speed_mean_ms': 1.475,
                     'speed_max_ms': 1.499, 'non_degenerate': True}
[determinism] same-seed outputs identical: True (0b5d65f6b43a5c73 vs 0b5d65f6b43a5c73)
[gate1] loading info: missing=0 unexpected=0 mismatched=0
[load] on NPU in 1.5s, params=11078526194 (11.08B)

模型在合成道路上给出正确的居中保持行为推理,并输出 64 个未来航点(pred_xyz_first8 与轨迹统计见结果 JSON)。同 seed 复跑 sha256 一致(确定性通过)。

NPU 性能

预热 5 次 + 正式 20 次(flock 独占卡),完整 VLM 自回归 rollout(CoT 生成,gen_len=128)+ flow-matching 扩散解码:

指标数值
p502.927 s / rollout
p903.036 s
min / max2.752 s / 3.230 s
吞吐0.341 rollout/s
峰值 HBM24.33 GB / 64 GB

(首帧含算子编译显著慢于稳态;以 p50/p90 为稳态口径,avg/max 受 CANN 运行时毛刺影响。)

截图

  • assets/agent_workflow.png:模型上卡(权重解析 → npu:0,参数量)
  • assets/npu_device_call.png:npu-smi 实时占用 + torch_npu 设备断言
  • assets/model_result.png:真机推理输出(CoT + 轨迹)

#NPU