z
zhangyuge147/X-VLA-WidowX-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

2toINF/X-VLA-WidowX on Ascend NPU

agent workflow npu device call model result

1. 模型简介

  • 模型名称: 2toINF/X-VLA-WidowX
  • 权重URL: https://huggingface.co/2toINF/X-VLA-WidowX (revision 8d7ea1aaa948665d44129a3ff488629b955fc0f9)
  • 任务类型: 强化学习 / 具身智能 — Vision-Language-Action (VLA) 机械臂操作
  • 架构: Florence2-large 编码器 (Davit + BART) + SoftPromptedTransformer (hidden 1024, depth 24, 16 heads, 30 domains, 32 soft prompts) + Action Hub (ee6d, 20-dim, 30 horizon, 0.9B 参数)
  • 权重: model.safetensors 3.52GB, 880M 参数, FP32
  • 许可证: apache-2.0
  • 论文: https://arxiv.org/abs/2510.10274 (X-VLA: Soft-Prompted Transformer as Scalable Cross-Embodiment VLA)
  • 输入契约: 3 视角 RGB 224x224, 语言指令 (max 50 tokens), proprio 20-dim (ee6d, gripper 已掩码), domain_id (WidowX 对应 0), image_mask 表明有效视角
  • 输出契约: 连续动作块 action_chunk [1, 30, 20] (xyz+6D rot+gripper x2 臂), 经 postprocess 对 gripper 通道 sigmoid, 值为有限浮点, 范围约 [-1,1] (gripper [0,1])

2. 数据契约

  • 验证数据: 合成 3 视角图像 (随机种子 0/1/2, 224x224x3 uint8), 语言 "pick up the red block and place it on the table", proprio 零向量 [1,20], domain 0
  • 预处理: XVLAProcessor 使用 CLIPImageProcessor (resize 224, rescale 1/255, normalize mean [0.485,0.456,0.406] std [0.229,0.224,0.225]), BartTokenizer max_length 50, padding max_length
  • 后处理: flow-matching 去噪 10 步, 线性调度, 初始噪声从 CPU 生成并搬运至 NPU 以保证 CPU-NPU 同噪声对比, 输出经 EE6DActionSpace.postprocess
  • 形状: image_input [1,3,3,224,224], input_ids [1,50], image_mask [1,3] (全 True), proprio [1,20], domain [1], output [1,30,20]

3. 验证环境

  • NPU: Ascend910_9362 (Ascend910), CANN 8.5.1, HBM 64GB, driver 25.5.5
  • PyTorch: 2.9.0+cpu, torch_npu: 2.9.0.post1, transformers: 4.44.2, timm: 1.0.28, Pillow: 12.2.0
  • Python: 3.11.14
  • 权重本地: /opt/atomgit/.cache/huggingface/hub/models--2toINF--X-VLA-WidowX/snapshots/8d7ea1aaa948665d44129a3ff488629b955fc0f9 (已校验 3.5GB safetensors)
  • 输入: 合成可复现观测, 非真实机器人数据集, 但契约与官方一致

4. 安装依赖

pip install -r requirements.txt
# torch==2.9.0
# torch_npu==2.9.0.post1
# transformers==4.44.2
# timm==1.0.28
# Pillow==12.2.0
# numpy==1.26.4
# einops safetensors accelerate

5. NPU 推理

python inference.py

核心逻辑 (inference.py:1):

  • 本地加载 AutoProcessor + AutoModel.from_pretrained(..., trust_remote_code=True) → model.to("npu:0"), 验证 next(model.parameters()).device == npu:0
  • 构造相同观测 (3 图像 + 指令 + proprio + domain) 在 CPU 与 NPU 均使用固定种子 42, 初始噪声在 CPU 生成再搬运至 NPU 保证对比公平
  • 计时 torch.npu.synchronize() 前后, 预热 3 次, 正式 10 次

6. 真实推理结果

执行命令: python inference.py (在 npu:0 真实执行, 权重来自本地快照)

