hums6666/nvidia-alpamayo-r1-10b
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

nvidia/Alpamayo-R1-10B — 昇腾 NPU 自动驾驶 VLA 适配

昇腾NPU

原模型:nvidia/Alpamayo-R1-10B(NVIDIA 自动驾驶 Vision-Language-Action 模型)

  • 模型类型:alpamayo_r1 / alpamayo1_5(VLA),基于 Cosmos-Reason2 VLM 骨干 + 扩散轨迹解码器
  • 原始权重:https://ai.gitcode.com/hf_mirrors/nvidia/Alpamayo-R1-10B
  • 适配框架:torch-npu(CANN + torch_npu),推理设备 npu:0,精度 bfloat16
  • 输入:前视相机图像;输出:6.4s 未来驾驶轨迹(64 个航点,10Hz)

适配要点(CUDA 清零 + NPU 迁移)

  • 全局 CUDA 清零:工程代码不使用任何 torch.cuda / .cuda() / device='cuda' 调用, 模型与输入统一迁移 npu:0;alpamayo1_5 代码包内的 torch.cuda.empty_cache() 已改写为 torch.npu.empty_cache()。
  • NPU 初始化保护:torch.npu.set_device(0) 包在 try-except 中,失败即抛明确错误。
  • 离线化:VLM 骨干(Cosmos-Reason2-8B,即 Qwen3-VL 架构)的 config + 处理器本地重建 于 backbone/Cosmos-Reason2-8B/,tokenizer vocab=151669,加 4000 轨迹 token + 28 特殊 token 后 vocab=155697,与权重/config 完全一致;推理不依赖外网。
  • 注意力兼容:attn_implementation=flash_attention_2 改为 sdpa(NPU 原生支持)。
  • 加载方式:config model_type=alpamayo_r1 / _target_=alpamayo_r1.* 适配为 alpamayo1_5 代码包可加载格式(hydra target 前缀改写),权重从本地 model_weights/ 加载。

模型输入 / 输出

模态键名形状说明
输入相机图像(1,3,H,W) uint8前视相机图像
输入ego_history_xyz(1,1,16,3)ego 历史轨迹(1.6s @10Hz,本地位移坐标系)
输入ego_history_rot(1,1,16,3,3)ego 历史姿态(旋转矩阵)
输出trajectory.xyz(64,3)未来 6.4s 轨迹航点(米,本地位移坐标系)
输出trajectory.rot(64,3,3)未来轨迹姿态
输出waypointslist[64]{x,y,z} 航点列表
输出reasoningstrChain-of-Causation 驾驶推理文本

权重缓存目录:./model_weights/nvidia/Alpamayo-R1-10B(约 22GB,不入库,由 download_weights.py 下载)。

环境要求

  • Python 3.11(实测 3.11.14)
  • 昇腾 NPU(Ascend910,实测 2×62GB HBM),torch_npu 已就绪
  • torch==2.9.0、transformers==4.57.6(Qwen3-VL 原生支持)、torch_npu
  • 详见 requirements.txt

使用方法

1) 下载权重

python3 download_weights.py

2) 命令行单图推理

python3 inference.py --img test_images/front_camera.png

输出轨迹 JSON:status/model/device/trajectory/waypoints。

3) FastAPI 服务

uvicorn inference:app --host 0.0.0.0 --port 8000
curl -X POST http://127.0.0.1:8000/predict -F "file=@test_images/front_camera.png"

适配脚本

  • inference.py:CLI + FastAPI 双模式 NPU 推理(CUDA 清零 + NPU 迁移)
  • download_weights.py:GitCode HF 镜像权重下载(WAF 429 退避)
  • alpamayo_code/:alpamayo1_5 代码包(已做 CUDA 清零与离线化适配)
  • backbone/Cosmos-Reason2-8B/:本地重建的 VLM 骨干 config + 处理器
  • assets/:适配取证截图

版权与许可

模型权重许可见原仓库 LICENSE;本仓库为昇腾 NPU 适配工程。