Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Environment:Sgl project Sglang Python Dependencies

From Leeroopedia


Knowledge Sources
Domains Infrastructure, Python
Last Updated 2026-02-10 00:00 GMT

Overview

Python 3.10+ environment with pinned dependencies including PyTorch 2.9.1, Transformers 4.57.1, FlashInfer 0.6.2, and 50+ packages for LLM serving, structured output, and multimodal inference.

Description

SGLang has a large dependency tree with many pinned versions to ensure reproducibility. The core serving runtime (srt) depends on PyTorch, Transformers, FlashInfer, Triton, sgl-kernel, xgrammar, and torchao for model loading, inference, attention computation, constrained decoding, and quantization. The frontend DSL (lang) adds openai, anthropic, and other API client libraries. Optional dependency groups cover checkpoint engines, diffusion models, tracing (OpenTelemetry), and testing. Platform-specific conditional dependencies handle ARM vs x86 differences (e.g., `torchcodec` excluded on ARM Linux).

Usage

Use this environment for all SGLang workflows. The Python dependencies are the foundational software layer required before any model serving can begin. All Implementation pages depend on subsets of these packages.

System Requirements

Category Requirement Notes
Python >= 3.10 Specified in pyproject.toml
OS Linux (primary), macOS (limited) Windows requires WSL2
Build Tools setuptools >= 61.0, wheel, ninja For compiling extensions
gRPC Compiler grpcio-tools == 1.75.1 For protobuf compilation during install

Dependencies

Core Packages (Pinned)

  • `torch` == 2.9.1
  • `torchao` == 0.9.0
  • `torchaudio` == 2.9.1
  • `torchvision` (latest compatible)
  • `transformers` == 4.57.1
  • `sgl-kernel` == 0.3.21
  • `flashinfer_python` == 0.6.2
  • `flashinfer_cubin` == 0.6.2
  • `cuda-python` == 12.9
  • `xgrammar` == 0.1.27
  • `outlines` == 0.1.11
  • `openai` == 2.6.1
  • `grpcio` == 1.75.1

Core Packages (Ranged)

  • `anthropic` >= 0.20.0
  • `llguidance` >= 0.7.11, < 0.8.0
  • `prometheus-client` >= 0.20.0
  • `pyzmq` >= 25.1.2
  • `nvidia-cutlass-dsl` >= 4.3.4
  • `apache-tvm-ffi` >= 0.1.5, < 0.2

Utility Packages

  • `fastapi`, `uvicorn`, `uvloop` (HTTP server)
  • `pillow`, `einops`, `numpy`, `scipy` (data processing)
  • `sentencepiece`, `tiktoken` (tokenization)
  • `huggingface_hub`, `hf_transfer` (model downloading)
  • `pydantic`, `msgspec`, `orjson` (serialization)
  • `psutil`, `py-spy`, `setproctitle` (process management)
  • `tqdm`, `IPython` (user interface)

Optional Dependency Groups

  • checkpoint-engine: `checkpoint-engine` == 0.1.2
  • diffusion: `st_attn`, `vsa` (not on ARM Linux)
  • tracing: OpenTelemetry packages for distributed tracing
  • test: `accelerate`, `bitsandbytes`, `peft`, `pytest`

Credentials

  • `HF_TOKEN`: HuggingFace API token for downloading gated models
  • `OPENAI_API_KEY`: For OpenAI backend in frontend DSL examples
  • `ANTHROPIC_API_KEY`: For Anthropic backend in frontend DSL examples

Quick Install

# Install from PyPI (recommended)
pip install "sglang[all]"

# Install from source
git clone https://github.com/sgl-project/sglang.git
cd sglang
pip install -e "python/.[all]"

# CPU-only variant
pip install "sglang-cpu"

Code Evidence

Python version requirement from `python/pyproject.toml:10`:

requires-python = ">=3.10"

Version assertion utility from `python/sglang/srt/utils/common.py:1080-1092`:

def assert_pkg_version(pkg: str, min_version: str, message: str):
    try:
        installed_version = version(pkg)
        if pkg_version.parse(installed_version) < pkg_version.parse(min_version):
            raise Exception(
                f"{pkg} is installed with version {installed_version}, which "
                f"is less than the minimum required version {min_version}. " + message
            )
    except PackageNotFoundError:
        raise Exception(
            f"{pkg} with minimum required version {min_version} is not installed. "
            + message
        )

Platform-conditional dependency from `python/pyproject.toml:71`:

"torchcodec==0.8.0 ; sys_platform != 'linux' or (sys_platform == 'linux' and platform_machine != 'aarch64' and platform_machine != 'arm64' and platform_machine != 'armv7l')"

Common Errors

Error Message Cause Solution
`{pkg} is installed with version X, which is less than the minimum required version Y` Package version too old `pip install --upgrade {pkg}>={version}`
`{pkg} with minimum required version X is not installed` Package missing entirely `pip install {pkg}`
`ImportError: No module named 'sgl_kernel'` sgl-kernel not installed `pip install sgl-kernel==0.3.21`
`ModuleNotFoundError: No module named 'flashinfer'` FlashInfer not installed `pip install flashinfer_python==0.6.2 flashinfer_cubin==0.6.2`
`grpc compilation failed during install` grpcio-tools version mismatch Ensure `grpcio-tools==1.75.1` is installed before building from source

Compatibility Notes

  • ARM Linux (aarch64): `torchcodec` and some diffusion packages excluded; `av` package added instead
  • CPU-only: Separate package `sglang-cpu` with reduced dependencies (no CUDA/FlashInfer)
  • NPU (Ascend): Separate `pyproject_npu.toml` with `torch_npu` and `sgl-kernel-npu`
  • XPU (Intel): Separate `pyproject_xpu.toml` with Intel-specific PyTorch
  • ROCm (AMD): Separate `pyproject_other.toml` with ROCm-compatible PyTorch

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment