transformers
9d5d0ee8 - Add `_get_num_multimodal_tokens` to more image/video processors (#50671)

Commit
1 day ago
Add `_get_num_multimodal_tokens` to more image/video processors (#50671) * Add `_get_num_multimodal_tokens` to more processors vLLM's Transformers modeling backend needs `_get_num_multimodal_tokens` to size placeholders without running the processor. Add it for image, video and audio processors whose models scatter features into `inputs_embeds`. The common image test now skips processors without an image processor, and the audio test's two-audios-per-text half can be disabled for processors that pair one audio with each text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> * Add `_get_num_multimodal_tokens` to Granite Speech Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> * Drop `_get_num_multimodal_tokens` from audio-only processors vLLM's Transformers backend only calls it with image and video sizes, so revert the audio-only processors and the audio branches of Inkling and Nemotron-H Omni. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> * Count embedding tokens for Llama4 and Ovis2 without `image_token_ids` overrides vLLM reads placeholders from `text_replacement_offsets`, not `mm_token_type_ids`, so revert the overrides and test the counts against the replacements instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> * Use dict literals in Llama4/Ovis2 token count tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> * Run the image token count test on both image processor backends Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> * Note GOT-OCR2 `num_image_tokens` fallback goes with the v5.29.0 deprecation Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> * Count embedding tokens from replacements in the token count tests `mm_token_type_ids` marks start/end/separator tokens for some models and not others, so compare `_get_num_multimodal_tokens` against the most repeated token in each item's `text_replacement_offsets` replacement instead, which is what vLLM counts. Align the helpers that also counted those extra tokens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> * Count embedding tokens from replacements in the SmolVLM and LFM2-VL tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> * Address review: fewer helpers in the token counters - LFM2-VL: drop `get_image_layout` and `get_number_of_image_patches` from the image processor; the processor resolves the kwargs and calls `_get_split_layout` itself. - Ovis2: inline `_get_tile_grid` back into its callers in both backends. - UnlimitedOCR: move the local patch grid computation from the image processor into the processor. - Molmo2: compute the `<im_patch>` count from the grid instead of building the replacement string. - DeepSeek-OCR-2: clarify why one patch is subtracted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Author
Parents
Loading