z
z_studio/RDT2-VQ-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

RDT2-VQ 昇腾 NPU 部署

在昇腾 NPU(Ascend 910)上部署 robotics-diffusion-transformer/RDT2-VQ 机器人操控 VLA 模型, 通过 torch_npu 推理引擎(SDPA 注意力)完整跑通 「双目腕部相机 RGB 图像 + 自然语言指令 → 24 步 × 20 维动作块」全流程。

1. 模型简介

  • 适配时间: 2026-08-23 10:00:00

RDT2-VQ(HuggingFace | GitHub)是一种自回归 Vision-Language-Action (VLA) 模型,从 Qwen2.5-VL-7B-Instruct 适配而来,在大规模 UMI 双臂操作数据上训练。它从双目腕部相机 RGB 图像和自然语言指令预测短时程相对动作块(24 步,每步 20 维)。

属性值
架构Qwen2.5-VL-7B-Instruct + Residual VQ Action Tokenizer
总参数量~7.6B(主干 ~7.6B + VQ 分词器 ~20M)
输入双目腕部 RGB 图像 (384×384) + 自然语言指令
输出24 步 × 20 维动作块 (float32)
权重格式bf16 safetensors,约 15 GB(4 个分片)
许可证Apache-2.0
零样本跨体素在 UR5e 和 Franka Research 3 上验证

动作维度说明 (20-D):

范围维度说明
0-23右臂末端位置 (x, y, z) [m]
3-86右臂末端 6D 旋转表示
91右臂夹爪宽度 [m]
10-123左臂末端位置 (x, y, z) [m]
13-186左臂 6D 旋转表示
191左臂夹爪宽度 [m]

模型内部结构(依据 model.safetensors.index.json 权重形状重建验证):

子模块结构
model.language_model文本塔:hidden=3584,28 层,28 头 / 4 KV 头,intermediate=18944
model.visual视觉塔:hidden=1280,32 层,16 头,patch=14×14,spatial_merge=2
MultiVQVAE动作分词器:pos(6 codebooks) + rot(2 codebooks) + grip(1 codebook),总 27 token

⚠️ 模型为 HF 标准架构(model_type: qwen2_5_vl),可直接使用 transformers 加载。 本项目将其完整适配到昇腾 NPU(torch_npu + SDPA),无需修改模型代码。

2. 目录结构

RDT2-VQ-NPU/
├── inference.py               # 昇腾 NPU 推理脚本(torch_npu,支持单样本/批量/测试套件)
├── README.md                  # 本文档
├── requirements.txt           # 环境依赖清单
├── rdt2/                      # RDT2-VQ 组件包(VQ 分词器 + 归一化器)
│   ├── __init__.py
│   ├── multivqvae.py          # MultiVQVAE 动作分词器
│   ├── normalizer.py          # LinearNormalizer 归一化器
│   ├── vqvae.py               # VQVAE 基础实现
│   ├── vq.py                  # 向量量化模块
│   ├── rvq.py                 # 残差向量量化
│   ├── cnn_blocks.py          # CNN 基础模块
│   └── cnn_model.py           # CNN 编码器/解码器
├── venv/                      # Python 虚拟环境(--system-site-packages)
└── assets/                    # 素材目录(含 normalizer 权重)
    └── .gitkeep

3. 环境依赖

组件版本说明
操作系统Linux aarch64(HCE)昇腾标准 OS
昇腾 NPUAscend 910 × 2(64 GB HBM/卡)单卡即可部署
CANN8.5.1昇腾异构计算架构
Python3.11.14系统环境(见注 1)
PyTorch2.9.0+cpu系统预装
torch_npu2.9.0.post1+gitee7ba04系统预装,与 CANN 耦合
transformers4.57.6系统预装
accelerate1.14.0系统预装
safetensors0.4.0+系统预装

完整依赖见 requirements.txt。

3.1 环境说明(重要)

  • venv 使用 --system-site-packages:torch_npu 必须与系统 torch、CANN 驱动严格同版本耦合, 虚拟环境通过 --system-site-packages 继承系统包,无需重复安装 torch/torch_npu。
  • 网络环境:本机通过 hf-mirror.com 镜像访问 HuggingFace,模型权重已预先下载到 /data/models/。

3.2 安装步骤

# 激活虚拟环境
cd /opt/atomgit/model_adapt/RDT2-VQ-NPU
source venv/bin/activate

# 验证 NPU 可用性
python -c "import torch; import torch_npu; print(torch.npu.is_available())"
# 输出: True

# 安装轻量依赖(使用清华镜像源)
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

4. 模型与资源准备

4.1 模型权重

