RDT2-VQ 昇腾 NPU 适配报告
模型信息
项目 值 模型 ID robotics-diffusion-transformer/RDT2-VQ架构 Qwen2_5_VLForConditionalGeneration参数量 ~7.5B(Qwen2.5-VL-7B 基础架构) 权重大小 16.58 GB (BF16,4 shards)Tensor 数量 729(Shard 1: 459 / Shard 2: 131 / Shard 3: 122 / Shard 4: 17) 用途 机器人操作任务(视觉条件化扩散策略)
硬件环境
项目 值 NPU 型号 2x Ascend910_9362 单卡 HBM 65,536 pages(约 64 GB) 推理后端 vLLM 0.18.0 + vllm-ascend 算子依赖 torch-npu 2.4.x / CANN 8.5.x
适配流程
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
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 字符是预期行为。
快速开始
1. 环境准备
pip install -r requirements.txt
2. 准备权重
将 4 个 safetensors shard 放置到 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
3. 运行推理
# 设置权重目录
export WEIGHT_DIR=/path/to/weights_final
# 基础推理(文本 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. 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)
已知问题
输出为动作 token :RDT2-VQ 输出机器人动作空间的离散 token,不是自然语言。需要使用对应的 tokenizer / decoder 将 token 映射为关节角度。
vLLM tokenizer 输出乱码 :使用 transformers 的 tokenizer 时,某些特殊 token 的 decode 可能产生非预期字符。建议使用模型配套的 chat template。
磁盘配额 :vLLM 的 model info cache 写入 /opt/atomgit/.cache/vllm/ 时可能出现 Disk quota exceeded,这是非致命的,不影响模型加载和推理。
参考