g
gcw_coj3XaOd/UnifoLM-VLM-Base
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

UnifoLM-VLM-Base - 昇腾 NPU 推理部署

1. 模型简介

模型名称: UnifoLM-VLM-Base (unitreerobotics/UnifoLM-VLM-Base)

模型链接: HuggingFace

模型描述: 统一机器人基础模型(Unified Robotics Foundation Model),基于 Qwen2.5-VL-7B 架构的视觉-语言-动作(VLA)模型,用于机器人操作任务。

模型架构: Qwen2.5-VL(Vision Transformer + Qwen2.5 LLM backbone)

参数规模: ~7.7B 参数(Qwen2.5-VL-7B base)

架构详情:

组件配置
语言模型 hidden_size3584
语言模型层数28
注意力头数28 (GQA, 4 KV heads)
FFN intermediate_size18944
视觉编码器 hidden_size1280
视觉 patch_size14
最大位置长度128,000 tokens

权重格式: safetensors, bfloat16, 4 shards (~15.6 GB total)


2. 环境依赖

硬件要求

组件要求
NPUAscend 910 (Ascend910_9362)
显存≥ 16 GB HBM(单卡)
CANN8.5.1

Python 依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
transformers>= 4.56.0HF transformers(需 >= 4.56 以支持 Gemma3Config)
vllm0.18.0vLLM-Ascend(模型架构已内置支持)
vllm-ascendlatestvLLM Ascend 插件
sentencepiece>= 0.1.99Tokenizer 依赖
Pillow>= 9.0图像处理
numpy< 2数值计算
accelerate>= 0.25.0模型加载加速

安装命令:

pip install torch torch_npu
pip install transformers>=4.56.0
pip install vllm==0.18.0 vllm-ascend
pip install sentencepiece Pillow numpy<2 accelerate

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

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

# 验证 CANN acl 模块
python3 -c "import acl; print('acl OK')"

3.2 模型下载

方式一:HuggingFace(推荐)

mkdir -p /tmp/unifolm_model_full
huggingface-cli download unitreerobotics/UnifoLM-VLM-Base \
  --local-dir /tmp/unifolm_model_full

方式二:AtomGit 镜像(HuggingFace 下载慢时使用) <AtomGit 镜像链接待补充>

3.3 运行推理

# 设置环境变量(CANN site-packages + thread safety patch)
export PYTHONPATH="/tmp/python_patch:/usr/local/Ascend/cann-8.5.1/python/site-packages:$PYTHONPATH"
export OMP_NUM_THREADS=1
export MKL_NUM_THREADS=1

# 文本推理
python inference.py --model-path /tmp/unifolm_model_full

# 仅文本推理(跳过图像测试)
python inference.py --model-path /tmp/unifolm_model_full --text-only

# 指定测试图像
python inference.py --model-path /tmp/unifolm_model_full --image /path/to/image.png

3.4 vLLM-Ascend 部署说明

该模型架构(Qwen2_5_VLForConditionalGeneration)已由 vLLM-Ascend 原生支持。 vLLM EngineCore 的多进程 spawned worker 可能存在 acl 模块导入问题, 如遇此问题,请使用 transformers-native 推理路径(inference.py)。

vllm serve /tmp/unifolm_model_full \
  --dtype bfloat16 \
  --tensor-parallel-size 1 \
  --max-model-len 8192 \
  --max-num-seqs 16 \
  --trust-remote-code false \
  --port 8000

3.5 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--text-onlyflagfalse仅文本推理,跳过图像
--imagestr/tmp/test_image.png测试图像路径
--max-new-tokensint128最大生成长度

4. 推理成功日志

4.1 文本推理日志

[NPU] Device: Ascend910_9362
[NPU] Before load - Allocated: 0 MB
[Step] Model loaded in 7.6s
[NPU] After load - Allocated: 15866 MB

[Test 1] Text-only inference (chat format)
Prompt: Hello, who are you? Please introduce yourself briefly.
Response: Hello! I am an AI digital assistant designed to provide information and answer questions to the best of my ability based on my programming and available data. How can I assist you today?
Time: 1.57s, Tokens: 37

[Test 2] Robotics domain question
Prompt: What skills does a robot need to manipulate objects?
Response: To manipulate objects, a robot would require a variety of skills. These include understanding and grasping the object's structure, using precise movements to move or rotate it, and applying force to exert control over the object. The robot should also have the ability to anticipate changes in the object's state...
Time: 3.31s, Tokens: 98

4.2 视觉-语言推理日志

[Test 3] Image understanding
Input shape: torch.Size([1, 98])
Image grid: tensor([[ 1, 16, 16]], device='npu:0')

Response: The image features a bright red square centered against a solid red background. The square is a smaller blue square that is perfectly positioned in the middle of the larger red square. This creates a striking contrast between the vibrant red and the cool blue tones, with the blue square serving as a focal point in the center of the composition.
Time: 2.68s, Tokens: 66

5. 测试样例及输出结果

样例 1:自我介绍

运行命令:

python inference.py --model-path /tmp/unifolm_model_full --text-only

输出:

[Input] Hello, who are you? Please introduce yourself briefly.
[Output] Hello! I am an AI digital assistant designed to provide information and answer questions to the best of my ability based on my programming and available data. How can I assist you today?
[Stats] 37 tokens, 1.57s (23.6 tok/s)

样例 2:机器人操作

运行命令:

python inference.py --model-path /tmp/unifolm_model_full --text-only

输出:

[Input] What skills does a robot need to manipulate objects?
[Output] To manipulate objects, a robot would require a variety of skills. These include understanding and grasping the object's structure, using precise movements to move or rotate it, and applying force to exert control over the object...
[Stats] 98 tokens, 3.31s (29.6 tok/s)

样例 3:图像理解(VLM 多模态)

运行命令:

python inference.py --model-path /tmp/unifolm_model_full --image /tmp/test_image.png

输出:

[Input Image] /tmp/test_image.png
[Input Text] Describe what you see in this image.
[Output] The image features a bright red square centered against a solid red background. The square is a smaller blue square that is perfectly positioned in the middle of the larger red square...
[Stats] 66 tokens, 2.68s (24.6 tok/s)

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. NPU 配置说明

  • NPU 型号: Ascend910_9362
  • NPU 数量: 2 卡(当前验证使用 1 卡)
  • Tensor Parallel: TP=1(单卡)
  • 显存占用: ~15,866 MB(总 HBM 65,536 MB)
  • CANN 版本: 8.5.1
  • vLLM 版本: 0.18.0 + vLLM-Ascend
  • transformers 版本: 4.57.6

8. 已知问题

  1. vLLM EngineCore 多进程问题: vLLM serve 启动时,spawned worker 进程无法导入 acl 模块,导致 EngineCore 崩溃。使用 transformers-native API 作为替代推理路径已验证可用。
  2. 线程安全补丁: torch_npu 初始化时 torch.set_num_threads 可能在 multiprocessing spawn 模式下触发 pool INTERNAL ASSERT FAILED。已在 inference.py 中内置 monkey-patch 修复。