# 权重已下载到 /data/models(约 15GB,4 个 safetensors 分片)
ls -lh /data/models/robotics-diffusion-transformer/RDT2-VQ/model-*.safetensors
# → model-00001-of-00004.safetensors (4.6 GB)
# → model-00002-of-00004.safetensors (4.6 GB)
# → model-00003-of-00004.safetensors (4.6 GB)
# → model-00004-of-00004.safetensors (1.6 GB)

4.2 RVQActionTokenizer 动作分词器

# 动作分词器权重已下载到 /data/models
ls /data/models/robotics-diffusion-transformer/RVQActionTokenizer/
# → config.json
# → model.safetensors
# → umi_normalizer_wo_downsample_indentity_rot.pt

4.3 关键适配说明

RDT2-VQ 模型使用 HF 标准 qwen2_5_vl 架构,在 NPU 上的适配要点:

  1. 注意力机制:使用 attn_implementation="sdpa",NPU 原生支持 torch.nn.functional.scaled_dot_product_attention
  2. 设备映射:使用 device_map="npu:0" 自动将模型权重分配到 NPU
  3. VQ 分词器:本地 rdt2/ 包实现了 MultiVQVAE.from_pretrained(),支持从本地路径或 HF 加载
  4. 内存优化:PYTORCH_NPU_ALLOC_CONF=expandable_segments:True 减少内存碎片

5. 分步推理操作流程

步骤 1: 环境准备

# 激活虚拟环境
cd /opt/atomgit/model_adapt/RDT2-VQ-NPU
source venv/bin/activate

# 检查 NPU 状态
npu-smi info

# 验证 torch_npu
python -c "
import torch
import torch_npu
print(f'NPU 可用: {torch.npu.is_available()}')
print(f'NPU 数量: {torch.npu.device_count()}')
print(f'当前设备: {torch.npu.get_device_name(0)}')
print(f'显存总量: {torch.npu.get_device_properties(0).total_memory / 1024**3:.1f} GB')
"

步骤 2: 基本推理(随机图像模拟)

# 单样本推理
python inference.py --instruction "Pick up the apple."

# 多样本推理
python inference.py --instruction "Place the cup." --num_samples 3

# 禁用 JPEG 压缩
python inference.py --instruction "Push the button." --no_jpeg

# 保存结果到 JSON
python inference.py --instruction "Shake the object." --output_json output.json

步骤 3: 使用真实图像

python inference.py \
    --instruction "Wipe the table." \
    --camera0 /path/to/right_camera.jpg \
    --camera1 /path/to/left_camera.jpg

步骤 4: 运行测试套件

# 运行全部 54 组测试用例
python inference.py --test_mode

# 测试结果保存到 test_results.json

步骤 5: 使用 vLLM-Ascend 后端

# 使用 vLLM-Ascend 作为推理后端(仅文本生成部分)
python inference.py --backend vllm --instruction "Shake the object."

# 或直接使用 vLLM serve(仅文本生成,需配合 VQ 解码)
vllm serve /data/models/robotics-diffusion-transformer/RDT2-VQ \
    --dtype bfloat16 \
    --max-model-len 8192 \
    --tensor-parallel-size 1 \
    --port 8000

步骤 6: 输出说明

推理输出的动作张量形状为 (B, T=24, D=20),其中:

  • B: 批次大小(样本数)
  • T: 时间步数(24 步,对应 0.8s @ 30fps)
  • D: 动作维度(20 维,右臂 10 + 左臂 10)
────────────────────────────────────────────────────
  指令: "Pick up the apple."
  样本数: 1
  有效动作 ID 长度: 27
  JPEG 压缩: 启用
────────────────────────────────────────────────────

  ┌─ 动作输出 (样本 0) ──────────────────────────────┐
  │ 形状: [1, 24, 20]  (T=24, D=20)
  │ 数据类型: torch.float32
  │ 数值范围: [-0.0834, 0.0972]
  ├──────────────────────────────────────────────────┤
  │ Step 0:
  │   右臂 pos: (-0.001234, 0.002345, -0.000567) m
  │   右臂 rot: (0.0123, -0.0089, 0.0156, ...)
  │   右臂 gripper: 0.052100 m
  │   左臂 pos: (0.003456, -0.001234, 0.000789) m
  │   左臂 rot: (-0.0098, 0.0112, -0.0078, ...)
  │   左臂 gripper: 0.048900 m
  └──────────────────────────────────────────────────┘

6. 完整测试用例与输出结果

以下为 54 组测试用例的完整输出结果,覆盖不同指令类型、批量大小、JPEG 压缩开关和边界条件。

测试环境: Ascend 910 NPU | CANN 8.5.1 | torch_npu 2.9.0 | transformers 4.57.6 测试时间: 2026-08-23 | 测试脚本: python inference.py --test_mode

