Image-Text-to-Text
Transformers
PyTorch
multilingual
internvl_chat
feature-extraction
internvl
custom_code
conversational
Instructions to use OpenGVLab/InternVL2-40B-AWQ with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/InternVL2-40B-AWQ with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenGVLab/InternVL2-40B-AWQ", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("OpenGVLab/InternVL2-40B-AWQ", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use OpenGVLab/InternVL2-40B-AWQ with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenGVLab/InternVL2-40B-AWQ" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenGVLab/InternVL2-40B-AWQ", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/OpenGVLab/InternVL2-40B-AWQ
- SGLang
How to use OpenGVLab/InternVL2-40B-AWQ with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "OpenGVLab/InternVL2-40B-AWQ" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenGVLab/InternVL2-40B-AWQ", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "OpenGVLab/InternVL2-40B-AWQ" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenGVLab/InternVL2-40B-AWQ", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use OpenGVLab/InternVL2-40B-AWQ with Docker Model Runner:
docker model run hf.co/OpenGVLab/InternVL2-40B-AWQ
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,126 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
pipeline_tag: image-text-to-text
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# InternVL2-40B-AWQ
|
| 7 |
+
|
| 8 |
+
[\[π GitHub\]](https://github.com/OpenGVLab/InternVL) [\[π Blog\]](https://internvl.github.io/blog/) [\[π InternVL 1.0 Paper\]](https://arxiv.org/abs/2312.14238) [\[π InternVL 1.5 Report\]](https://arxiv.org/abs/2404.16821)
|
| 9 |
+
|
| 10 |
+
[\[π¨οΈ Chat Demo\]](https://internvl.opengvlab.com/) [\[π€ HF Demo\]](https://huggingface.co/spaces/OpenGVLab/InternVL) [\[π Quick Start\]](#quick-start) [\[π δΈζθ§£θ―»\]](https://zhuanlan.zhihu.com/p/706547971) \[π [ιζη€ΎεΊ](https://modelscope.cn/organization/OpenGVLab) | [ζη¨](https://mp.weixin.qq.com/s/OUaVLkxlk1zhFb1cvMCFjg) \]
|
| 11 |
+
|
| 12 |
+
## Introduction
|
| 13 |
+
|
| 14 |
+
<div align="center">
|
| 15 |
+
<img src="https://raw.githubusercontent.com/InternLM/lmdeploy/0be9e7ab6fe9a066cfb0a09d0e0c8d2e28435e58/resources/lmdeploy-logo.svg" width="450"/>
|
| 16 |
+
</div>
|
| 17 |
+
|
| 18 |
+
### INT4 Weight-only Quantization and Deployment (W4A16)
|
| 19 |
+
|
| 20 |
+
LMDeploy adopts [AWQ](https://arxiv.org/abs/2306.00978) algorithm for 4bit weight-only quantization. By developed the high-performance cuda kernel, the 4bit quantized model inference achieves up to 2.4x faster than FP16.
|
| 21 |
+
|
| 22 |
+
LMDeploy supports the following NVIDIA GPU for W4A16 inference:
|
| 23 |
+
|
| 24 |
+
- Turing(sm75): 20 series, T4
|
| 25 |
+
|
| 26 |
+
- Ampere(sm80,sm86): 30 series, A10, A16, A30, A100
|
| 27 |
+
|
| 28 |
+
- Ada Lovelace(sm90): 40 series
|
| 29 |
+
|
| 30 |
+
Before proceeding with the quantization and inference, please ensure that lmdeploy is installed.
|
| 31 |
+
|
| 32 |
+
```shell
|
| 33 |
+
pip install lmdeploy[all]
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
This article comprises the following sections:
|
| 37 |
+
|
| 38 |
+
<!-- toc -->
|
| 39 |
+
|
| 40 |
+
- [Inference](#inference)
|
| 41 |
+
- [Service](#service)
|
| 42 |
+
|
| 43 |
+
<!-- tocstop -->
|
| 44 |
+
|
| 45 |
+
### Inference
|
| 46 |
+
|
| 47 |
+
Trying the following codes, you can perform the batched offline inference with the quantized model:
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
from lmdeploy import pipeline, TurbomindEngineConfig
|
| 51 |
+
from lmdeploy.vl import load_image
|
| 52 |
+
|
| 53 |
+
model = 'OpenGVLab/InternVL2-40B-AWQ'
|
| 54 |
+
image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
|
| 55 |
+
backend_config = TurbomindEngineConfig(model_format='awq')
|
| 56 |
+
pipe = pipeline(model, backend_config=backend_config, log_level='INFO')
|
| 57 |
+
response = pipe(('describe this image', image))
|
| 58 |
+
print(response.text)
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
For more information about the pipeline parameters, please refer to [here](https://github.com/InternLM/lmdeploy/blob/main/docs/en/inference/pipeline.md).
|
| 62 |
+
|
| 63 |
+
### Service
|
| 64 |
+
|
| 65 |
+
LMDeploy's `api_server` enables models to be easily packed into services with a single command. The provided RESTful APIs are compatible with OpenAI's interfaces. Below are an example of service startup:
|
| 66 |
+
|
| 67 |
+
```shell
|
| 68 |
+
lmdeploy serve api_server OpenGVLab/InternVL2-40B-AWQ --server-port 23333
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
To use the OpenAI-style interface, you need to install OpenAI:
|
| 72 |
+
|
| 73 |
+
```shell
|
| 74 |
+
pip install openai
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
Then, use the code below to make the API call:
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
from openai import OpenAI
|
| 81 |
+
|
| 82 |
+
client = OpenAI(api_key='YOUR_API_KEY', base_url='http://0.0.0.0:23333/v1')
|
| 83 |
+
model_name = client.models.list().data[0].id
|
| 84 |
+
response = client.chat.completions.create(
|
| 85 |
+
model=model_name,
|
| 86 |
+
messages=[{
|
| 87 |
+
'role':
|
| 88 |
+
'user',
|
| 89 |
+
'content': [{
|
| 90 |
+
'type': 'text',
|
| 91 |
+
'text': 'describe this image',
|
| 92 |
+
}, {
|
| 93 |
+
'type': 'image_url',
|
| 94 |
+
'image_url': {
|
| 95 |
+
'url':
|
| 96 |
+
'https://modelscope.oss-cn-beijing.aliyuncs.com/resource/tiger.jpeg',
|
| 97 |
+
},
|
| 98 |
+
}],
|
| 99 |
+
}],
|
| 100 |
+
temperature=0.8,
|
| 101 |
+
top_p=0.8)
|
| 102 |
+
print(response)
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
## License
|
| 106 |
+
|
| 107 |
+
This project is released under the MIT license, while InternLM is licensed under the Apache-2.0 license.
|
| 108 |
+
|
| 109 |
+
## Citation
|
| 110 |
+
|
| 111 |
+
If you find this project useful in your research, please consider citing:
|
| 112 |
+
|
| 113 |
+
```BibTeX
|
| 114 |
+
@article{chen2023internvl,
|
| 115 |
+
title={InternVL: Scaling up Vision Foundation Models and Aligning for Generic Visual-Linguistic Tasks},
|
| 116 |
+
author={Chen, Zhe and Wu, Jiannan and Wang, Wenhai and Su, Weijie and Chen, Guo and Xing, Sen and Zhong, Muyan and Zhang, Qinglong and Zhu, Xizhou and Lu, Lewei and Li, Bin and Luo, Ping and Lu, Tong and Qiao, Yu and Dai, Jifeng},
|
| 117 |
+
journal={arXiv preprint arXiv:2312.14238},
|
| 118 |
+
year={2023}
|
| 119 |
+
}
|
| 120 |
+
@article{chen2024far,
|
| 121 |
+
title={How Far Are We to GPT-4V? Closing the Gap to Commercial Multimodal Models with Open-Source Suites},
|
| 122 |
+
author={Chen, Zhe and Wang, Weiyun and Tian, Hao and Ye, Shenglong and Gao, Zhangwei and Cui, Erfei and Tong, Wenwen and Hu, Kongzhi and Luo, Jiapeng and Ma, Zheng and others},
|
| 123 |
+
journal={arXiv preprint arXiv:2404.16821},
|
| 124 |
+
year={2024}
|
| 125 |
+
}
|
| 126 |
+
```
|