sgl-project/sglang · error · ValueError

target.short_edge must be a positive integer, got {value!r}

Error message

target.short_edge must be a positive integer, got {value!r}

What it means

base_short_edge must be a positive integer and exactly integral — the check `short_edge != value` rejects floats like 512.5 and booleans, and `<= 0` rejects zero/negative values.

Source

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

        raise ValueError(
            f"target.aspect_ratio components must be positive, got {value!r}"
        )
    return w, h


def _nearest_multiple(value: float, multiple: int) -> int:
    return max(multiple, int(round(float(value) / multiple)) * multiple)


def _validate_base_short_edge(value: Any) -> int:
    try:
        short_edge = int(value)
    except (TypeError, ValueError) as exc:
        raise ValueError(
            f"target.short_edge must be an integer, got {value!r}"
        ) from exc
    if short_edge != value or short_edge <= 0:
        raise ValueError(f"target.short_edge must be a positive integer, got {value!r}")
    if short_edge != MINIMAX_H3_BASE_SHORT_EDGE:
        warn_unverified_short_edge(short_edge)
    return short_edge


def minimax_h3_resolve_spatial_shape(
    *,
    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.

View on GitHub (pinned to 0132848349)

Solutions

  1. Round/ceil the computed short edge to a whole positive integer
  2. Ensure scale factors can't drive it to zero

Example fix

# before
edge = base_edge * scale  # 256.5
# after
edge = max(1, round(base_edge * scale))
Defensive patterns

Strategy: validation

Validate before calling

def edge_ok(v):
    try: return int(v) == v and int(v) > 0
    except (TypeError, ValueError): return False

Type guard

def is_valid_short_edge(v) -> bool:
    try: return int(v) == v and int(v) > 0
    except (TypeError, ValueError): return False

Try / catch

null

Prevention

When it happens

Trigger: Calling minimax_h3_resolve_spatial_shape with base_short_edge=512.5, 0, -64, or True (bool compares equal to 1 but the equality/positivity logic plus intent fails for fractional/zero values).

Common situations: Dividing a configured edge by 2 or a scale factor producing a .5 float; passing a scaled-down value that rounds to 0.

Related errors


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