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 输出。
硬件与软件栈(已确认):
torch_npu.npu.set_device(0)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/ 下三张 PNGimport 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)测试条件:bf16、n_diffusion_steps=5、同一 seed、同 3 路摄像头 + 32 token 占位文本、waypoints_init 为结构化左转先验。NPU 峰值显存约 4994 MiB。
| metric | value | meaning / ideal |
|---|---|---|
| cos_sim | 0.999231 | cosine similarity (ideal +1.0) |
| max_abs | 0.808594 | max abs error (lower better) |
| mean_abs | 0.387007 | mean abs error (lower better) |
| sign_agreement | 97.66% | sign agreement (robust, |
| rel_l2 | 0.066935 | relative L2 error (lower better) |
| npu_vs_cpu_speedup | 89.83x | NPU 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)。
sign_agreement 采用 robust 版本(排除 |x|<0.05 的位置),避免 bf16 在跨零附近的浮点噪声把指标拉低;这是数值合理的选择,不是放宽验收。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。