sgl-project/sglang · error · ValueError

shape width and height must be positive finite numbers

Error message

shape width and height must be positive finite numbers

What it means

The width/height passed to minimax_h3_resolve_spatial_shape must be convertible to float. This variant fires when float(width)/float(height) raises TypeError (None) or ValueError (a non-numeric string).

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/minimax_h3/resolved_plan.py:133

    *,
    width: int | float,
    height: int | float,
    base_short_edge: int = MINIMAX_H3_BASE_SHORT_EDGE,
) -> dict[str, Any]:
    """Resolve one display ratio with the ``adapt_shape_v1`` math.

    This is the only implementation of adaptive target geometry. Callers may
    pass an explicit aspect-ratio pair or probed display dimensions; only the
    ratio is significant. The supported ratio range is inclusive 1:4 to 4:1.
    The returned dimensions are always 32px aligned; nearest-grid rounding may
    leave the final area slightly above the pre-round soft pixel budget.
    """
    base_short_edge = _validate_base_short_edge(base_short_edge)
    try:
        source_width = float(width)
        source_height = float(height)
    except (TypeError, ValueError) as exc:
        raise ValueError(
            "shape width and height must be positive finite numbers"
        ) from exc
    if (
        not math.isfinite(source_width)
        or not math.isfinite(source_height)
        or source_width <= 0.0
        or source_height <= 0.0
    ):
        raise ValueError("shape width and height must be positive finite numbers")

    ratio = source_width / source_height
    if not math.isfinite(ratio) or ratio <= 0.0:
        raise ValueError("shape ratio must be a positive finite number")
    if not MINIMAX_H3_MIN_ASPECT_RATIO <= ratio <= MINIMAX_H3_MAX_ASPECT_RATIO:
        raise ValueError(
            "adapt_shape_v1 ratio must be within the inclusive range "
            f"1:4 to 4:1, got {source_width:g}:{source_height:g}"
        )

View on GitHub (pinned to 0132848349)

Solutions

  1. Probe the source media for real pixel dimensions first and pass numbers
  2. Default/skip resolution when the probe returns None instead of forwarding it

Example fix

# before
shape = resolve_spatial_shape(w=probe.get("width"), h=probe.get("height"), ...)
# after
if probe.get("width") is None: raise RetryableProbeError(...)
shape = resolve_spatial_shape(w=probe["width"], h=probe["height"], ...)
Defensive patterns

Strategy: validation

Validate before calling

def dims_ok(w, h):
    try: return float(w) > 0 and float(h) > 0
    except (TypeError, ValueError): return False

Type guard

def is_valid_dims(w, h) -> bool:
    try:
        return float(w) > 0 and float(h) > 0
    except (TypeError, ValueError):
        return False

Try / catch

null

Prevention

When it happens

Trigger: Calling minimax_h3_resolve_spatial_shape with width=None or height='auto' — anything float() cannot parse.

Common situations: Passing an unresolved/deferred shape dict before probing actual media dimensions; a metadata probe failed and returned None.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/194d10e9ed809763. Report an issue: GitHub.