Install SGLang
- Docker
- pip / uv
- From source
Docker includes Python, SGLang, and its dependencies; no separate host Python installation is required.The docker images are available on Docker Hub at lmsysorg/sglang, built from Dockerfile.
Use Linux with a supported NVIDIA GPU, a CUDA 13-compatible driver, Docker Engine, and NVIDIA Container Toolkit. Complete the Toolkit guide’s Docker runtime configuration before starting a GPU container.SGLang images ship a CUDA 13 environment. CUDA 12 images (Image optionsThe examples use The container shell is ready for
-cu12 / -cu129) are no longer published; lmsysorg/sglang:v0.5.19-cu129 is the last CUDA 12 tag.Pull the imagelatest contains the newest stable release:latest. To use another image, replace the tag in the pull and run commands:- Nightly: Built daily from the latest
main, including changes not yet in a stable release. Choose a tag from the nightly image list. - Runtime: A smaller image of the same stable release, with inference dependencies and fewer development utilities. Use the
latest-runtimetag.
HF_CACHE_DIR to an absolute directory path on the host for downloaded model weights, replacing the placeholder below.For gated or private models, export your Hugging Face token as HF_TOKEN on the host and add --env HF_TOKEN before the image name in this command.sglang serve.Start a model server
Start a model server inside your Docker container or activated Python environment. ReplaceMODEL_PATH with a Hugging Face model ID or a local model directory:
- Quickstart: Launch a model and send a request to verify the server.
- Cookbook: Find model-specific launch arguments for your hardware.
Deployment options
Choose how to run SGLang as a service. Expand an option for setup instructions.Kubernetes
Serve models on a Kubernetes cluster, on one node or across multiple nodes.
Kubernetes
Serve models on a Kubernetes cluster, on one node or across multiple nodes.
Please check out OME, a Kubernetes operator for enterprise-grade management and serving of large language models (LLMs).
-
Option 1: For single node serving (typically when the model size fits into GPUs on one node)
Execute command
kubectl apply -f docker/k8s-sglang-service.yaml, to create k8s deployment and service, with llama-31-8b as example. -
Option 2: For multi-node serving (usually when a large model requires more than one GPU node, such as
DeepSeek-R1) Modify the LLM model path and arguments as necessary, then execute commandkubectl apply -f docker/k8s-sglang-distributed-sts.yaml, to create two nodes k8s statefulset and serving service.
Docker Compose
Run a model service on a single Docker host with a Compose configuration.
Docker Compose
Run a model service on a single Docker host with a Compose configuration.
This method is recommended if you plan to serve it as a service. A better approach is to use the k8s-sglang-service.yaml.
- Copy the compose.yml to your local machine
- Execute the command
docker compose up -din your terminal.
SkyPilot
Deploy on Kubernetes or across cloud providers from one YAML configuration.
SkyPilot
Deploy on Kubernetes or across cloud providers from one YAML configuration.
To deploy on Kubernetes or 12+ clouds, you can use SkyPilot.
- Install SkyPilot and set up Kubernetes cluster or cloud access: see SkyPilot’s documentation.
- Deploy on your own infra with a single command and get the HTTP API endpoint:
SkyPilot YAML: sglang.yaml
SkyPilot YAML: sglang.yaml
Config
Command
- To further scale up your deployment with autoscaling and failure recovery, check out the SkyServe + SGLang guide.
AWS SageMaker
Deploy on SageMaker with a pre-built SGLang image or your own container.
AWS SageMaker
Deploy on SageMaker with a pre-built SGLang image or your own container.
To deploy on SGLang on AWS SageMaker, check out AWS SageMaker InferenceAmazon Web Services provide supports for SGLang containers along with routine security patching. For available SGLang containers, check out AWS SGLang DLCs.To deploy a pre-built SGLang Deep Learning Container without building your own image, see Amazon SageMaker AI.To host a model with your own container, follow the following steps:
- Build a docker container with sagemaker.Dockerfile alongside the serve script.
- Push your container onto AWS ECR.
Build script: build-and-push.sh
Build script: build-and-push.sh
Command
- Deploy a model for serving on AWS Sagemaker, refer to deploy_and_serve_endpoint.py. For more information, check out sagemaker-python-sdk.
- By default, the model server on SageMaker will run with the following command:
python3 -m sglang.launch_server --model-path opt/ml/model --host 0.0.0.0 --port 8080. This is optimal for hosting your own model with SageMaker. - To modify your model serving parameters, the serve script allows for all available options within
python3 -m sglang.launch_server --helpcli by specifying environment variables with prefixSM_SGLANG_. - The serve script will automatically convert all environment variables with prefix
SM_SGLANG_fromSM_SGLANG_INPUT_ARGUMENTinto--input-argumentto be parsed intopython3 -m sglang.launch_servercli. - For example, to run Qwen/Qwen3-0.6B with reasoning parser, simply add additional environment variables
SM_SGLANG_MODEL_PATH=Qwen/Qwen3-0.6BandSM_SGLANG_REASONING_PARSER=qwen3.
- By default, the model server on SageMaker will run with the following command:
Troubleshooting
CUDA_HOME
If installation fails withOSError: CUDA_HOME environment variable is not set, set CUDA_HOME to your CUDA Toolkit installation directory. Replace the path below with the actual path on your machine:
/usr/local/cuda-VERSION. Alternatively, install FlashInfer first using the FlashInfer installation instructions, then retry the SGLang installation.
FlashInfer
- FlashInfer is the default attention kernel backend. It only supports sm75 and above. If you encounter any FlashInfer-related issues on sm75+ devices (e.g., T4, A10, A100, L4, L40S, H100), please switch to other kernels by adding
--attention-backend triton --sampling-backend pytorchand open an issue on GitHub. - To reinstall flashinfer locally, use the following command:
pip3 install --upgrade flashinfer-python --force-reinstall --no-depsand then delete the cache withrm -rf ~/.cache/flashinfer.
