本文档记录 InternVL2-2B 在 vLLM-Ascend 0.18.0rc1 环境的快速部署与验证结果。InternVL2-2B 是 OpenGVLab 发布的多模态大语言模型,由 InternViT-300M-448px(视觉编码器)、MLP 投影层和 InternLM2-1.8B(语言模型)组成,总参数约 2.2B,支持图片和视频输入。
vLLM 的模型注册表中已内置 InternVLChatModel 架构支持,结合 vLLM-Ascend 插件可直接在昇腾 NPU 上部署推理,无需额外代码适配。
相关获取地址:
quay.io/ascend/vllm-ascend:v0.18.0rc1参考文档:
| 组件 | 版本 |
|---|---|
vllm-ascend | 0.18.0rc1 |
vllm | 0.18.0+empty |
transformers | 4.57.6 |
torch-npu | 2.9.0.post1+gitee7ba04 |
Ascend910,1 逻辑卡,HBM 65536 MBOpenGVLab/InternVL2-2B(ModelScope 下载)8000pip install modelscope
modelscope download --model OpenGVLab/InternVL2-2B模型将下载至 ~/.cache/modelscope/hub/models/OpenGVLab/InternVL2-2B/。
export VLLM_USE_MODELSCOPE=True
export PYTORCH_NPU_ALLOC_CONF=max_split_size_mb:256import os
os.environ["VLLM_USE_MODELSCOPE"] = "True"
os.environ["PYTORCH_NPU_ALLOC_CONF"] = "max_split_size_mb:256"
from vllm import LLM, SamplingParams
MODEL_PATH = "OpenGVLab/InternVL2-2B"
llm = LLM(
model=MODEL_PATH,
max_model_len=4096,
trust_remote_code=True,
dtype="bfloat16",
limit_mm_per_prompt={"image": 10},
)
sampling_params = SamplingParams(max_tokens=512)
image_url = "https://modelscope.oss-cn-beijing.aliyuncs.com/resource/qwen.png"
outputs = llm.chat(
messages=[
{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": image_url}},
{"type": "text", "text": "Please provide a detailed description of this image"},
],
},
],
sampling_params=sampling_params,
)
print(outputs[0].outputs[0].text)vllm serve OpenGVLab/InternVL2-2B \
--trust-remote-code \
--dtype bfloat16 \
--max-model-len 32768 \
--enforce-eager服务启动后,可通过 curl 测试:
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "OpenGVLab/InternVL2-2B",
"messages": [
{"role": "user", "content": [
{"type": "image_url", "image_url": {"url": "https://modelscope.oss-cn-beijing.aliyuncs.com/resource/qwen.png"}},
{"type": "text", "text": "What is the text in the illustration?"}
]}
]
}'基础检查结果:
/v1/models 返回 200/v1/chat/completions 返回 2001.46s(权重加载)4.13 GB验证输出示例:
{
"model": "OpenGVLab/InternVL2-2B",
"choices": [
{
"message": {
"role": "assistant",
"content": "The image contains two distinct elements: a graphic logo on the left side and text branding on the right side."
},
"finish_reason": "stop"
}
]
}在 NPU 上使用 5 组多模态测试用例对模型进行精度验证,涵盖 OCR 文字识别、图像描述、视觉推理和中文理解等能力维度,全部通过。
| 测试用例 | 类别 | 输出 Token | 耗时 | 状态 |
|---|---|---|---|---|
| OCR Text Recognition | TextVQA | 14 | 1.66s | PASS |
| Image Detailed Description (image1) | DocVQA | 149 | 1.96s | PASS |
| Image Understanding (image2) | ChartQA | 170 | 2.35s | PASS |
| Visual Reasoning (image1) | Reasoning | 52 | 0.69s | PASS |
| Chinese Multimodal Understanding | General | 129 | 1.85s | PASS |
在 Ascend910 NPU 上使用 MMMU_val 数据集(30 个学科,900 个样本)进行完整精度评测:
| 指标 | NPU 结果 | GPU 参考值 |
|---|---|---|
| MMMU_val Overall | 36.6% (329/900) | 36.3% |
完整评测数据详见 npu_accuracy_mmmu_val.json。
以下为 InternVL2-2B 在 GPU 上的官方基准数据,供 NPU 部署参考对比:
| 基准测试 | GPU 参考值 | 说明 |
|---|---|---|
| MMMU_val | 36.3 | 多学科多模态理解(官方模型卡片) |
| DocVQAtest | 86.9 | 文档视觉问答 |
| ChartQAtest | 76.2 | 图表理解 |
| InfoVQAtest | 58.9 | 信息提取视觉问答 |
| TextVQAval | 73.4 | 自然场景文字识别 |
| OCRBench | 784 | OCR 基准 |
Flash Attention:模型原始 ViT 代码依赖 flash_attn(CUDA),在 NPU 上不可用时自动回退到 naive attention,不影响推理正确性。vLLM 内部使用 SDPA 作为 ViT 编码器的注意力后端。
ACL Graph:默认启用 PIECEWISE 模式,模型共 35 个图桶尺寸。如遇内存不足可添加 --enforce-eager 跳过图编译。
模型权重格式:权重文件为 model.safetensors(约 4.2GB),bfloat16 精度,单卡 Ascend910 可完整加载。
Tokenizer 警告:运行时可能出现 incorrect regex pattern 的 tokenizer 警告,不影响推理结果。
| 文件 | 说明 |
|---|---|
inference.py | 离线推理脚本 |
accuracy_test.py | 5 组多模态精度验证脚本 |
run_mmmu_eval.py | MMMU_val 完整基准评测脚本 |
npu_accuracy_mmmu_val.json | MMMU_val NPU 评测结果 |
verification_log.txt | 完整验证日志 |