Weiyun1025 commited on
Commit
2301c7e
·
verified ·
1 Parent(s): bb54d86

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +758 -279
README.md CHANGED
@@ -1,353 +1,832 @@
1
  ---
2
- library_name: transformers
3
  license: apache-2.0
4
- license_link: https://huggingface.co/Qwen/Qwen3-235B-A22B/blob/main/LICENSE
5
- pipeline_tag: text-generation
 
 
 
 
 
 
 
 
 
 
6
  ---
7
 
8
- # Qwen3-235B-A22B
9
- <a href="https://chat.qwen.ai/" target="_blank" style="margin: 2px;">
10
- <img alt="Chat" src="https://img.shields.io/badge/%F0%9F%92%9C%EF%B8%8F%20Qwen%20Chat%20-536af5" style="display: inline-block; vertical-align: middle;"/>
11
- </a>
12
 
13
- ## Qwen3 Highlights
14
 
15
- Qwen3 is the latest generation of large language models in Qwen series, offering a comprehensive suite of dense and mixture-of-experts (MoE) models. Built upon extensive training, Qwen3 delivers groundbreaking advancements in reasoning, instruction-following, agent capabilities, and multilingual support, with the following key features:
16
 
17
- - **Uniquely support of seamless switching between thinking mode** (for complex logical reasoning, math, and coding) and **non-thinking mode** (for efficient, general-purpose dialogue) **within single model**, ensuring optimal performance across various scenarios.
18
- - **Significantly enhancement in its reasoning capabilities**, surpassing previous QwQ (in thinking mode) and Qwen2.5 instruct models (in non-thinking mode) on mathematics, code generation, and commonsense logical reasoning.
19
- - **Superior human preference alignment**, excelling in creative writing, role-playing, multi-turn dialogues, and instruction following, to deliver a more natural, engaging, and immersive conversational experience.
20
- - **Expertise in agent capabilities**, enabling precise integration with external tools in both thinking and unthinking modes and achieving leading performance among open-source models in complex agent-based tasks.
21
- - **Support of 100+ languages and dialects** with strong capabilities for **multilingual instruction following** and **translation**.
22
 
23
- ## Model Overview
24
 
