[Bugfix] Count unsplit Idefics3 image patches (#48760)
Signed-off-by: nightcityblade <nightcityblade@gmail.com> Co-authored-by: nightcityblade <nightcityblade@gmail.com> Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
This commit is contained in:
co-authored by
nightcityblade
Cyrus Leung
parent
8b84e15066
commit
5b3f280a6d
@@ -17,6 +17,7 @@ from ...utils import build_model_context
|
||||
[
|
||||
({"max_image_size": {"longest_edge": 384}}, 1377),
|
||||
({"max_image_size": {"longest_edge": 768}}, 405),
|
||||
({"do_image_splitting": False}, 81),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("num_imgs", [1, 2])
|
||||
@@ -63,6 +64,14 @@ def test_processor_override(
|
||||
|
||||
# Ensure the placeholders format are correct
|
||||
hf_processor = processor.info.get_hf_processor(**hf_processor_mm_kwargs)
|
||||
num_patches = processor.info.get_num_patches(
|
||||
image_width=dummy_image.width,
|
||||
image_height=dummy_image.height,
|
||||
processor=hf_processor,
|
||||
mm_kwargs=hf_processor_mm_kwargs,
|
||||
)
|
||||
assert num_patches == expected_toks_per_img // hf_processor.image_seq_len
|
||||
|
||||
hf_processed_inputs = hf_processor(
|
||||
text=prompt,
|
||||
images=mm_data["image"],
|
||||
|
||||
@@ -137,7 +137,7 @@ class Idefics3ProcessingInfo(BaseProcessingInfo):
|
||||
mm_kwargs=mm_kwargs,
|
||||
)
|
||||
|
||||
return num_patches
|
||||
return max(num_patches, 1)
|
||||
|
||||
def _get_image_token(self, processor: Idefics3Processor) -> tuple[str, str, str]:
|
||||
image_token = processor.image_token
|
||||
|
||||
Reference in New Issue
Block a user