[Bugfix][GLM-5.3] Size the image encoder cache from the exact token ceiling (#59565)

Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
Co-authored-by: Kimi Code <kimi-code@moonshot.cn>
Co-authored-by: Isotr0py <Isotr0py@outlook.com>
This commit is contained in:
Yufeng He
2026-10-02 10:43:29 +00:00
committed by GitHub
co-authored by Kimi Code Isotr0py
parent af2a582d5c
commit 5688a4dd4a
2 changed files with 75 additions and 0 deletions
+24
View File
@@ -2,6 +2,7 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""GLM-5.3-Flash vision tower and multimodal processor."""
import math
from collections.abc import Mapping
from functools import partial
from typing import Any
@@ -672,6 +673,29 @@ class Glm5NextProcessingInfo(Glm4vProcessingInfo):
return int(override)
return self._processor_pixel_budget(self.get_hf_processor().video_processor)[1]
def get_image_size_with_most_features(self) -> ImageSize:
# The inherited square probe strands budget whenever the token
# ceiling is not a perfect square: with max_image_tokens=8000 the
# square refits to 2492x2492 (89x89 = 7921 tokens) while a
# 2240x2800 canvas reaches 80x100 = 8000, so the encoder cache came
# up short of the processor's own maximum and refused valid images
# (#59539). Factor the ceiling exactly instead of probing a square.
vision_config = self.get_hf_config().vision_config
factor = (
vision_config.patch_size
* vision_config.spatial_merge_size
* self.get_hf_processor().image_processor.patch_expand_factor
)
pixels_per_token = vision_config.temporal_patch_size * factor * factor
max_tokens = max(1, self._get_image_max_pixels() // pixels_per_token)
short_side = math.isqrt(max_tokens)
while max_tokens % short_side:
short_side -= 1
return ImageSize(
width=(max_tokens // short_side) * factor,
height=short_side * factor,
)
def _get_video_second_idx_glm46v(
self, metadata: dict[str, Any], total_frames: int
) -> list[int]: