eardoi/alpamayo-r1-10b-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

注:模型权重实际采用 NVIDIA OpenMDW-1.1 许可证(见官方模型卡);本仓库 license 字段因平台校验白名单限制标注为官方源码所用的 apache-2.0。

nvidia/Alpamayo-R1-10B on Ascend NPU

1. 简介

  • 模型来源: nvidia/Alpamayo-R1-10B(AtomGit 镜像: https://ai.gitcode.com/hf_mirrors/nvidia/Alpamayo-R1-10B)
  • 模型类型: NVIDIA 开源 Alpamayo R1 —— 面向自动驾驶社区的 10B 参数 Chain-of-Causation 推理 VLA 模型,基于 Cosmos-Reason2-8B(Qwen3-VL 骨干,8.2B),外加 2.3B diffusion 轨迹解码器(Action Expert)
  • 参数量: 10.5B(VLM 骨干 8.2B + Action Expert 2.3B;权重 20.6 GB,bf16,5 分片)
  • 输入/输出: 多路相机图像(默认 4 路)+ 文本指令 + 自车历史轨迹 → CoC 推理文本 + 6.4s 未来轨迹(64 个 waypoint)
  • 适配状态: SUCCESS
  • 适配说明: Alpamayo-R1 为自定义架构(AlpamayoR1,transformers 未内置,官方代码在 alpamayo_r1/ 目录 vendored),且官方依赖的 nvidia/Cosmos-Reason2-8B 分词器为 gated 仓库。本适配:
    1. vendor 官方源码 alpamayo_r1/(Apache-2.0);
    2. 本地化分词器:将 Cosmos-Reason2 分词器(151669 tokens)放入 cosmos_reason2/ 目录,规避 gated 访问;
    3. NPU 适配:attn_implementation 由 flash_attention_2 改为 sdpa(昇腾无 FA),tie_weights 增加 **kwargs 兼容 transformers 5.x,FlowMatching 的 beta 分布 tensor 固定 CPU 设备规避 meta tensor 初始化,通过 torch_npu 在 NPU 上完成加载与全链路 VLA 推理。
  • 适配时间: 2026-08-21
  • 硬件: {hardware NPU} Ascend 910B(torch_npu 2.9.0.post1,NPU 0,64GB HBM)

2. 验证环境

组件版本
python3.10 – 3.11
torch2.9.0
torch-npu2.9.0.post1
transformers5.15.0
CANN≥ 8.0
einops / hydra-core / colorlog0.8.x / 1.3.x / 6.x

3. 模型架构

┌──────────────────────────────────────────────┐
│ Qwen3-VL VLM 骨干 (Cosmos-Reason2-8B, 8.2B)   │
│ 4 路相机 × 4 帧 + 文本指令 + 历史轨迹          │
│   → CoC 推理文本 + 离散轨迹 token 前缀         │     Chain-of-Causation
└──────────────────────────────────────────────┘
  │  KV cache(36 层, num_kv_heads=8, head_dim=128)
  ▼
┌──────────────────────────────────────────────┐
│ Action Expert (Qwen3 文本解码器, 36 层, 2.3B) │  ← 与 VLM 共享 KV cache
│   → 每步去噪得到轨迹隐藏特征                    │     (GQA 形状一致)
└──────────────────────────────────────────────┘
  │
  ▼
┌──────────────────────────────────────────────┐
│ Diffusion (Flow-Matching) 轨迹解码器           │  ← Euler 10 步去噪
│   → 64 waypoint 未来轨迹 (xyz + R_rot)        │
└──────────────────────────────────────────────┘

4. 部署与使用

环境准备

# CANN + torch_npu(昇腾 NPU 必需)
source /usr/local/Ascend/ascend-toolkit/set_env.sh
pip install torch==2.9.0 torch_npu==2.9.0.post1 \
    -i https://repo.huaweicloud.com/repository/pypi/simple/

# 本项目依赖
pip install transformers==5.15.0 einops hydra-core colorlog safetensors \
    -i https://repo.huaweicloud.com/repository/pypi/simple/

模型权重

权重通过 git 镜像或 hub 下载(5 个 safetensors 分片,共 20.6GB):

git clone --depth 1 https://gitcode.com/hf_mirrors/nvidia/Alpamayo-R1-10B.git model_src

权重目录需含:config.json / model-*.safetensors / model.safetensors.index.json。

推理

# 全链路 VLA 轨迹生成(4 路相机合成输入 + 历史轨迹 → CoC 文本 + 64 waypoint)
python3 inference.py --traj-sim --model ./model_src --cosmos ./cosmos_reason2 --device npu:0

关键参数:

参数默认说明
--model./model_src权重目录(含 config.json + safetensors)
--cosmos./cosmos_reason2本地 Cosmos-Reason2 分词器目录
--devicenpu:0推理设备
--num-traj-samples1轨迹采样数
--max-new-tokens512VLM 最大生成 token 数

5. 推理验证(NPU 实测)

[info] device = npu:0
[info] params M = 11078.5
[inference] Model loaded in 12.1s
[inference] Trajectory sampled in 3.7s
============================================================
CHAIN-OF-CAUSATION (VLM 文本推理):
  sample[0]: [['Keep at the center of the lane to continue driving since the road ahead is clear']]
============================================================
PREDICTED FUTURE TRAJECTORY (xy, meters, 64 waypoints):
  sample[0] head: [[0.201 0.   ]
 [0.405 0.   ]
 [0.611 0.   ]
 [0.82  0.   ]]
  • 模型加载: ~12s(bf16,NPU 0)
  • 全链路推理(VLM rollout + diffusion 采样): ~3.7s
  • CoC 推理文本与未来轨迹输出正常,NPU 上运行稳定

6. 证据截图

截图说明
assets/agent_workflow.pngAgent 适配过程(环境准备 → 分析 → 推理脚本 → 验证 → 发布)
assets/npu_device_call.pngNPU 设备信息(Ascend 910B3)
assets/model_result.pngNPU 推理结果(CoC 文本 + 轨迹输出)

7. 目录结构

├── README.md                 # 模型卡片(本文件)
├── inference.py              # NPU 推理脚本(文本 / 全链路轨迹 / 服务化)
├── requirements.txt          # 依赖
├── verify_result.json        # NPU 实测验证结果
├── evidence/npu_inference.log# 推理日志
├── assets/                   # 三张证据截图
├── alpamayo_r1/              # vendored 官方源码(含 NPU 适配补丁)
└── cosmos_reason2/           # 本地化 Cosmos-Reason2 分词器(gated 规避)

8. 参考

  • 模型: https://huggingface.co/nvidia/Alpamayo-R1-10B
  • 代码: https://github.com/NVlabs/alpamayo
  • 论文: Alpamayo-R1: Bridging Reasoning and Action Prediction for Generalizable Autonomous Driving (arXiv:2511.00088)