Image-Text-to-Text
Transformers
PyTorch
multilingual
internvl_chat
feature-extraction
internvl
custom_code
conversational
Instructions to use OpenGVLab/InternVL2-2B-AWQ with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/InternVL2-2B-AWQ with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenGVLab/InternVL2-2B-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-2B-AWQ", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use OpenGVLab/InternVL2-2B-AWQ with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenGVLab/InternVL2-2B-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-2B-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-2B-AWQ
- SGLang
How to use OpenGVLab/InternVL2-2B-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-2B-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-2B-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-2B-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-2B-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-2B-AWQ with Docker Model Runner:
docker model run hf.co/OpenGVLab/InternVL2-2B-AWQ
Upload folder using huggingface_hub
Browse files- README.md +6 -20
- config.json +4 -1
README.md
CHANGED
|
@@ -47,17 +47,13 @@ This article comprises the following sections:
|
|
| 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-2B-AWQ'
|
| 54 |
-
system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。'
|
| 55 |
image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
|
| 56 |
-
chat_template_config = ChatTemplateConfig('internvl-internlm2')
|
| 57 |
-
chat_template_config.meta_instruction = system_prompt
|
| 58 |
backend_config = TurbomindEngineConfig(model_format='awq')
|
| 59 |
-
pipe = pipeline(model,
|
| 60 |
-
backend_config=backend_config))
|
| 61 |
response = pipe(('describe this image', image))
|
| 62 |
print(response.text)
|
| 63 |
```
|
|
@@ -66,20 +62,10 @@ For more information about the pipeline parameters, please refer to [here](https
|
|
| 66 |
|
| 67 |
### Service
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
```json
|
| 72 |
-
{
|
| 73 |
-
"model_name":"internvl-internlm2",
|
| 74 |
-
"meta_instruction":"我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。",
|
| 75 |
-
"stop_words":["<|im_start|>", "<|im_end|>"]
|
| 76 |
-
}
|
| 77 |
-
```
|
| 78 |
-
|
| 79 |
-
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.
|
| 80 |
|
| 81 |
```shell
|
| 82 |
-
lmdeploy serve api_server OpenGVLab/InternVL2-2B-AWQ --
|
| 83 |
```
|
| 84 |
|
| 85 |
To use the OpenAI-style interface, you need to install OpenAI:
|
|
@@ -96,7 +82,7 @@ from openai import OpenAI
|
|
| 96 |
client = OpenAI(api_key='YOUR_API_KEY', base_url='http://0.0.0.0:23333/v1')
|
| 97 |
model_name = client.models.list().data[0].id
|
| 98 |
response = client.chat.completions.create(
|
| 99 |
-
model=
|
| 100 |
messages=[{
|
| 101 |
'role':
|
| 102 |
'user',
|
|
@@ -118,7 +104,7 @@ print(response)
|
|
| 118 |
|
| 119 |
## License
|
| 120 |
|
| 121 |
-
This project is released under the MIT license, while
|
| 122 |
|
| 123 |
## Citation
|
| 124 |
|
|
|
|
| 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-2B-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 |
```
|
|
|
|
| 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-2B-AWQ --backend turbomind --server-port 23333 --model-format awq
|
| 69 |
```
|
| 70 |
|
| 71 |
To use the OpenAI-style interface, you need to install OpenAI:
|
|
|
|
| 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',
|
|
|
|
| 104 |
|
| 105 |
## License
|
| 106 |
|
| 107 |
+
This project is released under the MIT license, while InternLM2 is licensed under the Apache-2.0 license.
|
| 108 |
|
| 109 |
## Citation
|
| 110 |
|
config.json
CHANGED
|
@@ -84,7 +84,10 @@
|
|
| 84 |
"return_dict": true,
|
| 85 |
"return_dict_in_generate": false,
|
| 86 |
"rms_norm_eps": 1e-05,
|
| 87 |
-
"rope_scaling":
|
|
|
|
|
|
|
|
|
|
| 88 |
"rope_theta": 1000000,
|
| 89 |
"sep_token_id": null,
|
| 90 |
"suppress_tokens": null,
|
|
|
|
| 84 |
"return_dict": true,
|
| 85 |
"return_dict_in_generate": false,
|
| 86 |
"rms_norm_eps": 1e-05,
|
| 87 |
+
"rope_scaling": {
|
| 88 |
+
"factor": 2.0,
|
| 89 |
+
"type": "dynamic"
|
| 90 |
+
},
|
| 91 |
"rope_theta": 1000000,
|
| 92 |
"sep_token_id": null,
|
| 93 |
"suppress_tokens": null,
|