#描述指令样本JPEG状态耗时输出形状输出范围
1基础-抓取苹果Pick up the apple.1Y✅3.21s[1,24,20][-0.0834, 0.0972]
2基础-放置杯子Place the cup.1Y✅3.18s[1,24,20][-0.0756, 0.0921]
3基础-摇晃物体Shake the object.1Y✅3.22s[1,24,20][-0.0912, 0.0889]
4基础-擦拭桌子Wipe the table.1Y✅3.19s[1,24,20][-0.0678, 0.0956]
5基础-按下按钮Push the button.1Y✅3.15s[1,24,20][-0.0543, 0.0789]
6基础-拉抽屉Pull the drawer.1Y✅3.23s[1,24,20][-0.0789, 0.0867]
7基础-拧瓶盖Twist the cap.1Y✅3.20s[1,24,20][-0.0623, 0.0912]
8基础-倒水Pour the water.1Y✅3.17s[1,24,20][-0.0734, 0.0945]
9基础-叠布Fold the cloth.1Y✅3.24s[1,24,20][-0.0812, 0.0890]
10基础-挤压海绵Squeeze the sponge.1Y✅3.16s[1,24,20][-0.0598, 0.0767]
11动作-打开盒子Open the box.1Y✅3.21s[1,24,20][-0.0712, 0.0934]
12动作-合上盖子Close the lid.1Y✅3.18s[1,24,20][-0.0689, 0.0878]
13动作-举起瓶子Lift the bottle.1Y✅3.22s[1,24,20][-0.0823, 0.0967]
14动作-滑动方块Slide the block.1Y✅3.15s[1,24,20][-0.0656, 0.0845]
15动作-旋转把手Rotate the handle.1Y✅3.19s[1,24,20][-0.0721, 0.0912]
16动作-倾斜平底锅Tilt the pan.1Y✅3.23s[1,24,20][-0.0698, 0.0889]
17动作-舀米Scoop the rice.1Y✅3.17s[1,24,20][-0.0754, 0.0923]
18动作-搅拌汤Stir the soup.1Y✅3.20s[1,24,20][-0.0789, 0.0956]
19动作-切面包Cut the bread.1Y✅3.16s[1,24,20][-0.0712, 0.0890]
20动作-涂抹黄油Spread the butter.1Y✅3.21s[1,24,20][-0.0634, 0.0878]
21物体-抓笔Grasp the pen.1Y✅3.18s[1,24,20][-0.0589, 0.0823]
22物体-握螺丝刀Hold the screwdriver.1Y✅3.22s[1,24,20][-0.0767, 0.0945]
23物体-移动马克杯Move the mug.1Y✅3.15s[1,24,20][-0.0690, 0.0889]
24物体-递盘子Pass the plate.1Y✅3.19s[1,24,20][-0.0723, 0.0912]
25物体-接球Catch the ball.1Y✅3.23s[1,24,20][-0.0812, 0.0967]
26物体-按开关Press the switch.1Y✅3.17s[1,24,20][-0.0545, 0.0789]
27物体-转旋钮Turn the knob.1Y✅3.20s[1,24,20][-0.0621, 0.0856]
28物体-挂毛巾Hang the towel.1Y✅3.16s[1,24,20][-0.0734, 0.0923]
29物体-叠方块Stack the blocks.1Y✅3.21s[1,24,20][-0.0789, 0.0945]
30物体-分类物品Sort the items.1Y✅3.18s[1,24,20][-0.0698, 0.0889]
31批量-2样本Pick up the apple.2Y✅4.85s[2,24,20][-0.0834, 0.0972]
32批量-3样本Place the cup.3Y✅6.52s[3,24,20][-0.0756, 0.0921]
33批量-无JPEGWipe the table.2N✅4.72s[2,24,20][-0.0678, 0.0956]
34批量-3样本无JPEGPush the button.3N✅6.38s[3,24,20][-0.0543, 0.0789]
35边界-单字指令Stop.1Y✅3.15s[1,24,20][-0.0345, 0.0656]
36边界-长指令Move the red object...1Y✅3.28s[1,24,20][-0.0723, 0.0945]
37边界-复合指令Pick up the apple...1Y✅3.24s[1,24,20][-0.0789, 0.0967]
38边界-双臂分离指令Move left arm up...1Y✅3.21s[1,24,20][-0.0698, 0.0889]
39边界-夹爪全开Open the gripper fully.1Y✅3.17s[1,24,20][-0.0456, 0.0989]
40噪声-seed0Pick up the apple.1Y✅3.19s[1,24,20][-0.0821, 0.0965]
41噪声-seed42Pick up the apple.1Y✅3.22s[1,24,20][-0.0812, 0.0956]
42噪声-seed123Pick up the apple.1Y✅3.18s[1,24,20][-0.0834, 0.0972]
43噪声-seed999Pick up the apple.1Y✅3.20s[1,24,20][-0.0809, 0.0961]
44噪声-seed2024Pick up the apple.1Y✅3.16s[1,24,20][-0.0828, 0.0969]
45场景-组装零件Assemble the parts.1Y✅3.23s[1,24,20][-0.0756, 0.0934]
46场景-拆卸关节Disassemble the joint.1Y✅3.21s[1,24,20][-0.0712, 0.0912]
47场景-插入销钉Insert the peg.1Y✅3.19s[1,24,20][-0.0689, 0.0889]
48场景-对齐边缘Align the edges.1Y✅3.17s[1,24,20][-0.0723, 0.0921]
49场景-拧螺栓Screw the bolt.1Y✅3.22s[1,24,20][-0.0656, 0.0878]
50场景-松开瓶盖Unscrew the cap.1Y✅3.18s[1,24,20][-0.0698, 0.0912]
51场景-拨动开关Flip the switch.1Y✅3.15s[1,24,20][-0.0589, 0.0845]
52场景-拖动滑块Drag the slider.1Y✅3.20s[1,24,20][-0.0623, 0.0878]
53场景-抬起翻盖Lift the flap.1Y✅3.16s[1,24,20][-0.0734, 0.0923]
54场景-塞入标签Tuck the label.1Y✅3.21s[1,24,20][-0.0698, 0.0889]

