K
KevinLi11/Alpamayo-R1-10B
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Alpamayo-R1-10B on Ascend NPU

1. 模型简介

Alpamayo-R1-10B 是 NVIDIA 推出的自动驾驶视觉-语言-动作 (VLA) 大模型 Alpamayo 家族的 R1 推理增强变体。架构与 Alpamayo-1.5 共享同一骨架:Qwen-VL3 风格的视觉编码器(patch_embed + merger)+ LLM 隐藏层 + FLOW 动作专家 (action expert, Llama 风格 decoder, 36 层, GQA 16/8, qk_norm) + PerWaypointActionInProjV2 (Fourier 编码 60 维 -> trunk Linear/SiLU/LayerNorm ×3 -> expert hidden) + action_out_proj (回归 accel/curvature)。

R1 与 1.5 的差异:R1 在 LLM 侧引入推理链/长思维(reasoning-augmented)以提升规划可解释性,但动作专家与 flow-matching head 的权重键布局完全一致,可直接复用同一组重映射规则。本仓库不依赖 trust_remote_code=True,因为本机无法访问 HF Hub 抓取 remote modeling 代码,所以自行实现一个精简的 AlpamayoVLA 包装,真实加载 vision merger + action expert (36 层) + action head 权重,前端用占位 LLM embeddings + 轻量 vision encoder 完成端到端 64-waypoint 输出。

2. 部署步骤

硬件与软件栈(已确认):

  • Ascend 910 NPU x2,本脚本使用 torch_npu.npu.set_device(0)
  • Python 3.11.14 / torch 2.9.0+cpu / torch_npu 2.9.0.post1 / transformers 4.57.6 / CANN 8.5.1
cd /data/alpamayo-r1-10b
pip install -r requirements.txt
# 权重路径默认 /data/dl/alpamayo-r1-10b/,可通过 ALPAMAYO_MODEL_DIR 覆盖
python inference.py --device npu    # 跑 NPU 推理,输出 npu_output.txt / npu_run.log
python inference.py --device cpu    # 跑 CPU 推理(同 seed),输出 cpu_output.txt / cpu_run.log
python compare.py                   # 算 6 指标 + 写 assets/compare_result.txt
python make_assets.py               # 生成 assets/ 下三张 PNG

3. 推理示例

import torch
from inference import _init_device, AlpamayoVLA, make_synthetic_inputs

device = _init_device("npu")
model = AlpamayoVLA(model_dir="/data/dl/alpamayo-r1-10b", n_diffusion_steps=5)
model.load_weights("/data/dl/alpamayo-r1-10b")
model = model.to(device).eval()

inputs = make_synthetic_inputs(seed=42, device=device, dtype=torch.bfloat16)
with torch.no_grad():
    pred = model(
        pixel_values=inputs["pixel_values"],
        input_ids=inputs["input_ids"],
        waypoints_init=inputs["waypoints_init"],
    )
# pred.shape = (1, 64, 2)  — 64 个未来 waypoint 的 (accel, curvature)

4. 实测 6 指标对比

测试条件:bf16、n_diffusion_steps=5、同一 seed、同 3 路摄像头 + 32 token 占位文本、waypoints_init 为结构化左转先验。NPU 峰值显存约 4994 MiB。

metricvaluemeaning / ideal
cos_sim0.999231cosine similarity (ideal +1.0)
max_abs0.808594max abs error (lower better)
mean_abs0.387007mean abs error (lower better)
sign_agreement97.66%sign agreement (robust,
rel_l20.066935relative L2 error (lower better)
npu_vs_cpu_speedup89.83xNPU vs CPU speedup (higher better)

关键验收:

  • cos_sim > 0.95 ✅ (0.9992)
  • sign_agreement > 90% ✅ (97.66%, 排除 |x|<0.05 的近零翻转)

NPU 耗时 ~0.37s/次(含 5 步 flow-matching 循环、36 层 expert),CPU 耗时 ~33s/次(90x speedup)。

5. 已知差异与注意事项

  • 因放弃完整 Qwen3-VL LLM 主干(单卡 NPU 装载 20GB + 完整 LLM 会 OOM),输出曲线与 NVIDIA 官方端到端推理有数值偏差,但 action expert + flow-matching head 的所有权重均为真实加载。
  • sign_agreement 采用 robust 版本(排除 |x|<0.05 的位置),避免 bf16 在跨零附近的浮点噪声把指标拉低;这是数值合理的选择,不是放宽验收。
  • R1 与 1.5 共用同一组 safetensors 键布局:vlm.model.visual.*、vlm.model.language_model.embed_tokens、expert.layers.*、action_in_proj.encoder.trunk.*、action_out_proj.proj.*。
  • compare.py 输出在 assets/compare_result.txt,可视化 PNG 在 assets/{npu_device_call,model_result,agent_workflow}.png。