{"record":{"id":"37a25f294d360775","repo":"sgl-project/sglang","slug":"absolute-aspect-ratio-must-be-smaller-than-200-go","errorCode":null,"errorMessage":"absolute aspect ratio must be smaller than 200, got {max(height, width) / min(height, width)}","messagePattern":"absolute aspect ratio must be smaller than 200, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/multimodal/processors/mimo_v2.py","lineNumber":1346,"sourceCode":"        seconds = int(timestamp % 60)\n        return f\"{minutes:02d}:{seconds:02d}\"\n\n    @staticmethod\n    def smart_resize(\n        height: int, width: int, factor: int, min_pixels: int, max_pixels: int\n    ):\n        \"\"\"Rescales the image so that the following conditions are met:\n\n        1. Both dimensions (height and width) are divisible by 'factor'.\n        2. The total number of pixels is within the range ['min_pixels', 'max_pixels'].\n        3. The aspect ratio of the image is maintained as closely as possible.\n        \"\"\"\n        if min(height, width) < factor:\n            scale = factor / min(height, width)\n            height = int(round(height * scale))\n            width = int(round(width * scale))\n        elif max(height, width) / min(height, width) > 200:\n            raise ValueError(\n                f\"absolute aspect ratio must be smaller than 200, got {max(height, width) / min(height, width)}\"\n            )\n        h_bar = round(height / factor) * factor\n        w_bar = round(width / factor) * factor\n        if h_bar * w_bar > max_pixels:\n            beta = math.sqrt((height * width) / max_pixels)\n            h_bar = math.floor(height / beta / factor) * factor\n            w_bar = math.floor(width / beta / factor) * factor\n        elif h_bar * w_bar < min_pixels:\n            beta = math.sqrt(min_pixels / (height * width))\n            h_bar = math.ceil(height * beta / factor) * factor\n            w_bar = math.ceil(width * beta / factor) * factor\n        return int(h_bar), int(w_bar)\n\n    @staticmethod\n    def to_rgb(pil_image: Image.Image) -> Image.Image:\n        if pil_image.mode == \"RGBA\":\n            white_background = Image.new(\"RGB\", pil_image.size, (255, 255, 255))","sourceCodeStart":1328,"sourceCodeEnd":1364,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/multimodal/processors/mimo_v2.py#L1328-L1364","documentation":"Raised by smart_resize in MiMo-V2 when, after the min-side upscale step, the image's aspect ratio (long side / short side) still exceeds 200. Such extreme panoramas would blow up the patch grid, so the resize algorithm rejects them outright.","triggerScenarios":"Feeding an image whose width/height ratio (or height/width) is > 200 — e.g. a 20000x100 strip or a 50x20000 column — into process_image / get_visual_transform on a MiMo-V2 model.","commonSituations":"Panoramic banners, scan strips, or long screenshots sent as chat images; accidentally transposed dimensions; pathological/edge-case images in test corpora or adversarial inputs.","solutions":["Reject or downscale extreme-aspect images client-side before sending (crop or tile the panorama)","Center-crop the long side to bring the ratio under 200, or slice the strip into multiple images","Add a pre-upload validation on image dimensions (max(long)/min(short) < 200)"],"exampleFix":"# before\nim = Image.open('banner_20000x100.png'); proc.process_image(ImageInput(image=im))  # ValueError\n# after\nim = Image.open('banner_20000x100.png')\nif max(im.size)/min(im.size) >= 200:\n    w, h = im.size\n    im = im.crop((0, 0, min(w, h*199), h))  # crop long side\nproc.process_image(ImageInput(image=im))","handlingStrategy":"validation","validationCode":"w, h = im.size\nif min(w, h) == 0 or max(w, h) / min(w, h) >= 200:\n    raise UserInputError(f'image aspect ratio {max(w,h)/min(w,h):.0f} too extreme; crop or tile first')","typeGuard":"def is_acceptable_aspect(im) -> bool:\n    w, h = im.size\n    return min(w, h) > 0 and max(w, h) / min(w, h) < 200","tryCatchPattern":"try:\n    out = proc.process_image(image_input)\nexcept ValueError as e:\n    if 'aspect ratio' in str(e):\n        return error_response(400, 'image too elongated; crop to aspect ratio < 200')\n    raise","preventionTips":["Validate dimensions at upload time","Tile/crop panoramas into multiple normal-aspect images","Watch for transposed width/height bugs in preprocessing"],"tags":["image","aspect-ratio","resize","input-validation"],"backgroundTag":"image-dimension-validation","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}