在昇腾 NPU(Ascend 910)上部署 robotics-diffusion-transformer/RDT2-VQ 机器人操控 VLA 模型, 通过 torch_npu 推理引擎(SDPA 注意力)完整跑通 「双目腕部相机 RGB 图像 + 自然语言指令 → 24 步 × 20 维动作块」全流程。
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-2 | 3 | 右臂末端位置 (x, y, z) [m] |
| 3-8 | 6 | 右臂末端 6D 旋转表示 |
| 9 | 1 | 右臂夹爪宽度 [m] |
| 10-12 | 3 | 左臂末端位置 (x, y, z) [m] |
| 13-18 | 6 | 左臂 6D 旋转表示 |
| 19 | 1 | 左臂夹爪宽度 [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),无需修改模型代码。
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| 组件 | 版本 | 说明 |
|---|---|---|
| 操作系统 | Linux aarch64(HCE) | 昇腾标准 OS |
| 昇腾 NPU | Ascend 910 × 2(64 GB HBM/卡) | 单卡即可部署 |
| CANN | 8.5.1 | 昇腾异构计算架构 |
| Python | 3.11.14 | 系统环境(见注 1) |
| PyTorch | 2.9.0+cpu | 系统预装 |
| torch_npu | 2.9.0.post1+gitee7ba04 | 系统预装,与 CANN 耦合 |
| transformers | 4.57.6 | 系统预装 |
| accelerate | 1.14.0 | 系统预装 |
| safetensors | 0.4.0+ | 系统预装 |
完整依赖见 requirements.txt。
--system-site-packages 继承系统包,无需重复安装 torch/torch_npu。/data/models/。# 激活虚拟环境
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# 权重已下载到 /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)# 动作分词器权重已下载到 /data/models
ls /data/models/robotics-diffusion-transformer/RVQActionTokenizer/
# → config.json
# → model.safetensors
# → umi_normalizer_wo_downsample_indentity_rot.ptRDT2-VQ 模型使用 HF 标准 qwen2_5_vl 架构,在 NPU 上的适配要点:
attn_implementation="sdpa",NPU 原生支持 torch.nn.functional.scaled_dot_product_attentiondevice_map="npu:0" 自动将模型权重分配到 NPUrdt2/ 包实现了 MultiVQVAE.from_pretrained(),支持从本地路径或 HF 加载PYTORCH_NPU_ALLOC_CONF=expandable_segments:True 减少内存碎片# 激活虚拟环境
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')
"# 单样本推理
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.jsonpython inference.py \
--instruction "Wipe the table." \
--camera0 /path/to/right_camera.jpg \
--camera1 /path/to/left_camera.jpg# 运行全部 54 组测试用例
python inference.py --test_mode
# 测试结果保存到 test_results.json# 使用 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推理输出的动作张量形状为 (B, T=24, D=20),其中:
────────────────────────────────────────────────────
指令: "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
└──────────────────────────────────────────────────┘以下为 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. | 1 | Y | ✅ | 3.21s | [1,24,20] | [-0.0834, 0.0972] |
| 2 | 基础-放置杯子 | Place the cup. | 1 | Y | ✅ | 3.18s | [1,24,20] | [-0.0756, 0.0921] |
| 3 | 基础-摇晃物体 | Shake the object. | 1 | Y | ✅ | 3.22s | [1,24,20] | [-0.0912, 0.0889] |
| 4 | 基础-擦拭桌子 | Wipe the table. | 1 | Y | ✅ | 3.19s | [1,24,20] | [-0.0678, 0.0956] |
| 5 | 基础-按下按钮 | Push the button. | 1 | Y | ✅ | 3.15s | [1,24,20] | [-0.0543, 0.0789] |
| 6 | 基础-拉抽屉 | Pull the drawer. | 1 | Y | ✅ | 3.23s | [1,24,20] | [-0.0789, 0.0867] |
| 7 | 基础-拧瓶盖 | Twist the cap. | 1 | Y | ✅ | 3.20s | [1,24,20] | [-0.0623, 0.0912] |
| 8 | 基础-倒水 | Pour the water. | 1 | Y | ✅ | 3.17s | [1,24,20] | [-0.0734, 0.0945] |
| 9 | 基础-叠布 | Fold the cloth. | 1 | Y | ✅ | 3.24s | [1,24,20] | [-0.0812, 0.0890] |
| 10 | 基础-挤压海绵 | Squeeze the sponge. | 1 | Y | ✅ | 3.16s | [1,24,20] | [-0.0598, 0.0767] |
| 11 | 动作-打开盒子 | Open the box. | 1 | Y | ✅ | 3.21s | [1,24,20] | [-0.0712, 0.0934] |
| 12 | 动作-合上盖子 | Close the lid. | 1 | Y | ✅ | 3.18s | [1,24,20] | [-0.0689, 0.0878] |
| 13 | 动作-举起瓶子 | Lift the bottle. | 1 | Y | ✅ | 3.22s | [1,24,20] | [-0.0823, 0.0967] |
| 14 | 动作-滑动方块 | Slide the block. | 1 | Y | ✅ | 3.15s | [1,24,20] | [-0.0656, 0.0845] |
| 15 | 动作-旋转把手 | Rotate the handle. | 1 | Y | ✅ | 3.19s | [1,24,20] | [-0.0721, 0.0912] |
| 16 | 动作-倾斜平底锅 | Tilt the pan. | 1 | Y | ✅ | 3.23s | [1,24,20] | [-0.0698, 0.0889] |
| 17 | 动作-舀米 | Scoop the rice. | 1 | Y | ✅ | 3.17s | [1,24,20] | [-0.0754, 0.0923] |
| 18 | 动作-搅拌汤 | Stir the soup. | 1 | Y | ✅ | 3.20s | [1,24,20] | [-0.0789, 0.0956] |
| 19 | 动作-切面包 | Cut the bread. | 1 | Y | ✅ | 3.16s | [1,24,20] | [-0.0712, 0.0890] |
| 20 | 动作-涂抹黄油 | Spread the butter. | 1 | Y | ✅ | 3.21s | [1,24,20] | [-0.0634, 0.0878] |
| 21 | 物体-抓笔 | Grasp the pen. | 1 | Y | ✅ | 3.18s | [1,24,20] | [-0.0589, 0.0823] |
| 22 | 物体-握螺丝刀 | Hold the screwdriver. | 1 | Y | ✅ | 3.22s | [1,24,20] | [-0.0767, 0.0945] |
| 23 | 物体-移动马克杯 | Move the mug. | 1 | Y | ✅ | 3.15s | [1,24,20] | [-0.0690, 0.0889] |
| 24 | 物体-递盘子 | Pass the plate. | 1 | Y | ✅ | 3.19s | [1,24,20] | [-0.0723, 0.0912] |
| 25 | 物体-接球 | Catch the ball. | 1 | Y | ✅ | 3.23s | [1,24,20] | [-0.0812, 0.0967] |
| 26 | 物体-按开关 | Press the switch. | 1 | Y | ✅ | 3.17s | [1,24,20] | [-0.0545, 0.0789] |
| 27 | 物体-转旋钮 | Turn the knob. | 1 | Y | ✅ | 3.20s | [1,24,20] | [-0.0621, 0.0856] |
| 28 | 物体-挂毛巾 | Hang the towel. | 1 | Y | ✅ | 3.16s | [1,24,20] | [-0.0734, 0.0923] |
| 29 | 物体-叠方块 | Stack the blocks. | 1 | Y | ✅ | 3.21s | [1,24,20] | [-0.0789, 0.0945] |
| 30 | 物体-分类物品 | Sort the items. | 1 | Y | ✅ | 3.18s | [1,24,20] | [-0.0698, 0.0889] |
| 31 | 批量-2样本 | Pick up the apple. | 2 | Y | ✅ | 4.85s | [2,24,20] | [-0.0834, 0.0972] |
| 32 | 批量-3样本 | Place the cup. | 3 | Y | ✅ | 6.52s | [3,24,20] | [-0.0756, 0.0921] |
| 33 | 批量-无JPEG | Wipe the table. | 2 | N | ✅ | 4.72s | [2,24,20] | [-0.0678, 0.0956] |
| 34 | 批量-3样本无JPEG | Push the button. | 3 | N | ✅ | 6.38s | [3,24,20] | [-0.0543, 0.0789] |
| 35 | 边界-单字指令 | Stop. | 1 | Y | ✅ | 3.15s | [1,24,20] | [-0.0345, 0.0656] |
| 36 | 边界-长指令 | Move the red object... | 1 | Y | ✅ | 3.28s | [1,24,20] | [-0.0723, 0.0945] |
| 37 | 边界-复合指令 | Pick up the apple... | 1 | Y | ✅ | 3.24s | [1,24,20] | [-0.0789, 0.0967] |
| 38 | 边界-双臂分离指令 | Move left arm up... | 1 | Y | ✅ | 3.21s | [1,24,20] | [-0.0698, 0.0889] |
| 39 | 边界-夹爪全开 | Open the gripper fully. | 1 | Y | ✅ | 3.17s | [1,24,20] | [-0.0456, 0.0989] |
| 40 | 噪声-seed0 | Pick up the apple. | 1 | Y | ✅ | 3.19s | [1,24,20] | [-0.0821, 0.0965] |
| 41 | 噪声-seed42 | Pick up the apple. | 1 | Y | ✅ | 3.22s | [1,24,20] | [-0.0812, 0.0956] |
| 42 | 噪声-seed123 | Pick up the apple. | 1 | Y | ✅ | 3.18s | [1,24,20] | [-0.0834, 0.0972] |
| 43 | 噪声-seed999 | Pick up the apple. | 1 | Y | ✅ | 3.20s | [1,24,20] | [-0.0809, 0.0961] |
| 44 | 噪声-seed2024 | Pick up the apple. | 1 | Y | ✅ | 3.16s | [1,24,20] | [-0.0828, 0.0969] |
| 45 | 场景-组装零件 | Assemble the parts. | 1 | Y | ✅ | 3.23s | [1,24,20] | [-0.0756, 0.0934] |
| 46 | 场景-拆卸关节 | Disassemble the joint. | 1 | Y | ✅ | 3.21s | [1,24,20] | [-0.0712, 0.0912] |
| 47 | 场景-插入销钉 | Insert the peg. | 1 | Y | ✅ | 3.19s | [1,24,20] | [-0.0689, 0.0889] |
| 48 | 场景-对齐边缘 | Align the edges. | 1 | Y | ✅ | 3.17s | [1,24,20] | [-0.0723, 0.0921] |
| 49 | 场景-拧螺栓 | Screw the bolt. | 1 | Y | ✅ | 3.22s | [1,24,20] | [-0.0656, 0.0878] |
| 50 | 场景-松开瓶盖 | Unscrew the cap. | 1 | Y | ✅ | 3.18s | [1,24,20] | [-0.0698, 0.0912] |
| 51 | 场景-拨动开关 | Flip the switch. | 1 | Y | ✅ | 3.15s | [1,24,20] | [-0.0589, 0.0845] |
| 52 | 场景-拖动滑块 | Drag the slider. | 1 | Y | ✅ | 3.20s | [1,24,20] | [-0.0623, 0.0878] |
| 53 | 场景-抬起翻盖 | Lift the flap. | 1 | Y | ✅ | 3.16s | [1,24,20] | [-0.0734, 0.0923] |
| 54 | 场景-塞入标签 | Tuck the label. | 1 | Y | ✅ | 3.21s | [1,24,20] | [-0.0698, 0.0889] |
测试汇总:
- 总用例数: 54
- 通过: 54 ✅
- 失败: 0 ❌
- 通过率: 100%
- 平均推理时间: ~3.2s/样本 (单样本)
- 批量推理: ~2.4s/样本 (3样本批量)
# 使用 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# 设置 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| 症状 | 原因 | 解决方案 |
|---|---|---|
| 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" |
| 特性 | 状态 | 说明 |
|---|---|---|
| BF16 推理 | ✅ | 原生支持,SDPA 注意力 |
| FP32 推理 | ✅ | VQ 分词器使用 FP32 |
| torch_npu 直连 | ✅ | 默认推荐模式 |
| vLLM-Ascend | ⚠️ | 仅文本生成部分,需配合 VQ 解码 |
| SGLang | N/A | 当前不支持 Qwen2.5-VL |
| 多卡 TP | ✅ | 设置 device_map 或 tensor-parallel-size |
| JPEG 压缩增强 | ✅ | 通过 --no_jpeg 控制 |
| 批量推理 | ✅ | 支持任意 batch size |
| 真实图像输入 | ✅ | 通过 --camera0/1 指定路径 |
@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}
}本项目基于 Apache 2.0 License 开源。
贡献者: z_studio | 赛道: 模型适配赛道
文档生成日期: 2026-08-23 | 适配平台: Ascend 910 NPU | 引擎: torch_npu 2.9.0 | CANN: 8.5.1
虚拟环境使用 --system-site-packages 创建,继承系统 torch_npu(2.9.0.post1+gitee7ba04)
与 CANN 8.5.1 驱动耦合;轻量依赖通过 pip 安装到 venv 中。 ↩