25
- **Qwen3-235B-A22B** has the following features:
26
- - Type: Causal Language Models
27
- - Training Stage: Pretraining & Post-training
28
- - Number of Parameters: 235B in total and 22B activated
29
- - Number of Paramaters (Non-Embedding): 234B
30
- - Number of Layers: 94
31
- - Number of Attention Heads (GQA): 64 for Q and 4 for KV
32
- - Number of Experts: 128
33
- - Number of Activated Experts: 8
34
- - Context Length: 32,768 natively and [131,072 tokens with YaRN](#processing-long-texts).
35
 
36
- For more details, including benchmark evaluation, hardware requirements, and inference performance, please refer to our [blog](https://qwenlm.github.io/blog/qwen3/), [GitHub](https://github.com/QwenLM/Qwen3), and [Documentation](https://qwen.readthedocs.io/en/latest/).
37
 
38
- ## Quickstart
39
 
40
- The code of Qwen3-MoE has been in the latest Hugging Face `transformers` and we advise you to use the latest version of `transformers`.
41
 
42
- With `transformers<4.51.0`, you will encounter the following error:
43
- ```
44
- KeyError: 'qwen3_moe'
45
- ```
46
 
47
- The following contains a code snippet illustrating how to use the model generate content based on given inputs.
48
- ```python
49
- from transformers import AutoModelForCausalLM, AutoTokenizer
50
-
51
- model_name = "Qwen/Qwen3-235B-A22B"
52
-
53
- # load the tokenizer and the model
54
- tokenizer = AutoTokenizer.from_pretrained(model_name)
55
- model = AutoModelForCausalLM.from_pretrained(
56
- model_name,
57
- torch_dtype="auto",
58
- device_map="auto"
59
- )
60
-
61
- # prepare the model input
62
- prompt = "Give me a short introduction to large language model."
63
- messages = [
64
- {"role": "user", "content": prompt}
65
- ]
66
- text = tokenizer.apply_chat_template(
67
- messages,
68
- tokenize=False,
69
- add_generation_prompt=True,
70
- enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
71
- )
72
- model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
73
-
74
- # conduct text completion
75
- generated_ids = model.generate(
76
- **model_inputs,
77
- max_new_tokens=32768
78
- )
79
- output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
80
-
81
- # parsing thinking content
82
- try:
83
- # rindex finding 151668 (</think>)
84
- index = len(output_ids) - output_ids[::-1].index(151668)
85
- except ValueError:
86
- index = 0
87
-
88
- thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
89
- content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
90
-
91
- print("thinking content:", thinking_content)
92
- print("content:", content)
93
- ```
94
 
95
- For deployment, you can use `sglang>=0.4.6.post1` or `vllm>=0.8.5` or to create an OpenAI-compatible API endpoint:
96
- - SGLang:
97
- ```shell
98
- python -m sglang.launch_server --model-path Qwen/Qwen3-235B-A22B --reasoning-parser qwen3 --tp 8
99
- ```
100
- - vLLM:
101
- ```shell
102
- vllm serve Qwen/Qwen3-235B-A22B --enable-reasoning --reasoning-parser deepseek_r1
103
- ```
104
 
105
- For local use, applications such as Ollama, LMStudio, MLX-LM, llama.cpp, and KTransformers have also supported Qwen3.
106
 
107
- ## Switching Between Thinking and Non-Thinking Mode
 
 
 
 
 
 
 
 
 
 
108
 
109
- > [!TIP]
110
- > The `enable_thinking` switch is also available in APIs created by SGLang and vLLM.
111
- > Please refer to our documentation for [SGLang](https://qwen.readthedocs.io/en/latest/deployment/sglang.html#thinking-non-thinking-modes) and [vLLM](https://qwen.readthedocs.io/en/latest/deployment/vllm.html#thinking-non-thinking-modes) users.
112
 
113
- ### `enable_thinking=True`
114
 
115
- By default, Qwen3 has thinking capabilities enabled, similar to QwQ-32B. This means the model will use its reasoning abilities to enhance the quality of generated responses. For example, when explicitly setting `enable_thinking=True` or leaving it as the default value in `tokenizer.apply_chat_template`, the model will engage its thinking mode.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
- ```python
118
- text = tokenizer.apply_chat_template(
119
- messages,
120
- tokenize=False,
121
- add_generation_prompt=True,
122
- enable_thinking=True # True is the default value for enable_thinking
123
- )
124
- ```
125
 
126
- In this mode, the model will generate think content wrapped in a `<think>...</think>` block, followed by the final response.
127
 
128
- > [!NOTE]
129
- > For thinking mode, use `Temperature=0.6`, `TopP=0.95`, `TopK=20`, and `MinP=0` (the default setting in `generation_config.json`). **DO NOT use greedy decoding**, as it can lead to performance degradation and endless repetitions. For more detailed guidance, please refer to the [Best Practices](#best-practices) section.
130
 
 
131
 
132
- ### `enable_thinking=False`
133
 
134
- We provide a hard switch to strictly disable the model's thinking behavior, aligning its functionality with the previous Qwen2.5-Instruct models. This mode is particularly useful in scenarios where disabling thinking is essential for enhancing efficiency.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
  ```python
137
- text = tokenizer.apply_chat_template(
138
- messages,
139
- tokenize=False,
140
- add_generation_prompt=True,
141
- enable_thinking=False # Setting enable_thinking=False disables thinking mode
142
- )
 
 
 
143
  ```
144
 
145
- In this mode, the model will not generate any think content and will not include a `<think>...</think>` block.
146
 
147
- > [!NOTE]
148
- > For non-thinking mode, we suggest using `Temperature=0.7`, `TopP=0.8`, `TopK=20`, and `MinP=0`. For more detailed guidance, please refer to the [Best Practices](#best-practices) section.
 
 
 
 
 
 
 
 
 
 
149
 
150
- ### Advanced Usage: Switching Between Thinking and Non-Thinking Modes via User Input
151
 
152
- We provide a soft switch mechanism that allows users to dynamically control the model's behavior when `enable_thinking=True`. Specifically, you can add `/think` and `/no_think` to user prompts or system messages to switch the model's thinking mode from turn to turn. The model will follow the most recent instruction in multi-turn conversations.
 
 
 
 
 
 
 
 
 
 
 
 
 
153
 
154
- Here is an example of a multi-turn conversation:
 
 
155
 
156
  ```python
157
- from transformers import AutoModelForCausalLM, AutoTokenizer
 
 
 
158
 
159
- class QwenChatbot:
160
- def __init__(self, model_name="Qwen/Qwen3-235B-A22B"):
161
- self.tokenizer = AutoTokenizer.from_pretrained(model_name)
162
- self.model = AutoModelForCausalLM.from_pretrained(model_name)
163
- self.history = []
164
 
165
- def generate_response(self, user_input):
166
- messages = self.history + [{"role": "user", "content": user_input}]
167
 
168
- text = self.tokenizer.apply_chat_template(
169
- messages,
170
- tokenize=False,
171
- add_generation_prompt=True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
- inputs = self.tokenizer(text, return_tensors="pt")
175
- response_ids = self.model.generate(**inputs, max_new_tokens=32768)[0][len(inputs.input_ids[0]):].tolist()
176
- response = self.tokenizer.decode(response_ids, skip_special_tokens=True)
177
-
178
- # Update history
179
- self.history.append({"role": "user", "content": user_input})
180
- self.history.append({"role": "assistant", "content": response})
181
-
182
- return response
183
-
184
- # Example Usage
185
- if __name__ == "__main__":
186
- chatbot = QwenChatbot()
187
-
188
- # First input (without /think or /no_think tags, thinking mode is enabled by default)
189
- user_input_1 = "How many r's in strawberries?"
190
- print(f"User: {user_input_1}")
191
- response_1 = chatbot.generate_response(user_input_1)
192
- print(f"Bot: {response_1}")
193
- print("----------------------")
194
-
195
- # Second input with /no_think
196
- user_input_2 = "Then, how many r's in blueberries? /no_think"
197
- print(f"User: {user_input_2}")
198
- response_2 = chatbot.generate_response(user_input_2)
199
- print(f"Bot: {response_2}")
200
- print("----------------------")
201
-
202
- # Third input with /think
203
- user_input_3 = "Really? /think"
204
- print(f"User: {user_input_3}")
205
- response_3 = chatbot.generate_response(user_input_3)
206
- print(f"Bot: {response_3}")
207
  ```
208
 
209
- > [!NOTE]
210
- > For API compatibility, when `enable_thinking=True`, regardless of whether the user uses `/think` or `/no_think`, the model will always output a block wrapped in `<think>...</think>`. However, the content inside this block may be empty if thinking is disabled.
211
- > When `enable_thinking=False`, the soft switches are not valid. Regardless of any `/think` or `/no_think` tags input by the user, the model will not generate think content and will not include a `<think>...</think>` block.
 
 
212
 
213
- ## Agentic Use
214
 
215
- Qwen3 excels in tool calling capabilities. We recommend using [Qwen-Agent](https://github.com/QwenLM/Qwen-Agent) to make the best use of agentic ability of Qwen3. Qwen-Agent encapsulates tool-calling templates and tool-calling parsers internally, greatly reducing coding complexity.
 
 
 
 
 
 
 
 
216
 
217
- To define the available tools, you can use the MCP configuration file, use the integrated tool of Qwen-Agent, or integrate other tools by yourself.
218
  ```python
219
- from qwen_agent.agents import Assistant
220
-
221
- # Define LLM
222
- llm_cfg = {
223
- 'model': 'Qwen3-235B-A22B',
224
-
225
- # Use the endpoint provided by Alibaba Model Studio:
226
- # 'model_type': 'qwen_dashscope',
227
- # 'api_key': os.getenv('DASHSCOPE_API_KEY'),
228
-
229
- # Use a custom endpoint compatible with OpenAI API:
230
- 'model_server': 'http://localhost:8000/v1', # api_base
231
- 'api_key': 'EMPTY',
232
-
233
- # Other parameters:
234
- # 'generate_cfg': {
235
- # # Add: When the response content is `<think>this is the thought</think>this is the answer;
236
- # # Do not add: When the response has been separated by reasoning_content and content.
237
- # 'thought_in_content': True,
238
- # },
239
- }
240
 
241
- # Define Tools
242
- tools = [
243
- {'mcpServers': { # You can specify the MCP configuration file
244
- 'time': {
245
- 'command': 'uvx',
246
- 'args': ['mcp-server-time', '--local-timezone=Asia/Shanghai']
247
- },
248
- "fetch": {
249
- "command": "uvx",
250
- "args": ["mcp-server-fetch"]
251
- }
252
- }
253
- },
254
- 'code_interpreter', # Built-in tools
255
- ]
256
 
257
- # Define Agent
258
- bot = Assistant(llm=llm_cfg, function_list=tools)
 
259
 
260
- # Streaming generation
261
- messages = [{'role': 'user', 'content': 'https://qwenlm.github.io/blog/ Introduce the latest developments of Qwen'}]
262
- for responses in bot.run(messages=messages):
263
- pass
264
- print(responses)
265
  ```
266
 
267
- ## Processing Long Texts
268
 
269
- Qwen3 natively supports context lengths of up to 32,768 tokens. For conversations where the total length (including both input and output) significantly exceeds this limit, we recommend using RoPE scaling techniques to handle long texts effectively. We have validated the model's performance on context lengths of up to 131,072 tokens using the [YaRN](https://arxiv.org/abs/2309.00071) method.
270
 
271
- YaRN is currently supported by several inference frameworks, e.g., `transformers` and `llama.cpp` for local use, `vllm` and `sglang` for deployment. In general, there are two approaches to enabling YaRN for supported frameworks:
 
 
 
272
 
273
- - Modifying the model files:
274
- In the `config.json` file, add the `rope_scaling` fields:
275
- ```json
276
- {
277
- ...,
278
- "rope_scaling": {
279
- "rope_type": "yarn",
280
- "factor": 4.0,
281
- "original_max_position_embeddings": 32768
282
- }
283
- }
284
- ```
285
- For `llama.cpp`, you need to regenerate the GGUF file after the modification.
286
 
287
- - Passing command line arguments:
 
 
 
288
 
289
- For `vllm`, you can use
290
- ```shell
291
- vllm serve ... --rope-scaling '{"rope_type":"yarn","factor":4.0,"original_max_position_embeddings":32768}' --max-model-len 131072
292
- ```
 
293
 
294
- For `sglang`, you can use
295
- ```shell
296
- python -m sglang.launch_server ... --json-model-override-args '{"rope_scaling":{"rope_type":"yarn","factor":4.0,"original_max_position_embeddings":32768}}'
297
- ```
298
 
299
- For `llama-server` from `llama.cpp`, you can use
300
- ```shell
301
- llama-server ... --rope-scaling yarn --rope-scale 4 --yarn-orig-ctx 32768
302
- ```
303
 
304
- > [!IMPORTANT]
305
- > If you encounter the following warning
306
- > ```
307
- > Unrecognized keys in `rope_scaling` for 'rope_type'='yarn': {'original_max_position_embeddings'}
308
- > ```
309
- > please upgrade `transformers>=4.51.0`.
310
 
311
- > [!NOTE]
312
- > All the notable open-source frameworks implement static YaRN, which means the scaling factor remains constant regardless of input length, **potentially impacting performance on shorter texts.**
313
- > We advise adding the `rope_scaling` configuration only when processing long contexts is required.
314
- > It is also recommended to modify the `factor` as needed. For example, if the typical context length for your application is 65,536 tokens, it would be better to set `factor` as 2.0.
315
 
316
- > [!NOTE]
317
- > The default `max_position_embeddings` in `config.json` is set to 40,960. This allocation includes reserving 32,768 tokens for outputs and 8,192 tokens for typical prompts, which is sufficient for most scenarios involving short text processing. If the average context length does not exceed 32,768 tokens, we do not recommend enabling YaRN in this scenario, as it may potentially degrade model performance.
 
 
 
 
 
 
318
 
319
- > [!TIP]
320
- > The endpoint provided by Alibaba Model Studio supports dynamic YaRN by default and no extra configuration is needed.
321
 
322
- ## Best Practices
323
 
324
- To achieve optimal performance, we recommend the following settings:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
 
326
- 1. **Sampling Parameters**:
327
- - For thinking mode (`enable_thinking=True`), use `Temperature=0.6`, `TopP=0.95`, `TopK=20`, and `MinP=0`. **DO NOT use greedy decoding**, as it can lead to performance degradation and endless repetitions.
328
- - For non-thinking mode (`enable_thinking=False`), we suggest using `Temperature=0.7`, `TopP=0.8`, `TopK=20`, and `MinP=0`.
329
- - For supported frameworks, you can adjust the `presence_penalty` parameter between 0 and 2 to reduce endless repetitions. However, using a higher value may occasionally result in language mixing and a slight decrease in model performance.
330
 
331
- 2. **Adequate Output Length**: We recommend using an output length of 32,768 tokens for most queries. For benchmarking on highly complex problems, such as those found in math and programming competitions, we suggest setting the max output length to 38,912 tokens. This provides the model with sufficient space to generate detailed and comprehensive responses, thereby enhancing its overall performance.
332
 
333
- 3. **Standardize Output Format**: We recommend using prompts to standardize model outputs when benchmarking.
334
- - **Math Problems**: Include "Please reason step by step, and put your final answer within \boxed{}." in the prompt.
335
- - **Multiple-Choice Questions**: Add the following JSON structure to the prompt to standardize responses: "Please show your choice in the `answer` field with only the choice letter, e.g., `"answer": "C"`."
336
 
337
- 4. **No Thinking Content in History**: In multi-turn conversations, the historical model output should only include the final output part and does not need to include the thinking content. It is implemented in the provided chat template in Jinja2. However, for frameworks that do not directly use the Jinja2 chat template, it is up to the developers to ensure that the best practice is followed.
338
 
339
- ### Citation
 
 
340
 
341
- If you find our work helpful, feel free to give us a cite.
342
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
343
  ```
344
- @misc{qwen3technicalreport,
345
- title={Qwen3 Technical Report},
346
- author={Qwen Team},
347
- year={2025},
348
- eprint={2505.09388},
349
- archivePrefix={arXiv},
350
- primaryClass={cs.CL},
351
- url={https://arxiv.org/abs/2505.09388},
 
 
 
 
 
 
 
352
  }
353
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
 
2
  license: apache-2.0
3
+ pipeline_tag: image-text-to-text
4
+ library_name: transformers
5
+ base_model:
6
+ - OpenGVLab/InternVL3_5-241B-A28B-Pretrained
7
+ base_model_relation: finetune
8
+ datasets:
9
+ - OpenGVLab/MMPR-v1.2
10
+ language:
11
+ - multilingual
12
+ tags:
13
+ - internvl
14
+ - custom_code
15
  ---
16
 
17
+ # InternVL3_5-241B-A28B-Instruct
 
 
 
18
 
19
+ [\[📂 GitHub\]](https://github.com/OpenGVLab/InternVL) [\[📜 InternVL 1.0\]](https://huggingface.co/papers/2312.14238) [\[📜 InternVL 1.5\]](https://huggingface.co/papers/2404.16821) [\[📜 InternVL 2.5\]](https://huggingface.co/papers/2412.05271) [\[📜 InternVL2.5-MPO\]](https://huggingface.co/papers/2411.10442) [\[📜 InternVL3\]](https://huggingface.co/papers/2504.10479) [\[📜 InternVL3.5\]](TBD)
20
 
21
+ [\[🆕 Blog\]](https://internvl.github.io/blog/) [\[🗨️ Chat Demo\]](https://chat.intern-ai.org.cn/) [\[🚀 Quick Start\]](#quick-start) [\[📖 Documents\]](https://internvl.readthedocs.io/en/latest/)
22
 
23
+ <div align="center">
24
+ <img width="500" alt="image" src="https://cdn-uploads.huggingface.co/production/uploads/64006c09330a45b03605bba3/zJsd2hqd3EevgXo6fNgC-.png">
25
+ </div>
 
 
26
 
27
+ ## Introduction
28
 
29
+ We introduce *InternVL3.5*, a new family of open-source multimodal models with a significant improvement in versatility, reasoning, and efficiency. InternVL3.5 is equipped with strong reasoning ability via a scalable reinforcement learning framework, termed *Cascade Reinforcement Learning (Cascade RL)*. Through an offline RL phase for efficient convergence and an online RL stage for distribution refinement, Cascade RL efficiently realizes a coarse-to-fine RL process and achieves significant gains for downstream reasoning tasks. To further improve inference efficiency, we introduce a *Visual Resolution Router (ViR)* that dynamically selects the trade-off resolution of visual tokens for MLLMs while maintaining original performance. Combining with ViR, the *Decoupled Vision-Language Deployment (DvD)* is adopted to deploy the vision encoder and the language model on separate GPUs to balance computational load.
30
+ Benefiting from these innovations, InternVL3.5 achieves up to +18.3\% improvement in overall reasoning performance and 4.05 \\(\times\\) speedup in inference efficiency compared to its predecessor (i.e., InternVL3). In addition to these improvements, we have infused InternVL3.5 with a variety of new capabilities including GUI agent, embodied agent, etc.
31
+ Specifically, InternVL3.5-241B-A28B achieves the highest overall score on multimodal general, reasoning, text, and agency tasks among leading open source MLLMs, and narrows the gap with top commercial models such as GPT-5.
 
 
 
 
 
 
 
32
 
33
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/performance.jpg)
34
 
35
+ > Hatched bars represent closed-source commercial models. We report average scores on a set of multimodal general, reasoning, text, and agentic benchmarks: MMBench v1.1 (en), MMStar,BLINK, HallusionBench, AI2D, OCRBench, MMVet, MME-RealWorld (en), MVBench, VideoMME, MMMU, MathVista, MathVision, MathVerse, DynaMath, WeMath, LogicVista, MATH500, AIME24, AIME25, GPQA, MMLU-Pro, GAOKAO, IFEval, SGP-Bench, VSI-Bench, ERQA, SpaCE-10, and OmniSpatial.
36
 
37
+ See [quick start](#quick-start) for how to use our model.
38
 
39
+ ## InternVL3.5 Family
 
 
 
40
 
41
+ In the following table, we provide an overview of the InternVL3.5 series.
42
+ To maintain consistency with earlier generations, we provide two model formats: [the GitHub format](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B), consistent with prior releases, and [the HF format](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B-HF), aligned with the official Transformers standard.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
+ > If you want to convert the checkpoint between these two formats, please refer to the scripts about [custom2hf](https://github.com/OpenGVLab/InternVL/blob/main/internvl_chat/tools/internvl_custom2hf.py) and [hf2custom](https://github.com/OpenGVLab/InternVL/blob/main/internvl_chat/tools/internvl_hf2custom.py).
 
 
 
 
 
 
 
 
45
 
 
46
 
47
+ | Model | #Vision Param | #Language Param | #Total Param | HF Link | ModelScope Link |
48
+ | --------------------- | ------------- | --------------- | ------------ | ------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------- |
49
+ | InternVL3.5-1B | 0.3B | 0.8B | 1.1B | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-1B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-1B) |
50
+ | InternVL3.5-2B | 0.3B | 2.0B | 2.3B | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-2B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-2B) |
51
+ | InternVL3.5-4B | 0.3B | 4.4B | 4.7B | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-4B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-4B) |
52
+ | InternVL3.5-8B | 0.3B | 8.2B | 8.5B | [��� link](https://huggingface.co/OpenGVLab/InternVL3_5-8B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-8B) |
53
+ | InternVL3.5-14B | 0.3B | 14.8B | 15.1B | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-14B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-14B) |
54
+ | InternVL3.5-38B | 5.5B | 32.8B | 38.4B | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-38B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-38B) |
55
+ | InternVL3.5-20B-A4B | 0.3B | 20.9B | 21.2B-A4B | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-GPT-OSS-20B-A4B-Preview) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-GPT-OSS-20B-A4B-Preview) |
56
+ | InternVL3.5-30B-A3B | 0.3B | 30.5B | 30.8B-A3B | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-30B-A3B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-30B-A3B) |
57
+ | InternVL3.5-241B-A28B | 5.5B | 235.1B | 240.7B-A29B | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-241B-A28B) |
58
 
 
 
 
59
 
60
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/performance_overall.jpg)
61
 
62
+ > We conduct the evaluation with [VLMEvalkit](https://github.com/open-compass/VLMEvalKit). ***To enable the Thinking mode of our model, please set the system prompt to [R1_SYSTEM_PROMPT](https://github.com/open-compass/VLMEvalKit/blob/main/vlmeval/vlm/internvl/internvl_chat.py#L38).*** When enabling Thinking mode, we recommend setting `do_sample=True` and `temperature=0.6` to mitigate undesired repetition.
63
+
64
+ Our training pipeline comprises four stages: Multimodal Continual Pre-Training (**CPT**), Supervised Fine-Tuning (**SFT**), and Cascade Reinforcement Learning (**CascadeRL**). In CascadeRL, we first fine-tune the model using Mixed Preference Optimization (**MPO**) under an offline RL setting, followed by **GSPO** under an oneline RL setting.
65
+ For the Flash version of InternVL3.5, we additionally introduce a lightweight training stage, termed Visual Consistency Learning (**ViCO**), which reduces the token cost required to represent an image patch.
66
+
67
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/training_pipeline.jpg)
68
+
69
+ Here, we also open-source the model weights after different training stages for potential research usage.
70
+ ***If you're unsure which version to use, please select the one without any suffix, as it has completed the full training pipeline.***
71
+
72
+
73
+ | Model | Training Pipeline | HF Link | ModelScope Link |
74
+ | -------------------------------- | --------------------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
75
+ | InternVL3.5-1B-Pretrained | CPT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-1B-Pretrained) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-1B-Pretrained) |
76
+ | InternVL3.5-1B-Instruct | CPT + SFT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-1B-Instruct) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-1B-Instruct) |
77
+ | InternVL3.5-1B-MPO | CPT + SFT + MPO | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-1B-MPO) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-1B-MPO) |
78
+ | InternVL3.5-1B | CPT + SFT + CascadeRL | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-1B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-1B) |
79
+ | InternVL3.5-2B-Pretrained | CPT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-2B-Pretrained) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-2B-Pretrained) |
80
+ | InternVL3.5-2B-Instruct | CPT + SFT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-2B-Instruct) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-2B-Instruct) |
81
+ | InternVL3.5-2B-MPO | CPT + SFT + MPO | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-2B-MPO) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-2B-MPO) |
82
+ | InternVL3.5-2B | CPT + SFT + CascadeRL | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-2B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-2B) |
83
+ | InternVL3.5-4B-Pretrained | CPT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-4B-Pretrained) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-4B-Pretrained) |
84
+ | InternVL3.5-4B-Instruct | CPT + SFT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-4B-Instruct) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-4B-Instruct) |
85
+ | InternVL3.5-4B-MPO | CPT + SFT + MPO | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-4B-MPO) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-4B-MPO) |
86
+ | InternVL3.5-4B | CPT + SFT + CascadeRL | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-4B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-4B) |
87
+ | InternVL3.5-8B-Pretrained | CPT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-8B-Pretrained) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-8B-Pretrained) |
88
+ | InternVL3.5-8B-Instruct | CPT + SFT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-8B-Instruct) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-8B-Instruct) |
89
+ | InternVL3.5-8B-MPO | CPT + SFT + MPO | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-8B-MPO) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-8B-MPO) |
90
+ | InternVL3.5-8B | CPT + SFT + CascadeRL | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-8B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-8B) |
91
+ | InternVL3.5-14B-Pretrained | CPT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-14B-Pretrained) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-14B-Pretrained) |
92
+ | InternVL3.5-14B-Instruct | CPT + SFT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-14B-Instruct) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-14B-Instruct) |
93
+ | InternVL3.5-14B-MPO | CPT + SFT + MPO | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-14B-MPO) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-14B-MPO) |
94
+ | InternVL3.5-14B | CPT + SFT + CascadeRL | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-14B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-14B) |
95
+ | InternVL3.5-30B-A3B-Pretrained | CPT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-30B-A3B-Pretrained) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-30B-A3B-Pretrained) |
96
+ | InternVL3.5-30B-A3B-Instruct | CPT + SFT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-30B-A3B-Instruct) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-30B-A3B-Instruct) |
97
+ | InternVL3.5-30B-A3B-MPO | CPT + SFT + MPO | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-30B-A3B-MPO) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-30B-A3B-MPO) |
98
+ | InternVL3.5-30B-A3B | CPT + SFT + CascadeRL | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-30B-A3B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-30B-A3B) |
99
+ | InternVL3.5-38B-Pretrained | CPT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-38B-Pretrained) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-38B-Pretrained) |
100
+ | InternVL3.5-38B-Instruct | CPT + SFT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-38B-Instruct) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-38B-Instruct) |
101
+ | InternVL3.5-38B-MPO | CPT + SFT + MPO | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-38B-MPO) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-38B-MPO) |
102
+ | InternVL3.5-38B | CPT + SFT + CascadeRL | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-38B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-38B) |
103
+ | InternVL3.5-241B-A28B-Pretrained | CPT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B-Pretrained) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-241B-A28B-Pretrained) |
104
+ | InternVL3.5-241B-A28B-Instruct | CPT + SFT | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B-Instruct) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-241B-A28B-Instruct) |
105
+ | InternVL3.5-241B-A28B-MPO | CPT + SFT + MPO | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B-MPO) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-241B-A28B-MPO) |
106
+ | InternVL3.5-241B-A28B | CPT + SFT + CascadeRL | [🤗 link](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B) | [🤖 link](https://www.modelscope.cn/models/OpenGVLab/InternVL3_5-241B-A28B) |
107
+
108
+
109
+ > The Flash version of our model will be released as soon as possible.
110
+
111
+
112
+
113
+ ## Model Architecture
114
+
115
+ `InternVL3.5`:
116
+ This series of models follow the "ViT–MLP–LLM" paradigm adopted in previous versions of InternVL.
117
+ We initialize the language model using the Qwen3 series and GPT-OSS, and the vision encoder using InternViT-300M and InternViT-6B.
118
+ The Dynamic High Resolution strategy introduced in InternVL1.5 is also retained in our design.
119
+
120
+
121
+ `InternVL3.5-Flash`:
122
+ Compared to InternVL3.5, InternVL3.5-Flash further integrates the *Visual Resolution Router (ViR)*, thus yielding a series of efficient variants friendly suitable for resource-constrained scenarios.
123
+ Specifically, in InternVL3.5, each image patch is initially represented as 1024 visual tokens for the vision encoder, which are then compressed into 256 tokens via a pixel shuffle module before being passed to the Large Language Model (LLM).
124
+ In InternVL3.5-Flash, as shown in the Figure below, an additional pixel shuffle module with a higher compression rate is included, enabling the compression of visual tokens down to 64 tokens.
125
+ For each patch, the patch router determines the appropriate compression rate by assessing its semantic richness, and routes it to the corresponding pixel shuffle module accordingly.
126
+ Benefiting from this patch-aware compression mechanism, InternVL3.5-Flash is able to reduce the number of visual tokens by 50\% while maintaining nearly 100\% of the performance of InternVL3.5.
127
+
128
+
129
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/architecture.jpg)
130
+
131
+ ## Training and Deployment Strategy
132
+
133
+ ### Pre-Training
134
+
135
+ During the pre-training stage, we update all model parameters jointly using the combination of large-scale text and multimodal corpora. Specifically, given an arbitrary training sample consisting of a multimodal token sequence \\(\mathbf{x}=\left(x_1, x_2, \ldots, x_L\right)\\), the next token prediction (NTP) loss is calculated on each text token as follows:
136
+
137
+ $$
138
+ \mathcal{L}_{i}=-\log p_\theta\left(x_i \mid x_1, \ldots, x_{i-1}\right),
139
+ $$
140
+
141
+ where \\(x_i\\) is the predicted token and prefix tokens in \\(\{x_1, x_2, \ldots, x_{i-1}\}\\) can be either text tokens or image tokens. Notably, for conversation samples, only response tokens are included for the calculation of the loss.
142
+ Additionally, to mitigate bias toward either longer or shorter responses during training, we adopt the square averaging to re-weight the NTP loss as follows:
143
+
144
+ $$
145
+ \mathcal{L}_{i}^{'} = \frac{w_i}{\sum_j w_j} \cdot \mathcal{L}_i, \quad w_i = \frac{1}{N^{0.5}},
146
+ $$
147
+
148
+ where \\(N\\) denotes the number of tokens in the training sample on which the loss needs to be calculated. The random JPEG compression is also included to enhance the model's real-world performance.
149
+
150
+ ### Supervised Fine-Tuning
151
+
152
+ During the SFT phase, we adopt the same objective as in the pre-training stage and use the square-root averaging strategy to calculate the final loss. In this stage, the context window is set to 32K tokens to adapt long-context information.
153
+ Compared to InternVL3, the SFT stage of InternVL3.5 contains more high-quality and diverse training data derived from three sources:
154
+
155
+ (1) Instruction-following data from InternVL3, which are reused to preserve broad coverage of vision–language tasks.
156
+
157
+ (2) Multimodal reasoning data in the "Thinking" mode, which are included to instill long-thinking capabilities in the model. To construct such data, we first use InternVL3-78B to describe the image and then input the description into DeepSeek-R1 to sample rollouts with detailed reasoning processes. Rollouts with an incorrect final answer are filtered out. The questions in these datasets cover various expert domains, such as mathematics and scientific disciplines, thereby strengthening performance on different reasoning tasks.
158
+
159
+ (3) Capability-expansion datasets, which endow InternVL3.5 with new skills, including GUI-based interaction, embodied interaction, and scalable vect
160
+
161
+ ### Cascade Reinforcement Learning
162
+
163
+ Cascade RL aims to combine the benefits of offline RL and online RL to progressively facilitate the post-training of MLLMs in an efficient manner.
164
+ Specifically, we first fine-tune the model using an offline RL algorithm as an efficient warm-up stage to reach a satisfied results, which can guarantee the high-quality rollouts for the latter stage.
165
+ Subsequently, we employ an online RL algorithm to further refine the output distribution based on rollouts generated by the model itself. Compared to the single offline or online RL stage, our cascaded RL achieves significant performance improvements at a fraction of the GPU time cost.
166
+
167
+
168
+
169
+ During the offline RL stage, we employ mixed preference optimization (MPO) to fine-tune the model. Specifically, the training objective of MPO is a combination of preference loss \\(\mathcal{L}_{p}\\), quality loss \\(\mathcal{L}_{q}\\), and generation loss \\(\mathcal{L}_{g}\\), which can be formulated as follows:
170
+
171
+ $$
172
+ \mathcal{L}_{\text{MPO}}=
173
+ w_{p} \mathcal{L}_{p}
174
+ +
175
+ w_{q} \mathcal{L}_{q}
176
+ +
177
+ w_{g} \mathcal{L}_{g}
178
+ ,
179
+ $$
180
+
181
+ where \\(w_{*}\\) represents the weight assigned to each loss component.
182
+ The DPO loss, BCO loss, and LM loss serve as the preference loss, quality loss, and generation loss, respectively.
183
+
184
+
185
+ During the online RL stage, we employ GSPO, without reference model constraints, as our online RL algorithm, which we find more effective in training both dense and mixture-of-experts (MoE) models. Similar to GRPO, the advantage is defined as the normalized reward across responses sampled from the same query.
186
+ The training objective of GSPO is given by:
187
+
188
+ $$
189
+ \mathcal{L}_{\mathrm{GSPO}}(\theta)=\mathbb{E}_{x \sim \mathcal{D},\left\{y_i\right\}_{i=1}^G \sim \pi_{\theta \text { old }}(\cdot \mid x)}\left[\frac{1}{G} \sum_{i=1}^G \min \left(s_i(\theta) \widehat{A}_i, \operatorname{clip}\left(s_i(\theta), 1-\varepsilon, 1+\varepsilon\right) \widehat{A}_i\right)\right],
190
+ $$
191
+
192
+ where the importance sampling ratio is defined as the geometric mean of the per-token ratios.
193
+
194
+ > Please see [our paper](TBD) for more technical and experimental details.
195
+
196
+
197
+ ### Visual Consistency Learning
198
+
199
+
200
+ We further include ViCO as an additional training stage to integrate the *visual resolution router (ViR)* into InternVL3.5, thereby reducing the inference cost of InternVL3.5. The obtained efficient version of InternVL3.5 are termed as *InternVL3.5-Flash*. In particular, ViCO comprises two stages:
201
+
202
+ `Consistency training`:
203
+ In this stage, the entire model is trained to minimize the divergence between response distributions conditioned on visual tokens with different compression rates.
204
+ In practice, we introduce an extra reference model, which is frozen and initialized with InternVL3.5.
205
+ Given a sample, each image patch is represented as either 256 or 64 tokens, and the training objective is defined as follows:
206
+
207
+
208
+ $$
209
+ \mathcal{L}_\text{ViCO} =
210
+ \mathbb{E}_{\xi \sim \mathcal{R}} \Bigg[
211
+ \frac{1}{N} \sum_{i=1}^{N} \mathrm{KL} \Big(
212
+ \pi_{\theta_{ref}}\left(y_i \mid y_{<i}, I\right) \;\Big\|\;
213
+ \pi_{\theta_{policy}}\left(y_i \mid y_{<i}, I_\xi\right)
214
+ \Big)
215
+ \Bigg],
216
+ $$
217
+
218
+ where \\(\mathrm{KL}\) denotes the KL divergence and \(\xi\) denotes the compression rate, which is uniformly sampled from \(\{\frac{1}{4},\frac{1}{16}\}\). The image \(I_\xi\) is represented as 256 tokens when \(\xi=\frac{1}{4}\) and 64 tokens when \(\xi=\frac{1}{16}\). Notably, the reference model always performs inference with \(\xi=\frac{1}{4}\).
219
+
220
+
221
+ `Router training`:
222
+ This stage aims to train the ViR to select an appropriate trade-off resolution for different inputs.
223
+ ViR is formulated as a binary classifier and trained using standard cross-entropy loss.
224
+ To construct the route targets, we first compute the KL divergence between the model outputs conditioned on uncompressed visual tokens (i.e., 256 tokens per patch) and those conditioned on compressed visual tokens (i.e., 64 tokens per patch).
225
+ During this stage, the main MLLM (ViT, MLP and LLM) is kept frozen, and only the ViR is trained.
226
+ Specifically, we first compute the loss ratio for each patch:
227
+
228
+ $$
229
+ r_i = \frac{\mathcal{L}_\text{ViCO}\big(y_i \mid I_{\frac{1}{16}}\big)}{\mathcal{L}_\text{ViCO}\big(y_i \mid I_{\frac{1}{4}}\big)},
230
+ $$
231
+
232
+ which quantifies the relative increase in loss caused by compressing the visual tokens. Based on this ratio, the binary ground-truth label for the patch router is defined as:
233
+
234
+ $$
235
+ y_i^\text{router} =
236
+ \begin{cases}
237
+ 0, & r_i < \tau \; \text{(compression has negligible impact)} \\
238
+ 1, & r_i \ge \tau \; \text{(compression has significant impact)},
239
+ \end{cases}
240
+ $$
241
+
242
+ where \(y_i^{\text{router}}=0\) and \(y_i^{\text{router}}=1\) indicate that the compression rate \(\xi\) is set to \(\tfrac{1}{16}\) and \(\tfrac{1}{4}\), respectively.
243
+
244
+ > Please see [our paper](TBD) for more technical and experimental details.
245
+
246
+
247
+ ### Test-Time Scaling
248
+
249
+
250
+ Test-time scaling (TTS) has been empirically demonstrated as an effective approach to enhance the reasoning capabilities of LLMs and MLLMs, particularly for complex tasks necessitating multi-step inference.
251
+ In this work, we implement a comprehensive test-time scaling approach that simultaneously improves reasoning depth (i.e., deep thinking) and breadth (i.e., parallel thinking).
252
+
253
+ `Deep Thinking`: By activating the Thinking mode, we guide the model to deliberately engage in step-by-step reasoning (i.e., decomposing complex problems into logical steps and validating intermediate conclusions) prior to generating the final answer. This approach systematically improves the logical structure of solutions for complex problems, particularly those requiring multi-step inference, and enhances reasoning depth.
254
+
255
+ `Parallel Thinking`: Following InternVL3, for reasoning tasks, we adopt the Best-of-N (BoN) strategy by employing [VisualPRM-v1.1](https://huggingface.co/OpenGVLab/VisualPRM-8B-v1_1) as the critic model to select the optimal response from multiple reasoning candidates.
256
+ This approach improves reasoning breadth.
257
+
258
+ > Notably, unless otherwise specified, the experimental results reported in our paper are obtained without applying TTS. Thus far, we have only applied TTS to reasoning benchmarks, since we found that the model already exhibits strong perception and understanding capabilities, and initiating TTS yields no significant improvement.
259
+
260
+
261
+ ### Decoupled Vision-Language Deployment
262
+
263
+ In multimodal inference, the vision encoder and language model have distinct computational characteristics. The vision encoder that transforms images into semantic features is highly parallelizable and does not rely on long-term history state. In contrast, the language model adopts the inference in an autoregressive manner, which requires previous states to compute the next one. This sequential property makes the language part more sensitive to memory bandwidth and latency.
264
+ When MLLMs are deployed online at scale, the vision and language models often block each other, thus incurring additional inference cost. This effect becomes more pronounced with larger vision models or higher-resolution images.
265
+
266
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/DvD.jpg)
267
+
268
+ As shown in the Figure above, we propose decoupled vision-language deployment (DvD) to address this issue by separating vision and language processing, with a particular focus on optimizing the prefilling stage. The vision subsystem batches and processes images to produce compact feature embeddings, which are then transmitted to the language subsystem for fusion with the text context prior to decoding. This separation alleviates blocking and brings multimodal prefilling performance closer to that of pure language models.
269
+ In our system implementation, the ViT and MLP (and ViR for InternVL3.5-Flash) are deployed on the vision server, while the language server executes only the LLM. The communication is unidirectional, transmitting BF16 visual features over TCP, with RDMA optionally employed to achieve higher transmission speed. Vision processing, feature transmission, and language processing are organized into an asynchronous three-stage pipeline, enabling overlapped execution and minimizing pipeline stalls.
270
+
271
+
272
+ DvD increases GPU utilization and processing efficiency on the vision side, while enabling the language server to focus exclusively on the LLM’s prefilling and decoding without being blocked by vision computation. This design leads to improved throughput and responsiveness. Moreover, the architecture supports independent hardware cost optimization for the vision and language modules, and facilitates the seamless integration of new modules without requiring modifications to the language server deployment.
273
 
 
 
 
 
 
 
 
 
274
 
275
+ ## Evaluation on Multimodal Capability
276
 
277
+ ### Multimodal Reasoning and Mathematics
 
278
 
279
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/performance_reasoning.jpg)
280
 
