liuhongwei-2026/X-VLA-Libero
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

X-VLA-Libero (0.9B) on Ascend NPU

模型适配 · 强化学习视觉-语言-动作 (VLA) 策略 · 昇腾 NPU

Beta 版本头信息

{hardware NPU}

1. 简介

  • 模型来源: 2toINF/X-VLA-Libero(AtomGit 镜像: https://ai.gitcode.com/hf_mirrors/2toINF/X-VLA-Libero)
  • 模型类型: X-VLA —— X-VLA: Soft-Prompted Transformer as Scalable Cross-Embodiment Vision-Language-Action Model(arXiv:2510.10274)。本仓库为 Libero Edition:在 Libero 仿真基准(30 个任务域)上强化学习微调的 VLA 策略,输入第一视角图像 + 语言指令,输出 30 步 × 20 维的末端执行器动作轨迹(ee6d:xyz + 6D 旋转 × 2 组 + 2 路夹爪,流匹配去噪)。
  • 参数量: 879,481,230(879.5M,fp32)
  • 架构: Florence-2 编码器骨干(DaViT 视觉塔 + BART 12+12 层语言编码器,仅用 encoder)→ 视觉/文本特征融合 → SoftPromptedTransformer(24 层、1024 维、16 头,含 30 域 × 32 token 可学习软提示 + 时间步嵌入)→ Action Hub(ee6d 动作空间,gripper sigmoid 后处理)。
  • 适配状态: SUCCESS
  • 适配说明: X-VLA 为 VLA 强化学习模型(非 LLM),不适用 vLLM-Ascend;本项目采用 torch_npu 在昇腾 NPU 上直接加载推理。完整 vendor 官方源码(xvla/ 自包含包),全程 fp32 推理,精度与 CPU 一致(cos=0.999990,见 §3)。具体适配点见 §5。
  • 适配时间: 2026-08-21
  • 硬件: {hardware NPU} Ascend 910B(torch_npu 2.9.0.post1,CANN 8.5.1)

2. 验证环境

组件版本
torch2.9.0+cpu
torch-npu2.9.0.post1
CANN8.5.1
transformers4.57.6
numpy1.26.4
Python3.11.14
NPUAscend 910B ×2(本验证使用 npu:1)

3. 精度验证(CPU vs NPU)

固定同一随机噪声(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

4. 服务化推理(FastAPI)

inference.py --mode serve 在 NPU 上启动 FastAPI 服务(POST /act):

python inference.py --mode serve --device npu:1 --port 8011
import 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]。

5. NPU 适配点

#适配点说明
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
2SoftPromptedTransformer 注意力vendored transformer.py 的 _has_sdp_attention() 在 torch_npu 可用时返回 False,改用手写 q@k·softmax·v eager 路径
3tied 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] 动作轨迹

6. 快速开始

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 覆盖。

7. 项目结构

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

8. 引用

@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}
}