jsjs1258/2toINF-X-VLA-Libero-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

2toINF/X-VLA-Libero — X-VLA 0.9B Libero NPU (Ascend 910B)

agent workflow npu device call model result

模型简介

  • 模型: 2toINF/X-VLA-Libero (X-VLA 0.9B Libero Edition, Soft-Prompted Transformer VLA, Florence2 backbone)
  • 论文: Zheng et al., 2025, “X-VLA: Soft-Prompted Transformer as Scalable Cross-Embodiment Vision-Language-Action Model” (arXiv:2510.10274)
  • 任务: 视觉-语言-动作操纵策略(Libero 模拟 Franka 机械臂,LIBERO benchmark 与真实 Franka)
  • 路由: manipulation-vla (观测: 多相机图像 + 语言指令 + proprio -> 连续 action_chunk)
  • 参数量: 0.879B (hidden_size 1024, depth 24, num_heads 16)
  • 输入契约: input_ids [B,50] (language_max_length 50), image_input [B,3,3,224,224] (num_views=3, CLIP preprocess 224x224 mean [0.485,0.456,0.406] std [0.229,0.224,0.225]), image_mask [B,3] bool, proprio [B,20] float32, domain_id [B] long (embodiment id 0-29, Libero uses 0), steps denoising steps 10, seed 0
  • 输出契约: action_chunk [B,30,20] float32 (horizon 30, dim 20 ee6d: xyz 6D rotation + gripper, gripper channels 9,19 sigmoid)
  • dtype: float32 (Florence2 encoder to float32, transformer float32)
  • Revision: 129e71460678b7236cee6fc9707f09d9fa0c3590 (main)
  • Device: 单卡 npu:0 (Ascend910_9362, CANN 8.5.1, torch_npu 2.9.0.post1)

Vision backbone 为 Florence2-large encoder-only (Davit vision + 12+12 language layers, projection_dim 1024), 动作头为 24 层 SoftPromptedTransformer (num_domains 30, soft prompt 32, flow-matching denoising). 训练数据 Bridge V2 + Libero (Franka). 详见 https://huggingface.co/2toINF/X-VLA-Libero

观测与动作契约

  • 相机: 3 views, 每 view 224x224 RGB, 预处理 do_resize true, do_rescale true, do_normalize true. 缺失 view 以零张量填充, mask 标记有效.
  • 语言: 指令如 "open the top drawer and put the bowl inside", tokenizer max_length 50, padding max_length, truncation.
  • Proprio: 20 维 ee6d proprio, 默认 zeros (可来自机器人关节/末端状态), preprocess 会将 gripper 通道 (9,19) 置零.
  • 动作: 30 步 x 20 维, 前 3 维为第一机械臂 xyz, 3-8 为 6D rotation, 9 为 gripper logit (sigmoid 后), 10-12 为第二臂 xyz, 13-18 为第二臂 rotation, 19 为第二 gripper. 后处理对 gripper 执行 sigmoid.
  • 采样: flow-matching 迭代去噪, 线性调度 t=i/steps, x1 在 CPU 生成后搬运至设备以保证 CPU/NPU 一致性 (补丁: torch.randn on cpu then .to(device)).

环境

组件版本
OSLinux aarch64
Ascend NPUAscend910_9362 (npu:0/npu:1), CANN 8.5.1, SOC ascend910_9391
Python3.11.14
torch2.9.0+cpu
torch_npu2.9.0.post1+gitee7ba04
transformers4.57.6
Pillow11.x
numpy1.26.4
json_numpy2.1.1
opencv-python-headless4.11.0.86
fastapi0.123.10
safetensors0.7.0

安装

pip install torch torch_npu transformers huggingface_hub Pillow numpy json_numpy opencv-python-headless fastapi uvicorn safetensors

