华为昇腾模型适配第2期,适配模型为 edge-inference/smolvla-so101-pick-orange
SmolVLA SO101 PickOrange 是一个视觉-语言-动作(VLA)机器人策略模型,基于 SmolVLA 架构(SmolVLM2-500M-Video-Instruct 骨干 + 流匹配动作专家)。该模型在 LeIsaac(Isaac Sim)仿真环境中,针对 SO101 机器人臂执行"pick orange"(从桌上捡起橙子放到盘子里)任务进行了微调。模型权重 1.2GB,参数量约 262.7M(VLM 骨干 + Action Expert 流匹配去噪模块)。
本适配将模型部署到华为昇腾 NPU(Ascend910B)上,使用 torch_npu 原生推理,通过 FastAPI 提供 HTTP 服务。
| 项目 | 信息 |
|---|---|
| 硬件 | Ascend 910B (NPU 7, 64GB HBM) |
| 操作系统 | Linux (aarch64) |
| Python | 3.11.14 |
| PyTorch | 2.9.0 |
| torch_npu | 2.9.0.post1 |
| vLLM | 0.18.0 (vLLM-Ascend 门禁失败,模型非 LLM 架构) |
| lerobot | 0.4.4 (自带 SmolVLA 策略代码) |
| transformers | 4.57.6 |
| 推理方式 | torch_npu 原生推理 + FastAPI 服务化 |
python3 inference.py \
--weights /path/to/smolvla-so101-pick-orange \
--device npu:0 \
--state "0.1,0.2,0.3,0.4,0.5,0.6" \
--task "pick the orange and place it on the plate"python3 inference.py --serve --port 8000 --device npu:0服务启动后,可通过以下接口调用:
健康检查:
curl http://localhost:8000/health推理请求:
curl -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{
"state": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6],
"task": "pick the orange and place it on the plate"
}'# 使用合成测试图像 + 默认状态向量
python3 inference.py --weights smolvla-so101-pick-orange \
--device npu:0 \
--state "0.1,0.2,0.3,0.4,0.5,0.6" \
--task "pick the orange and place it on the plate"预期输出:
| 指标 | 数值 |
|---|---|
| 模型加载时间 | 18.7s (NPU, 离线模式) |
| 推理时间(单次) | 418ms (NPU fp32) |
| 动作输出维度 | 50步 x 6维关节位置 |
| 流匹配去噪步数 | 10步 |
| 图像输入 | 2路 480x640 RGB(front + wrist) |
| AICore 占用 | 峰值 ~20%(推理时) |
| HBM 占用 | 模型加载后约 3.2GB |
| 对比项 | 结果 |
|---|---|
| CPU fp32 vs NPU fp32 | 差异 < 0.7%(bf16 舍入正常范围) |
| 权重加载 | 500/500 键完全匹配 |
| 补丁影响 | torch.bucketize bf16→fp32 转换不影响精度 |
| 噪声种子 | 固定种子下输出可复现 |
smolvla 架构,需改用 torch_npu 原生推理。torch.bucketize 输入为 bf16,昇腾 searchsorted 不支持 bf16。需在 torch.bucketize 前将 bf16 输入转 fp32。torch.where 要求 condition 为 bool 类型,eager_attention_forward 中需将 Long 类型 mask 转为 bool。input_features 为 dict 类型,需转为 PolicyFeature 对象,包括 FeatureType 枚举转换。MEAN_STD 归一化,统计参数存储在 policy_preprocessor_step_5_normalizer_processor.safetensors 和 policy_postprocessor_step_0_unnormalizer_processor.safetensors 中。HF_HUB_OFFLINE=1 使用本地 cache。