{"record":{"id":"03b57b617ebee919","repo":"sgl-project/sglang","slug":"encounter-invalid-h-bar-h-bar-w-bar-w-bar","errorCode":null,"errorMessage":"encounter invalid h_bar: {h_bar}, w_bar: {w_bar}","messagePattern":"encounter invalid h_bar: (.+?), w_bar: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/multimodal/processors/ernie45_vl.py","lineNumber":79,"sourceCode":"            new_height = max(factor, round_by_factor(height, factor))\n            new_width = floor_by_factor(new_height * MAX_RATIO, factor)\n\n        height = new_height\n        width = new_width\n\n    h_bar = max(factor, round_by_factor(height, factor))\n    w_bar = max(factor, round_by_factor(width, factor))\n    if h_bar * w_bar > max_pixels:\n        beta = math.sqrt((height * width) / max_pixels)\n        h_bar = floor_by_factor(height / beta, factor)\n        w_bar = floor_by_factor(width / beta, factor)\n    elif h_bar * w_bar < min_pixels:\n        beta = math.sqrt(min_pixels / (height * width))\n        h_bar = ceil_by_factor(height * beta, factor)\n        w_bar = ceil_by_factor(width * beta, factor)\n\n    if min_pixels > h_bar * w_bar or h_bar * w_bar > max_pixels:\n        raise ValueError(f\"encounter invalid h_bar: {h_bar}, w_bar: {w_bar}\")\n\n    return h_bar, w_bar\n\n\ndef resize_image(\n    image,\n    min_pixels: int = MIN_PIXELS,\n    max_pixels: int = MAX_PIXELS,\n    size_factor: int = IMAGE_FACTOR,\n) -> Image.Image:\n    width, height = image.size\n    min_pixels = min_pixels\n    max_pixels = max_pixels\n    resized_height, resized_width = smart_resize(\n        height,\n        width,\n        factor=size_factor,\n        min_pixels=min_pixels,","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/multimodal/processors/ernie45_vl.py#L61-L97","documentation":"Raised by ernie45_vl.smart_resize after scaling the image to satisfy a min_pixels constraint: the ceil-by-factor adjustment pushed h_bar*w_bar below min_pixels or above max_pixels, so no valid factored resolution exists. This happens when min_pixels/max_pixels are inconsistent (min > max) or the pixel bounds are incompatible with the factor (patch size) quantization.","triggerScenarios":"Calling resize_image or preprocess_video with min_pixels > max_pixels; min_pixels so close to max_pixels that ceil_by_factor jumps over the window; height or width of 0 / degenerate input.","commonSituations":"Overriding processor kwargs with user-supplied min_pixels/max_pixels without ordering them (e.g. min=1000000, max=786432); copying limits tuned for a different patch factor; tiny/corrupt images where scaling can't land on a factor multiple inside bounds.","solutions":["Ensure min_pixels <= max_pixels and leave a factor-sized gap between them (multiple of 28*28=784 for factor 16 style patches)","Sanitize user overrides before calling preprocess: clamp min_pixels to at most max_pixels","Reject or upscale degenerate images (width/height < factor) before preprocessing"],"exampleFix":"# before\nres = processor.resize_image(img, min_pixels=1003520, max_pixels=786432)\n# after\nMIN = 4*28*28*4; MAX = 16384*28*28\nres = processor.resize_image(img, min_pixels=min(MIN, MAX), max_pixels=MAX)","handlingStrategy":"validation","validationCode":"F = 28; FAC = F*F\nif not (min_pixels <= max_pixels) or (max_pixels - min_pixels) < 4*FAC:\n    min_pixels = min(min_pixels, max_pixels - 4*FAC)\nif img.width < F or img.height < F:\n    raise SkipSample('image smaller than patch factor')","typeGuard":"def sane_pixel_bounds(min_p: int, max_p: int, factor: int = 28) -> bool:\n    return min_p <= max_p and (max_p - min_p) >= factor*factor","tryCatchPattern":"try:\n    h, w = smart_resize(ih, iw, factor, min_p, max_p)\nexcept ValueError:\n    h, w = smart_resize(ih, iw, factor, FACTOR*FACTOR*4, 16384*FACTOR*FACTOR)  # safe defaults","preventionTips":["Never let user min_pixels exceed max_pixels","Keep a factor-multiple gap between bounds","Reject images with dimensions below the patch factor"],"tags":["multimodal","image-preprocessing","ernie-4-5-vl","pixel-limits"],"backgroundTag":"image-resize-bounds-violation","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}