[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>
This commit is contained in:
ahmed xijiaat
2026-09-29 15:21:27 +00:00
committed by GitHub
co-authored by OpenAI Codex Isotr0py
parent 741edeebee
commit ac7f3e11ea
@@ -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(