2
gcw_BOxvkDDf/x-vla-libero
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

X-VLA-Libero · Ascend NPU 适配

将 HuggingFace 模型 2toINF/X-VLA-Libero (Florence2 基座 Vision-Language-Action 机械臂策略,LIBERO 桌面操作基准)适配到华为昇腾 NPU(torch_npu)。

  • 输入:LIBERO 桌面场景图片 + 语言指令
  • 输出:30 步 × 20 维末端执行器动作轨迹(action_mode=ee6d,含 xyz 位置、6D 旋转、夹爪开合)

运行环境

  • Python 3.11 / torch 2.9.0 / torch_npu / CANN(Ascend 910)
  • transformers 4.57.6(trust_remote_code 加载仓库自带 modeling_xvla.py 等)
  • 依赖:einops timm json-numpy opencv-python-headless python-multipart

权重

python3 /opt/atomgit/adapt/_shared/download_weights.py 2toINF/X-VLA-Libero

权重缓存于 ./model_weights/2toINF/X-VLA-Libero/,加载时优先命中本地缓存。

命令行推理

python inference.py --img sample_libero.png --input "pick up the black bowl and place it on the plate"

--img 缺省使用工程内 sample_libero.png(PIL 生成的厨房台面黑碗 + 盘子场景图), --input 缺省为 "pick up the black bowl and place it on the plate"。可选 --steps 10、--domain_id 0。

FastAPI 服务

python inference.py --serve --host 0.0.0.0 --port 8015
  • GET / — HTML 上传页(图片 + 指令)
  • POST /predict — multipart file + instruction,返回动作轨迹 JSON
curl -s -X POST http://127.0.0.1:8015/predict \
  -F file=@sample_libero.png \
  -F instruction="pick up the black bowl and place it on the plate"

NPU 化说明

  • 全部 CUDA 设备调用已清除;get_device() 优先 npu:0,异常回退 cpu。
  • 模型与输入张量均迁移至 NPU;grep -rin cuda 工程 .py 零残留。
  • 适配 transformers 4.57.6:Florence2PreTrainedModel._supports_sdpa/_supports_flash_attn_2 在 language_model 尚不存在时返回 False;get_output_embeddings 在 lm_head 被 XVLA wrapper 删除(encoder-only)时返回 None。
  • flash-attn 未安装时自动走 eager attention。
  • 个别算子若 NPU 不支持,采用等价 torch 算子或局部 CPU fallback(返回前 .to(device) 回 NPU)。