sgl-project/sglang · error · ValueError

scalar_type_id {scalar_type_id} doesn't exists.

Error message

scalar_type_id {scalar_type_id} doesn't exists.

What it means

scalar_type.from_id looks up a compressed-integer scalar type (as used by torch.compile / inductor for quantized dtypes) in a static registry keyed by small integer IDs. If the ID is not registered, it raises, since there is no scalar type to construct.

Source

Thrown at python/sglang/kernels/aot/python/sgl_kernel/scalar_type.py:312

        cls, exponent: int, mantissa: int, finite_values_only: bool, nan_repr: NanRepr
    ) -> "ScalarType":
        """
        Create a non-standard floating point type
        (i.e. does not follow IEEE 754 conventions).
        """
        assert mantissa > 0 and exponent > 0
        assert nan_repr != NanRepr.IEEE_754, (
            "use `float_IEEE754` constructor for floating point types that "
            "follow IEEE 754 conventions"
        )
        ret = cls(exponent, mantissa, True, 0, finite_values_only, nan_repr)
        ret.id  # noqa B018: make sure the id is cached
        return ret

    @classmethod
    def from_id(cls, scalar_type_id: int):
        if scalar_type_id not in _SCALAR_TYPES_ID_MAP:
            raise ValueError(f"scalar_type_id {scalar_type_id} doesn't exists.")
        return _SCALAR_TYPES_ID_MAP[scalar_type_id]


# naming generally follows: https://github.com/jax-ml/ml_dtypes
# for floating point types (leading f) the scheme is:
#  `float<size_bits>_e<exponent_bits>m<mantissa_bits>[flags]`
#  flags:
#  - no-flags: means it follows IEEE 754 conventions
#  - f: means finite values only (no infinities)
#  - n: means nans are supported (non-standard encoding)
# for integer types the scheme is:
#  `[u]int<size_bits>[b<bias>]`
#  - if bias is not present it means its zero


class scalar_types:
    int4 = ScalarType.int_(4, None)
    uint4 = ScalarType.uint(4, None)

View on GitHub (pinned to 0132848349)

Solutions

  1. Upgrade sgl-kernel (and torch) so the registry knows the ID that was serialized
  2. Regenerate/re-serialize the artifact with the current versions instead of reusing old IDs
  3. Print sorted(_SCALAR_TYPES_ID_MAP) to confirm which IDs are supported before from_id

Example fix

# before
t = ScalarType.from_id(some_id)
# after
from python.sgl_kernel.scalar_type import _SCALAR_TYPES_ID_MAP
assert some_id in _SCALAR_TYPES_ID_MAP, f'unknown id {some_id}'
t = ScalarType.from_id(some_id)
Defensive patterns

Strategy: type-guard

Validate before calling

from sgl_kernel.scalar_type import _SCALAR_TYPES_ID_MAP
if sid not in _SCALAR_TYPES_ID_MAP: raise KeyError(f'unsupported scalar_type_id {sid}')

Type guard

def known_scalar_id(sid): return sid in _SCALAR_TYPES_ID_MAP

Prevention

When it happens

Trigger: Calling ScalarType.from_id(n) with n not in _SCALAR_TYPES_ID_MAP — e.g. a newly introduced torch scalar type ID, a hand-invented ID, or an ID from a mismatched torch version serialized by newer code.

Common situations: Loading quantized torch.compile artifacts or configs produced by a different PyTorch/sgl-kernel version where new scalar types were added; deserializing ids from untrusted/stale sources.

Related errors


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