DashInfer-VLM:VLM并行加速,突破vLLM性能极限

引言

DashInfer-VLM是一款专为视觉多模态大模型VLM设计的推理架构,特别针对Qwen VL模型的推理加速进行了优化。与其它VLM推理加速框架相比,DashInfer-VLM的独特之处在于其将VIT和LLM部分分离,实现并行运行,互不干扰。

这种设计使得VLM中的图片、视频预处理以及VIT的特征抽取部分不会中断LLM的生成,实现了VIT/LLM分离的架构,成为开源社区首个采用该架构的VLM服务框架。


(adsbygoogle=window.adsbygoogle||[]).push({});

在多卡部署中,每张卡上都有一个ViT处理单元,这在视频和多图场景下表现出显著的性能优势。

此外,ViT部分支持内存缓存,在多轮对话中无需重复计算ViT。

以下是架构图及基于4卡72B配置的示例。

DashInfer-VLM,多模态SOTA推理性能,超vLLM!-1

 

架构图详细描述了流程和架构:

  • ViT部分,支持多种推理引擎,如TensorRT或onnxruntime(框架内对ViT模型进行onnx模型导出,默认支持TensorRT)。
  • LLM部分,使用DashInfer进行推理。
  • 缓存部分,支持ViT结果Memory Cache,LLM部分Prerfix Cache,LLM多模态Prefix Cache(默认未开启)。

 

代码地址:

https://github.com/modelscope/dash-infer

文档地址: 

https://dashinfer.readthedocs.io/en/latest/vlm/vlm_offline_inference_en.html

 

最佳实践

在魔搭社区免费GPU算力上体验DashInfer:

首先是dashinfer-vlm和TensorRT的安装。

# 首先安装所需的 package
import os

# 下载并安装 dashinfer 2.0.0rc2 版本
# 如果需要,可以使用 wget 下载并解压 TensorRT 包
# pip 安装 dashinfer 2.0.0rc2
#!pip install https://github.com/modelscope/dash-infer/releases/download/v2.0.0-rc2/dashinfer-2.0.0rc2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
#!wget https://modelscope.oss-cn-beijing.aliyuncs.com/releases/TensorRT-10.6.0.26.Linux.x86_64-gnu.cuda-12.6.tar.gz
#!tar -xvzf TensorRT-10.6.0.26.Linux.x86_64-gnu.cuda-12.6.tar.gz

# 下载到本地并替换为 modelscope 对应的 URL
# 安装 dashinfer,因 package 较大,推荐下载到本地后安装
#!wget https://modelscope.oss-cn-beijing.aliyuncs.com/releases/dashinfer-2.0.0rc3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
#!pip install ./dashinfer-2.0.0rc3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

# 安装 dashinfer vlm
#!pip install dashinfer-vlm

# 安装 OpenAI 客户端
#!pip install openai==1.56.2

# 安装 TensorRT 的 Python 包,从下载的包中打开安装
#!pip install TensorRT-10.6.0.26/python/tensorrt-10.6.0-cp310-none-linux_x86_64.whl

 

TensorRT 需要进行环境变量配置:

import os

# 获取 TensorRT 运行时库的路径
trt_runtime_path = os.getcwd() + "/TensorRT-10.6.0.26/lib/"

# 获取当前的 LD_LIBRARY_PATH 环境变量值
current_ld_library_path = os.environ.get('LD_LIBRARY_PATH', '')

# 将新路径添加到现有值中
if current_ld_library_path:
# 如果 LD

环境安装完成,启动 dashinfer vlm对模型进行推理,并形成一个openai兼容的server,模型可以更换为7B、72B等。

 

默认会使用环境里面所有的GPU显存

!dashinfer_vlm_serve --model qwen/Qwen2-VL-2B-Instruct --port 8000 --host 127.0.0.1

这个过程会初始化DashInfer,以及ViT用的外部引擎(这里是TensorRT),并起一个openai的service。

 

看到这些日志表示TRT初始化成功:

DashInfer-VLM,多模态SOTA推理性能,超vLLM!-1

 

看到这些日志,表示DashInfer初始化成功:

DashInfer-VLM,多模态SOTA推理性能,超vLLM!-1

 

看到这些日志,表示openai服务初始化成功:

DashInfer-VLM,多模态SOTA推理性能,超vLLM!-1

 

到这里全部初始化成功,可以打开另一个notebook进行client和benchmark

Notebook地址:https://modelscope.cn/notebook/share/ipynb/6ea987c5/vl-start-server.ipynb

 

图片理解Demo

展示一个多张图片的图片理解的demo:

# Install the required OpenAI client version
!pip install openai==1.56.2 # VL support requires a recent OpenAI client.

from openai import OpenAI

# Initialize the OpenAI client
client = OpenAI(
base_url="http://localhost:8000/v1", 
api_key="EMPTY"
)

# Prepare the API call for a chat completion
response = client.chat.completions.create(
model="model",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Are these images different?"},
{
"type": "image_url",
"image_url": {
"url": "https://farm4.staticflickr.com/3075/3168662394_7d7103de7d_z_d.jpg",
}
},
{
"type": "image_url",
"image_url": {
"url": "https://farm2.staticflickr.com/1533/26541536141_41abe98db3_z_d.jpg",
}
},
],
}
],
stream=True,
max_completion_tokens=1024,
temperature=0.1,
)

# Process the streamed response
full_response = ""
for chunk in response:
# Append the delta content to the full response
full_response += chunk.choices[0].delta.content
print(".", end="") # Print a dot for each chunk received

# Print the full response
print(f"\nImage: Full Response:\n{full_response}")

 

视频理解demo

由于openai没有定义标准的视频接口,本文提供了一个video_url的type,会自动进行视频下载,抽帧,分析的工作。

# video example
!pip install openai==1.56.2 # Ensure the OpenAI client supports video link features.

from openai import OpenAI

# Initialize the OpenAI client
client = OpenAI(
base_url="http://localhost:8000/v1",
api_key="EMPTY"
)

# Create a chat completion request with a video URL
response = client.chat.completions.create(
model="model",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "Generate a compelling description that I can upload along with the video."
},
{
"type": "video_url",
"video_url": {
"url": "https://cloud.video.taobao.com/vod/JCM2

相关推荐

暂无评论

发表评论