Phi-3 视觉#
介绍#
Phi-3 是微软推出的一系列小型语言和多模态模型。LMDeploy 支持以下多模态模型。
模型 |
大小 |
支持的推理引擎 |
---|---|---|
42亿 |
PyTorch |
|
42亿 |
PyTorch |
下一章将演示如何使用LMDeploy部署Phi-3模型,以microsoft/Phi-3.5-vision-instruct为例。
安装#
请按照安装指南安装LMDeploy,并安装依赖项Flash-Attention
# It is recommended to find the whl package that matches the environment from the releases on https://github.com/Dao-AILab/flash-attention.
pip install flash-attn
离线推理#
以下示例代码展示了VLM管道的基本用法。更多示例,请参考VLM离线推理管道
from lmdeploy import pipeline
from lmdeploy.vl import load_image
pipe = pipeline('microsoft/Phi-3.5-vision-instruct')
image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
response = pipe(('describe this image', image))
print(response)
在线服务#
启动服务#
你可以通过lmdeploy serve api_server
CLI启动服务器:
lmdeploy serve api_server microsoft/Phi-3.5-vision-instruct
与OpenAI
集成#
这里是一个通过openai包与v1/chat/completions
服务交互的示例。
在运行之前,请通过pip install openai
安装openai包。
from openai import OpenAI
client = OpenAI(api_key='YOUR_API_KEY', base_url='http://0.0.0.0:23333/v1')
model_name = client.models.list().data[0].id
response = client.chat.completions.create(
model=model_name,
messages=[{
'role':
'user',
'content': [{
'type': 'text',
'text': 'Describe the image please',
}, {
'type': 'image_url',
'image_url': {
'url':
'https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg',
},
}],
}],
temperature=0.8,
top_p=0.8)
print(response)