From ac7f3e11ea88fff26e322f529c2e563dac2f663a Mon Sep 17 00:00:00 2001 From: ahmed xijiaat <52128022+xijiaat@users.noreply.github.com> Date: Wed, 30 Sep 2026 00:21:27 +0900 Subject: [PATCH] [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 Co-authored-by: Isotr0py --- .../deepseek_v41/common/mm_preprocess.py | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/vllm/models/deepseek_v41/common/mm_preprocess.py b/vllm/models/deepseek_v41/common/mm_preprocess.py index 7710edb43f..017f5f87a2 100644 --- a/vllm/models/deepseek_v41/common/mm_preprocess.py +++ b/vllm/models/deepseek_v41/common/mm_preprocess.py @@ -275,15 +275,28 @@ class DeepseekV4VLProcessingInfo(BaseProcessingInfo): hf_config = self.get_hf_config() patch_size = hf_config.vision_patch_size downsample_ratio = hf_config.vision_downsample_ratio - # A square maximizes the ViT patch count (area) within the token - # budget; solve the budget-derived size directly to keep the dummy - # image small. budget = hf_config.vision_max_n_token - side = budget * patch_size * downsample_ratio - best_h, best_w = solve_resize_ratio( - side, side, patch_size, downsample_ratio, budget - ) - return ImageSize(width=best_w, height=best_h) + max_wh_ratio = hf_config.vision_max_wh_ratio + best_h = best_w = 0 + # Each LLM row costs an extra newline token. Maximize the ViT grid, + # including the patch rounding after the optional aspect-ratio clamp. + for n_llm_h in range(1, (budget - 2) // 2 + 1): + n_vit_h = n_llm_h * downsample_ratio + n_vit_w = ((budget - 2) // n_llm_h - 1) * downsample_ratio + if max_wh_ratio is not None: + n_vit_w = min(n_vit_w, math.ceil(n_vit_h * max_wh_ratio)) + if n_vit_h * n_vit_w > best_h * best_w: + best_h, best_w = n_vit_h, n_vit_w + if best_h == 0: + raise ValueError( + "Image token budget and aspect ratio allow no image patches" + ) + height, width = best_h * patch_size, best_w * patch_size + # Avoid the min-pixels upscaler perturbing the selected aspect ratio. + scale = 1 + while height * width * scale * scale < hf_config.vision_min_pixels: + scale *= 2 + return ImageSize(width=width * scale, height=height * scale) class DeepseekV4VLDummyInputsBuilder(