A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 16, 02:00 UTC
[Model] Port deepseek-vl2 processor, remove dependency (#12169)
Signed-off-by: Isotr0py <2037008807@qq.com>
Isotr0py committed
Jan 18, 2025 at 13:59 UTC
02798ecabed36f4c255f5a12ad6c271f95cd8c4e
8 files changed
+385
-49
.buildkite/test-pipeline.yaml
-1
@@ -52,7 +52,6 @@ steps:
52
- tests/worker
53
- tests/standalone_tests/lazy_torch_compile.py
54
commands:
55
- - pip install git+https://github.com/Isotr0py/DeepSeek-VL2.git # Used by multimoda processing test
55
- python3 standalone_tests/lazy_torch_compile.py
56
- pytest -v -s mq_llm_engine # MQLLMEngine
57
- pytest -v -s async_engine # AsyncLLMEngine
docs/source/models/supported_models.md
+2
-8
@@ -767,16 +767,10 @@ See [this page](#generative-models) for more information on how to use generativ
767
<sup>E</sup> Pre-computed embeddings can be inputted for this modality.
768
<sup>+</sup> Multiple items can be inputted per text prompt for this modality.
769
770
-````{note}
771
-To use `DeepSeek-VL2` series models, you need to install a fork version `deepseek_vl2` package:
772
-
773
-```shell
774
-pip install git+https://github.com/Isotr0py/DeepSeek-VL2.git
770
+```{note}
771
+To use `DeepSeek-VL2` series models, you have to pass `--hf_overrides '{"architectures": ["DeepseekVLV2ForCausalLM"]}'` when running vLLM.
772
```
773
777
-Besides, to run `DeepSeek-VL2` series models, you have to pass `--hf_overrides '{"architectures": ["DeepseekVLV2ForCausalLM"]}'` when running vLLM.
778
-````
779
-
774
```{note}
775
To use `TIGER-Lab/Mantis-8B-siglip-llama3`, you have to pass `--hf_overrides '{"architectures": ["MantisForConditionalGeneration"]}'` when running vLLM.
776
```
examples/offline_inference/vision_language_multi_image.py
+1
-1
@@ -393,7 +393,7 @@ def load_qwen2_vl(question, image_urls: List[str]) -> ModelRequestData:
393
394
model_example_map = {
395
"aria": load_aria,
396
- "deepseek_vl2": load_deepseek_vl2,
396
+ "deepseek_vl_v2": load_deepseek_vl2,
397
"h2ovl_chat": load_h2onvl,
398
"idefics3": load_idefics3,
399
"internvl_chat": load_internvl,
tests/models/decoder_only/vision_language/test_models.py
+1
-1
@@ -190,7 +190,7 @@ VLM_TEST_SETTINGS = {
190
dtype="bfloat16",
191
),
192
"deepseek_vl_v2": VLMTestInfo(
193
- models=["deepseek-ai/deepseek-vl2-tiny"],
193
+ models=["Isotr0py/deepseek-vl2-tiny"], # model repo using dynamic module
194
test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
195
prompt_formatter=lambda img_prompt: f"<|User|>: {img_prompt}\n\n<|Assistant|>: ", # noqa: E501
196
max_model_len=4096,
tests/models/multimodal/processing/test_common.py
+3
@@ -22,6 +22,8 @@ def _test_processing_correctness(
22
):
23
if model_id == "TIGER-Lab/Mantis-8B-siglip-llama3":
24
hf_overrides = {"architectures": ["MantisForConditionalGeneration"]}
25
+ elif model_id == "deepseek-ai/deepseek-vl2-tiny":
26
+ hf_overrides = {"architectures": ["DeepseekVLV2ForCausalLM"]}
27
else:
28
hf_overrides = {}
29
@@ -139,6 +141,7 @@ def _test_processing_correctness(
141
("rhymes-ai/Aria", {"image": True}),
142
("Salesforce/blip2-opt-2.7b", {"image": False}),
143
("facebook/chameleon-7b", {"image": False}),
144
+ ("deepseek-ai/deepseek-vl2-tiny", {"image": True}),
145
("adept/fuyu-8b", {"image": False}),
146
("llava-hf/llava-1.5-7b-hf", {"image": True}),
147
("llava-hf/llava-v1.6-mistral-7b-hf", {"image": True}),
vllm/model_executor/models/deepseek_vl2.py
+13
-38
@@ -1,7 +1,7 @@
1
# adapted from https://github.com/deepseek-ai/DeepSeek-VL2/blob/faf18023f24b962b32d9f0a2d89e402a8d383a78/deepseek_vl2/models/modeling_deepseek_vl_v2.py
2
"""Inference-only Deepseek-VL2 model compatible with HuggingFace weights."""
3
import math
4
-from functools import cached_property, partial
4
+from functools import cached_property
5
from typing import (Iterable, List, Literal, Mapping, Optional, Set, Tuple,
6
TypedDict, Union)
7
@@ -9,7 +9,7 @@ import torch
9
import torch.nn as nn
10
import torch.nn.functional as F
11
from einops import rearrange, repeat
12
-from transformers import AutoProcessor, BatchFeature, ProcessorMixin
12
+from transformers import BatchFeature
13
14
from vllm.attention import AttentionMetadata
15
from vllm.config import VllmConfig
@@ -31,6 +31,8 @@ from vllm.sequence import IntermediateTensors
31
from vllm.transformers_utils.configs.deepseek_vl2 import (DeepseekVLV2Config,
32
MlpProjectorConfig,
33
VisionEncoderConfig)
34
+from vllm.transformers_utils.processors.deepseek_vl2 import (
35
+ DeepseekVLV2Processor)
36
from vllm.utils import is_list_of
37
38
from .interfaces import SupportsMultiModal, SupportsPP
@@ -129,25 +131,8 @@ class DeepseekVL2ProcessingInfo(BaseProcessingInfo):
131
def get_hf_config(self):
132
return self.ctx.get_hf_config(DeepseekVLV2Config)
133
132
- def get_hf_processor(self) -> ProcessorMixin:
133
- # TODO(Isotr0py): we should get rid of dependency on deepseek_vl2
134
- # in the future, because it's flasky and lack of maintenance.
135
- try:
136
- from deepseek_vl2.models.processing_deepseek_vl_v2 import (
137
- DeepseekVLV2Processor, select_best_resolution)
138
- AutoProcessor.register("DeepseekVLV2Processor",
139
- DeepseekVLV2Processor)
140
- except ModuleNotFoundError as exc:
141
- raise ModuleNotFoundError(
142
- "You need to `pip install "
143
- "git+https://github.com/deepseek-ai/DeepSeek-VL2.git` "
144
- "to use this model") from exc
145
-
146
- processor = self.ctx.get_hf_processor(DeepseekVLV2Processor)
147
- processor.select_best_resolution = partial(
148
- select_best_resolution,
149
- candidate_resolutions=processor.candidate_resolutions)
150
- return processor
134
+ def get_hf_processor(self) -> DeepseekVLV2Processor:
135
+ return self.ctx.get_hf_processor(DeepseekVLV2Processor)
136
137
def get_supported_mm_limits(self) -> Mapping[str, Optional[int]]:
138
return {"image": None}
@@ -224,31 +209,21 @@ class DeepseekVL2MultiModalProcessor(
209
mm_kwargs: Mapping[str, object],
210
) -> BatchFeature:
211
if mm_data:
227
- outputs = self.info.ctx.call_hf_processor(
212
+ processed_outputs = self.info.ctx.call_hf_processor(
213
self.info.get_hf_processor(**mm_kwargs),
214
dict(prompt=prompt, **mm_data),
215
mm_kwargs,
216
)
232
-
233
- # Deepseek-vl2 processor don't return BatchFeature,
234
- # we need to manually create it
235
- processed_outputs = dict(input_ids=outputs["input_ids"])
236
- processed_outputs = BatchFeature(data=dict(processed_outputs),
237
- tensor_type="pt")
238
-
239
- # Remove batch dimension from processor outputs,
240
- # because we will try batch to create NestedTensors
217
target_dtype = self.info.ctx.model_config.dtype
242
- pixel_values = outputs["images"].to(target_dtype).squeeze(0)
243
- images_spatial_crop = outputs["images_spatial_crop"].squeeze(0)
218
+ pixel_values = processed_outputs.pop("pixel_values").to(
219
+ target_dtype)
220
+ # split pixel values into patches corresponding to each image
221
+ images_spatial_crop = processed_outputs["images_spatial_crop"]
222
patches_per_image = [
223
x.prod().item() + 1 for x in images_spatial_crop
224
]
247
-
248
- # Rename `images` -> `pixel_values` to avoid confusion
249
- processed_outputs["pixel_values"] = list(
250
- pixel_values.split(patches_per_image))
251
- processed_outputs["images_spatial_crop"] = images_spatial_crop
225
+ pixel_values = pixel_values.split(patches_per_image)
226
+ processed_outputs["pixel_values"] = pixel_values
227
else:
228
tokenizer = self.info.get_tokenizer()
229
processed_outputs = tokenizer(prompt,
vllm/transformers_utils/processors/__init__.py
new
+4
@@ -0,0 +1,4 @@
1
+from vllm.transformers_utils.processors.deepseek_vl2 import (
2
+ DeepseekVLV2Processor)
3
+
4
+__all__ = ["DeepseekVLV2Processor"]
vllm/transformers_utils/processors/deepseek_vl2.py
new
+361
@@ -0,0 +1,361 @@
1
+# yapf: disable
2
+# ruff: noqa: E501
3
+# coding=utf-8
4
+# adapted from https://github.com/deepseek-ai/DeepSeek-VL2/blob/ff23960c5cf9e6874b44be38af930cfb0ccbb620/deepseek_vl2/models/processing_deepseek_vl_v2.py
5
+# Copyright (c) 2023-2024 DeepSeek.
6
+#
7
+# Permission is hereby granted, free of charge, to any person obtaining a copy of
8
+# this software and associated documentation files (the "Software"), to deal in
9
+# the Software without restriction, including without limitation the rights to
10
+# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11
+# the Software, and to permit persons to whom the Software is furnished to do so,
12
+# subject to the following conditions:
13
+#
14
+# The above copyright notice and this permission notice shall be included in all
15
+# copies or substantial portions of the Software.
16
+#
17
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19
+# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20
+# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21
+# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+import math
25
+from typing import List, Tuple
26
+
27
+import torch
28
+import torchvision.transforms as T
29
+from PIL import Image, ImageOps
30
+from transformers import AutoProcessor, BatchFeature, LlamaTokenizerFast
31
+from transformers.processing_utils import ProcessorMixin
32
+
33
+
34
+class ImageTransform:
35
+
36
+ def __init__(self,
37
+ mean: Tuple[float, float, float] = (0.5, 0.5, 0.5),
38
+ std: Tuple[float, float, float] = (0.5, 0.5, 0.5),
39
+ normalize: bool = True):
40
+ self.mean = mean
41
+ self.std = std
42
+ self.normalize = normalize
43
+
44
+ transform_pipelines = [T.ToTensor()]
45
+
46
+ if normalize:
47
+ transform_pipelines.append(T.Normalize(mean, std))
48
+
49
+ self.transform = T.Compose(transform_pipelines)
50
+
51
+ def __call__(self, pil_img: Image.Image):
52
+ x = self.transform(pil_img)
53
+ return x
54
+
55
+
56
+class DeepseekVLV2Processor(ProcessorMixin):
57
+ tokenizer_class = ("LlamaTokenizer", "LlamaTokenizerFast")
58
+ attributes = ["tokenizer"]
59
+
60
+ def __init__(
61
+ self,
62
+ tokenizer: LlamaTokenizerFast,
63
+ candidate_resolutions: Tuple[Tuple[int, int]],
64
+ patch_size: int,
65
+ downsample_ratio: int,
66
+ image_mean: Tuple[float, float, float] = (0.5, 0.5, 0.5),
67
+ image_std: Tuple[float, float, float] = (0.5, 0.5, 0.5),
68
+ normalize: bool = True,
69
+ image_token: str = "<image>",
70
+ pad_token: str = "<|▁pad▁|>",
71
+ add_special_token: bool = False,
72
+ sft_format: str = "deepseek",
73
+ mask_prompt: bool = True,
74
+ ignore_id: int = -100,
75
+ **kwargs,
76
+ ):
77
+
78
+ self.candidate_resolutions = candidate_resolutions
79
+ self.image_size = candidate_resolutions[0][0]
80
+ self.patch_size = patch_size
81
+ self.image_mean = image_mean
82
+ self.image_std = image_std
83
+ self.normalize = normalize
84
+ self.downsample_ratio = downsample_ratio
85
+
86
+ self.image_transform = ImageTransform(mean=image_mean, std=image_std, normalize=normalize)
87
+ self.tokenizer = tokenizer
88
+ self.tokenizer.padding_side = 'left' # must set this,padding side with make a difference in batch inference
89
+
90
+ # add the pad_token as special token to use 'tokenizer.pad_token' and 'tokenizer.pad_token_id'
91
+ if tokenizer.pad_token is None:
92
+ self.tokenizer.add_special_tokens({'pad_token': pad_token})
93
+
94
+ # add image token
95
+ image_token_id = self.tokenizer.vocab.get(image_token)
96
+ if image_token_id is None:
97
+ special_tokens = [image_token]
98
+ special_tokens_dict = {"additional_special_tokens": special_tokens}
99
+ self.tokenizer.add_special_tokens(special_tokens_dict)
100
+ self.image_token_id = self.tokenizer.vocab.get(image_token)
101
+
102
+ # add five special tokens for grounding-related tasks
103
+ # <|ref|>, <|/ref|>, <|det|>, <|/det|>, <|grounding|>
104
+ special_tokens = ['<|ref|>', '<|/ref|>', '<|det|>', '<|/det|>', '<|grounding|>']
105
+ special_tokens_dict = {"additional_special_tokens": special_tokens}
106
+ self.tokenizer.add_special_tokens(special_tokens_dict)
107
+
108
+ # add special tokens for SFT data
109
+ special_tokens = ["<|User|>", "<|Assistant|>"]
110
+ special_tokens_dict = {"additional_special_tokens": special_tokens}
111
+ self.tokenizer.add_special_tokens(special_tokens_dict)
112
+
113
+ self.image_token = image_token
114
+ self.pad_token = pad_token
115
+ self.add_special_token = add_special_token
116
+ self.sft_format = sft_format
117
+ self.mask_prompt = mask_prompt
118
+ self.ignore_id = ignore_id
119
+
120
+ super().__init__(
121
+ tokenizer,
122
+ **kwargs,
123
+ )
124
+
125
+ def select_best_resolution(self, image_size):
126
+ # used for cropping
127
+ original_width, original_height = image_size
128
+ best_fit = None
129
+ max_effective_resolution = 0
130
+ min_wasted_resolution = float("inf")
131
+
132
+ for width, height in self.candidate_resolutions:
133
+ scale = min(width / original_width, height / original_height)
134
+ downscaled_width, downscaled_height = int(
135
+ original_width * scale), int(original_height * scale)
136
+ effective_resolution = min(downscaled_width * downscaled_height,
137
+ original_width * original_height)
138
+ wasted_resolution = (width * height) - effective_resolution
139
+
140
+ if effective_resolution > max_effective_resolution or (
141
+ effective_resolution == max_effective_resolution
142
+ and wasted_resolution < min_wasted_resolution):
143
+ max_effective_resolution = effective_resolution
144
+ min_wasted_resolution = wasted_resolution
145
+ best_fit = (width, height)
146
+
147
+ return best_fit
148
+
149
+ @property
150
+ def bos_id(self):
151
+ return self.tokenizer.bos_token_id
152
+
153
+ @property
154
+ def eos_id(self):
155
+ return self.tokenizer.eos_token_id
156
+
157
+ @property
158
+ def pad_id(self):
159
+ return self.tokenizer.pad_token_id
160
+
161
+ def encode(self, text: str, bos: bool = True, eos: bool = False):
162
+ t = self.tokenizer.encode(text, add_special_tokens=False)
163
+
164
+ if bos:
165
+ t = [self.bos_id] + t
166
+ if eos:
167
+ t = t + [self.eos_id]
168
+
169
+ return t
170
+
171
+ def decode(self, t: List[int], **kwargs) -> str:
172
+ return self.tokenizer.decode(t, **kwargs)
173
+
174
+ def process_one(
175
+ self,
176
+ prompt: str,
177
+ images: List[Image.Image],
178
+ inference_mode: bool = True,
179
+ **kwargs,
180
+ ):
181
+ """
182
+
183
+ Args:
184
+ prompt (str): the formatted prompt;
185
+ conversations (List[Dict]): conversations with a list of messages;
186
+ images (List[ImageType]): the list of images;
187
+ inference_mode (bool): if True, then remove the last eos token;
188
+ system_prompt (str): the system prompt;
189
+ **kwargs:
190
+
191
+ Returns:
192
+ outputs (BaseProcessorOutput): the output of the processor,
193
+ - input_ids (torch.LongTensor): [N + image tokens]
194
+ - target_ids (torch.LongTensor): [N + image tokens]
195
+ - pixel_values (torch.FloatTensor): [n_patches, 3, H, W]
196
+ - image_id (int): the id of the image token
197
+ - num_image_tokens (List[int]): the number of image tokens
198
+ """
199
+
200
+ assert (prompt is not None and images is not None
201
+ ), "prompt and images must be used at the same time."
202
+
203
+ sft_format = prompt
204
+ tokenized_str, images_list, images_seq_mask, images_spatial_crop, num_image_tokens = self.tokenize_with_images(
205
+ sft_format, images, bos=True, eos=True, cropping=len(images) <= 2)
206
+ masked_tokenized_str = []
207
+ for token_index in tokenized_str:
208
+ if token_index != self.image_token_id:
209
+ masked_tokenized_str.append(token_index)
210
+ else:
211
+ masked_tokenized_str.append(self.ignore_id)
212
+
213
+ assert len(tokenized_str) == len(images_seq_mask) == len(masked_tokenized_str), \
214
+ (f"tokenized_str's length {len(tokenized_str)}, input_ids' length {len(masked_tokenized_str)}, "
215
+ f"imags_seq_mask's length {len(images_seq_mask)}, are not equal")
216
+
217
+ input_ids = torch.LongTensor(tokenized_str)
218
+ target_ids = torch.LongTensor(masked_tokenized_str)
219
+ images_seq_mask = torch.tensor(images_seq_mask, dtype=torch.bool)
220
+
221
+ # set input_ids < 0 | input_ids == self.image_token_id as ignore_id
222
+ target_ids[(input_ids < 0) |
223
+ (input_ids == self.image_token_id)] = self.ignore_id
224
+ input_ids[input_ids < 0] = self.pad_id
225
+
226
+ if inference_mode:
227
+ # 去掉结尾的eos token
228
+ assert input_ids[-1] == self.eos_id
229
+ input_ids = input_ids[:-1]
230
+ target_ids = target_ids[:-1]
231
+ images_seq_mask = images_seq_mask[:-1]
232
+
233
+ if len(images_list) == 0:
234
+ pixel_values = torch.zeros((1, 3, self.image_size, self.image_size))
235
+ images_spatial_crop = torch.zeros((1, 2), dtype=torch.long)
236
+ else:
237
+ pixel_values = torch.stack(images_list, dim=0)
238
+ images_spatial_crop = torch.tensor(images_spatial_crop, dtype=torch.long)
239
+
240
+ input_ids = input_ids.unsqueeze(0)
241
+
242
+ prepare = BatchFeature(
243
+ data=dict(
244
+ input_ids=input_ids,
245
+ pixel_values=pixel_values,
246
+ images_seq_mask=images_seq_mask,
247
+ images_spatial_crop=images_spatial_crop,
248
+ num_image_tokens=num_image_tokens,
249
+ ),
250
+ tensor_type="pt",
251
+ )
252
+ return prepare
253
+
254
+ def __call__(
255
+ self,
256
+ *,
257
+ prompt: str,
258
+ images: List[Image.Image],
259
+ inference_mode: bool = True,
260
+ **kwargs,
261
+ ):
262
+ """
263
+
264
+ Args:
265
+ prompt (str): the formatted prompt;
266
+ images (List[ImageType]): the list of images;
267
+ inference_mode (bool): if True, then remove the last eos token;
268
+ **kwargs:
269
+
270
+ Returns:
271
+ outputs (BaseProcessorOutput): the output of the processor,
272
+ - input_ids (torch.LongTensor): [N + image tokens]
273
+ - images (torch.FloatTensor): [n_images, 3, H, W]
274
+ - image_id (int): the id of the image token
275
+ - num_image_tokens (List[int]): the number of image tokens
276
+ """
277
+
278
+ prepare = self.process_one(
279
+ prompt=prompt,
280
+ images=images,
281
+ inference_mode=inference_mode,
282
+ )
283
+
284
+ return prepare
285
+
286
+ def tokenize_with_images(
287
+ self,
288
+ conversation: str,
289
+ images: List[Image.Image],
290
+ bos: bool = True,
291
+ eos: bool = True,
292
+ cropping: bool = True,
293
+ ):
294
+ """Tokenize text with <image> tags."""
295
+ assert conversation.count(self.image_token) == len(images)
296
+ text_splits = conversation.split(self.image_token)
297
+ images_list, images_seq_mask, images_spatial_crop = [], [], []
298
+ num_image_tokens = []
299
+ tokenized_str = []
300
+ for text_sep, image in zip(text_splits, images):
301
+ """encode text_sep"""
302
+ tokenized_sep = self.encode(text_sep, bos=False, eos=False)
303
+ tokenized_str += tokenized_sep
304
+ images_seq_mask += [False] * len(tokenized_sep)
305
+
306
+ """select best resolution for anyres"""
307
+ if cropping:
308
+ best_width, best_height = self.select_best_resolution(image.size)
309
+ else:
310
+ best_width, best_height = self.image_size, self.image_size
311
+
312
+ """process the global view"""
313
+ global_view = ImageOps.pad(image, (self.image_size, self.image_size),
314
+ color=tuple(int(x * 255) for x in self.image_transform.mean))
315
+ images_list.append(self.image_transform(global_view))
316
+
317
+ """process the local views"""
318
+ local_view = ImageOps.pad(image, (best_width, best_height),
319
+ color=tuple(int(x * 255) for x in self.image_transform.mean))
320
+ for i in range(0, best_height, self.image_size):
321
+ for j in range(0, best_width, self.image_size):
322
+ images_list.append(
323
+ self.image_transform(local_view.crop((j, i, j + self.image_size, i + self.image_size))))
324
+
325
+ """record height / width crop num"""
326
+ num_width_tiles, num_height_tiles = best_width // self.image_size, best_height // self.image_size
327
+ images_spatial_crop.append([num_width_tiles, num_height_tiles])
328
+
329
+ """add image tokens"""
330
+ h = w = math.ceil((self.image_size // self.patch_size) / self.downsample_ratio)
331
+ # global views tokens h * (w + 1), 1 is for line separator
332
+ tokenized_image = [self.image_token_id] * h * (w + 1)
333
+ # add a separator between global and local views
334
+ tokenized_image += [self.image_token_id]
335
+ # local views tokens, (num_height_tiles * h) * (num_width_tiles * w + 1)
336
+ tokenized_image += [self.image_token_id] * (num_height_tiles * h) * (num_width_tiles * w + 1)
337
+
338
+ tokenized_str += tokenized_image
339
+ images_seq_mask += [True] * len(tokenized_image)
340
+ num_image_tokens.append(len(tokenized_image))
341
+
342
+ """process the last text split"""
343
+ tokenized_sep = self.encode(text_splits[-1], bos=False, eos=False)
344
+ tokenized_str += tokenized_sep
345
+ images_seq_mask += [False] * len(tokenized_sep)
346
+
347
+ """add the bos and eos tokens"""
348
+ if bos:
349
+ tokenized_str = [self.bos_id] + tokenized_str
350
+ images_seq_mask = [False] + images_seq_mask
351
+ if eos:
352
+ tokenized_str = tokenized_str + [self.eos_id]
353
+ images_seq_mask = images_seq_mask + [False]
354
+
355
+ assert len(tokenized_str) == len(
356
+ images_seq_mask), f"tokenize_with_images func: tokenized_str's length {len(tokenized_str)} is not equal to imags_seq_mask's length {len(images_seq_mask)}"
357
+
358
+ return tokenized_str, images_list, images_seq_mask, images_spatial_crop, num_image_tokens
359
+
360
+
361
+AutoProcessor.register("DeepseekVLV2Processor", DeepseekVLV2Processor)