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

X-VLA-Pt — Florence2-based Vision-Language-Action Model on Ascend NPU

This repository adapts 2toINF/X-VLA-Pt — a Florence2-based Vision-Language-Action (VLA) model (~0.9B params, single model.safetensors, action mode ee6d, 30 action steps) — to run on Ascend NPU via torch-npu. All CUDA-related calls are removed; the model and input tensors are placed on npu:0.

ItemValue
Base modelFlorence-2 large encoder + SoftPromptedTransformer
Model classXVLA (model_type: xvla)
Action spaceee6d (end-effector xyz + 6D rotation + gripper, dim 20)
Weightsmodel.safetensors (~3.3 GB) cached under model_weights/
Devicenpu:0 (Ascend), bfloat16
LicenseApache-2.0

What is X-VLA-Pt?

X-VLA is a soft-prompted Transformer Vision-Language-Action model for cross-embodiment robot learning. It uses:

  1. Florence2 encoder as the vision-language backbone (image + language instruction),
  2. SoftPromptedTransformer as a flow-matching action denoiser,
  3. Action Hub for action-space definition / pre- and post-processing.

For a single input image and a language instruction the model predicts an action sequence (num_actions x dim_action). This repo focuses on the NPU inference path.


Repository layout

.
├── inference.py            # CLI + FastAPI dual-mode inference on npu:0 (no CUDA)
├── README.md
├── xvla/                   # snapshot of the repo's custom modeling code (Apache-2.0)
│   ├── modeling_xvla.py            # XVLA model class
│   ├── configuration_xvla.py       # XVLAConfig
│   ├── modeling_florence2.py       # Florence2 backbone
│   ├── configuration_florence2.py
│   ├── processing_xvla.py          # XVLAProcessor
│   ├── transformer.py              # SoftPromptedTransformer
│   └── action_hub.py               # action-space registry (ee6d / joint / agibot)
├── config.json / preprocessor_config.json / tokenizer.json / vocab.json
├── assets/                 # screenshots (published to repo root)
└── model_weights/          # <-- local cache, git-ignored, NOT pushed
    └── X-VLA-Pt/
        ├── model.safetensors
        ├── config.json
        ├── ... modeling files ...

NPU adaptation notes

  • No CUDA anywhere. grep -rni cuda on the codebase returns nothing. All tensors use .to(device) / .to(npu:0) and the modeling code derives the device from the inputs, so it is device-agnostic by design.
  • Device init is wrapped in try-except inside inference.init_device() with a clear error message if the Ascend NPU is unavailable.
  • Model and input tensors (input_ids, image_input, image_mask, proprio, domain_id) are placed on npu:0; the model runs in bfloat16.
  • torch_npu prints many harmless ownership/collect-env warnings on stdout — these can be ignored.
  • The custom modeling code is loaded from the bundled xvla package (xvla.modeling_xvla.XVLA, xvla.processing_xvla.XVLAProcessor) — a device-agnostic snapshot of the repo's modeling files with a timm-free DropPath fallback and the newer-transformers attention-capability flags (_supports_sdpa etc.) so the model instantiates cleanly.

Installation

pip install torch torch_npu transformers huggingface_hub fastapi uvicorn pillow numpy opencv-python json_numpy

Set the HF endpoint to the GitCode mirror used for downloads:

export HF_ENDPOINT=https://hf-mirror.com

CLI inference (single image)

python3 inference.py --img test.png --instruction "pick up the object"

The weights are auto-downloaded into ./model_weights/X-VLA-Pt on the first run and reused afterwards (local cache is checked first; no re-download).

Example output (truncated):

{
  "model": "2toINF/X-VLA-Pt",
  "device": "npu:0",
  "instruction": "pick up the object",
  "action_mode": "ee6d",
  "num_actions": 30,
  "dim_action": 20,
  "domain_id": 0,
  "steps": 6,
  "action": [...],
  "status": "ok"
}

Options: --img <path>, --instruction "...", --domain <id>, --steps <n>, --seed <n>, --dtype bfloat16|float32.


FastAPI service (image upload)

python3 inference.py --server --host 0.0.0.0 --port 8000
# health check
curl http://127.0.0.1:8000/health

# inference: POST an image file (multipart)
curl -X POST http://127.0.0.1:8000/predict \
  -F "file=@test.png" \
  -F "instruction=pick up the object" \
  -F "domain_id=0" \
  -F "steps=6"

Response is the same JSON result as the CLI mode.


Verification (this project)

Ran on Ascend 910 (CANN 8.5.1, torch-npu):

$ python3 inference.py --img test.png
[INFO] Using local weights from ./model_weights/X-VLA-Pt
[INFO] Device: npu:0
[INFO] Running single-image inference on npu:0: test.png
{ "model": "2toINF/X-VLA-Pt", "device": "npu:0", ... "action": [...] , "status": "ok" }

Notes & caveats

  • This is a flow-matching action predictor: the output is seeded (default --seed 0) so results are reproducible across runs.
  • num_actions=30 future end-effector poses (dim 20 per step, ee6d) are returned. The action_mean row in the JSON gives a compact summary; the last two channels are the post-processed (sigmoid) gripper values.
  • Token-embedding caveat: the published model.safetensors does not ship the shared embed_tokens weight matrix (it is tied to the Florence2 decoder, which the XVLA code deletes). On load, transformers therefore reports that vlm.language_model.model.encoder.embed_tokens.weight is newly initialized. This is a property of the upstream checkpoint (the same warning appears with the official AutoModel.from_pretrained(..., trust_remote_code=True) usage) and does not affect the flow-matching action head; the model still runs and produces a deterministic output on npu:0.
  • If a custom op is unsupported on a given NPU variant, the vision-encoding path (Florence2 backbone) still runs on NPU; the xvla package keeps the modeling code self-contained (no mandatory timm dependency — a local DropPath fallback is used when timm is absent).
  • torch_npu prints many ownership / collect-env warnings on stdout — they are harmless and can be ignored.