gcw_mXoV1I2Z/X-VLA-Pt
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

X-VLA-Pt · 昇腾 NPU 适配版 (Ascend torch-npu)

模型: 2toINF/X-VLA-Pt — 0.9B 视觉-语言-动作 (Vision-Language-Action, VLA) 策略模型。 本仓库为该模型在 昇腾 910 (torch-npu) 上的适配工程, 提供 inference.py 双模式推理入口 (CLI + FastAPI)。

模型简介

X-VLA-Pt 是一个端到端 VLA (Vision-Language-Action) 模型, 接收 图像 与 语言指令, 输出机器人的 动作轨迹 (end-effector 位姿 + 夹爪)。

  • 视觉语言骨干: Microsoft Florence-2 (large, encoder-only)
  • 时序/动作头: SoftPromptedTransformer (domain-aware)
  • 动作空间: ee6d (end-effector xyz + 6D 旋转 + 夹爪), dim_action = 20
  • 输出动作步数: num_actions = 30

输入 / 输出格式

项说明
输入图像1 张或多张视角图像 (PIL / JPEG), 预处理至 224×224, 归一化 (CLIP mean/std)
输入指令自然语言文本, 如 "pick up the red block"
输出动作actions: 形状 [30, 20] 的浮点数组 (30 步 × 20 维 ee6d 动作)
动作语义通道 0-2/10-12: xyz 位置(缩放 500); 3-8/13-18: 6D 旋转(缩放 10); 9/19: 夹爪开合(sigmoid)

NPU 适配要点 (模板① CUDA 清理)

  • 全代码域禁止任何 CUDA 调用 (.cuda() / torch.cuda.* / device="cuda" / CUDA_VISIBLE_DEVICES / cudnn.*)。
  • 模型与输入 Tensor 全部迁移 npu:N; 入口 import torch_npu 并 torch.npu.set_device(N)。
  • NPU 初始化失败直接报错退出, 不做 CPU/CUDA 回退。
  • 仓库自带 modeling_xvla.py / modeling_florence2.py / processing_xvla.py / transformer.py / action_hub.py 经审查不含任何 CUDA 代码; Florence2 的 flash-attn 为条件导入, 未安装时自动回落到 eager/SDPA 注意力。
  • 权重加载: AutoModel.from_pretrained(..., trust_remote_code=True, torch_dtype=torch.bfloat16)。

使用方式

环境

pip install -r requirements.txt

1. CLI 单图推理

python inference.py --img test_input.png --text "pick up the red block" --device npu:1

输出 JSON, 含 actions (30×20), last_action, last_gripper, exit_status, inference_ms 等。

2. FastAPI 服务

python inference.py --serve --port 8000          # 默认 device=npu:1

请求:

curl -F "file=@test_input.png" -F "text=pick up the red block" http://127.0.0.1:8000/predict

返回与 CLI 相同的 JSON 推理结果。

3. 权重缓存

权重自动从 hf-mirror.com (回退 ai.gitcode.com/hf_mirrors) 下载并缓存到 ./model_weights/X-VLA-Pt/, 已缓存直接复用 (打印 [cache-hit]), 可用 --force_download 强制重下。

证据截图

  • assets/agent_workflow.png — NPU 部署依赖安装 + 任务启动总日志
  • assets/npu_device_call.png — CLI 命令行推理成功输出
  • assets/model_result.png — FastAPI 返回推理结果

许可证

模型 Apache-2.0 (来源 2toINF/X-VLA-Pt)。