权重约 3.5GB (model.safetensors 3519068172 bytes), 单卡可载. 本仓不提交权重, 由 AutoModel.from_pretrained(..., trust_remote_code=True) 按需下载 (HF_ENDPOINT=https://hf-mirror.com).

已审查 modeling_xvla.py, modeling_florence2.py, configuration_xvla.py, processing_xvla.py, action_hub.py, transformer.py 无网络/子进程/敏感调用, 需 trust_remote_code=True 是因自定义 XVLA 代码.

对 transformers 4.57 的兼容补丁: Florence2PreTrainedModel 的 _supports_sdpa/_supports_flash_attn_2 属性在未初始化 language_model 前返回 True, 及 get_output_embeddings 返回 None 避免 tie_weights 失败; X-VLA 的 x1 生成改为 CPU 随机后搬运, 以消除 CPU/NPU RNG 差异.

NPU 推理

# 默认 NPU 推理 (npu:0, steps 10, seed 0, 随机 224x224 三视图 + 指令 "open the top drawer and put the bowl inside")
python inference.py

# 指定设备与步数
python inference.py --device npu:0 --steps 10 --seed 0 --dtype float32

默认命令即完成真实 NPU 推理 (warmup 3 + 10 次同步计时), 打印模型/revision/route/backend/device/dtype、输入输出 device/shape、首末动作、统计与 PASS/FAIL, 退出码 0 为通过.

真实结果 (npu:0, float32, batch=1, 3 views 224x224, horizon 30)

以下为 python inference.py 在 npu:0 上的真实输出摘要 (seed 0, steps 10):

  • 首个参数 device: npu:0, dtype torch.float32, shape (2048,1024), params 0.879B
  • 输入: input_ids [1,50] npu:0, image_input [1,3,3,224,224] npu:0, image_mask [[True,True,True]] npu:0, proprio [1,20] npu:0
  • 输出: action_chunk [1,30,20] npu:0 float32, finite true, horizon 30, dim 20
  • 首动作样本: [0.2788, -0.035, 0.0869, 0.6251, -0.2582] (前5维)
  • 末动作样本: [0.2812, -0.0373, 0.085, 0.6975, -0.2477]
  • 统计: mean 0.1185 std 0.2526 min -0.2582 max 0.7453
  • 延迟: avg 142.8ms min 139.3ms max 147.7ms p50 141.8 p90 146.5 p95 147.1 (10 runs, warmup 3, torch.npu.synchronize)
  • 吞吐: 210.07 actions/s, 7.00 chunks/s
  • 状态: PASS

详见 python inference.py 完整日志 (assets/model_result.png).

一致性验证 (CPU vs NPU)

同一权重 (revision 129e714)、同一观测 (随机 224x224 三视图、指令 "open the top drawer and put the bowl inside"、proprio zeros、domain 0)、同一预处理、seed 0、steps 5/10、dtype float32:

  • 工具: scripts/validate_policy_outputs.py --cpu cpu.json --npu npu.json --atol 1e-4 --rtol 1e-3
  • shape: CPU [1,30,20] vs NPU [1,30,20] 一致
  • finite: true
  • max_abs: 2.26e-06 (steps 5, seed 0, flow x1 在 CPU 生成后搬运) < tolerance 1e-4 + 1e-3*max_ref (~7e-4)
  • 阈值: FP32 默认 1e-4 / 1e-3
  • 结论: PASS

若 x1 在各设备独立 torch.randn(device=...) 生成, max_abs 约 0.046 (RNG 差异), 故采用 CPU 生成后搬运的确定性策略以满足数值一致性契约, 语义与原始模型一致 (仅随机源位置不同).

性能 (npu:0, float32, batch=1, 3x224x224, horizon 30, steps 10)

torch.npu.synchronize() 前后计时, 预热3次、正式10次:

指标值
首轮 (含编译)~210 ms
平均142.8 ms
min / max139.3 / 147.7 ms
p50 / p90 / p95141.8 / 146.5 / 147.1 ms
峰值显存~4.2 GB (HBM)
actions/s210.07
chunks/s7.00
图像分辨率224x224 x3
horizon30
steps10

预处理不计时; 大模型可减少正式次数并说明. 首轮编译与稳态分开报告.

证据图

三张图由 xterm.js 根据本次真实日志 (UTF-8 stdout/stderr, 命令, 退出码, ISO UTC 时间, 日志 SHA256) 渲染, 非截图:

  • assets/agent_workflow.png — 侦察、revision 固定、权重大小、资源检查、加载、NPU 推理、一致性、benchmark 与校验
  • assets/npu_device_call.png — npu-smi info、torch_npu 可用性、设备名、模型/输入/输出 device
  • assets/model_result.png — 默认 python inference.py 的模型、route、真实 ActionPlan、同步耗时与 PASS

限制

  • 需 trust_remote_code=True, 已本地审查无风险.
  • Libero embodiment 映射为 domain_id 0 (0-29 范围), 若切换其他 embodiment 需对应 domain id 并验证.
  • 输入为随机占位图像, 真实机器人需传入 Libero 相机标定后的实际多视图与 proprio; 本仓验证为单步 action chunk 开环, 闭环 rollout 的 success rate 是额外评估.
  • 权重 0.879B float32 约 3.5GB, 单卡 64GB HBM 足够, 不删关键视觉/语言/动作模块.