@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 741f4e046b
Fork 0

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 6, 21:45 UTC

fix: align lfm2 thumbnail token counting with HF (#36707)

tianshu-Michael-yu committed Mar 11, 2026 at 10:28 UTC 741f4e046bb7e5c5a6093d9fc294865ad7a8e721
1 file changed +19 -1
vllm/model_executor/models/lfm2_vl.py
+19 -1
@@ -324,7 +324,25 @@ class Lfm2VLProcessingInfo(BaseProcessingInfo):
324 )
325 tile_size = mm_kwargs.get("tile_size", image_processor.tile_size)
326
327 - num_thumbnail_tokens = spatial_shapes[-1].prod() // (downsample_factor**2)
327 + thumbnail_height_patches = int(spatial_shapes[-1][0].item())
328 + thumbnail_width_patches = int(spatial_shapes[-1][1].item())
329 + # HF computes thumbnail tokens as
330 + # ceil(h_patches / downsample_factor) * ceil(w_patches / downsample_factor).
331 + # We assert divisibility here so any processor/model drift is surfaced
332 + # immediately instead of being hidden by floor division.
333 + assert thumbnail_height_patches % downsample_factor == 0, (
334 + "LFM2-VL thumbnail height patch grid must be divisible by "
335 + f"downsample_factor, got height_patches={thumbnail_height_patches}, "
336 + f"downsample_factor={downsample_factor}"
337 + )
338 + assert thumbnail_width_patches % downsample_factor == 0, (
339 + "LFM2-VL thumbnail width patch grid must be divisible by "
340 + f"downsample_factor, got width_patches={thumbnail_width_patches}, "
341 + f"downsample_factor={downsample_factor}"
342 + )
343 + num_thumbnail_tokens = math.ceil(
344 + thumbnail_height_patches / downsample_factor
345 + ) * math.ceil(thumbnail_width_patches / downsample_factor)
346 num_patches_tile = tile_size // encoder_patch_size
347 dwn_num_patches_tile = math.ceil(num_patches_tile / downsample_factor)
348 num_tiles_tokens = dwn_num_patches_tile * dwn_num_patches_tile