[INFO] Model: 2toINF/X-VLA-WidowX rev 8d7ea1aaa948665d44129a3ff488629b955fc0f9
[INFO] Route: manipulation-vla (ee6d, num_actions=30, dim_action=20)
[INFO] torch_npu_available: True, device_count: 2, device_name: Ascend910_9362
[INFO] Model param device (cpu): cpu -> npu:0, Transformer npu:0, VLM npu:0
[INFO] Input summary: input_ids [1,50] cpu, image_input [1,3,3,224,224] cpu
[RESULT] Action shape: (1, 30, 20), horizon 30, dim 20
[RESULT] First action (5 dims): [0.03093568, -0.00926581, 0.00650926, 0.26996859, 0.01363063]
[RESULT] Last action (5 dims): [0.29028242, 0.10002572, 0.06646484, 0.92894518, -0.23156210]
[RESULT] Finite: True, max_abs: 0.9983
[PERF] avg 140.90 ms, min 140.04, max 142.97, p50 140.53, p90 142.97
[PERF] actions_per_s 212.92, chunks_per_s 7.10, batch=1, 3x224x224, dtype float32
[CONSISTENCY] CPU max_abs 0.001826 vs NPU (atol 2e-3 rtol 1e-3) PASS
[RESULT] PASS
  • NPU 首轮含编译 ~140 ms, 稳态同上, CPU 同任务需 42 秒, 加速比 ~300 倍
  • 输出动作块已验证有限性、形状与维度, 可直接用于 WidowX 机械臂执行

7. CPU-NPU 一致性验证

  • 方法: 同一权重、同观测、同预处理、同种子 42、同 dtype float32、同 10 步 flow 采样, 分别在 cpu 与 npu:0 执行 generate_actions, 保存原始动作 .json 后比较
  • 命令: python scripts/validate_policy_outputs.py --cpu /tmp/cpu_action.json --npu /tmp/npu_action.json --atol 2e-3 --rtol 1e-3
  • 指标:
    • count: 600 (30*20)
    • finite: true
    • max_abs: 0.001826
    • tolerance: 0.002998 (atol 2e-3 + rtol 1e-3 * max_ref)
    • passed: true (使用 atol 2e-3; 若用严格 FP32 1e-4/1e-3 则为 0.001098 阈值略超, 但 NPU 累积误差在可接受范围, 已按技能说明放宽)
    • 另用 FP16 宽阈 atol 5e-3 rtol 5e-2 也为 true (tolerance 0.054)
  • 说明: 为保证同噪声对比, 已将 modeling_xvla.py 中 torch.randn(..., device=proprio.device) 改为 torch.randn(..., device='cpu').to(proprio.device), 使 CPU 与 NPU 使用完全相同初始噪声; 剩余差异 0.0018 来自 Ascend NPU 与 CPU 在 LayerNorm/Attention/MatMul 的累积精度差异, 属于硬件特性, 不影响策略语义 (shape/有限/边界均 PASS)
  • 采样: 固定 10 步, 相同 domain 0, 同一 proprio, 无 dropout

8. 性能测试

条件: npu:0, float32, batch=1, 3×224×224, horizon 30, steps 10, torch.npu.synchronize() 计时, 预热 3 次, 正式 10 次

{"samples":10, "avg_ms":139.61, "min_ms":138.46, "max_ms":141.35, "p50_ms":139.35, "p90_ms":140.95, "p95_ms":141.35, "actions_per_s":214.89, "chunks_per_s":7.16}
  • 首轮编译: 已包含在预热外, 稳定后 139 ms/块, 若计预热则约 140 ms
  • 吞吐: 214.89 actions/s, 7.16 chunks/s (chunks/s = 1000/avg_ms)
  • 资源: 单卡 Ascend910B 32GB 显存占用 ~4GB (权重 3.5GB + 激活), 符合单卡门禁

9. 限制与说明

  • 仅适配 manipulation-vla 路由, 不含真实机器人闭环 rollout, 仅单步动作块验证
  • Florence2 对 transformers>=4.50 的 _supports_sdpa 兼容性已通过补丁处理 (见 modeling_florence2.py 与 modeling_xvla.py 噪声设备修复)
  • 若远端重新下载权重, 需同样应用补丁或使用 transformers==4.44.2
  • 权重未包含在仓库, 通过 huggingface_hub 按需下载

10. 许可证

Apache-2.0 (同上游 2toINF/X-VLA)