{"record":{"id":"66065fa8ef4dcafe","repo":"sgl-project/sglang","slug":"sglang-use-mlx-requires-stable-torch-2-13-x-and-ml-66065f","errorCode":null,"errorMessage":"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","messagePattern":"SGLANG_USE_MLX requires stable Torch 2\\.13\\.x and MLX >= 0\\.32\\.0; found Torch (.+?) \\+ MLX (.+?); reinstall with the srt_mps extra","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/hardware_backend/mlx/runtime.py","lineNumber":45,"sourceCode":"    return not version.is_prerelease and version >= minimum\n\n\n@lru_cache(maxsize=1)\ndef _validate_runtime() -> None:\n    try:\n        import mlx.core as mx\n    except ImportError:\n        raise RuntimeError(\n            \"SGLANG_USE_MLX requires stable Torch 2.13.x and MLX >= 0.32.0, \"\n            \"but MLX is not installed; reinstall with \"\n            \"the srt_mps extra\"\n        ) from None\n    mlx_version = getattr(mx, \"__version__\", None)\n    torch_version = getattr(torch, \"__version__\", None)\n    if not _is_stable_series(\n        torch_version, _SUPPORTED_TORCH_SERIES\n    ) or not _is_stable_at_least(mlx_version, _MIN_MLX_VERSION):\n        raise RuntimeError(\n            \"SGLANG_USE_MLX requires stable Torch 2.13.x and MLX >= 0.32.0; \"\n            \"found \"\n            f\"Torch {torch_version or 'unknown'} + MLX {mlx_version or 'unknown'}; \"\n            \"reinstall with the srt_mps extra\"\n        )\n\n    mps_backend = getattr(torch.backends, \"mps\", None)\n    is_mps_available = getattr(mps_backend, \"is_available\", None)\n    if not callable(is_mps_available) or not is_mps_available():\n        raise RuntimeError(\"SGLANG_USE_MLX requires an available PyTorch MPS device\")\n\n    metal = getattr(mx, \"metal\", None)\n    is_available = getattr(metal, \"is_available\", None)\n    if not callable(is_available) or not is_available():\n        raise RuntimeError(\"SGLANG_USE_MLX requires an available MLX Metal device\")\n\n\n@lru_cache(maxsize=1)","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/hardware_backend/mlx/runtime.py#L27-L63","documentation":"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.","triggerScenarios":"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__.","commonSituations":"Upgrading Torch past 2.13.x; using torch nightly wheels; an old MLX pinned by another package; version attributes missing in stripped/nightly builds.","solutions":["Reinstall via the srt_mps extra which pins compatible versions: pip install -e \".[srt_mps]\" --force-reinstall","Pin torch to the stable 2.13.x line (e.g. pip install 'torch~=2.13.0')","Upgrade MLX: pip install -U 'mlx>=0.32.0'","Check reported versions: python -c \"import torch, mlx.core as mx; print(torch.__version__, mx.__version__)\"","Disable the backend (unset SGLANG_USE_MLX) if you don't need MLX"],"exampleFix":"# before: torch 2.14.0.dev / mlx 0.29\npip install torch==2.14.0.dev20260801 mlx==0.29.0\n# after\npip install 'torch==2.13.*' 'mlx>=0.32.0'","handlingStrategy":"validation","validationCode":"import torch\nfrom packaging.version import Version\ndef mlx_versions_ok():\n    t = Version(torch.__version__.split(\"+\")[0])\n    assert t.release[:2] == (2, 13), f\"torch {t} not 2.13.x\"\n    import mlx.core as mx\n    assert Version(mx.__version__) >= Version(\"0.32.0\"), f\"mlx {mx.__version__} < 0.32.0\"\n    return True","typeGuard":null,"tryCatchPattern":"try:\n    use_mlx()\nexcept RuntimeError as e:\n    if \"reinstall with\" in str(e):\n        pin_and_reinstall()  # torch~=2.13.0, mlx>=0.32.0\n    raise","preventionTips":["Pin torch~=2.13.0 and mlx>=0.32.0 in requirements","Avoid torch nightly/rc wheels when SGLANG_USE_MLX is set","Add a version preflight to deploy scripts"],"tags":["mlx","version-mismatch","torch","mps","sglang"],"backgroundTag":"version-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}