doubility123 commited on
Commit
6a7bd38
Β·
1 Parent(s): 2c1a288
Files changed (1) hide show
  1. README.md +9 -399
README.md CHANGED
@@ -1,399 +1,9 @@
1
- <!-- markdownlint-disable first-line-h1 -->
2
- <!-- markdownlint-disable html -->
3
- <!-- markdownlint-disable no-duplicate-header -->
4
-
5
- <div align="center">
6
- <img src="images/logo.svg" width="60%" alt="DeepSeek LLM" />
7
- </div>
8
- <hr>
9
- <div align="center">
10
-
11
- <a href="https://www.deepseek.com/" target="_blank">
12
- <img alt="Homepage" src="images/badge.svg" />
13
- </a>
14
- <a href="" target="_blank">
15
- <img alt="Chat" src="https://img.shields.io/badge/πŸ€–%20Chat-DeepSeek%20VL-536af5?color=536af5&logoColor=white" />
16
- </a>
17
- <a href="https://huggingface.co/deepseek-ai" target="_blank">
18
- <img alt="Hugging Face" src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-DeepSeek%20AI-ffc107?color=ffc107&logoColor=white" />
19
- </a>
20
-
21
- </div>
22
-
23
-
24
- <div align="center">
25
-
26
- <a href="https://discord.gg/Tc7c45Zzu5" target="_blank">
27
- <img alt="Discord" src="https://img.shields.io/badge/Discord-DeepSeek%20AI-7289da?logo=discord&logoColor=white&color=7289da" />
28
- </a>
29
- <a href="images/qr.jpeg" target="_blank">
30
- <img alt="Wechat" src="https://img.shields.io/badge/WeChat-DeepSeek%20AI-brightgreen?logo=wechat&logoColor=white" />
31
- </a>
32
- <a href="https://twitter.com/deepseek_ai" target="_blank">
33
- <img alt="Twitter Follow" src="https://img.shields.io/badge/Twitter-deepseek_ai-white?logo=x&logoColor=white" />
34
- </a>
35
-
36
- </div>
37
-
38
- <div align="center">
39
-
40
- <a href="LICENSE-CODE">
41
- <img alt="Code License" src="https://img.shields.io/badge/Code_License-MIT-f5de53?&color=f5de53">
42
- </a>
43
- <a href="LICENSE-MODEL">
44
- <img alt="Model License" src="https://img.shields.io/badge/Model_License-Model_Agreement-f5de53?&color=f5de53">
45
- </a>
46
- </div>
47
-
48
-
49
- <p align="center">
50
- <a href="https://github.com/deepseek-ai/DeepSeek-VL2/tree/main?tab=readme-ov-file#3-model-download"><b>πŸ“₯ Model Download</b></a> |
51
- <a href="https://github.com/deepseek-ai/DeepSeek-VL2/tree/main?tab=readme-ov-file#4-quick-start"><b>⚑ Quick Start</b></a> |
52
- <a href="https://github.com/deepseek-ai/DeepSeek-VL2/tree/main?tab=readme-ov-file#5-license"><b>πŸ“œ License</b></a> |
53
- <a href="https://github.com/deepseek-ai/DeepSeek-VL2/tree/main?tab=readme-ov-file#6-citation"><b>πŸ“– Citation</b></a> <br>
54
- <a href="./DeepSeek_VL2_paper.pdf"><b>πŸ“„ Paper Link</b></a> |
55
- <a href="https://arxiv.org/abs/2412.10302"><b>πŸ“„ Arxiv Paper Link</b></a> |
56
- <a href=""><b>πŸ‘οΈ Demo</b></a>
57
- </p>
58
-
59
- ## 1. Introduction
60
-
61
- Introducing DeepSeek-VL2, an advanced series of large Mixture-of-Experts (MoE) Vision-Language Models that significantly improves upon its predecessor, DeepSeek-VL. DeepSeek-VL2 demonstrates superior capabilities across various tasks, including but not limited to visual question answering, optical character recognition, document/table/chart understanding, and visual grounding. Our model series is composed of three variants: DeepSeek-VL2-Tiny, DeepSeek-VL2-Small and DeepSeek-VL2, with 1.0B, 2.8B and 4.5B activated parameters respectively.
62
- DeepSeek-VL2 achieves competitive or state-of-the-art performance with similar or fewer activated parameters compared to existing open-source dense and MoE-based models.
63
-
64
-
65
- [DeepSeek-VL2: Mixture-of-Experts Vision-Language Models for Advanced Multimodal Understanding]()
66
-
67
- Zhiyu Wu*, Xiaokang Chen*, Zizheng Pan*, Xingchao Liu*, Wen Liu**, Damai Dai, Huazuo Gao, Yiyang Ma, Chengyue Wu, Bingxuan Wang, Zhenda Xie, Yu Wu, Kai Hu, Jiawei Wang, Yaofeng Sun, Yukun Li, Yishi Piao, Kang Guan, Aixin Liu, Xin Xie, Yuxiang You, Kai Dong, Xingkai Yu, Haowei Zhang, Liang Zhao, Yisong Wang, Chong Ruan*** (* Equal Contribution, ** Project Lead, *** Corresponding author)
68
-
69
- ![](./images/vl2_teaser.jpeg)
70
-
71
- ## 2. Release
72
- βœ… <b>2024-12-25</b>: Gradio Demo Example, Incremental Prefilling and VLMEvalKit Support.
73
-
74
- βœ… <b>2024-12-13</b>: DeepSeek-VL2 family released, including <code>DeepSeek-VL2-tiny</code>, <code>DeepSeek-VL2-small</code>, <code>DeepSeek-VL2</code>.
75
-
76
- ## 3. Model Download
77
-
78
- We release the DeepSeek-VL2 family, including <code>DeepSeek-VL2-tiny</code>, <code>DeepSeek-VL2-small</code>, <code>DeepSeek-VL2</code>.
79
- To support a broader and more diverse range of research within both academic and commercial communities.
80
- Please note that the use of this model is subject to the terms outlined in [License section](#5-license).
81
-
82
- ### Huggingface
83
-
84
- | Model | Sequence Length | Download |
85
- |--------------|-----------------|-----------------------------------------------------------------------------|
86
- | DeepSeek-VL2-tiny | 4096 | [πŸ€— Hugging Face](https://huggingface.co/deepseek-ai/deepseek-vl2-tiny) |
87
- | DeepSeek-VL2-small | 4096 | [πŸ€— Hugging Face](https://huggingface.co/deepseek-ai/deepseek-vl2-small) |
88
- | DeepSeek-VL2 | 4096 | [πŸ€— Hugging Face](https://huggingface.co/deepseek-ai/deepseek-vl2) |
89
-
90
-
91
- ## 4. Quick Start
92
-
93
- ### Installation
94
-
95
- On the basis of `Python >= 3.8` environment, install the necessary dependencies by running the following command:
96
-
97
- ```shell
98
- pip install -e .
99
- ```
100
-
101
- ### Simple Inference Example with One Image
102
-
103
- **Note: You may need 80GB GPU memory to run this script with deepseek-vl2-small and even larger for deepseek-vl2.**
104
-
105
- ```python
106
- import torch
107
- from transformers import AutoModelForCausalLM
108
-
109
- from deepseek_vl2.models import DeepseekVLV2Processor, DeepseekVLV2ForCausalLM
110
- from deepseek_vl2.utils.io import load_pil_images
111
-
112
-
113
- # specify the path to the model
114
- model_path = "deepseek-ai/deepseek-vl2-tiny"
115
- vl_chat_processor: DeepseekVLV2Processor = DeepseekVLV2Processor.from_pretrained(model_path)
116
- tokenizer = vl_chat_processor.tokenizer
117
-
118
- vl_gpt: DeepseekVLV2ForCausalLM = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True)
119
- vl_gpt = vl_gpt.to(torch.bfloat16).cuda().eval()
120
-
121
- ## single image conversation example
122
- ## Please note that <|ref|> and <|/ref|> are designed specifically for the object localization feature. These special tokens are not required for normal conversations.
123
- ## If you would like to experience the grounded captioning functionality (responses that include both object localization and reasoning), you need to add the special token <|grounding|> at the beginning of the prompt. Examples could be found in Figure 9 of our paper.
124
- conversation = [
125
- {
126
- "role": "<|User|>",
127
- "content": "<image>\n<|ref|>The giraffe at the back.<|/ref|>.",
128
- "images": ["./images/visual_grounding_1.jpeg"],
129
- },
130
- {"role": "<|Assistant|>", "content": ""},
131
- ]
132
-
133
- # load images and prepare for inputs
134
- pil_images = load_pil_images(conversation)
135
- prepare_inputs = vl_chat_processor(
136
- conversations=conversation,
137
- images=pil_images,
138
- force_batchify=True,
139
- system_prompt=""
140
- ).to(vl_gpt.device)
141
-
142
- # run image encoder to get the image embeddings
143
- inputs_embeds = vl_gpt.prepare_inputs_embeds(**prepare_inputs)
144
-
145
- # run the model to get the response
146
- outputs = vl_gpt.language.generate(
147
- inputs_embeds=inputs_embeds,
148
- attention_mask=prepare_inputs.attention_mask,
149
- pad_token_id=tokenizer.eos_token_id,
150
- bos_token_id=tokenizer.bos_token_id,
151
- eos_token_id=tokenizer.eos_token_id,
152
- max_new_tokens=512,
153
- do_sample=False,
154
- use_cache=True
155
- )
156
-
157
- answer = tokenizer.decode(outputs[0].cpu().tolist(), skip_special_tokens=False)
158
- print(f"{prepare_inputs['sft_format'][0]}", answer)
159
- ```
160
-
161
- And the output is something like:
162
- ```
163
- <|User|>: <image>
164
- <|ref|>The giraffe at the back.<|/ref|>.
165
-
166
- <|Assistant|>: <|ref|>The giraffe at the back.<|/ref|><|det|>[[580, 270, 999, 900]]<|/det|><|end▁of▁sentence|>
167
- ```
168
-
169
- ### Simple Inference Example with Multiple Images
170
-
171
- **Note: You may need 80GB GPU memory to run this script with deepseek-vl2-small and even larger for deepseek-vl2.**
172
-
173
- ```python
174
- import torch
175
- from transformers import AutoModelForCausalLM
176
-
177
- from deepseek_vl2.models import DeepseekVLV2Processor, DeepseekVLV2ForCausalLM
178
- from deepseek_vl2.utils.io import load_pil_images
179
-
180
-
181
- # specify the path to the model
182
- model_path = "deepseek-ai/deepseek-vl2-tiny"
183
- vl_chat_processor: DeepseekVLV2Processor = DeepseekVLV2Processor.from_pretrained(model_path)
184
- tokenizer = vl_chat_processor.tokenizer
185
-
186
- vl_gpt: DeepseekVLV2ForCausalLM = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True)
187
- vl_gpt = vl_gpt.to(torch.bfloat16).cuda().eval()
188
-
189
- # multiple images/interleaved image-text
190
- conversation = [
191
- {
192
- "role": "<|User|>",
193
- "content": "This is image_1: <image>\n"
194
- "This is image_2: <image>\n"
195
- "This is image_3: <image>\n Can you tell me what are in the images?",
196
- "images": [
197
- "images/multi_image_1.jpeg",
198
- "images/multi_image_2.jpeg",
199
- "images/multi_image_3.jpeg",
200
- ],
201
- },
202
- {"role": "<|Assistant|>", "content": ""}
203
- ]
204
-
205
- # load images and prepare for inputs
206
- pil_images = load_pil_images(conversation)
207
- prepare_inputs = vl_chat_processor(
208
- conversations=conversation,
209
- images=pil_images,
210
- force_batchify=True,
211
- system_prompt=""
212
- ).to(vl_gpt.device)
213
-
214
- # run image encoder to get the image embeddings
215
- inputs_embeds = vl_gpt.prepare_inputs_embeds(**prepare_inputs)
216
-
217
- # run the model to get the response
218
- outputs = vl_gpt.language.generate(
219
- inputs_embeds=inputs_embeds,
220
- attention_mask=prepare_inputs.attention_mask,
221
- pad_token_id=tokenizer.eos_token_id,
222
- bos_token_id=tokenizer.bos_token_id,
223
- eos_token_id=tokenizer.eos_token_id,
224
- max_new_tokens=512,
225
- do_sample=False,
226
- use_cache=True
227
- )
228
-
229
- answer = tokenizer.decode(outputs[0].cpu().tolist(), skip_special_tokens=False)
230
- print(f"{prepare_inputs['sft_format'][0]}", answer)
231
- ```
232
-
233
- And the output is something like:
234
- ```
235
- <|User|>: This is image_1: <image>
236
- This is image_2: <image>
237
- This is image_3: <image>
238
- Can you tell me what are in the images?
239
-
240
- <|Assistant|>: The images show three different types of vegetables. Image_1 features carrots, which are orange with green tops. Image_2 displays corn cobs, which are yellow with green husks. Image_3 contains raw pork ribs, which are pinkish-red with some marbling.<|end▁of▁sentence|>
241
- ```
242
-
243
- ### Simple Inference Example with Incremental Prefilling
244
-
245
- **Note: We use incremental prefilling to inference within 40GB GPU using deepseek-vl2-small.**
246
-
247
- ```python
248
- import torch
249
- from transformers import AutoModelForCausalLM
250
-
251
- from deepseek_vl2.models import DeepseekVLV2Processor, DeepseekVLV2ForCausalLM
252
- from deepseek_vl2.utils.io import load_pil_images
253
-
254
-
255
- # specify the path to the model
256
- model_path = "deepseek-ai/deepseek-vl2-small"
257
- vl_chat_processor: DeepseekVLV2Processor = DeepseekVLV2Processor.from_pretrained(model_path)
258
- tokenizer = vl_chat_processor.tokenizer
259
-
260
- vl_gpt: DeepseekVLV2ForCausalLM = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True)
261
- vl_gpt = vl_gpt.to(torch.bfloat16).cuda().eval()
262
-
263
- # multiple images/interleaved image-text
264
- conversation = [
265
- {
266
- "role": "<|User|>",
267
- "content": "This is image_1: <image>\n"
268
- "This is image_2: <image>\n"
269
- "This is image_3: <image>\n Can you tell me what are in the images?",
270
- "images": [
271
- "images/multi_image_1.jpeg",
272
- "images/multi_image_2.jpeg",
273
- "images/multi_image_3.jpeg",
274
- ],
275
- },
276
- {"role": "<|Assistant|>", "content": ""}
277
- ]
278
-
279
- # load images and prepare for inputs
280
- pil_images = load_pil_images(conversation)
281
- prepare_inputs = vl_chat_processor(
282
- conversations=conversation,
283
- images=pil_images,
284
- force_batchify=True,
285
- system_prompt=""
286
- ).to(vl_gpt.device)
287
-
288
- with torch.no_grad():
289
- # run image encoder to get the image embeddings
290
- inputs_embeds = vl_gpt.prepare_inputs_embeds(**prepare_inputs)
291
-
292
- # incremental_prefilling when using 40G GPU for vl2-small
293
- inputs_embeds, past_key_values = vl_gpt.incremental_prefilling(
294
- input_ids=prepare_inputs.input_ids,
295
- images=prepare_inputs.images,
296
- images_seq_mask=prepare_inputs.images_seq_mask,
297
- images_spatial_crop=prepare_inputs.images_spatial_crop,
298
- attention_mask=prepare_inputs.attention_mask,
299
- chunk_size=512 # prefilling size
300
- )
301
-
302
- # run the model to get the response
303
- outputs = vl_gpt.generate(
304
- inputs_embeds=inputs_embeds,
305
- input_ids=prepare_inputs.input_ids,
306
- images=prepare_inputs.images,
307
- images_seq_mask=prepare_inputs.images_seq_mask,
308
- images_spatial_crop=prepare_inputs.images_spatial_crop,
309
- attention_mask=prepare_inputs.attention_mask,
310
- past_key_values=past_key_values,
311
-
312
- pad_token_id=tokenizer.eos_token_id,
313
- bos_token_id=tokenizer.bos_token_id,
314
- eos_token_id=tokenizer.eos_token_id,
315
- max_new_tokens=512,
316
-
317
- do_sample=False,
318
- use_cache=True,
319
- )
320
-
321
- answer = tokenizer.decode(outputs[0][len(prepare_inputs.input_ids[0]):].cpu().tolist(), skip_special_tokens=False)
322
-
323
- print(f"{prepare_inputs['sft_format'][0]}", answer)
324
- ```
325
-
326
- And the output is something like:
327
- ```
328
- <|User|>: This is image_1: <image>
329
- This is image_2: <image>
330
- This is image_3: <image>
331
- Can you tell me what are in the images?
332
-
333
- <|Assistant|>: The first image contains carrots. The second image contains corn. The third image contains meat.<|end▁of▁sentence|>
334
- ```
335
-
336
- ### Full Inference Example
337
- ```shell
338
- # without incremental prefilling
339
- CUDA_VISIBLE_DEVICES=0 python inference.py --model_path "deepseek-ai/deepseek-vl2"
340
-
341
- # with incremental prefilling, when using 40G GPU for vl2-small
342
- CUDA_VISIBLE_DEVICES=0 python inference.py --model_path "deepseek-ai/deepseek-vl2-small" --chunk_size 512
343
-
344
- ```
345
-
346
-
347
- ### Gradio Demo
348
-
349
- * Install the necessary dependencies:
350
- ```shell
351
- pip install -e .[gradio]
352
- ```
353
-
354
- * then run the following command:
355
-
356
- ```shell
357
- # vl2-tiny, 3.37B-MoE in total, activated 1B, can be run on a single GPU < 40GB
358
- CUDA_VISIBLE_DEVICES=2 python web_demo.py \
359
- --model_name "deepseek-ai/deepseek-vl2-tiny" \
360
- --port 37914
361
-
362
-
363
- # vl2-small, 16.1B-MoE in total, activated 2.4B
364
- # If run on A100 40GB GPU, you need to set the `--chunk_size 512` for incremental prefilling for saving memory and it might be slow.
365
- # If run on > 40GB GPU, you can ignore the `--chunk_size 512` for faster response.
366
- CUDA_VISIBLE_DEVICES=2 python web_demo.py \
367
- --model_name "deepseek-ai/deepseek-vl2-small" \
368
- --port 37914 \
369
- --chunk_size 512
370
-
371
- # # vl27.5-MoE in total, activated 4.2B
372
- CUDA_VISIBLE_DEVICES=2 python web_demo.py \
373
- --model_name "deepseek-ai/deepseek-vl2" \
374
- --port 37914
375
- ```
376
-
377
- * **Important**: This is a basic and native demo implementation without any deployment optimizations, which may result in slower performance. For production environments, consider using optimized deployment solutions, such as vllm, sglang, lmdeploy, etc. These optimizations will help achieve faster response times and better cost efficiency.
378
-
379
- ## 5. License
380
-
381
- This code repository is licensed under [MIT License](./LICENSE-CODE). The use of DeepSeek-VL2 models is subject to [DeepSeek Model License](./LICENSE-MODEL). DeepSeek-VL2 series supports commercial use.
382
-
383
- ## 6. Citation
384
-
385
- ```
386
- @misc{wu2024deepseekvl2mixtureofexpertsvisionlanguagemodels,
387
- title={DeepSeek-VL2: Mixture-of-Experts Vision-Language Models for Advanced Multimodal Understanding},
388
- author={Zhiyu Wu and Xiaokang Chen and Zizheng Pan and Xingchao Liu and Wen Liu and Damai Dai and Huazuo Gao and Yiyang Ma and Chengyue Wu and Bingxuan Wang and Zhenda Xie and Yu Wu and Kai Hu and Jiawei Wang and Yaofeng Sun and Yukun Li and Yishi Piao and Kang Guan and Aixin Liu and Xin Xie and Yuxiang You and Kai Dong and Xingkai Yu and Haowei Zhang and Liang Zhao and Yisong Wang and Chong Ruan},
389
- year={2024},
390
- eprint={2412.10302},
391
- archivePrefix={arXiv},
392
- primaryClass={cs.CV},
393
- url={https://arxiv.org/abs/2412.10302},
394
- }
395
- ```
396
-
397
- ## 7. Contact
398
-
399
- If you have any questions, please raise an issue or contact us at [service@deepseek.com](mailto:service@deepseek.com).
 
1
+ title: Chat with DeepSeek-VL2-small
2
+ emoji: 🐬
3
+ colorFrom: blue
4
+ colorTo: red
5
+ sdk: gradio
6
+ sdk_version: 4.21.0
7
+ app_file: app.py
8
+ pinned: false
9
+ license: mit