sgl-project/sglang · error · RuntimeError

SGLANG_USE_MLX requires stable Torch 2.13.x and MLX >= 0.32.

Error message

SGLANG_USE_MLX requires stable Torch 2.13.x and MLX >= 0.32.0; found Torch {torch_version or 'unknown'} + MLX {mlx_version or 'unknown'}; reinstall with the srt_mps extra

What it means

Raised by the MLX runtime validator when `mlx.core` imports fine but the installed Torch/MLX version pair is unsupported: Torch must be a stable 2.13.x release and MLX must be >= 0.32.0. The message echoes the versions it found (or 'unknown' if __version__ is missing), so mismatched or pre-release/dev builds fail fast.

Source

Thrown at python/sglang/srt/hardware_backend/mlx/runtime.py:45

    return not version.is_prerelease and version >= minimum


@lru_cache(maxsize=1)
def _validate_runtime() -> None:
    try:
        import mlx.core as mx
    except ImportError:
        raise RuntimeError(
            "SGLANG_USE_MLX requires stable Torch 2.13.x and MLX >= 0.32.0, "
            "but MLX is not installed; reinstall with "
            "the srt_mps extra"
        ) from None
    mlx_version = getattr(mx, "__version__", None)
    torch_version = getattr(torch, "__version__", None)
    if not _is_stable_series(
        torch_version, _SUPPORTED_TORCH_SERIES
    ) or not _is_stable_at_least(mlx_version, _MIN_MLX_VERSION):
        raise RuntimeError(
            "SGLANG_USE_MLX requires stable Torch 2.13.x and MLX >= 0.32.0; "
            "found "
            f"Torch {torch_version or 'unknown'} + MLX {mlx_version or 'unknown'}; "
            "reinstall with the srt_mps extra"
        )

    mps_backend = getattr(torch.backends, "mps", None)
    is_mps_available = getattr(mps_backend, "is_available", None)
    if not callable(is_mps_available) or not is_mps_available():
        raise RuntimeError("SGLANG_USE_MLX requires an available PyTorch MPS device")

    metal = getattr(mx, "metal", None)
    is_available = getattr(metal, "is_available", None)
    if not callable(is_available) or not is_available():
        raise RuntimeError("SGLANG_USE_MLX requires an available MLX Metal device")


@lru_cache(maxsize=1)

View on GitHub (pinned to 0132848349)

Solutions

  1. Reinstall via the srt_mps extra which pins compatible versions: pip install -e ".[srt_mps]" --force-reinstall
  2. Pin torch to the stable 2.13.x line (e.g. pip install 'torch~=2.13.0')
  3. Upgrade MLX: pip install -U 'mlx>=0.32.0'
  4. Check reported versions: python -c "import torch, mlx.core as mx; print(torch.__version__, mx.__version__)"
  5. Disable the backend (unset SGLANG_USE_MLX) if you don't need MLX

Example fix

# before: torch 2.14.0.dev / mlx 0.29
pip install torch==2.14.0.dev20260801 mlx==0.29.0
# after
pip install 'torch==2.13.*' 'mlx>=0.32.0'
Defensive patterns

Strategy: validation

Validate before calling

import torch
from packaging.version import Version
def mlx_versions_ok():
    t = Version(torch.__version__.split("+")[0])
    assert t.release[:2] == (2, 13), f"torch {t} not 2.13.x"
    import mlx.core as mx
    assert Version(mx.__version__) >= Version("0.32.0"), f"mlx {mx.__version__} < 0.32.0"
    return True

Try / catch

try:
    use_mlx()
except RuntimeError as e:
    if "reinstall with" in str(e):
        pin_and_reinstall()  # torch~=2.13.0, mlx>=0.32.0
    raise

Prevention

When it happens

Trigger: SGLANG_USE_MLX=1 with Torch 2.12/2.14 or a nightly/rc 2.13 build (_is_stable_series fails), or MLX < 0.32.0, or an mlx.core/torch build lacking __version__.

Common situations: Upgrading Torch past 2.13.x; using torch nightly wheels; an old MLX pinned by another package; version attributes missing in stripped/nightly builds.

Related errors


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