[Bugfix] Profile maximum DeepSeek V4.1 vision features (#57898)

Signed-off-by: ahmed xijiaat <52128022+xijiaat@users.noreply.github.com> Co-authored-by: OpenAI Codex <noreply@openai.com> Co-authored-by: Isotr0py <Isotr0py@outlook.com>

ahmed xijiaat committed Sep 30, 2026 at 00:21 UTC ac7f3e11ea88fff26e322f529c2e563dac2f663a
1 file changed +21 -8
vllm/models/deepseek_v41/common/mm_preprocess.py
+21 -8
@@ -275,15 +275,28 @@ class DeepseekV4VLProcessingInfo(BaseProcessingInfo):
275 hf_config = self.get_hf_config()
276 patch_size = hf_config.vision_patch_size
277 downsample_ratio = hf_config.vision_downsample_ratio
278 - # A square maximizes the ViT patch count (area) within the token
279 - # budget; solve the budget-derived size directly to keep the dummy
280 - # image small.
278 budget = hf_config.vision_max_n_token
282 - side = budget * patch_size * downsample_ratio
283 - best_h, best_w = solve_resize_ratio(
284 - side, side, patch_size, downsample_ratio, budget
285 - )
286 - return ImageSize(width=best_w, height=best_h)
279 + max_wh_ratio = hf_config.vision_max_wh_ratio
280 + best_h = best_w = 0
281 + # Each LLM row costs an extra newline token. Maximize the ViT grid,
282 + # including the patch rounding after the optional aspect-ratio clamp.
283 + for n_llm_h in range(1, (budget - 2) // 2 + 1):
284 + n_vit_h = n_llm_h * downsample_ratio
285 + n_vit_w = ((budget - 2) // n_llm_h - 1) * downsample_ratio
286 + if max_wh_ratio is not None:
287 + n_vit_w = min(n_vit_w, math.ceil(n_vit_h * max_wh_ratio))
288 + if n_vit_h * n_vit_w > best_h * best_w:
289 + best_h, best_w = n_vit_h, n_vit_w
290 + if best_h == 0:
291 + raise ValueError(
292 + "Image token budget and aspect ratio allow no image patches"
293 + )
294 + height, width = best_h * patch_size, best_w * patch_size
295 + # Avoid the min-pixels upscaler perturbing the selected aspect ratio.
296 + scale = 1
297 + while height * width * scale * scale < hf_config.vision_min_pixels:
298 + scale *= 2
299 + return ImageSize(width=width * scale, height=height * scale)
300
301
302 class DeepseekV4VLDummyInputsBuilder(