unsubscribe
commited on
Commit
•
63fe63a
1
Parent(s):
17e5bd4
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,344 @@
|
|
1 |
-
---
|
2 |
-
license:
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: other
|
3 |
+
license_name: qwen
|
4 |
+
license_link: https://huggingface.co/Qwen/Qwen2.5-72B-Instruct/blob/main/LICENSE
|
5 |
+
pipeline_tag: image-text-to-text
|
6 |
+
library_name: transformers
|
7 |
+
base_model:
|
8 |
+
- OpenGVLab/InternViT-6B-448px-V2_5
|
9 |
+
- Qwen/Qwen2.5-72B-Instruct
|
10 |
+
base_model_relation: merge
|
11 |
+
language:
|
12 |
+
- multilingual
|
13 |
+
tags:
|
14 |
+
- internvl
|
15 |
+
- custom_code
|
16 |
+
---
|
17 |
+
|
18 |
+
# InternVL2_5-78B-AWQ
|
19 |
+
|
20 |
+
[\[📂 GitHub\]](https://github.com/OpenGVLab/InternVL) [\[📜 InternVL 1.0\]](https://huggingface.co/papers/2312.14238) [\[📜 InternVL 1.5\]](https://huggingface.co/papers/2404.16821) [\[📜 Mini-InternVL\]](https://arxiv.org/abs/2410.16261) [\[📜 InternVL 2.5\]](https://huggingface.co/papers/2412.05271)
|
21 |
+
|
22 |
+
[\[🆕 Blog\]](https://internvl.github.io/blog/) [\[🗨️ Chat Demo\]](https://internvl.opengvlab.com/) [\[🤗 HF Demo\]](https://huggingface.co/spaces/OpenGVLab/InternVL) [\[🚀 Quick Start\]](#quick-start) [\[📖 Documents\]](https://internvl.readthedocs.io/en/latest/)
|
23 |
+
|
24 |
+
<div align="center">
|
25 |
+
<img width="500" alt="image" src="https://cdn-uploads.huggingface.co/production/uploads/64006c09330a45b03605bba3/zJsd2hqd3EevgXo6fNgC-.png">
|
26 |
+
</div>
|
27 |
+
|
28 |
+
## Introduction
|
29 |
+
|
30 |
+
We are excited to introduce **InternVL 2.5**, an advanced multimodal large language model (MLLM) series that builds upon InternVL 2.0, maintaining its core model architecture while introducing significant enhancements in training and testing strategies as well as data quality.
|
31 |
+
|
32 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/5HDAGOQOZvS1EtI107Ac-.png)
|
33 |
+
|
34 |
+
## InternVL 2.5 Family
|
35 |
+
|
36 |
+
In the following table, we provide an overview of the InternVL 2.5 series.
|
37 |
+
|
38 |
+
| Model Name | Vision Part | Language Part | HF Link |
|
39 |
+
| :-------------: | :-------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------: | :---------------------------------------------------------: |
|
40 |
+
| InternVL2_5-1B | [InternViT-300M-448px-V2_5](https://huggingface.co/OpenGVLab/InternViT-300M-448px-V2_5) | [Qwen2.5-0.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct) | [🤗 link](https://huggingface.co/OpenGVLab/InternVL2_5-1B) |
|
41 |
+
| InternVL2_5-2B | [InternViT-300M-448px-V2_5](https://huggingface.co/OpenGVLab/InternViT-300M-448px-V2_5) | [internlm2_5-1_8b-chat](https://huggingface.co/internlm/internlm2_5-1_8b-chat) | [🤗 link](https://huggingface.co/OpenGVLab/InternVL2_5-2B) |
|
42 |
+
| InternVL2_5-4B | [InternViT-300M-448px-V2_5](https://huggingface.co/OpenGVLab/InternViT-300M-448px-V2_5) | [Qwen2.5-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-3B-Instruct) | [🤗 link](https://huggingface.co/OpenGVLab/InternVL2_5-4B) |
|
43 |
+
| InternVL2_5-8B | [InternViT-300M-448px-V2_5](https://huggingface.co/OpenGVLab/InternViT-300M-448px-V2_5) | [internlm2_5-7b-chat](https://huggingface.co/internlm/internlm2_5-7b-chat) | [🤗 link](https://huggingface.co/OpenGVLab/InternVL2_5-8B) |
|
44 |
+
| InternVL2_5-26B | [InternViT-6B-448px-V2_5](https://huggingface.co/OpenGVLab/InternViT-6B-448px-V2_5) | [internlm2_5-20b-chat](https://huggingface.co/internlm/internlm2_5-20b-chat) | [🤗 link](https://huggingface.co/OpenGVLab/InternVL2_5-26B) |
|
45 |
+
| InternVL2_5-38B | [InternViT-6B-448px-V2_5](https://huggingface.co/OpenGVLab/InternViT-6B-448px-V2_5) | [Qwen2.5-32B-Instruct](https://huggingface.co/Qwen/Qwen2.5-32B-Instruct) | [🤗 link](https://huggingface.co/OpenGVLab/InternVL2_5-38B) |
|
46 |
+
| InternVL2_5-78B | [InternViT-6B-448px-V2_5](https://huggingface.co/OpenGVLab/InternViT-6B-448px-V2_5) | [Qwen2.5-72B-Instruct](https://huggingface.co/Qwen/Qwen2.5-72B-Instruct) | [🤗 link](https://huggingface.co/OpenGVLab/InternVL2_5-78B) |
|
47 |
+
|
48 |
+
## Model Architecture
|
49 |
+
|
50 |
+
As shown in the following figure, InternVL 2.5 retains the same model architecture as its predecessors, InternVL 1.5 and 2.0, following the "ViT-MLP-LLM" paradigm. In this new version, we integrate a newly incrementally pre-trained InternViT with various pre-trained LLMs, including InternLM 2.5 and Qwen 2.5, using a randomly initialized MLP projector.
|
51 |
+
|
52 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/BiiyXN6NOk0p-3rl3ueyL.png)
|
53 |
+
|
54 |
+
As in the previous version, we applied a pixel unshuffle operation, reducing the number of visual tokens to one-quarter of the original. Besides, we adopted a similar dynamic resolution strategy as InternVL 1.5, dividing images into tiles of 448×448 pixels. The key difference, starting from InternVL 2.0, is that we additionally introduced support for multi-image and video data.
|
55 |
+
|
56 |
+
## Training Strategy
|
57 |
+
|
58 |
+
### Dynamic High-Resolution for Multimodal Data
|
59 |
+
|
60 |
+
In InternVL 2.0 and 2.5, we extend the dynamic high-resolution training approach, enhancing its capabilities to handle multi-image and video datasets.
|
61 |
+
|
62 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/xoMY6rwRrNxbAGYPNyU8g.png)
|
63 |
+
|
64 |
+
- For single-image datasets, the total number of tiles `n_max` are allocated to a single image for maximum resolution. Visual tokens are enclosed in `<img>` and `</img>` tags.
|
65 |
+
|
66 |
+
- For multi-image datasets, the total number of tiles `n_max` are distributed across all images in a sample. Each image is labeled with auxiliary tags like `Image-1` and enclosed in `<img>` and `</img>` tags.
|
67 |
+
|
68 |
+
- For videos, each frame is resized to 448×448. Frames are labeled with tags like `Frame-1` and enclosed in `<img>` and `</img>` tags, similar to images.
|
69 |
+
|
70 |
+
### Single Model Training Pipeline
|
71 |
+
|
72 |
+
The training pipeline for a single model in InternVL 2.5 is structured across three stages, designed to enhance the model's visual perception and multimodal capabilities.
|
73 |
+
|
74 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/5NduZeCPLgPJTFr0RGTq3.png)
|
75 |
+
|
76 |
+
- **Stage 1: MLP Warmup.** In this stage, only the MLP projector is trained while the vision encoder and language model are frozen. A dynamic high-resolution training strategy is applied for better performance, despite increased cost. This phase ensures robust cross-modal alignment and prepares the model for stable multimodal training.
|
77 |
+
|
78 |
+
- **Stage 1.5: ViT Incremental Learning (Optional).** This stage allows incremental training of the vision encoder and MLP projector using the same data as Stage 1. It enhances the encoder’s ability to handle rare domains like multilingual OCR and mathematical charts. Once trained, the encoder can be reused across LLMs without retraining, making this stage optional unless new domains are introduced.
|
79 |
+
|
80 |
+
- **Stage 2: Full Model Instruction Tuning.** The entire model is trained on high-quality multimodal instruction datasets. Strict data quality controls are enforced to prevent degradation of the LLM, as noisy data can cause issues like repetitive or incorrect outputs. After this stage, the training process is complete.
|
81 |
+
|
82 |
+
### Progressive Scaling Strategy
|
83 |
+
|
84 |
+
We introduce a progressive scaling strategy to align the vision encoder with LLMs efficiently. This approach trains with smaller LLMs first (e.g., 20B) to optimize foundational visual capabilities and cross-modal alignment before transferring the vision encoder to larger LLMs (e.g., 72B) without retraining. This reuse skips intermediate stages for larger models.
|
85 |
+
|
86 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/AVb_PSxhJq1z2eUFNYoqQ.png)
|
87 |
+
|
88 |
+
Compared to Qwen2-VL's 1.4 trillion tokens, InternVL2.5-78B uses only 120 billion tokens—less than one-tenth. This strategy minimizes redundancy, maximizes pre-trained component reuse, and enables efficient training for complex vision-language tasks.
|
89 |
+
|
90 |
+
### Training Enhancements
|
91 |
+
|
92 |
+
To improve real-world adaptability and performance, we introduce two key techniques:
|
93 |
+
|
94 |
+
- **Random JPEG Compression**: Random JPEG compression with quality levels between 75 and 100 is applied as a data augmentation technique. This simulates image degradation from internet sources, enhancing the model's robustness to noisy images.
|
95 |
+
|
96 |
+
- **Loss Reweighting**: To balance the NTP loss across responses of different lengths, we use a reweighting strategy called **square averaging**. This method balances contributions from responses of varying lengths, mitigating biases toward longer or shorter responses.
|
97 |
+
|
98 |
+
### Data Organization
|
99 |
+
|
100 |
+
#### Dataset Configuration
|
101 |
+
|
102 |
+
In InternVL 2.0 and 2.5, the organization of the training data is controlled by several key parameters to optimize the balance and distribution of datasets during training.
|
103 |
+
|
104 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/2LJe24b1ua3gjI9gDitVl.png)
|
105 |
+
|
106 |
+
- **Data Augmentation:** JPEG compression is applied conditionally: enabled for image datasets to enhance robustness and disabled for video datasets to maintain consistent frame quality.
|
107 |
+
|
108 |
+
- **Maximum Tile Number:** The parameter `n_max` controls the maximum tiles per dataset. For example, higher values (24–36) are used for multi-image or high-resolution data, lower values (6–12) for standard images, and 1 for videos.
|
109 |
+
|
110 |
+
- **Repeat Factor:** The repeat factor `r` adjusts dataset sampling frequency. Values below 1 reduce a dataset's weight, while values above 1 increase it. This ensures balanced training across tasks and prevents overfitting or underfitting.
|
111 |
+
|
112 |
+
#### Data Filtering Pipeline
|
113 |
+
|
114 |
+
During development, we found that LLMs are highly sensitive to data noise, with even small anomalies—like outliers or repetitive data—causing abnormal behavior during inference. Repetitive generation, especially in long-form or CoT reasoning tasks, proved particularly harmful.
|
115 |
+
|
116 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/aka8ZRiKF3ajdyZBnNFZI.png)
|
117 |
+
|
118 |
+
To address this challenge and support future research, we designed an efficient data filtering pipeline to remove low-quality samples.
|
119 |
+
|
120 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/70l1UxnX-Arn0NoOGwpth.png)
|
121 |
+
|
122 |
+
The pipeline includes two modules, for **pure-text data**, three key strategies are used:
|
123 |
+
|
124 |
+
1. **LLM-Based Quality Scoring**: Each sample is scored (0–10) using a pre-trained LLM with domain-specific prompts. Samples scoring below a threshold (e.g., 7) are removed to ensure high-quality data.
|
125 |
+
2. **Repetition Detection**: Repetitive samples are flagged using LLM-based prompts and manually reviewed. Samples scoring below a stricter threshold (e.g., 3) are excluded to avoid repetitive patterns.
|
126 |
+
3. **Heuristic Rule-Based Filtering**: Anomalies like abnormal sentence lengths or duplicate lines are detected using rules. Flagged samples undergo manual verification to ensure accuracy before removal.
|
127 |
+
|
128 |
+
For **multimodal data**, two strategies are used:
|
129 |
+
|
130 |
+
1. **Repetition Detection**: Repetitive samples in non-academic datasets are flagged and manually reviewed to prevent pattern loops. High-quality datasets are exempt from this process.
|
131 |
+
2. **Heuristic Rule-Based Filtering**: Similar rules are applied to detect visual anomalies, with flagged data verified manually to maintain integrity.
|
132 |
+
|
133 |
+
#### Training Data
|
134 |
+
|
135 |
+
As shown in the following figure, from InternVL 1.5 to 2.0 and then to 2.5, the fine-tuning data mixture has undergone iterative improvements in scale, quality, and diversity. For more information about the training data, please refer to our technical report.
|
136 |
+
|
137 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/GaTY9Lde02YzclASMthDa.png)
|
138 |
+
|
139 |
+
## Evaluation on Multimodal Capability
|
140 |
+
|
141 |
+
### Multimodal Reasoning and Mathematics
|
142 |
+
|
143 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/ihFWMRHbF0lpFTkLqnnj1.png)
|
144 |
+
|
145 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/Nrzq0kjlitjp_jrJCqtwX.png)
|
146 |
+
|
147 |
+
### OCR, Chart, and Document Understanding
|
148 |
+
|
149 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/3yCMoLjlbsqY7ZJViGzih.png)
|
150 |
+
|
151 |
+
### Multi-Image & Real-World Comprehension
|
152 |
+
|
153 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/DSnalmEyhDVQ9GE0GPCla.png)
|
154 |
+
|
155 |
+
### Comprehensive Multimodal & Hallucination Evaluation
|
156 |
+
|
157 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/Z7Raj3TGDiV1H81pDHtoG.png)
|
158 |
+
|
159 |
+
### Visual Grounding
|
160 |
+
|
161 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/lPcIrng8MPSg_PM1hpDPt.png)
|
162 |
+
|
163 |
+
### Multimodal Multilingual Understanding
|
164 |
+
|
165 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/BPpbAOX36RV8RTnm3j-gs.png)
|
166 |
+
|
167 |
+
### Video Understanding
|
168 |
+
|
169 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/uD5aYt2wNYL94Xn8MOVih.png)
|
170 |
+
|
171 |
+
## Evaluation on Language Capability
|
172 |
+
|
173 |
+
Training InternVL 2.0 models led to a decline in pure language capabilities. InternVL 2.5 addresses this by collecting more high-quality open-source data and filtering out low-quality data, achieving better preservation of pure language performance.
|
174 |
+
|
175 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/mxuSKvSY-kfI8zePpXj6y.png)
|
176 |
+
|
177 |
+
## Deployment
|
178 |
+
|
179 |
+
### LMDeploy
|
180 |
+
|
181 |
+
LMDeploy is a toolkit for compressing, deploying, and serving LLM, developed by the MMRazor and MMDeploy teams.
|
182 |
+
|
183 |
+
```sh
|
184 |
+
pip install lmdeploy>=0.5.3
|
185 |
+
```
|
186 |
+
|
187 |
+
LMDeploy abstracts the complex inference process of multi-modal Vision-Language Models (VLM) into an easy-to-use pipeline, similar to the Large Language Model (LLM) inference pipeline.
|
188 |
+
|
189 |
+
#### A 'Hello, world' Example
|
190 |
+
|
191 |
+
```python
|
192 |
+
from lmdeploy import pipeline, TurbomindEngineConfig
|
193 |
+
from lmdeploy.vl import load_image
|
194 |
+
|
195 |
+
model = 'OpenGVLab/InternVL2_5-78B-AWQ'
|
196 |
+
image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
|
197 |
+
pipe = pipeline(model, backend_config=TurbomindEngineConfig(session_len=8192, tp=4))
|
198 |
+
response = pipe(('describe this image', image))
|
199 |
+
print(response.text)
|
200 |
+
```
|
201 |
+
|
202 |
+
If `ImportError` occurs while executing this case, please install the required dependency packages as prompted.
|
203 |
+
|
204 |
+
#### Multi-images Inference
|
205 |
+
|
206 |
+
When dealing with multiple images, you can put them all in one list. Keep in mind that multiple images will lead to a higher number of input tokens, and as a result, the size of the context window typically needs to be increased.
|
207 |
+
|
208 |
+
question = 'Describe this video in detail.'
|
209 |
+
|
210 |
+
```python
|
211 |
+
from lmdeploy import pipeline, TurbomindEngineConfig
|
212 |
+
from lmdeploy.vl import load_image
|
213 |
+
from lmdeploy.vl.constants import IMAGE_TOKEN
|
214 |
+
|
215 |
+
model = 'OpenGVLab/InternVL2_5-78B-AWQ'
|
216 |
+
pipe = pipeline(model, backend_config=TurbomindEngineConfig(session_len=8192, tp=4))
|
217 |
+
|
218 |
+
image_urls=[
|
219 |
+
'https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg',
|
220 |
+
'https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/det.jpg'
|
221 |
+
]
|
222 |
+
|
223 |
+
images = [load_image(img_url) for img_url in image_urls]
|
224 |
+
# Numbering images improves multi-image conversations
|
225 |
+
response = pipe((f'Image-1: {IMAGE_TOKEN}\nImage-2: {IMAGE_TOKEN}\ndescribe these two images', images))
|
226 |
+
print(response.text)
|
227 |
+
```
|
228 |
+
|
229 |
+
#### Batch Prompts Inference
|
230 |
+
|
231 |
+
Conducting inference with batch prompts is quite straightforward; just place them within a list structure:
|
232 |
+
|
233 |
+
```python
|
234 |
+
from lmdeploy import pipeline, TurbomindEngineConfig
|
235 |
+
from lmdeploy.vl import load_image
|
236 |
+
|
237 |
+
model = 'OpenGVLab/InternVL2_5-78B-AWQ'
|
238 |
+
pipe = pipeline(model, backend_config=TurbomindEngineConfig(session_len=8192, tp=4))
|
239 |
+
|
240 |
+
image_urls=[
|
241 |
+
"https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg",
|
242 |
+
"https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/det.jpg"
|
243 |
+
]
|
244 |
+
prompts = [('describe this image', load_image(img_url)) for img_url in image_urls]
|
245 |
+
response = pipe(prompts)
|
246 |
+
print(response)
|
247 |
+
```
|
248 |
+
|
249 |
+
#### Multi-turn Conversation
|
250 |
+
|
251 |
+
There are two ways to do the multi-turn conversations with the pipeline. One is to construct messages according to the format of OpenAI and use above introduced method, the other is to use the `pipeline.chat` interface.
|
252 |
+
|
253 |
+
```python
|
254 |
+
from lmdeploy import pipeline, TurbomindEngineConfig, GenerationConfig
|
255 |
+
from lmdeploy.vl import load_image
|
256 |
+
|
257 |
+
model = 'OpenGVLab/InternVL2_5-78B-AWQ'
|
258 |
+
pipe = pipeline(model, backend_config=TurbomindEngineConfig(session_len=8192, tp=4))
|
259 |
+
|
260 |
+
image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg')
|
261 |
+
gen_config = GenerationConfig(top_k=40, top_p=0.8, temperature=0.8)
|
262 |
+
sess = pipe.chat(('describe this image', image), gen_config=gen_config)
|
263 |
+
print(sess.response.text)
|
264 |
+
sess = pipe.chat('What is the woman doing?', session=sess, gen_config=gen_config)
|
265 |
+
print(sess.response.text)
|
266 |
+
```
|
267 |
+
|
268 |
+
#### Service
|
269 |
+
|
270 |
+
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:
|
271 |
+
|
272 |
+
```shell
|
273 |
+
lmdeploy serve api_server OpenGVLab/InternVL2_5-78B-AWQ --backend turbomind --server-port 23333 --tp 4
|
274 |
+
```
|
275 |
+
|
276 |
+
To use the OpenAI-style interface, you need to install OpenAI:
|
277 |
+
|
278 |
+
```shell
|
279 |
+
pip install openai
|
280 |
+
```
|
281 |
+
|
282 |
+
Then, use the code below to make the API call:
|
283 |
+
|
284 |
+
```python
|
285 |
+
from openai import OpenAI
|
286 |
+
|
287 |
+
client = OpenAI(api_key='YOUR_API_KEY', base_url='http://0.0.0.0:23333/v1')
|
288 |
+
model_name = client.models.list().data[0].id
|
289 |
+
response = client.chat.completions.create(
|
290 |
+
model=model_name,
|
291 |
+
messages=[{
|
292 |
+
'role':
|
293 |
+
'user',
|
294 |
+
'content': [{
|
295 |
+
'type': 'text',
|
296 |
+
'text': 'describe this image',
|
297 |
+
}, {
|
298 |
+
'type': 'image_url',
|
299 |
+
'image_url': {
|
300 |
+
'url':
|
301 |
+
'https://modelscope.oss-cn-beijing.aliyuncs.com/resource/tiger.jpeg',
|
302 |
+
},
|
303 |
+
}],
|
304 |
+
}],
|
305 |
+
temperature=0.8,
|
306 |
+
top_p=0.8)
|
307 |
+
print(response)
|
308 |
+
```
|
309 |
+
|
310 |
+
## License
|
311 |
+
|
312 |
+
This project is released under the MIT License. This project uses the pre-trained Qwen2.5-72B-Instruct as a component, which is licensed under the Qwen License.
|
313 |
+
|
314 |
+
## Citation
|
315 |
+
|
316 |
+
If you find this project useful in your research, please consider citing:
|
317 |
+
|
318 |
+
```BibTeX
|
319 |
+
@article{chen2024expanding,
|
320 |
+
title={Expanding Performance Boundaries of Open-Source Multimodal Models with Model, Data, and Test-Time Scaling},
|
321 |
+
author={Chen, Zhe and Wang, Weiyun and Cao, Yue and Liu, Yangzhou and Gao, Zhangwei and Cui, Erfei and Zhu, Jinguo and Ye, Shenglong and Tian, Hao and Liu, Zhaoyang and others},
|
322 |
+
journal={arXiv preprint arXiv:2412.05271},
|
323 |
+
year={2024}
|
324 |
+
}
|
325 |
+
@article{gao2024mini,
|
326 |
+
title={Mini-internvl: A flexible-transfer pocket multimodal model with 5\% parameters and 90\% performance},
|
327 |
+
author={Gao, Zhangwei and Chen, Zhe and Cui, Erfei and Ren, Yiming and Wang, Weiyun and Zhu, Jinguo and Tian, Hao and Ye, Shenglong and He, Junjun and Zhu, Xizhou and others},
|
328 |
+
journal={arXiv preprint arXiv:2410.16261},
|
329 |
+
year={2024}
|
330 |
+
}
|
331 |
+
@article{chen2024far,
|
332 |
+
title={How Far Are We to GPT-4V? Closing the Gap to Commercial Multimodal Models with Open-Source Suites},
|
333 |
+
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},
|
334 |
+
journal={arXiv preprint arXiv:2404.16821},
|
335 |
+
year={2024}
|
336 |
+
}
|
337 |
+
@inproceedings{chen2024internvl,
|
338 |
+
title={Internvl: Scaling up vision foundation models and aligning for generic visual-linguistic tasks},
|
339 |
+
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 others},
|
340 |
+
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
|
341 |
+
pages={24185--24198},
|
342 |
+
year={2024}
|
343 |
+
}
|
344 |
+
```
|