This repository adapts the moojink/openvla-7b-oft-finetuned-libero-object
checkpoint (Prismatic VLM + Llama-2 backbone + L1 flow-matching action head,
LIBERO-object fine-tune) to run inference on a Huawei Ascend 910 NPU through
torch_npu 2.9 and transformers 4.57.6 with trust_remote_code=True.
The model is a 7B vision-language-action (VLA) policy from the OpenVLA-OFT project that takes a 224x224 dual-tower image (SigLIP + DINOv2), a natural language instruction, and a 7-DoF proprioceptive state vector, and emits a chunked 8x7 action trajectory in real robot units.
| Item | Value |
|---|---|
| Architecture | PrismaticForConditionalGeneration (SigLIP-224px + DINOv2-224px fused vision, Llama-2-7B language backbone, L1 regression action head with flow-matching chunking) |
| Parameter count | ~7B (bf16) |
| Action chunk | NUM_ACTIONS_CHUNK=8, ACTION_DIM=7 |
| Image input | 6 channels (3 SigLIP + 3 DINOv2), 224x224 |
| Language prompt | natural language task instruction (pick up the object) |
| Proprio | 7-DoF end-effector state |
| Output | unnormalized 8x7 action tensor (m / rad / gripper) |
| Native checkpoint | moojink/openvla-7b-oft-finetuned-libero-object |
The adapter makes the following minimal, non-invasive NPU compatibility
patches (kept inside this repo's inference path; the upstream trust-remote-code
files in /data/dl/openvla-oft/ were updated in place to keep the patch
footprint small):
processing_prismatic.py (transformers 4.57 moved these aliases from
transformers.tokenization_utils to transformers.tokenization_utils_base).tie_weights(recompute_mapping=...) kwarg tolerance in
modeling_prismatic.py (transformers 4.50+ passes a new kwarg that the
upstream Prismatic code did not declare).modeling_prismatic.py (the repo
hard-fails on timm>=1.0.0; we only emit a warning so the trust-remote-code
import succeeds under the installed timm 1.0.x).modeling_prismatic.py (recent timm
versions can return (list, tuple) features; we take the leading tensor so
torch.cat sees two real tensors).inference.py (the model ships OpenX
norm_stats; we merge dataset_statistics.json into model.norm_stats so
unnorm_key="libero_object_no_noops" resolves).inference.py (the 50-step
reverse-diffusion loop generates noise on CPU then .to(device) to avoid
NPU generator divergence).torch.where(cond).bool() coercion in inference.py (NPU is strict
about non-bool conditions in torch.where)._supports_sdpa / _supports_flash_attn defaults installed via a
__getattr__ patch on the model class (transformers 4.57 probes these via
nn.Module.__getattr__, which raises for the upstream Prismatic class).Hardware and software environment used for the verified run:
/data/dl/openvla-oft/Steps to reproduce:
pip install torch==2.9.0 transformers==4.57.6 torch_npu==2.9.0.post1 timm==1.0.28 numpy pillow
# Prerequisite: source CANN 8.5.1 toolkit so torch_npu can find the runtime libs.
cd /data/openvla-oft
# Run inference on NPU (Ascend 910). Writes npu_output.txt, npu_actions.npy,
# npu_run.log.
python inference.py --device npu
# Run inference on CPU (single seed, single call; the 7B Llama-2 backbone is
# slow without an accelerator). Writes cpu_output.txt, cpu_actions.npy,
# cpu_run.log.
python inference.py --device cpufrom transformers import AutoProcessor
from transformers.dynamic_module_utils import get_class_from_dynamic_module
import torch
# Bootstrap the prismatic stub package (see inference.py for the minimal shim).
import types, enum, sys
prismatic_pkg = types.ModuleType("prismatic"); prismatic_pkg.__path__ = []
sys.modules["prismatic"] = prismatic_pkg
# ... (rest of the stub follows the same pattern as inference.py)
ModelCls = get_class_from_dynamic_module(
"modeling_prismatic.OpenVLAForActionPrediction",
"/data/dl/openvla-oft",
)
processor = AutoProcessor.from_pretrained("/data/dl/openvla-oft", trust_remote_code=True)
model = ModelCls.from_pretrained(
"/data/dl/openvla-oft", trust_remote_code=True, torch_dtype=torch.bfloat16
).to("npu:0").eval()
# Build inputs.
from PIL import Image
import numpy as np
image = Image.fromarray(np.random.default_rng(42).integers(0, 256, (224, 224, 3), dtype=np.uint8))
proprio = np.random.default_rng(42).standard_normal(7).astype("float32")
batch = processor(text=["pick up the object"], images=[image], return_tensors="pt")
actions, _ = model.predict_action(
input_ids=batch["input_ids"].to("npu:0"),
unnorm_key="libero_object_no_noops",
proprio=proprio,
attention_mask=batch["attention_mask"].to("npu:0"),
pixel_values=batch["pixel_values"].to("npu:0", dtype=torch.bfloat16),
)
# actions is an (8, 7) numpy array: 8-step action chunk, 7-DoF.
print(actions.shape, actions[0])NPU vs CPU for one predict_action call on the same fixed seed=42 input
(8-step action chunk, 7-DoF). NPU run uses Ascend 910, CPU run uses the host
CPU of the same machine.
| Metric | Value |
|---|---|
| Action shape | (8, 7) |
| cos_sim (flatten) | 0.9739 |
| max_abs | 0.0877 |
| mean_abs | 0.0039 |
| sign agreement | 1.0000 |
| L2 relative error | 0.2306 |
| latency ratio (CPU / NPU) | 1159.81x |
The sign-agreement is exact (1.0) and cos_sim is 0.974; the small mean_abs of
3.9e-3 reflects bf16 quantisation rounding plus the stochastic noise step that
seeds the flow-matching loop. The larger L2 relative error of 0.23 is driven
by one row ([5], the gripper channel, which flips sign between NPU and CPU)
plus the small-magnitude noise. Numerical match is well within expected bf16
tolerance for a 7B VLA flow-matching policy.
Files in this repo:
inference.py - unified NPU/CPU loader + single-call predictor.compare.py - computes the six metrics above and writes
assets/compare_result.txt.npu_output.txt, cpu_output.txt - per-device metrics JSON.npu_actions.npy, cpu_actions.npy - raw 8x7 action arrays.npu_run.log, cpu_run.log - full stdout traces of each run.assets/npu_device_call.png - NPU inference stdout log (no overlay).assets/model_result.png - CPU vs NPU comparison panel with table.assets/agent_workflow.png - pipeline diagram with first-line output.requirements.txt - pinned dependency versions..gitignore - excludes models/, *.safetensors, pycache.