281
+ ### OCR, Chart, and Document Understanding
282
 
283
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/performance_ocr.jpg)
284
+
285
+ ### Multi-Image Understanding & Real-World Comprehension
286
+
287
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/performance_multi_images.jpg)
288
+
289
+ ### Comprehensive Multimodal Understanding & Multimodal Hallucination Evaluation
290
+
291
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/performance_comprehensive.jpg)
292
+
293
+ ### Visual Grounding
294
+
295
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/performance_grounding.jpg)
296
+
297
+ ### Multimodal Multilingual Understanding
298
+
299
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/performance_multilingual.jpg)
300
+
301
+ ### Video Understanding
302
+
303
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/performance_video.jpg)
304
+
305
+ ### GUI Tasks
306
+
307
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/performance_gui.jpg)
308
+
309
+ ### Embodied Tasks
310
+
311
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/performance_embody.jpg)
312
+
313
+ ### SVG Tasks
314
+
315
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/performance_svg.jpg)
316
+
317
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/performance_svg_gen.jpg)
318
+
319
+ ## Evaluation on Language Capability
320
+
321
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/performance_text.jpg)
322
+
323
+ ## Ablation Study
324
+
325
+ ### Cascade Reinforcement Learning
326
+
327
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/ablation_cascade_rl.jpg)
328
+
329
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/ablation_cascade_rl_table.jpg)
330
+
331
+ ### Decoupled Vision-Language Deployment
332
+
333
+
334
+ ![image/jpg](https://huggingface.co/OpenGVLab/InternVL3_5-241B-A28B/resolve/main/images/ablation_dvd.jpg)
335
+
336
+ ## Quick Start
337
+
338
+ We provide an example code to run `InternVL3.5-8B` using `transformers`. Please note that our models with up to 30B parameters can be deployed on a single A100 GPU, while the 38B model requires two A100 GPUs and the 235B model requires eight A100 GPUs.
339
+
340
+ > In most cases, both [LMDeploy](https://github.com/InternLM/lmdeploy) and [vLLM](https://github.com/vllm-project/vllm) can be used for model deployment. However, for InternVL3.5-20B-A4B, we recommend using vLLM since lmdeploy has not yet supported GPT-OSS.
341
+
342
+ > Please use transformers>=4.52.1 to ensure the model works normally. For the 20B version of our model, transformers>=4.55.0 is required.
343
+
344
+ ### Model Loading
345
+
346
+ #### 16-bit (bf16 / fp16)
347
 
348
  ```python
349
+ import torch
350
+ from transformers import AutoTokenizer, AutoModel
351
+ path = "OpenGVLab/InternVL3_5-8B"
352
+ model = AutoModel.from_pretrained(
353
+ path,
354
+ torch_dtype=torch.bfloat16,
355
+ low_cpu_mem_usage=True,
356
+ use_flash_attn=True,
357
+ trust_remote_code=True).eval().cuda()
358
  ```
359
 
360
+ #### BNB 8-bit Quantization
361
 
362
+ ```python
363
+ import torch
364
+ from transformers import AutoTokenizer, AutoModel
365
+ path = "OpenGVLab/InternVL3_5-8B"
366
+ model = AutoModel.from_pretrained(
367
+ path,
368
+ torch_dtype=torch.bfloat16,
369
+ load_in_8bit=True,
370
+ low_cpu_mem_usage=True,
371
+ use_flash_attn=True,
372
+ trust_remote_code=True).eval()
373
+ ```
374
 
375
+ #### Multiple GPUs
376
 
377
+ ```python
378
+ import math
379
+ import torch
380
+ from transformers import AutoTokenizer, AutoModel
381
+
382
+ path = "OpenGVLab/InternVL3_5-8B"
383
+ model = AutoModel.from_pretrained(
384
+ path,
385
+ torch_dtype=torch.bfloat16,
386
+ low_cpu_mem_usage=True,
387
+ use_flash_attn=True,
388
+ trust_remote_code=True,
389
+ device_map="auto").eval()
390
+ ```
391
 
392
+ ### Thinking Mode
393
+
394
+ To enable thinking mode, please set the system prompt to our Thinking System Prompt. When enabling Thinking mode, we recommend setting `do_sample=True` and `temperature=0.6` to mitigate undesired repetition.
395
 
396
  ```python
397
+ R1_SYSTEM_PROMPT = """
398
+ You are an AI assistant that rigorously follows this response protocol:
399
+
400
+ 1. First, conduct a detailed analysis of the question. Consider different angles, potential solutions, and reason through the problem step-by-step. Enclose this entire thinking process within <think> and </think> tags.
401
 
402
+ 2. After the thinking section, provide a clear, concise, and direct answer to the user's question. Separate the answer from the think section with a newline.
 
 
 
 
403
 
404
+ Ensure that the thinking process is thorough but remains focused on the query. The final answer should be standalone and not reference the thinking section.
405
+ """.strip()
406
 
407
+ model.system_message = R1_SYSTEMP_PROMPT
408
+ ```
409
+
410
+ ### Inference with Transformers
411
+
412
+ ```python
413
+ import math
414
+ import numpy as np
415
+ import torch
416
+ import torchvision.transforms as T
417
+ from decord import VideoReader, cpu
418
+ from PIL import Image
419
+ from torchvision.transforms.functional import InterpolationMode
420
+ from transformers import AutoModel, AutoTokenizer
421
+
422
+ IMAGENET_MEAN = (0.485, 0.456, 0.406)
423
+ IMAGENET_STD = (0.229, 0.224, 0.225)
424
+
425
+ def build_transform(input_size):
426
+ MEAN, STD = IMAGENET_MEAN, IMAGENET_STD
427
+ transform = T.Compose([
428
+ T.Lambda(lambda img: img.convert('RGB') if img.mode != 'RGB' else img),
429
+ T.Resize((input_size, input_size), interpolation=InterpolationMode.BICUBIC),
430
+ T.ToTensor(),
431
+ T.Normalize(mean=MEAN, std=STD)
432
+ ])
433
+ return transform
434
+
435
+ def find_closest_aspect_ratio(aspect_ratio, target_ratios, width, height, image_size):
436
+ best_ratio_diff = float('inf')
437
+ best_ratio = (1, 1)
438
+ area = width * height
439
+ for ratio in target_ratios:
440
+ target_aspect_ratio = ratio[0] / ratio[1]
441
+ ratio_diff = abs(aspect_ratio - target_aspect_ratio)
442
+ if ratio_diff < best_ratio_diff:
443
+ best_ratio_diff = ratio_diff
444
+ best_ratio = ratio
445
+ elif ratio_diff == best_ratio_diff:
446
+ if area > 0.5 * image_size * image_size * ratio[0] * ratio[1]:
447
+ best_ratio = ratio
448
+ return best_ratio
449
+
450
+ def dynamic_preprocess(image, min_num=1, max_num=12, image_size=448, use_thumbnail=False):
451
+ orig_width, orig_height = image.size
452
+ aspect_ratio = orig_width / orig_height
453
+
454
+ # calculate the existing image aspect ratio
455
+ target_ratios = set(
456
+ (i, j) for n in range(min_num, max_num + 1) for i in range(1, n + 1) for j in range(1, n + 1) if
457
+ i * j <= max_num and i * j >= min_num)
458
+ target_ratios = sorted(target_ratios, key=lambda x: x[0] * x[1])
459
+
460
+ # find the closest aspect ratio to the target
461
+ target_aspect_ratio = find_closest_aspect_ratio(
462
+ aspect_ratio, target_ratios, orig_width, orig_height, image_size)
463
+
464
+ # calculate the target width and height
465
+ target_width = image_size * target_aspect_ratio[0]
466
+ target_height = image_size * target_aspect_ratio[1]
467
+ blocks = target_aspect_ratio[0] * target_aspect_ratio[1]
468
+
469
+ # resize the image
470
+ resized_img = image.resize((target_width, target_height))
471
+ processed_images = []
472
+ for i in range(blocks):
473
+ box = (
474
+ (i % (target_width // image_size)) * image_size,
475
+ (i // (target_width // image_size)) * image_size,
476
+ ((i % (target_width // image_size)) + 1) * image_size,
477
+ ((i // (target_width // image_size)) + 1) * image_size
478
  )
479
+ # split the image
480
+ split_img = resized_img.crop(box)
481
+ processed_images.append(split_img)
482
+ assert len(processed_images) == blocks
483
+ if use_thumbnail and len(processed_images) != 1:
484
+ thumbnail_img = image.resize((image_size, image_size))
485
+ processed_images.append(thumbnail_img)
486
+ return processed_images
487
+
488
+ def load_image(image_file, input_size=448, max_num=12):
489
+ image = Image.open(image_file).convert('RGB')
490
+ transform = build_transform(input_size=input_size)
491
+ images = dynamic_preprocess(image, image_size=input_size, use_thumbnail=True, max_num=max_num)
492
+ pixel_values = [transform(image) for image in images]
493
+ pixel_values = torch.stack(pixel_values)
494
+ return pixel_values
495
+
496
+ path = 'OpenGVLab/InternVL3_5-8B'
497
+ model = AutoModel.from_pretrained(
498
+ path,
499
+ torch_dtype=torch.bfloat16,
500
+ load_in_8bit=False,
501
+ low_cpu_mem_usage=True,
502
+ use_flash_attn=True,
503
+ trust_remote_code=True,
504
+ device_map="auto").eval()
505
+ tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True, use_fast=False)
506
+
507
+ # set the max number of tiles in `max_num`
508
+ pixel_values = load_image('./examples/image1.jpg', max_num=12).to(torch.bfloat16).cuda()
509
+ generation_config = dict(max_new_tokens=1024, do_sample=True)
510
+
511
+ # pure-text conversation (纯文本对话)
512
+ question = 'Hello, who are you?'
513
+ response, history = model.chat(tokenizer, None, question, generation_config, history=None, return_history=True)
514
+ print(f'User: {question}\nAssistant: {response}')
515
+
516
+ question = 'Can you tell me a story?'
517
+ response, history = model.chat(tokenizer, None, question, generation_config, history=history, return_history=True)
518
+ print(f'User: {question}\nAssistant: {response}')
519
+
520
+ # single-image single-round conversation (单图单轮对话)
521
+ question = '<image>\nPlease describe the image shortly.'
522
+ response = model.chat(tokenizer, pixel_values, question, generation_config)
523
+ print(f'User: {question}\nAssistant: {response}')
524
+
525
+ # single-image multi-round conversation (单图多轮对话)
526
+ question = '<image>\nPlease describe the image in detail.'
527
+ response, history = model.chat(tokenizer, pixel_values, question, generation_config, history=None, return_history=True)
528
+ print(f'User: {question}\nAssistant: {response}')
529
+
530
+ question = 'Please write a poem according to the image.'
531
+ response, history = model.chat(tokenizer, pixel_values, question, generation_config, history=history, return_history=True)
532
+ print(f'User: {question}\nAssistant: {response}')
533
+
534
+ # multi-image multi-round conversation, combined images (多图多轮对话,拼接图像)
535
+ pixel_values1 = load_image('./examples/image1.jpg', max_num=12).to(torch.bfloat16).cuda()
536
+ pixel_values2 = load_image('./examples/image2.jpg', max_num=12).to(torch.bfloat16).cuda()
537
+ pixel_values = torch.cat((pixel_values1, pixel_values2), dim=0)
538
+
539
+ question = '<image>\nDescribe the two images in detail.'
540
+ response, history = model.chat(tokenizer, pixel_values, question, generation_config,
541
+ history=None, return_history=True)
542
+ print(f'User: {question}\nAssistant: {response}')
543
+
544
+ question = 'What are the similarities and differences between these two images.'
545
+ response, history = model.chat(tokenizer, pixel_values, question, generation_config,
546
+ history=history, return_history=True)
547
+ print(f'User: {question}\nAssistant: {response}')
548
+
549
+ # multi-image multi-round conversation, separate images (多图多轮对话,独立图像)
550
+ pixel_values1 = load_image('./examples/image1.jpg', max_num=12).to(torch.bfloat16).cuda()
551
+ pixel_values2 = load_image('./examples/image2.jpg', max_num=12).to(torch.bfloat16).cuda()
552
+ pixel_values = torch.cat((pixel_values1, pixel_values2), dim=0)
553
+ num_patches_list = [pixel_values1.size(0), pixel_values2.size(0)]
554
+
555
+ question = 'Image-1: <image>\nImage-2: <image>\nDescribe the two images in detail.'
556
+ response, history = model.chat(tokenizer, pixel_values, question, generation_config,
557
+ num_patches_list=num_patches_list,
558
+ history=None, return_history=True)
559
+ print(f'User: {question}\nAssistant: {response}')
560
+
561
+ question = 'What are the similarities and differences between these two images.'
562
+ response, history = model.chat(tokenizer, pixel_values, question, generation_config,
563
+ num_patches_list=num_patches_list,
564
+ history=history, return_history=True)
565
+ print(f'User: {question}\nAssistant: {response}')
566
+
567
+ # batch inference, single image per sample (单图批处理)
568
+ pixel_values1 = load_image('./examples/image1.jpg', max_num=12).to(torch.bfloat16).cuda()
569
+ pixel_values2 = load_image('./examples/image2.jpg', max_num=12).to(torch.bfloat16).cuda()
570
+ num_patches_list = [pixel_values1.size(0), pixel_values2.size(0)]
571
+ pixel_values = torch.cat((pixel_values1, pixel_values2), dim=0)
572
+
573
+ questions = ['<image>\nDescribe the image in detail.'] * len(num_patches_list)
574
+ responses = model.batch_chat(tokenizer, pixel_values,
575
+ num_patches_list=num_patches_list,
576
+ questions=questions,
577
+ generation_config=generation_config)
578
+ for question, response in zip(questions, responses):
579
+ print(f'User: {question}\nAssistant: {response}')
580
+
581
+ # video multi-round conversation (视频多轮对话)
582
+ def get_index(bound, fps, max_frame, first_idx=0, num_segments=32):
583
+ if bound:
584
+ start, end = bound[0], bound[1]
585
+ else:
586
+ start, end = -100000, 100000
587
+ start_idx = max(first_idx, round(start * fps))
588
+ end_idx = min(round(end * fps), max_frame)
589
+ seg_size = float(end_idx - start_idx) / num_segments
590
+ frame_indices = np.array([
591
+ int(start_idx + (seg_size / 2) + np.round(seg_size * idx))
592
+ for idx in range(num_segments)
593
+ ])
594
+ return frame_indices
595
+
596
+ def load_video(video_path, bound=None, input_size=448, max_num=1, num_segments=32):
597
+ vr = VideoReader(video_path, ctx=cpu(0), num_threads=1)
598
+ max_frame = len(vr) - 1
599
+ fps = float(vr.get_avg_fps())
600
+
601
+ pixel_values_list, num_patches_list = [], []
602
+ transform = build_transform(input_size=input_size)
603
+ frame_indices = get_index(bound, fps, max_frame, first_idx=0, num_segments=num_segments)
604
+ for frame_index in frame_indices:
605
+ img = Image.fromarray(vr[frame_index].asnumpy()).convert('RGB')
606
+ img = dynamic_preprocess(img, image_size=input_size, use_thumbnail=True, max_num=max_num)
607
+ pixel_values = [transform(tile) for tile in img]
608
+ pixel_values = torch.stack(pixel_values)
609
+ num_patches_list.append(pixel_values.shape[0])
610
+ pixel_values_list.append(pixel_values)
611
+ pixel_values = torch.cat(pixel_values_list)
612
+ return pixel_values, num_patches_list
613
+
614
+ video_path = './examples/red-panda.mp4'
615
+ pixel_values, num_patches_list = load_video(video_path, num_segments=8, max_num=1)
616
+ pixel_values = pixel_values.to(torch.bfloat16).cuda()
617
+ video_prefix = ''.join([f'Frame{i+1}: <image>\n' for i in range(len(num_patches_list))])
618
+ question = video_prefix + 'What is the red panda doing?'
619
+ # Frame1: <image>\nFrame2: <image>\n...\nFrame8: <image>\n{question}
620
+ response, history = model.chat(tokenizer, pixel_values, question, generation_config,
621
+ num_patches_list=num_patches_list, history=None, return_history=True)
622
+ print(f'User: {question}\nAssistant: {response}')
623
+
624
+ question = 'Describe this video in detail.'
625
+ response, history = model.chat(tokenizer, pixel_values, question, generation_config,
626
+ num_patches_list=num_patches_list, history=history, return_history=True)
627
+ print(f'User: {question}\nAssistant: {response}')
628
+ ```
629
 
630
+ #### Streaming Output
631
+
632
+ Besides this method, you can also use the following code to get streamed output.
633
+
634
+ ```python
635
+ from transformers import TextIteratorStreamer
636
+ from threading import Thread
637
+
638
+ # Initialize the streamer
639
+ streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True, timeout=10)
640
+ # Define the generation configuration
641
+ generation_config = dict(max_new_tokens=1024, do_sample=False, streamer=streamer)
642
+ # Start the model chat in a separate thread
643
+ thread = Thread(target=model.chat, kwargs=dict(
644
+ tokenizer=tokenizer, pixel_values=pixel_values, question=question,
645
+ history=None, return_history=False, generation_config=generation_config,
646
+ ))
647
+ thread.start()
648
+
649
+ # Initialize an empty string to store the generated text
650
+ generated_text = ''
651
+ # Loop through the streamer to get the new text as it is generated
652
+ for new_text in streamer:
653
+ if new_text == model.conv_template.sep:
654
+ break
655
+ generated_text += new_text
656
+ print(new_text, end='', flush=True) # Print each new chunk of generated text on the same line
 
 
 
 
 
 
657
  ```
658
 
659
+ ## Finetune
660
+
661
+ Many repositories now support fine-tuning of the InternVL series models, including [InternVL](https://github.com/OpenGVLab/InternVL), [SWIFT](https://github.com/modelscope/ms-swift), [XTuner](https://github.com/InternLM/xtuner), and others. Please refer to their documentation for more details on fine-tuning.
662
+
663
+ ## Deployment
664
 
665
+ ### LMDeploy
666
 
667
+ LMDeploy is a toolkit for compressing, deploying, and serving LLMs & VLMs.
668
+
669
+ ```sh
670
+ pip install lmdeploy>=0.9.1
671
+ ```
672
+
673
+ 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.
674
+
675
+ #### A 'Hello, world' Example
676
 
 
677
  ```python
678
+ from lmdeploy import pipeline, PytorchEngineConfig
679
+ from lmdeploy.vl import load_image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
680
 
681
+ image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
682
 
683
+ # Please set tp=2 for the 38B version and tp=8 for the 241B-A28B version.
684
+ model = 'OpenGVLab/InternVL3_5-8B'
685
+ pipe = pipeline(model, backend_config=PytorchEngineConfig(session_len=32768, tp=1))
686
 
687
+ response = pipe(('describe this image', image))
688
+ print(response.text)
 
 
 
689
  ```
690
 
691
+ #### Multi-images Inference
692
 
693
+ 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.
694
 
695
+ ```python
696
+ from lmdeploy import pipeline, PytorchEngineConfig
697
+ from lmdeploy.vl import load_image
698
+ from lmdeploy.vl.constants import IMAGE_TOKEN
699
 
700
+ # Please set tp=2 for the 38B version and tp=8 for the 241B-A28B version.
701
+ model = 'OpenGVLab/InternVL3_5-8B'
702
+ pipe = pipeline(model, backend_config=PytorchEngineConfig(session_len=32768, tp=1))
 
 
 
 
 
 
 
 
 
 
703
 
704
+ image_urls=[
705
+ 'https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg',
706
+ 'https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/det.jpg'
707
+ ]
708
 
709
+ images = [load_image(img_url) for img_url in image_urls]
710
+ # Numbering images improves multi-image conversations
711
+ response = pipe((f'Image-1: {IMAGE_TOKEN}\nImage-2: {IMAGE_TOKEN}\ndescribe these two images', images))
712
+ print(response.text)
713
+ ```
714
 
715
+ #### Batch Prompts Inference
 
 
 
716
 
717
+ Conducting inference with batch prompts is quite straightforward; just place them within a list structure:
 
 
 
718
 
719
+ ```python
720
+ from lmdeploy import pipeline, PytorchEngineConfig
721
+ from lmdeploy.vl import load_image
 
 
 
722
 
723
+ # Please set tp=2 for the 38B version and tp=8 for the 241B-A28B version.
724
+ model = 'OpenGVLab/InternVL3_5-8B'
725
+ pipe = pipeline(model, backend_config=PytorchEngineConfig(session_len=32768, tp=1))
 
726
 
727
+ image_urls=[
728
+ "https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg",
729
+ "https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/det.jpg"
730
+ ]
731
+ prompts = [('describe this image', load_image(img_url)) for img_url in image_urls]
732
+ response = pipe(prompts)
733
+ print(response)
734
+ ```
735
 
736
+ #### Multi-turn Conversation
 
737
 
738
+ 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.
739
 
740
+ ```python
741
+ from lmdeploy import pipeline, PytorchEngineConfig, GenerationConfig
742
+ from lmdeploy.vl import load_image
743
+
744
+ # Please set tp=2 for the 38B version and tp=8 for the 241B-A28B version.
745
+ model = 'OpenGVLab/InternVL3_5-8B'
746
+ pipe = pipeline(model, backend_config=PytorchEngineConfig(session_len=32768, tp=1))
747
+
748
+ image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/demo/resources/human-pose.jpg')
749
+ gen_config = GenerationConfig(top_k=50, top_p=0.95, temperature=0.6, max_new_tokens=8192)
750
+ sess = pipe.chat(('describe this image', image), gen_config=gen_config)
751
+ print(sess.response.text)
752
+ sess = pipe.chat('What is the woman doing?', session=sess, gen_config=gen_config)
753
+ print(sess.response.text)
754
+ ```
755
 
756
+ #### Service
 
 
 
757
 
758
+ 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:
759
 
760
+ ```shell
761
+ lmdeploy serve api_server OpenGVLab/InternVL3_5-8B --server-port 23333 --tp 1
762
+ ```
763
 
764
+ To use the OpenAI-style interface, you need to install OpenAI:
765
 
766
+ ```shell
767
+ pip install openai
768
+ ```
769
 
770
+ Then, use the code below to make the API call:
771
 
772
+ ```python
773
+ from openai import OpenAI
774
+
775
+ client = OpenAI(api_key='YOUR_API_KEY', base_url='http://0.0.0.0:23333/v1')
776
+ model_name = client.models.list().data[0].id
777
+ response = client.chat.completions.create(
778
+ model=model_name,
779
+ messages=[{
780
+ 'role':
781
+ 'user',
782
+ 'content': [{
783
+ 'type': 'text',
784
+ 'text': 'describe this image',
785
+ }, {
786
+ 'type': 'image_url',
787
+ 'image_url': {
788
+ 'url':
789
+ 'https://modelscope.oss-cn-beijing.aliyuncs.com/resource/tiger.jpeg',
790
+ },
791
+ }],
792
+ }],
793
+ temperature=0.8,
794
+ top_p=0.8)
795
+ print(response)
796
  ```
797
+
798
+ ## License
799
+
800
+ This project is released under the apache-2.0 License. This project uses the pre-trained Qwen3 as a component, which is licensed under the apache-2.0 License.
801
+
802
+ ## Citation
803
+
804
+ If you find this project useful in your research, please consider citing:
805
+
806
+ ```BibTeX
807
+ @article{chen2024expanding,
808
+ title={Expanding Performance Boundaries of Open-Source Multimodal Models with Model, Data, and Test-Time Scaling},
809
+ 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},
810
+ journal={arXiv preprint arXiv:2412.05271},
811
+ year={2024}
812
  }
813
+ @article{wang2024mpo,
814
+ title={Enhancing the Reasoning Ability of Multimodal Large Language Models via Mixed Preference Optimization},
815
+ author={Wang, Weiyun and Chen, Zhe and Wang, Wenhai and Cao, Yue and Liu, Yangzhou and Gao, Zhangwei and Zhu, Jinguo and Zhu, Xizhou and Lu, Lewei and Qiao, Yu and Dai, Jifeng},
816
+ journal={arXiv preprint arXiv:2411.10442},
817
+ year={2024}
818
+ }
819
+ @article{chen2024far,
820
+ title={How Far Are We to GPT-4V? Closing the Gap to Commercial Multimodal Models with Open-Source Suites},
821
+ 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},
822
+ journal={arXiv preprint arXiv:2404.16821},
823
+ year={2024}
824
+ }
825
+ @inproceedings{chen2024internvl,
826
+ title={Internvl: Scaling up vision foundation models and aligning for generic visual-linguistic tasks},
827
+ 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},
828
+ booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
829
+ pages={24185--24198},
830
+ year={2024}
831
+ }
832
+ ```