Image-Text-to-Text
Transformers
PyTorch
multilingual
internvl_chat
feature-extraction
internvl
custom_code
Instructions to use OpenGVLab/InternVL-Chat-V1-1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/InternVL-Chat-V1-1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenGVLab/InternVL-Chat-V1-1", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("OpenGVLab/InternVL-Chat-V1-1", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use OpenGVLab/InternVL-Chat-V1-1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenGVLab/InternVL-Chat-V1-1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenGVLab/InternVL-Chat-V1-1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/OpenGVLab/InternVL-Chat-V1-1
- SGLang
How to use OpenGVLab/InternVL-Chat-V1-1 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/InternVL-Chat-V1-1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenGVLab/InternVL-Chat-V1-1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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/InternVL-Chat-V1-1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenGVLab/InternVL-Chat-V1-1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use OpenGVLab/InternVL-Chat-V1-1 with Docker Model Runner:
docker model run hf.co/OpenGVLab/InternVL-Chat-V1-1
Update README.md
Browse files
README.md
CHANGED
|
@@ -43,10 +43,38 @@ It is _**the largest open-source vision/vision-language foundation model (14B)**
|
|
| 43 |
|
| 44 |
We will provide a minimum code example to run InternVL-Chat using only the `transformers` library.
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
```python
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
```
|
| 51 |
|
| 52 |
## Examples
|
|
|
|
| 43 |
|
| 44 |
We will provide a minimum code example to run InternVL-Chat using only the `transformers` library.
|
| 45 |
|
| 46 |
+
You also can use our [online demo](https://internvl.opengvlab.com/) for a quick experience of this model.
|
| 47 |
|
| 48 |
```python
|
| 49 |
+
import torch
|
| 50 |
+
from PIL import Image
|
| 51 |
+
from transformers import AutoModel, CLIPImageProcessor
|
| 52 |
+
from transformers import AutoTokenizer
|
| 53 |
+
|
| 54 |
+
path = "OpenGVLab/InternVL-Chat-Chinese-V1-1"
|
| 55 |
+
model = AutoModel.from_pretrained(
|
| 56 |
+
path,
|
| 57 |
+
torch_dtype=torch.bfloat16,
|
| 58 |
+
low_cpu_mem_usage=True,
|
| 59 |
+
trust_remote_code=True,
|
| 60 |
+
device_map='auto').eval()
|
| 61 |
+
|
| 62 |
+
tokenizer = AutoTokenizer.from_pretrained(path)
|
| 63 |
+
image = Image.open('./examples/image2.jpg').convert('RGB')
|
| 64 |
+
image = image.resize((448, 448))
|
| 65 |
+
image_processor = CLIPImageProcessor.from_pretrained(path)
|
| 66 |
+
|
| 67 |
+
pixel_values = image_processor(images=image, return_tensors='pt').pixel_values
|
| 68 |
+
pixel_values = pixel_values.to(torch.bfloat16).cuda()
|
| 69 |
+
|
| 70 |
+
generation_config = dict(
|
| 71 |
+
num_beams=1,
|
| 72 |
+
max_new_tokens=512,
|
| 73 |
+
do_sample=False,
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
question = "请详细描述图片"
|
| 77 |
+
response = model.chat(tokenizer, pixel_values, question, generation_config)
|
| 78 |
```
|
| 79 |
|
| 80 |
## Examples
|