{"record":{"id":"9620d2f4ac3dff55","repo":"sgl-project/sglang","slug":"shape-ratio-must-be-a-positive-finite-number","errorCode":null,"errorMessage":"shape ratio must be a positive finite number","messagePattern":"shape ratio must be a positive finite number","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/minimax_h3/resolved_plan.py","lineNumber":146,"sourceCode":"    base_short_edge = _validate_base_short_edge(base_short_edge)\n    try:\n        source_width = float(width)\n        source_height = float(height)\n    except (TypeError, ValueError) as exc:\n        raise ValueError(\n            \"shape width and height must be positive finite numbers\"\n        ) from exc\n    if (\n        not math.isfinite(source_width)\n        or not math.isfinite(source_height)\n        or source_width <= 0.0\n        or source_height <= 0.0\n    ):\n        raise ValueError(\"shape width and height must be positive finite numbers\")\n\n    ratio = source_width / source_height\n    if not math.isfinite(ratio) or ratio <= 0.0:\n        raise ValueError(\"shape ratio must be a positive finite number\")\n    if not MINIMAX_H3_MIN_ASPECT_RATIO <= ratio <= MINIMAX_H3_MAX_ASPECT_RATIO:\n        raise ValueError(\n            \"adapt_shape_v1 ratio must be within the inclusive range \"\n            f\"1:4 to 4:1, got {source_width:g}:{source_height:g}\"\n        )\n\n    if ratio >= 1.0:\n        nominal_width = float(base_short_edge) * ratio\n        nominal_height = float(base_short_edge)\n    else:\n        nominal_width = float(base_short_edge)\n        nominal_height = float(base_short_edge) / ratio\n    nominal_area = nominal_width * nominal_height\n    if nominal_area > MINIMAX_H3_MAX_PIXELS:\n        size_mode = \"area\"\n        scale = math.sqrt(float(MINIMAX_H3_MAX_PIXELS) / nominal_area)\n        nominal_width *= scale\n        nominal_height *= scale","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/minimax_h3/resolved_plan.py#L128-L164","documentation":"After width/height pass finiteness checks, their ratio must itself be a positive finite number. In practice this only fires for degenerate float cases (e.g. width=5e-324 with height huge making the ratio underflow to 0, or overflow to inf).","triggerScenarios":"Calling minimax_h3_resolve_spatial_shape with extremely tiny/huge dimension pairs whose division underflows to 0.0 or overflows to inf despite both inputs being finite and positive.","commonSituations":"Denormalized float dimensions from a buggy scaler; passing values in the wrong units (e.g. normalized 0.0001 fractions).","solutions":["Pass true pixel dimensions, not normalized/unitless fractions","Clamp inputs to a sane pixel range (e.g. 1..100000) before resolving"],"exampleFix":"# before\nresolve_spatial_shape(width=0.0001, height=10000.0, ...)\n# after\nresolve_spatial_shape(width=1920, height=1080, ...)","handlingStrategy":"validation","validationCode":"import math\ndef ratio_finite(w, h):\n    try: r = float(w) / float(h); return math.isfinite(r) and r > 0\n    except (TypeError, ValueError, ZeroDivisionError): return False","typeGuard":"def has_finite_ratio(w, h) -> bool:\n    import math\n    try:\n        r = float(w) / float(h)\n        return math.isfinite(r) and r > 0\n    except Exception:\n        return False","tryCatchPattern":"null","preventionTips":["Pass true pixel dimensions, never normalized fractions"],"tags":["minimax-h3","spatial","ratio","floating-point"],"backgroundTag":"floating-point-overflow","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}