liuhongwei-2026/beaver-7b-v1.0-reward
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

2toINF/X-VLA-WidowX on Ascend NPU

模型适配 · VLA 强化学习机器人策略 (Vision-Language-Action) · 昇腾 NPU

Beta 版本头信息

{hardware NPU}

1. 简介

  • 模型来源: 2toINF/X-VLA-WidowX(AtomGit 镜像: https://ai.gitcode.com/hf_mirrors/2toINF/X-VLA-WidowX)
  • 模型类型: X-VLA (Extended Vision-Language-Action) —— 清华 AIR-Dream / 2toINF 提出的跨本体 VLA 基础模型(Zheng et al., 2025, arXiv:2510.10274)。X-VLA-WidowX 是面向 WidowX 机械臂的 0.9B 参数策略,采用 Flow Matching(线性插值迭代去噪)生成 30 步、20 维末端执行器动作(ee6d 动作空间:位置 + 6D 旋转 + 夹爪),适用于强化学习 / 模仿学习部署。
  • 模型结构:
    • 视觉语言骨干: Florence2-large 编码器(DaViT 视觉塔 + 文本编码器,projection_dim=1024)
    • 动作头: Soft-Prompted Transformer(24 层 / 1024 维 / 16 头,含 30 个本体的 domain-aware soft prompts)
    • 动作空间: ee6d(dim_action=20,gripper_idx=(9,19),位置 XYZ_SCALE=500、旋转 ROT_SCALE=10、夹爪 sigmoid)
  • 参数量: 879.5M
  • 输入: 1~3 视角 RGB 图像(224×224,CLIP 归一化)+ 语言指令 + proprio 状态(20 维)+ domain_id
  • 输出: [30, 20] 归一化动作序列(末端 xyz / 6D 旋转 / 夹爪开合)

2. 适配说明

  • 该模型是 VLA 强化学习策略(非自回归纯文本 LLM),不适用 vLLM-Ascend;本项目在 torch_npu 上直接加载推理,全程 fp32 零精度损失,无算子替换、无 CUDA 依赖。
  • 模型代码(modeling_florence2.py / modeling_xvla.py / transformer.py / action_hub.py / processing_xvla.py / 两个 configuration)已 vendor 进 xvla/ 包,自包含可离线加载,不依赖 trust_remote_code 或外网。
  • transformers 4.57 兼容性修复(vendor 代码基于旧版 transformers):
    • Florence2PreTrainedModel._supports_sdpa / _supports_flash_attn_2 由 property 委托改为带 getattr 守卫,避免 __init__ 期间 language_model 尚未赋值导致 AttributeError;
    • Florence2LanguageForConditionalGeneration.get_output_embeddings 加守卫(XVLA 裁剪了 decoder/lm_head,tie_weights() 不再报错)。
  • flow-matching 可复现对比: 推理从随机噪声 x1 迭代去噪,脚本复刻官方 generate_actions 去噪循环并支持 --seed 注入同一初始噪声,保证 CPU/NPU 逐位可比。

3. 环境准备

# Python 3.11 + CANN 8.5.1 + torch_npu 2.9.0.post1
pip install torch==2.9.0 torch_npu==2.9.0.post1 -i https://mirrors.aliyun.com/pypi/simple/
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

4. 权重获取

权重约 3.5GB(model.safetensors,sha256 fb5e3d58...c4a7f),三路通道任选:

# 通道一:AtomGit 镜像(gitcode LFS,约 16MB/s)
git clone https://gitcode.com/hf_mirrors/2toINF/X-VLA-WidowX.git /tmp/models/X-VLA-WidowX

# 通道二:HF 镜像(hf-mirror)
HF_ENDPOINT=https://hf-mirror.com python -c "
from huggingface_hub import snapshot_download
snapshot_download('2toINF/X-VLA-WidowX', local_dir='/tmp/models/X-VLA-WidowX')
"

# 通道三:ModelScope(若镜像已收录)
# python -c "from modelscope import snapshot_download; snapshot_download('2toINF/X-VLA-WidowX', local_dir='/tmp/models/X-VLA-WidowX')"

注意:本项目目录仅含代码与文档,权重不随仓分发,推理时通过 --model-dir 指向本地权重目录。

5. 推理验证(昇腾 NPU)

5.1 单次推理(NPU 卡 1)

python3 inference.py --model-dir /tmp/models/X-VLA-WidowX \
    --image assets/demo_widowx.png --instruction "push the can to the right" \
    --device npu:1 --seed 42

5.2 合成演示图(无需外部图片,快速验证)

python3 inference.py --model-dir /tmp/models/X-VLA-WidowX --synthetic-demo --device npu:1

5.3 CPU vs NPU 精度对比(固定同一初始噪声,含 NPU 预热)

python3 inference.py --model-dir /tmp/models/X-VLA-WidowX --synthetic-demo \
    --device npu:1 --seed 42 --compare

6. 验证结果(本仓库实测)

指标结果
设备Ascend 910 (npu:1),torch_npu 2.9.0.post1,CANN 8.5.1
推理时延172.8 ms / 次(10 步 flow-matching 去噪,fp32)
CPU 对照时延35445.9 ms / 次
CPU vs NPU cosine 相似度0.99999959
CPU vs NPU max abs error2.18e-03(动作量纲 1e-2,误差 3 个量级以下)
输出形状(30, 20) 动作序列(30 步 × 20 维 ee6d)

7. 输出说明

generate_actions 输出 20 维 ee6d 动作向量,通道布局:

  • [0:3] — 末端位置 xyz(归一化,XYZ_SCALE=500)
  • [3:9] — 6D 旋转表示
  • [9] — 夹爪 logits(postprocess 后经 sigmoid → 0~1 开合度)
  • [10:13] / [13:19] / [19] — 第二组动作通道(双 gripper 布局,gripper_idx=(9,19))

动作序列保存至 /tmp/xvla_action.npy,可直接供机器人执行器消费。

8. 目录结构

X-VLA-WidowX/
├── inference.py        # 推理脚本(torch_npu 直接加载 + flow-matching 去噪 + CPU 对比)
├── README.md           # 部署说明文档
├── requirements.txt    # 环境依赖清单
├── xvla/               # vendored 模型代码包(自包含,离线加载)
│   ├── modeling_xvla.py / modeling_florence2.py / transformer.py
│   ├── action_hub.py / processing_xvla.py
│   └── configuration_xvla.py / configuration_florence2.py
└── assets/             # 截图素材(agent_workflow.png / npu_device_call.png / model_result.png)

9. 服务化推理(可选)

模型自带 FastAPI 服务(XVLA._build_app / run),可启动 HTTP 服务化推理:

from xvla import XVLA, XVLAConfig, XVLAProcessor
model = XVLA.from_pretrained("/tmp/models/X-VLA-WidowX").to("npu:1")
processor = XVLAProcessor.from_pretrained("/tmp/models/X-VLA-WidowX")
model.run(processor, host="0.0.0.0", port=8000)
# POST /act  {"image0": ..., "language_instruction": "...", "proprio": [...], "domain_id": 0}

10. 参考

  • 模型主页: https://huggingface.co/2toINF/X-VLA-WidowX
  • 论文: X-VLA: Soft-Prompted Transformer as Scalable Cross-Embodiment Vision-Language-Action Model(arXiv:2510.10274)
  • 项目网站: https://thu-air-dream.github.io/X-VLA/