Mllama#
介绍#
Llama3.2-VL 是 Meta 推出的一系列大型语言和多模态模型。
我们将演示如何使用LMDeploy部署一个Llama3.2-VL模型,以meta-llama/Llama-3.2-11B-Vision-Instruct为例。
安装#
请按照安装指南安装LMDeploy。
离线推理#
以下示例代码展示了VLM管道的基本用法。更多示例,请参考VLM离线推理管道
from lmdeploy import pipeline
from lmdeploy.vl import load_image
pipe = pipeline('meta-llama/Llama-3.2-11B-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 meta-llama/Llama-3.2-11B-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)