[Bugfix][Processor] Replace bare asserts with ValueError in DeepseekVLV2/OCR processors (#53854)

Signed-off-by: adisivaprasad <adisivaprasad@users.noreply.github.com>
Co-authored-by: adisivaprasad <adisivaprasad@users.noreply.github.com>
This commit is contained in:
adisivaprasad
2026-08-26 09:10:54 +00:00
committed by GitHub
co-authored by adisivaprasad
parent 2267d3b112
commit 73bd7c83c4
3 changed files with 42 additions and 8 deletions
@@ -250,9 +250,8 @@ class DeepseekOCRProcessor(ProcessorMixin):
- num_image_tokens (List[int]): the number of image tokens
"""
assert prompt is not None and images is not None, (
"prompt and images must be used at the same time."
)
if prompt is None or images is None:
raise ValueError("prompt and images must be used at the same time.")
sft_format = prompt
@@ -311,7 +310,13 @@ class DeepseekOCRProcessor(ProcessorMixin):
):
"""Tokenize text with <image> tags."""
assert conversation.count(self.image_token) == len(images)
num_image_tags = conversation.count(self.image_token)
if num_image_tags != len(images):
raise ValueError(
f"Number of {self.image_token!r} tokens in prompt "
f"({num_image_tags}) does not match number of images "
f"({len(images)})."
)
text_splits = conversation.split(self.image_token)
images_list, images_crop_list, images_seq_mask, images_spatial_crop = (
[],
@@ -203,9 +203,8 @@ class DeepseekVLV2Processor(ProcessorMixin):
- num_image_tokens (list[int]): the number of image tokens
"""
assert prompt is not None and images is not None, (
"prompt and images must be used at the same time."
)
if prompt is None or images is None:
raise ValueError("prompt and images must be used at the same time.")
sft_format = prompt
(
@@ -310,7 +309,13 @@ class DeepseekVLV2Processor(ProcessorMixin):
cropping: bool = True,
):
"""Tokenize text with <image> tags."""
assert conversation.count(self.image_token) == len(images)
num_image_tags = conversation.count(self.image_token)
if num_image_tags != len(images):
raise ValueError(
f"Number of {self.image_token!r} tokens in prompt "
f"({num_image_tags}) does not match number of images "
f"({len(images)})."
)
text_splits = conversation.split(self.image_token)
images_list, images_seq_mask, images_spatial_crop = [], [], []
num_image_tokens = []