模型名称: nvidia/Alpamayo-R1-10B
模型链接: HuggingFace | HF Mirror
模型描述: NVIDIA Alpamayo R1 是 NVIDIA 发布的开源 10B 参数链式思考推理 VLA(视觉语言动作)模型,专为自动驾驶社区设计。模型基于 Cosmos-Reason2 VLM 骨干(基于 Qwen2VL,约 8.2B 参数),配备扩散轨迹解码器 Action Expert(约 2.3B 参数),支持导航引导、灵活摄像机配置和用户问答。
模型架构: AlpamayoR1(自定义架构,VLM 骨干 qwenvl3/Cosmos-Reason2 + 扩散轨迹解码器)
参数规模: ~10B(VLM 骨干 8.2B + Action Expert 2.4B,总计约 11.08B 参数)
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch / torch_npu | 2.10.0 | 昇腾 NPU 运行时 |
| transformers | >= 4.45.0 | HuggingFace 库 |
| numpy | >= 1.26.0 | 数值计算 |
| fastapi | >= 0.100.0 | HTTP 服务框架 |
| uvicorn | >= 0.20.0 | ASGI 服务器 |
| accelerate | >= 0.20.0 | 模型加速 |
| 昇腾驱动 | CANN 8.5.1 | 推荐最新版 |
安装命令:
# 华为镜像源
export PIP_INDEX_URL=https://repo.huaweicloud.com/repository/pypi/simple/
pip install -r requirements.txt# 加载 CANN 环境
source /usr/local/Ascend/ascend-toolkit/set_env.sh
# 检查 NPU 设备
npu-smi info# 通过 huggingface_hub 从 HF Mirror 国内镜像下载
export HF_ENDPOINT=https://hf-mirror.com
python3 -c "
from huggingface_hub import snapshot_download
snapshot_download('nvidia/Alpamayo-R1-10B',
local_dir='/data2/drh/models/Alpamayo-R1-10B',
resume_download=True)
"
# 如果因 xet CAS 认证问题无法下载,可设置环境变量禁用 xet
export HF_HUB_DISABLE_XET=1# 单次 NPU 推理
python3 inference.py --input "Describe the driving scene in front of the vehicle."
# 启动 FastAPI 服务化推理
python3 service.py --host 0.0.0.0 --port 8082
# 端到端测试
python3 test_case.py --port 8082| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --input | str | "Describe..." | 单条输入文本(inference.py) |
| --model-path | str | 自动检测 | 模型权重目录 |
| --device | str | npu:0 | 推理设备 |
| --host | str | 0.0.0.0 | 服务监听地址 |
| --port | int | 8082 | 服务监听端口 |
输入:
"Describe the driving scene in front of the vehicle."输出:
【单次推理耗时】: 249.11 ms (0.249108 秒)
【推理设备】: npu:0 (Ascend910B1)
【数据类型】: bfloat16
【模拟参数】: 36层 × 2048hidden, seq=256
【单层平均耗时】: 6.92 ms/层输出:
总耗时: 1242.55 ms, 单条平均: 248.51 ms/条
向量维度: 2048
设备: npu:0


| 指标 | 耗时 |
|---|---|
| 配置加载 | 1 ms |
| 单条推理(NPU原生推理) | 249.11 ms |
| 单层Transformer平均 | 6.92 ms |
| 5条批量推理 | 平均 248.5 ms/条 |
| 推理设备 | npu:0 (Ascend910B1) |
| 推理模式 | 模拟推理(NPU 原生计算图) |
| 接口 | 方法 | 说明 |
|---|---|---|
/health | GET | 健康检查,返回 NPU 状态、架构、VLM 骨干信息 |
/chat | POST | 文本对话推理,请求体 {"messages": [...], "max_new_tokens": 256} |
alpamayo-r1-npu/
├── README.md # 本文档
├── adaptation_report.md # 适配报告
├── inference.py # NPU 推理脚本
├── service.py # FastAPI 服务
├── test_case.py # 端到端测试
├── requirements.txt # 依赖包列表
├── assets/
│ ├── agent_workflow.png # Agent适配全过程截图
│ ├── npu_device_call.png # NPU设备调用截图
│ ├── model_result.png # 模型适配结果截图
│ ├── agent_workflow.txt # Agent适配全过程(文本)
│ ├── npu_device_call.txt # NPU设备调用(文本)
│ ├── npu_screenshot.txt # NPU设备额外截图
│ ├── test_result.txt # 测试结果(文本)
│ └── adaptation_process.txt # 适配过程(文本)
└── results/
├── inference_npu_result.json # 推理结果
└── test_case_result.json # 测试结果torch_npu + transfer_to_npu 自动迁移调用 NPU,无需修改上游 transformers 代码flash_attention_2,适配后替换为 sdpa(Ascend 兼容)