Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -677,7 +677,59 @@ InternVL 2.0 是一个多模态大语言模型系列,包含各种规模的模
|
|
| 677 |
|
| 678 |
### LMDeploy
|
| 679 |
|
| 680 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 681 |
|
| 682 |
### vLLM
|
| 683 |
|
|
|
|
| 677 |
|
| 678 |
### LMDeploy
|
| 679 |
|
| 680 |
+
#### API部署
|
| 681 |
+
|
| 682 |
+
为了将InternVL2部署成API,请先配置聊天模板配置文件。创建如下的 JSON 文件 `chat_template.json`。
|
| 683 |
+
|
| 684 |
+
```json
|
| 685 |
+
{
|
| 686 |
+
"model_name":"internvl-internlm2",
|
| 687 |
+
"meta_instruction":"我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。",
|
| 688 |
+
"stop_words":["<|im_start|>", "<|im_end|>"]
|
| 689 |
+
}
|
| 690 |
+
```
|
| 691 |
+
|
| 692 |
+
LMDeploy 的 `api_server` 使模型能够通过一个命令轻松打包成服务。提供的 RESTful API 与 OpenAI 的接口兼容。以下是服务启动的示例:
|
| 693 |
+
|
| 694 |
+
> **⚠️ 注意**: 请务必安装Flash Attention; 否则,使用`——tp`将存在异常。
|
| 695 |
+
|
| 696 |
+
```shell
|
| 697 |
+
CUDA_VISIBLE_DEVICES=0,1,2,3 lmdeploy serve api_server OpenGVLab/InternVL2-Llama3-76B --backend turbomind --server-port 23333 --chat-template chat_template.json --tp 4
|
| 698 |
+
```
|
| 699 |
+
|
| 700 |
+
为了使用OpenAI风格的API接口,您需要安装OpenAI:
|
| 701 |
+
|
| 702 |
+
```shell
|
| 703 |
+
pip install openai
|
| 704 |
+
```
|
| 705 |
+
|
| 706 |
+
然后,使用下面的代码进行API调用:
|
| 707 |
+
|
| 708 |
+
```python
|
| 709 |
+
from openai import OpenAI
|
| 710 |
+
|
| 711 |
+
client = OpenAI(api_key='YOUR_API_KEY', base_url='http://0.0.0.0:23333/v1')
|
| 712 |
+
model_name = client.models.list().data[0].id
|
| 713 |
+
response = client.chat.completions.create(
|
| 714 |
+
model=model_name,
|
| 715 |
+
messages=[{
|
| 716 |
+
'role':
|
| 717 |
+
'user',
|
| 718 |
+
'content': [{
|
| 719 |
+
'type': 'text',
|
| 720 |
+
'text': 'describe this image',
|
| 721 |
+
}, {
|
| 722 |
+
'type': 'image_url',
|
| 723 |
+
'image_url': {
|
| 724 |
+
'url':
|
| 725 |
+
'https://modelscope.oss-cn-beijing.aliyuncs.com/resource/tiger.jpeg',
|
| 726 |
+
},
|
| 727 |
+
}],
|
| 728 |
+
}],
|
| 729 |
+
temperature=0.8,
|
| 730 |
+
top_p=0.8)
|
| 731 |
+
print(response)
|
| 732 |
+
```
|
| 733 |
|
| 734 |
### vLLM
|
| 735 |
|