weasonlee/Embodied-R1.5
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

🤖 Embodied-R1.5 (Ascend NPU 适配)

Embodied-R1.5:一个基于 Qwen3-VL 的具身推理多模态模型,面向机器人/具身智能场景的视觉-语言理解与推理任务(论文 / 模型由 IffYuan 发布)。

本仓库将其适配到 华为昇腾 Ascend NPU(torch_npu 2.9.0.post1 + transformers 4.57.6),并提供 inference.py 在 NPU 与 CPU 上分别推理、对比精度与耗时。

模型简介

  • 模型:IffYuan/Embodied-R1.5
  • 架构:Qwen3VLForConditionalGeneration(model_type qwen3_vl,语言模型 36 层 / hidden 4096 / vocab 151936,视觉塔 depth 27 / hidden 1152),transformers 4.57.6 原生支持,AutoModelForImageTextToText + AutoProcessor 直接加载
  • 输入:单/多张图像 + 自然语言指令
  • 输出:teacher-forcing logits 或自回归文本
  • 精度:原始权重 bf16

部署步骤

# 1. 安装依赖(Python 3.11,需已安装 CANN / torch_npu 2.9.0.post1)
pip install -r requirements.txt

# 2. 下载权重(若尚未下载,含 4 个 shard)
mkdir -p models
HF_ENDPOINT=https://hf-mirror.com HF_HUB_DOWNLOAD_TIMEOUT=120 python -c \
  "from huggingface_hub import snapshot_download; \
   snapshot_download('IffYuan/Embodied-R1.5', local_dir='models')"

推理示例

# CPU 推理(bf16,作为精度参照,保存 results/cpu_logits.npy)
python inference.py --device cpu

# NPU 推理(bf16,自动与 CPU 结果对比 cos_sim / max_abs_err / mean_abs_err)
python inference.py --device npu

脚本使用 PIL 合成一张含几何色块与文字的测试图 + "Describe the scene and propose the next manipulation action for the robot." 指令,teacher-forcing 前向取 logits。

示例输出(NPU,Ascend 910):

torch 2.9.0+cpu
torch_npu 2.9.0.post1+gitee7ba04
torch.npu.is_available(): True
torch.npu.device_count(): 2
[npu] input tokens: 167
[npu] logits shape: [1, 167, 151936]
[npu] mean forward latency: 93.20 ms (2 repeats)
[compare] npu vs cpu:
  cos_sim      = 0.964368
  max_abs_err  = 29.406250
  mean_abs_err = 0.725456

CPU vs NPU 精度对比

指标CPU (bf16)NPU (bf16)差异
cos_sim1.00.964368高度一致
max_abs_err—29.406250logits 量纲大,相对极小
mean_abs_err—0.725456极小
单次前向耗时64921.28 ms93.20 msNPU 快约 697×

对比基于完全相同的合成观测与指令(teacher-forcing logits [1, 167, 151936],约 2540 万元素)。Qwen3-VL 在昇腾 NPU 上 fp16 前向易产生 NaN logits(与同族 Qwen2.5-VL 一致),故采用 bf16(与模型原始权重精度一致)。

目录结构

.
├── inference.py          # NPU/CPU 推理与精度对比脚本
├── requirements.txt      # 依赖清单
├── readme.md             # 本文档
└── assets/               # 运行截图