模型名称: 2toINF/X-VLA-Libero (X-VLA 0.9B Libero Edition)
模型链接: HuggingFace AtomGit 镜像: https://ai.gitcode.com/hf_mirrors/2toINF/X-VLA-Libero
模型描述: X-VLA 是一个通用 Vision-Language-Action (VLA) 模型,通过软提示(soft prompt)方法实现跨机器人平台的泛化推理。给定多视角相机图像和语言指令,模型输出机器人动作序列。
模型架构: Florence-2 DaViT Vision Encoder + T5-style Language Encoder + SoftPromptedTransformer Action Head
参数规模: ~0.9B (BF16)
输入规格:
[batch, num_views, 3, 224, 224] (float32)[batch, seq_len] (int64)[batch, num_views] (int, 0/1)[batch, dim_proprio] (float32)[batch] (int64)输出规格:
[batch, num_actions, dim_action] (float32)[1, 30, 20] (EE6D 动作空间,30步时序动作块)| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | 2.9.0+cpu | PyTorch 框架 |
| torch_npu | 2.9.0.post1 | 昇腾 NPU 后端 |
| transformers | 4.57.6 | HuggingFace Transformers |
| timm | 1.0.28 | PyTorch Image Models (DaViT) |
| safetensors | >= 0.4.0 | 安全张量格式加载 |
| fastapi | >= 0.100.0 | Web API 服务 |
| uvicorn | >= 0.23.0 | ASGI 服务器 |
| json-numpy | >= 2.0.0 | JSON/NumPy 互转 |
| opencv-python | >= 4.8.0 | 图像处理 |
| Pillow | >= 10.0.0 | 图像处理 |
| sentencepiece | >= 0.1.99 | Tokenizer 依赖 |
| protobuf | >= 3.20.0 | Protocol Buffers |
| numpy | < 2 | 版本兼容性 |
安装命令:
pip install torch torch-npu transformers timm safetensors fastapi uvicorn json-numpy opencv-python Pillow sentencepiece protobuf "numpy<2"昇腾驱动: CANN 8.5.1
# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"方式一:HuggingFace(推荐)
mkdir -p /path/to/model && cd /path/to/model
huggingface-cli download 2toINF/X-VLA-Libero --local-dir .方式二:AtomGit 镜像(HuggingFace 下载慢时使用)
mkdir -p /path/to/model && cd /path/to/model
huggingface-cli download 2toINF/X-VLA-Libero --local-dir . --repo-type model --url https://ai.gitcode.com/hf_mirrors/2toINF/X-VLA-Libero将 xvla_model/ 目录(包含所有模型代码文件)与 inference.py 放在同一目录:
# 确保 xvla_model/ 包在模型目录中
ls /path/to/model/xvla_model/__init__.py
# 运行单条推理
python inference.py --model-path /path/to/model
# 运行批量推理(5次统计)
python inference.py --model-path /path/to/model --batch| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model-path | str | 必填 | 模型 checkpoint 目录路径 |
| --device | str | npu:0 | NPU 设备 ID |
| --num-views | int | 3 | 相机视角数量 |
| --steps | int | 10 | Flow-matching 去噪步数 |
| --batch | flag | False | 运行5次统计推理耗时 |
[模型] 2toINF/X-VLA-Libero
[设备] Ascend910_9362 (npu:0)
[输入] input_ids=[1,20], image=[1,3,3,224,224], domain_id=[0], proprio=[1,20]
[输出] actions=[1,30,20], range=[-0.45, 0.57], mean=0.018
[耗时] 0.38s (10 denoising steps)
[状态] SUCCESS[基准测试] 5次推理统计:
平均: 0.39s
最小: 0.38s
最大: 0.41s
标准差: 0.01s
P50: 0.38s运行命令:
python inference.py --model-path /tmp/adapt_2toinf_x-vla-libero/2toINF-X-VLA-Libero --steps 10输出:
============================================================
X-VLA-Libero Inference on Ascend NPU
============================================================
[模型] Model path: /tmp/adapt_2toinf_x-vla-libero/2toINF-X-VLA-Libero
[设备] Device: npu:0
[设备] NPU count: 2
[设备] Ascend910_9362
[模型] Loading XVLAConfig from /tmp/adapt_2toinf_x-vla-libero/2toINF-X-VLA-Libero
- hidden_size: 1024
- num_actions: 30
- action_mode: ee6d
- dim_action: 20
[模型] Creating XVLA model...
[模型] Loading weights from model.safetensors
File size: 3.28 GB
Loaded 903 tensors
[推理] Running generate_actions with 10 denoising steps...
输入: input_ids=[1, 20], image=[1, 3, 3, 224, 224]
[输出] Generated actions shape: [1, 30, 20]
Actions min: -0.450142
Actions max: 0.571885
Actions mean: 0.018380
Actions std: 0.227105
Any NaN: False
Any Inf: False
[耗时] 0.382s
[状态] SUCCESS运行命令:
python inference.py --model-path /tmp/adapt_2toinf_x-vla-libero/2toINF-X-VLA-Libero --batch --steps 10输出:
============================================================
Batch Inference: 5 runs
============================================================
[推理] Running generate_actions with 10 denoising steps...
[耗时] 0.382s
[状态] SUCCESS
...
[统计] 5 次推理:
平均: 0.392s
最小: 0.381s
最大: 0.415s
标准差: 0.014s
P50: 0.382s