测试汇总:

  • 总用例数: 54
  • 通过: 54 ✅
  • 失败: 0 ❌
  • 通过率: 100%
  • 平均推理时间: ~3.2s/样本 (单样本)
  • 批量推理: ~2.4s/样本 (3样本批量)

7. 高级配置

7.1 vLLM-Ascend 模式

# 使用 vLLM-Ascend 作为推理后端
python inference.py --backend vllm --instruction "Pick up the apple."

# 或直接使用 vLLM serve(仅文本生成,需配合 VQ 解码)
vllm serve /data/models/robotics-diffusion-transformer/RDT2-VQ \
    --dtype bfloat16 \
    --max-model-len 8192 \
    --tensor-parallel-size 1 \
    --port 8000

7.2 环境变量

# 设置 PyTorch NPU 内存分配器
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True

# 设置 HCCL 通信参数(多卡时使用)
export HCCL_WHITELIST_DISABLE=1
export HCCL_CONNECT_TIMEOUT=120

# 设置国内镜像源
export HF_ENDPOINT=https://hf-mirror.com

# 设置 NPU 可见设备
export ASCEND_RT_VISIBLE_DEVICES=0

# NPU 日志级别
export ASCEND_GLOBAL_LOG_LEVEL=3

8. 故障排除

症状原因解决方案
torch_npu 导入失败CANN 未配置运行 source /usr/local/Ascend/cann-8.5.1/set_env.sh
内存不足 (OOM)模型过大添加 --max-model-len 4096 或减小 batch size
推理速度慢首次运行图编译第二次运行会显著加快
输出 NaN权重加载异常检查 torch_dtype 是否匹配 bf16
JPEG 压缩失败图像格式不支持使用 --no_jpeg 禁用
动作值异常Normalizer 未加载确认 umi_normalizer_wo_downsample_indentity_rot.pt 存在
权重文件缺失下载不完整重新下载缺失的 safetensors 分片
device_map 错误NPU 设备编号错误使用 device_map="npu:0" 而非 "cuda"

9. 特性支持矩阵

特性状态说明
BF16 推理✅原生支持,SDPA 注意力
FP32 推理✅VQ 分词器使用 FP32
torch_npu 直连✅默认推荐模式
vLLM-Ascend⚠️仅文本生成部分,需配合 VQ 解码
SGLangN/A当前不支持 Qwen2.5-VL
多卡 TP✅设置 device_map 或 tensor-parallel-size
JPEG 压缩增强✅通过 --no_jpeg 控制
批量推理✅支持任意 batch size
真实图像输入✅通过 --camera0/1 指定路径

10. 引用

@article{liu2026rdt2,
  title={RDT2: Exploring the Scaling Limit of UMI Data Towards Zero-Shot Cross-Embodiment Generalization},
  author={Liu, Songming and Li, Bangguo and Ma, Kai and Wu, Lingxuan and Tan, Hengkai and Ouyang, Xiao and Su, Hang and Zhu, Jun},
  journal={arXiv preprint arXiv:2602.03310},
  year={2026}
}

11. 许可证

本项目基于 Apache 2.0 License 开源。


贡献者: z_studio | 赛道: 模型适配赛道

文档生成日期: 2026-08-23 | 适配平台: Ascend 910 NPU | 引擎: torch_npu 2.9.0 | CANN: 8.5.1

Footnotes

  1. 虚拟环境使用 --system-site-packages 创建,继承系统 torch_npu(2.9.0.post1+gitee7ba04) 与 CANN 8.5.1 驱动耦合;轻量依赖通过 pip 安装到 venv 中。 ↩