sgl-project/sglang · error · ValueError

{path} must be a non-negative finite number

Error message

{path} must be a non-negative finite number

What it means

Optional non-negative condition floats must be finite and >= 0. Negative values, -inf, and NaN raise this error (unlike the positive variant, 0.0 is allowed).

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/minimax_h3/request_validation.py:76

def _optional_positive_finite_float(value: Any, path: str) -> float | None:
    if value is None:
        return None
    if isinstance(value, bool) or not isinstance(value, (int, float)):
        raise ValueError(f"{path} must be a number")
    normalized = float(value)
    if not math.isfinite(normalized) or normalized <= 0.0:
        raise ValueError(f"{path} must be a positive finite number")
    return normalized


def _optional_nonnegative_finite_float(value: Any, path: str) -> float | None:
    if value is None:
        return None
    if isinstance(value, bool) or not isinstance(value, (int, float)):
        raise ValueError(f"{path} must be a number")
    normalized = float(value)
    if not math.isfinite(normalized) or normalized < 0.0:
        raise ValueError(f"{path} must be a non-negative finite number")
    return normalized


def _validate_target(target: Any, *, profile: MiniMaxH3TaskProfile) -> dict[str, Any]:
    path = "target"
    if not isinstance(target, Mapping):
        raise ValueError(f"{path} is required and must be an object")
    # The canonical target has a deliberately small projection.  Transport
    # compatibility keys are ignored; only these three declared values are
    # validated and emitted below.
    short_edge = _require_int(target.get("short_edge"), f"{path}.short_edge")
    if short_edge <= 0:
        raise ValueError(f"{path}.short_edge must be positive, got {short_edge}")
    if short_edge != MINIMAX_H3_RECOMMENDED_SHORT_EDGE:
        # Same guard the resolver applies. Without it the recommended value warns
        # that it is "outside the verified configuration", naming itself as the
        # verified one.
        warn_unverified_short_edge(short_edge)

View on GitHub (pinned to 0132848349)

Solutions

  1. Clamp to max(0.0, v) after confirming finiteness client-side
  2. Fix timestamp computation so offsets are non-negative
  3. Check for NaN before serializing (json allows it by default)

Example fix

# before
{"start_time_seconds": -0.1}
# after
{"start_time_seconds": 0.0}
Defensive patterns

Strategy: validation

Validate before calling

import math
assert v is None or (math.isfinite(v) and v >= 0), f"{path} must be non-negative finite"

Type guard

import math
def opt_nonneg_finite(v: Any) -> bool:
    return v is None or (isinstance(v, (int, float)) and math.isfinite(v) and v >= 0)

Prevention

When it happens

Trigger: Passing start_time_seconds = -0.1, float('nan'), or -inf in a request's conditions block.

Common situations: Clock/reference mismatches producing small negative timestamps, or NaN propagating from upstream arithmetic on unset values.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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