@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / dcf6ee8592
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 8, 08:45 UTC

[Bugfix] Fix encoder cache underestimation for GLM-4V/GLM-OCR single image (#34483)

Signed-off-by: haosdent <haosdent@gmail.com>

haosdent committed Feb 13, 2026 at 13:04 UTC dcf6ee8592b4f33593feb579b7a420d155ada374
1 file changed +22 -2
vllm/model_executor/models/glm4_1v.py
+22 -2
@@ -869,9 +869,28 @@ class Glm4vProcessingInfo(BaseProcessingInfo):
869
870 return preprocessed_size, num_vision_tokens
871
872 + def _get_image_max_pixels(self) -> int:
873 + """Read max_pixels from the HF image processor config.
874 +
875 + Despite the name, ``longest_edge`` is a pixel **area** (total pixel
876 + count), not an edge length. The HF processor passes it directly to
877 + ``smart_resize`` as the ``max_pixels`` argument, which constrains
878 + ``t_bar * h_bar * w_bar <= max_pixels``.
879 + """
880 + return self.get_image_processor().size["longest_edge"]
881 +
882 def get_image_size_with_most_features(self) -> ImageSize:
883 + # Use num_frames=1 for single-image budget estimation.
884 + # _get_vision_info defaults to num_frames=16 (video), which
885 + # makes smart_resize constrain 16*H*W <= max_pixels, vastly
886 + # underestimating the spatial budget for a single image and
887 + # causing encoder cache overflow for large images
888 + # (see https://github.com/vllm-project/vllm/issues/34040).
889 max_image_size, _ = self._get_vision_info(
874 - image_width=9999999, image_height=9999999
890 + image_width=9999999,
891 + image_height=9999999,
892 + num_frames=1,
893 + max_image_pixels=self._get_image_max_pixels(),
894 )
895 return max_image_size
896
@@ -884,7 +903,8 @@ class Glm4vProcessingInfo(BaseProcessingInfo):
903 _, num_image_tokens = self._get_vision_info(
904 image_width=image_width,
905 image_height=image_height,
887 - max_image_pixels=28 * 28 * 2 * 6144,
906 + num_frames=1,
907 + max_image_pixels=self._get_image_max_pixels(),
908 )
909 return num_image_tokens
910