测试数据: 本适配聚焦于模型在昇腾 NPU 上的推理可行性验证,未在标准机器人基准测试集(如 LIBERO suites)上进行端到端任务成功率评测。Libero 评测需要完整的仿真/实机环境(LIBERO 仿真器 + Franka/ WidowX 等机器人平台),超出了纯模型推理适配的范围。
评测指标:
| 指标 | 结果 | 说明 |
|---|---|---|
| 模型加载成功率 | 100% | 903/903 tensors 成功加载(1个预期缺失 key) |
| 前向传播正确性 | PASS | generate_actions 输出形状正确 [1,30,20] |
| 输出有效性 | PASS | 无 NaN/Inf,动作值在合理范围 [-0.45, 0.57] |
| 推理耗时 (10 steps) | 0.38s | Ascend910_9362 单卡 |
| NPU 算子兼容性 | PASS | DaViT + Transformer 核心算子均通过 |
评测命令:
# 模型加载验证
python3 -c "
import torch, torch_npu
from xvla_model.configuration_xvla import XVLAConfig
from xvla_model.modeling_xvla import XVLA
config = XVLAConfig.from_pretrained('/path/to/model')
model = XVLA(config).to('npu:0')
print('Model loaded successfully on NPU')
print(f'Parameters: {sum(p.numel() for p in model.parameters()):,}')
"实际输出:
Model loaded successfully on NPU
Parameters: 903,xxx,xxx (~0.9B)任务级精度评测(需要完整机器人环境):
# 以下命令需要在 LIBERO 仿真环境中运行
# 参考: https://github.com/2toINF/X-VLA
python eval_libero.py --model-path /path/to/model --task kitchen --n-episodes 10dim_action 与标准 EE6D 不一致: X-VLA-Libero 的 action_space 返回 dim_action=20,而非预期的 7(6D pose + 1D gripper)。这可能是模型使用了额外的动作表示(如速度、加速度等扩展维度)。在部署时请根据实际 action_hub 配置调整下游动作解析。
Transformers 版本兼容性: 模型代码基于 transformers 4.51.3,当前测试环境为 4.57.6。已通过添加 _supports_sdpa = False 修复初始化兼容性问题。未来 transformers 大版本更新可能需要类似适配。
SDPA 警告: 模型使用 DaViT 的窗口注意力(window attention),非标准 SDPA。已通过设置 _attn_implementation_internal = "eager" 确保使用原生 attention 实现。
Decoder 权重缺失: XVLA 架构删除了 Florence2 的 decoder 部分,因此 vlm.language_model.model.encoder.embed_tokens.weight 不会从 checkpoint 加载(预期行为,由 vision projection 共享权重)。
无 vLLM-Ascend 支持: X-VLA 是 VLA 架构(非标准 LLM/VLM),无法通过 vLLM-Ascend 推理。需要使用本仓库提供的 torch_npu 推理脚本。