g
gcw_coj3XaOd/XiaomiRobotics_Xiaomi-Robotics-0-LIBERO
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Xiaomi-Robotics-0-LIBERO (MiBoT) - 昇腾 NPU 推理部署

1. 模型简介

模型名称: XiaomiRobotics/Xiaomi-Robotics-0-LIBERO

模型链接: HuggingFace

模型描述: MiBoT (Mi Robotics Behavior Transformer) 是一个视觉-语言-动作(Vision-Language-Action, VLA)机器人操作模型,基于 Qwen3-VL-4B 视觉语言模型和 DiT(Diffusion Transformer)动作预测头构建。模型接收机器人第一人称视角图像和自然语言指令,输出机器人动作序列。

模型架构:

  • VLM 骨干:Qwen3-VL-4B-Instruct(36层 Transformer,隐藏维度 2560)
  • 视觉编码器:ViT(patch_size=16, temporal_patch_size=2, spatial_merge_size=2)
  • 动作头:DiT(16层 Diffusion Transformer,隐藏维度 1024)
  • 总参数量:4.72B(4,716,274,176)

输入规格:

  • 图像:224×224 或 448×448 RGB(需 5D tensor: B×3×temporal_patch_size×H×W)
  • 文本指令:字符串(自动注入 image_token)
  • 机器人状态:(1, 32) float tensor

输出规格:

  • 动作序列:(30, 32) float tensor — 30步动作预测,每步32维

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
transformers>= 4.50.0HuggingFace Transformers
Pillow>= 9.0图像处理
numpy>= 1.20数组处理
huggingface_hub>= 0.20.0模型下载(注意:需 < 0.36 避免 strict dataclass 兼容问题)
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

NPU 硬件: 2x Ascend910_9362(共 128 GB HBM)

安装命令:

pip install torch torch_npu transformers Pillow numpy huggingface_hub

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"

3.2 模型下载

方式一:HuggingFace(推荐)

hf download XiaomiRobotics/Xiaomi-Robotics-0-LIBERO --local-dir /path/to/mibot_model

方式二:AtomGit 镜像(HuggingFace 下载慢时使用)

https://gitcode.com/gcw_coj3XaOd/XiaomiRobotics_Xiaomi-Robotics-0-LIBERO

3.3 运行推理

单条推理:

python inference.py \
  --model-path /path/to/mibot_model \
  --image /path/to/robot_view.jpg \
  --text "pick the red apple from the table"

批量推理:

python inference.py \
  --model-path /path/to/mibot_model \
  --image /path/to/robot_view.jpg \
  --text "pick the red apple from the table" \
  --batch-size 4

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--imagestr必填输入图像路径
--textstr"pick the red apple from the table"自然语言指令
--batch-sizeint1批处理大小
--num-stepsint5Diffusion 采样步数
--seedint42随机种子
--devicestr"npu:0"设备
--dtypestr"bfloat16"数据类型

4. 推理成功日志

4.1 模型加载

[模型] MiBoTForActionGeneration
[设备] Ascend910_9362 (npu:0)
[参数量] 4,716,274,176 (4.72B)
[NPU内存] 9,071 MB allocated
[状态] SUCCESS

4.2 单条推理日志(224×224)

[输入] text="pick the red apple from the table", image=224x224, state=(1,32)
[输出] actions=(30, 32), range=[-3.5625, 3.5469], mean=-0.0430
[状态] SUCCESS

4.3 单条推理日志(448×448)

[输入] text="pick the red apple from the table", image=448x448, state=(1,32)
[输出] actions=(30, 32), range=[-3.6406, 3.5312], mean=-0.0496
[状态] SUCCESS

4.4 批量推理日志(batch=4)

[输入] batch=4, image=448x448
[输出] actions=(4, 30, 32)
  sample 0: range=[-3.6406, 3.5312]
  sample 1: range=[-4.1250, 4.3438]
  sample 2: range=[-3.9844, 4.1250]
  sample 3: range=[-4.9688, 3.4375]
[状态] SUCCESS

5. 测试样例及输出结果

样例 1:224×224 图像推理

运行命令:

python inference.py \
  --model-path /path/to/mibot_model \
  --image examples/robot_view_224.jpg \
  --text "pick the red apple from the table"

输出:

============================================================
TEST: small image 224x224
============================================================
  Output shape: (1, 30, 32)
  Range: [-3.5625, 3.5469]
  Mean: -0.0430
  PASS

样例 2:448×448 图像推理

运行命令:

python inference.py \
  --model-path /path/to/mibot_model \
  --image examples/robot_view_448.jpg \
  --text "pick the red apple from the table"

输出:

============================================================
TEST: large image 448x448
============================================================
  Output shape: (1, 30, 32)
  Range: [-3.6406, 3.5312]
  Mean: -0.0496
  PASS

样例 3:批量推理(batch=4)

运行命令:

python inference.py \
  --model-path /path/to/mibot_model \
  --image examples/robot_view_448.jpg \
  --text "pick the red apple from the table" \
  --batch-size 4

输出:

============================================================
TEST: Batch inference (batch_size=4)
============================================================
  Output shape: (4, 30, 32)
  sample 0: shape=(30, 32), range=[-3.6406, 3.5312]
  sample 1: shape=(30, 32), range=[-4.1250, 4.3438]
  sample 2: shape=(30, 32), range=[-3.9844, 4.1250]
  sample 3: shape=(30, 32), range=[-4.9688, 3.4375]
  PASS

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型最终适配结果

模型适配结果


7. 关键实现细节

7.1 pixel_values 格式(重要)

MiBoT 的视觉编码器使用 Conv3d 处理时空 patch,要求输入为 5D tensor:

# 正确格式: (B, 3, temporal_patch_size, H, W)
pixel_values = torch.rand(1, 3, 2, 448, 448, device=device, dtype=torch.bfloat16)

内部执行:

hidden_states = hidden_states.view(-1, 3, temporal_patch_size, patch_size, patch_size)
# (1*448*448, 3, 2, 16, 16) -> groups of 2 frames each of 16x16 patches

7.2 image_grid_thw 格式

image_grid_thw 使用 原始 patch 单位(非合并后):

# 对于 448x448 图像, patch_size=16: grid = 28x28 (raw patches)
image_grid_thw = torch.tensor([[1, 28, 28]], device=device, dtype=torch.long)
# 内部会自动计算合并后: 28*28 // (2*2) = 196 tokens

7.3 huggingface_hub 兼容性

transformers 4.57.x 与 huggingface_hub >= 0.36 存在 strict dataclass 验证冲突(str | None 类型不被支持)。解决方案:

# 从 config.json 中移除 transformers_version 字段
import json
with open("config.json") as f:
    cfg = json.load(f)
cfg.pop("transformers_version", None)

8. NPU 配置说明

  • NPU 型号: Ascend910_9362 × 2
  • HBM: 64 GB per chip,共 128 GB
  • 模型内存占用: ~9 GB (bfloat16, single NPU)
  • CANN 版本: 8.5.1
  • torch_npu 版本: 2.9.0.post1

9. 已知问题

  1. Tokenizer regex 警告: 加载 tokenizer 时会提示 Mistral regex pattern 问题,不影响实际推理功能
  2. huggingface_hub 兼容性: huggingface_hub >= 0.36 与 transformers 4.57.x 存在 strict dataclass 类型验证冲突,需移除 config.json 中的 transformers_version 字段