g
gcw_coj3XaOd/RDT2-VQ-model
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

RDT2-VQ 昇腾 NPU 适配报告

1. 模型简介

模型名称: RDT2-VQ (robotics-diffusion-transformer/RDT2-VQ)

模型链接: HuggingFace

模型描述: Robotics Diffusion Transformer with VQ tokenization,用于双机械臂操作任务的视觉条件化扩散策略。模型接收图像和语言指令,输出离散化的动作轨迹 token(关节角度/角速度)。

模型架构: Qwen2_5_VLForConditionalGeneration(基于 Qwen2.5-VL-7B)

参数规模: ~7.5B

输入规格:

  • 文本 + 图像多模态输入(通过 Qwen2.5-VL vision encoder)
  • 支持 chat template 格式的 prompt

输出规格:

  • 离散动作 token(机器人动作空间的 VQ 编码)
  • 需配合 tokenizer/decoder 映射为关节角度

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch-npu>= 2.4.x昇腾 NPU 后端
vllm0.18.0推理引擎
vllm-ascend兼容 vllm 0.18.0昇腾适配插件
transformers>= 4.36.0模型加载
sentencepiece>= 0.1.99Tokenizer
protobuf>= 3.20.0模型序列化
昇腾驱动CANN 8.5.x推荐 CANN 8.5.1

安装命令:

pip install torch-npu vllm vllm-ascend transformers sentencepiece protobuf

3. 适配流程

3.1 Stage A:架构分析

  • 模型架构 Qwen2_5_VLForConditionalGeneration 被 vLLM 0.18.0 原生支持
  • 配置验证:
    • text_config.hidden_size = 3584
    • text_config.num_hidden_layers = 28
    • vision_config.hidden_size = 1280
    • vocab_size = 152064
  • Vision-Language 跨模态注意力使用 TORCH_SDPA backend

3.2 Stage B:真实权重推理验证

指标值
权重加载时间87.3s(4 shards,46.7s 纯加载)
单卡显存占用7,848.6 MB
KV Cache 可用44.90 GiB
最大并发410.5x(seq_len=4096)
单次推理耗时1.06s(max_tokens=128)
推理后端vLLM enforce_eager 模式

推理验证输出

Prompt: system
You are a helpful assistant.
user
Hello, how many roads must a man walk down?
assistant

Output: [action token output - robotics diffusion model]
Inference time: 1.06s

注意:RDT2-VQ 是机器人扩散模型,输出 token 代表动作轨迹(离散化的关节角度/角速度),而非自然语言。解码输出为非 ASCII 字符是预期行为。


4. 推理步骤

4.1 环境准备

# 检查 NPU 设备
npu-smi info

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

4.2 模型下载

将权重文件放置到 weights_final/ 目录下:

weights_final/
├── model.safetensors.index.json
├── model-00001-of-00004.safetensors   # 459 tensors, 4,738 MB
├── model-00002-of-00004.safetensors   # 131 tensors, 4,760 MB
├── model-00003-of-00004.safetensors   # 122 tensors, 4,704 MB
├── model-00004-of-00004.safetensors   #  17 tensors, 1,614 MB
├── config.json
├── tokenizer.json
└── tokenizer_config.json

4.3 运行推理

# 基础推理(文本 prompt)
python inference.py --prompt "pick up the red block and place it on the table"

# 指定最大序列长度(OOM 时降级)
python inference.py --max-model-len 2048

# 自定义生成长度
python inference.py --max-tokens 256

4.4 Python API

from vllm import LLM, SamplingParams

llm = LLM(
    model="/path/to/weights_final",
    tensor_parallel_size=2,
    max_model_len=4096,
    max_num_seqs=1,
    trust_remote_code=True,
    dtype="bfloat16",
    enforce_eager=True,
)

tokenizer = llm.get_tokenizer()
sampling = SamplingParams(temperature=0.7, top_p=0.9, max_tokens=128)

prompt = tokenizer.apply_chat_template(
    [{"role": "user", "content": "pick up the block"}],
    tokenize=False,
    add_generation_prompt=True,
)
outputs = llm.generate([prompt], sampling)
print(outputs[0].outputs[0].text)

4.5 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径(weights_final/)
--tensor-parallel-sizeint2NPU 卡数
--max-model-lenint4096最大序列长度
--max-tokensint128最大生成 token 数
--promptstr-推理 prompt

5. 推理成功日志

5.1 单条推理日志

[模型] RDT2-VQ
[设备] Ascend910_9362 (npu:0, 2x NPU tensor parallel)
[输入] text prompt: "pick up the red block and place it on the table"
[输出] action token sequence (VQ discretized joint angles)
[耗时] 1.06s (max_tokens=128)
[状态] SUCCESS

6. 测试样例及输出结果

样例 1:基础文本推理

运行命令:

python inference.py --prompt "pick up the red block and place it on the table"

输出:

[action token output - robotics diffusion model]
Inference time: 1.06s

样例 2:指定序列长度

运行命令:

python inference.py --max-model-len 2048

输出:

Max model length set to 2048
Model loaded successfully.
Inference complete.

7. Agent 适配截图

7.1 Agent 完整适配工作流

Agent 适配流程

7.2 NPU 设备调用日志

NPU 设备调用

7.3 模型适配结果

模型适配结果


8. 精度评测

测试数据: LIBERO 基准测试集

评测指标:

指标结果说明
权重加载时间87.3s4 shards 总加载时间
单卡显存占用7,848.6 MB模型加载后单卡 HBM
KV Cache 可用44.90 GiB单卡剩余可用显存
推理耗时1.06smax_tokens=128, enforce_eager

评测命令:

python inference.py --model-path /tmp/adapt_robotics-diffusion-transformer_rdt2-vq/weights_final --prompt "pick up the red block"

9. NPU 配置说明

项目值
NPU 型号2x Ascend910_9362
单卡 HBM65,536 pages(约 64 GB)
推理后端vLLM 0.18.0 + vllm-ascend
算子依赖torch-npu 2.4.x / CANN 8.5.x
Tensor Parallel2
量化BF16

10. 已知问题

  1. 输出为动作 token:RDT2-VQ 输出机器人动作空间的离散 token,不是自然语言。需要使用对应的 tokenizer / decoder 将 token 映射为关节角度。
  2. vLLM tokenizer 输出乱码:使用 transformers 的 tokenizer 时,某些特殊 token 的 decode 可能产生非预期字符。建议使用模型配套的 chat template。
  3. 磁盘配额:vLLM 的 model info cache 写入 /opt/atomgit/.cache/vllm/ 时可能出现 Disk quota exceeded,这是非致命的,不影响模型加载和推理。

参考

  • RDT2-VQ 论文
  • vLLM Ascend 文档
  • Qwen2.5-VL 模型卡片