Source Code Compilation and Build
Obtain the SGLang source code, build Python wheels and CUDA extension wheels from the source code, and install the build products.
- Obtain the SGLang 0.5.10 source code.
1git clone --branch v0.5.10 --depth 1 https://github.com/sgl-project/sglang.git
- Build a Python wheel from the source code.
1 2 3 4
cd sglang SETUPTOOLS_SCM_PRETEND_VERSION=0.5.10 \ python3 -m pip wheel --no-build-isolation --no-deps \ --wheel-dir /tmp/sglang-build/python ./python
- Build a CUDA extension wheel from the source code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
export CUDA_HOME=/usr/local/cuda-13.0 export PATH=$CUDA_HOME/bin:$PATH export LD_LIBRARY_PATH=$CUDA_HOME/lib64:${LD_LIBRARY_PATH:-} export TORCH_CUDA_ARCH_LIST="8.0" export MAX_JOBS=8 export NVCC_THREADS=1 export CMAKE_BUILD_PARALLEL_LEVEL=8 export CMAKE_ARGS="-DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_CUDA_ARCHITECTURES=80" export Torch_DIR=$(python3 - <<'PY' import pathlib import torch print(pathlib.Path(torch.__file__).resolve().parent / "share" / "cmake" / "Torch") PY ) export CMAKE_PREFIX_PATH=$(python3 - <<'PY' import torch.utils print(torch.utils.cmake_prefix_path) PY ) python3 -m pip wheel --no-build-isolation --no-deps \ --wheel-dir /tmp/sglang-build/kernel ./sgl-kernel
- Install the local build product.
1 2 3 4 5 6 7 8
python3 -m pip install \ typing_extensions filelock fsspec jinja2 networkx sympy mpmath numpy packaging \ tqdm requests aiohttp fastapi uvicorn pydantic orjson pyzmq psutil pillow \ sentencepiece safetensors tokenizers transformers==5.3.0 pybase64 setproctitle \ partial_json_parser diskcache msgspec interegular lark pycountry pycryptodomex \ gguf openai anthropic prometheus-client uvloop watchfiles soundfile tiktoken IPython python3 -m pip install --force-reinstall --no-deps /tmp/sglang-build/kernel/*.whl python3 -m pip install --force-reinstall --no-deps /tmp/sglang-build/python/*.whl
When installing the local build product, use --no-deps to retain the confirmed CUDA version of PyTorch and prevent the PyTorch version from being replaced during dependency parsing. After the installation is complete, check again that both torch.backends.cuda.is_built() and torch.cuda.is_available() return True.
The following is an example of the build product.
1 2
sglang-0.5.10-py3-none-any.whl sglang_kernel-0.4.1-*.whl
Parent topic: Developer Guide