模型适配 · 强化学习视觉-语言-动作 (VLA) 策略 · 昇腾 NPU
Beta 版本头信息
{hardware NPU}xvla/ 自包含包),全程 fp32 推理,精度与 CPU 一致(cos=0.999990,见 §3)。具体适配点见 §5。{hardware NPU} Ascend 910B(torch_npu 2.9.0.post1,CANN 8.5.1)| 组件 | 版本 |
|---|---|
| torch | 2.9.0+cpu |
| torch-npu | 2.9.0.post1 |
| CANN | 8.5.1 |
| transformers | 4.57.6 |
| numpy | 1.26.4 |
| Python | 3.11.14 |
| NPU | Ascend 910B ×2(本验证使用 npu:1) |
固定同一随机噪声(seed=1234),以确定性去噪循环对比 CPU 参考与 NPU 输出:
RESULT cos=0.999990 max_abs_diff=3.272533e-03 shape=(1, 30, 20)| 指标 | 值 |
|---|---|
| 余弦相似度 (cos) | 0.999990 |
| 最大绝对误差 (max_abs_diff) | 3.27e-03 |
| CPU 去噪耗时(10 步) | 19.14s |
| NPU 去噪耗时(10 步,warm-up 后) | 0.21s |
inference.py --mode serve 在 NPU 上启动 FastAPI 服务(POST /act):
python inference.py --mode serve --device npu:1 --port 8011import json, urllib.request, numpy as np, json_numpy
payload = {
'image0': json_numpy.dumps(np.random.randint(0, 255, (224, 224, 3), dtype=np.uint8)),
'language_instruction': 'pick up the red block',
'proprio': json_numpy.dumps(np.zeros(20, dtype=np.float32)),
'domain_id': 0,
'steps': 10,
}
req = urllib.request.Request('http://127.0.0.1:8011/act',
data=json.dumps(payload).encode(),
headers={'Content-Type': 'application/json'})
resp = json.loads(urllib.request.urlopen(req, timeout=60).read().decode())
action = np.asarray(resp['action']) # (30, 20)验证输出:action shape (30, 20),gripper 通道(idx 9/19)经 sigmoid 落在 [0,1]。
| # | 适配点 | 说明 |
|---|---|---|
| 1 | 强制 eager 注意力 | transformers 4.57 默认 autoset 为 sdpa,NPU 上会走 aclnnFlashAttentionScore 报 ERR00100;在 vendored configuration_florence2.py 三个 config 类中强制 _attn_implementation = "eager",并将 _supports_sdpa/_supports_flash_attn_2 置为 False |
| 2 | SoftPromptedTransformer 注意力 | vendored transformer.py 的 _has_sdp_attention() 在 torch_npu 可用时返回 False,改用手写 q@k·softmax·v eager 路径 |
| 3 | tied embedding 权重别名 | checkpoint 只存 model.shared.weight,encoder.embed_tokens.weight 为 tie 别名;加载时从 shared 复制补齐后 strict 加载(missing=0, unexpected=0) |
| 4 | 依赖自包含 | vendor modeling_florence2.py/configuration_florence2.py/processing_xvla.py 等官方源码到 xvla/ 包,消除对 transformers 5.x / 原仓 remote code 的依赖 |
| 5 | 输入输出 | 图像经 CLIP 预处理 224×224,语言指令 BART 分词(max 50),proprio [B,20],输出 [B,30,20] 动作轨迹 |
pip install -r requirements.txt
# 单样本推理(默认 npu:1)
python inference.py --mode single --device npu:1 --steps 10
# CPU vs NPU 精度对比
python inference.py --mode compare --device npu:1 --steps 10
# FastAPI 服务化
python inference.py --mode serve --device npu:1 --port 8011权重文件:model.safetensors(3.5GB,sha256 260cc58869125b826e93bcaa60bca3ea37bcc7aaf893d368a991ca14fde9f0c8),默认路径 /tmp/models/X-VLA-Libero/model.safetensors,可用环境变量 XVLA_WEIGHTS / XVLA_DEVICE 覆盖。
X-VLA-Libero/
├── inference.py # 推理脚本(single / compare / serve)
├── README.md # 部署说明文档
├── requirements.txt # 环境依赖清单
├── assets/ # 截图素材文件夹
│ ├── agent_workflow.png
│ ├── npu_device_call.png
│ └── model_result.png
└── xvla/ # vendor 自包含源码 + 配置文件
├── modeling_xvla.py
├── modeling_florence2.py
├── configuration_xvla.py
├── configuration_florence2.py
├── transformer.py
├── action_hub.py
├── processing_xvla.py
├── config.json
├── preprocessor_config.json
├── tokenizer_config.json
├── tokenizer.json
└── vocab.json@article{zheng2025x,
title = {X-VLA: Soft-Prompted Transformer as Scalable Cross-Embodiment Vision-Language-Action Model},
author = {Zheng, Jinliang and Li, Jianxiong and Wang, Zhihao and Liu, Dongxiu and Kang, Xirui
and Feng, Yuchun and Zheng, Yinan and Zou, Jiayin and Chen, Yilun and Zeng, Jia and others},
journal = {arXiv preprint arXiv:2510.10274},
year = {2025}
}