Skip to main content

Overview

SGLang provides a high-performance inference server that can be launched using the sglang serve command. The server supports various deployment modes including HTTP, gRPC, and disaggregated prefill-decode architectures.

Basic Usage

Starting the Server

The simplest way to launch a server:

Common Launch Options

Server Modes

HTTP Server (Default)

The default server mode provides OpenAI-compatible HTTP endpoints:
Available Endpoints:
  • /v1/chat/completions - Chat completions API
  • /v1/completions - Text completions API
  • /v1/embeddings - Embeddings generation
  • /health - Health check endpoint
  • /get_model_info - Model information

gRPC Server

For lower latency in high-throughput scenarios:

Disaggregated Prefill-Decode

SGLang supports separating prefill and decode into different instances for optimized resource utilization. Prefill Server:
Decode Server:

Parallelism Options

Tensor Parallelism

Split model across multiple GPUs:

Pipeline Parallelism

Distribute model layers across GPUs:

Data Parallelism

Run multiple replicas for increased throughput:

Performance Optimization

Memory Management

float
default:"auto"
Fraction of GPU memory to allocate for static usage (model weights + KV cache). Default is automatically calculated based on GPU memory and model size.
int
default:"auto"
Maximum number of tokens to process in a single prefill batch. Larger values improve throughput but require more memory.
int
default:"null"
Maximum total number of tokens in the KV cache pool. Limits memory usage.

CUDA Graph Optimization

CUDA graphs reduce kernel launch overhead:
int
default:"auto"
Maximum batch size for CUDA graph capture. Higher values enable batching more requests but require more memory. Set to 0 to disable.
bool
default:"false"
Disable CUDA graph optimization entirely.

Radix Attention Cache

Accelerate requests with shared prefixes:
bool
default:"false"
Disable the radix attention cache (prefix caching).
bool
default:"false"
Include cache hit rate statistics in API responses.

Multi-Node Deployment

For distributed training across multiple machines:

Quantization

Reduce memory usage with quantization:
Supported quantization methods:
  • fp8 - FP8 quantization for reduced memory
  • awq - Activation-aware Weight Quantization
  • gptq - GPTQ quantization
  • marlin - Marlin sparse format
  • bitsandbytes - 8-bit and 4-bit quantization

Monitoring and Logging

Enable Metrics

Metrics are exposed at http://localhost:30000/metrics in Prometheus format.

Request Logging

bool
default:"false"
Log all incoming requests and responses.
string
default:"info"
Set logging verbosity. Options: debug, info, warning, error.

Health Checks and Warmup

Server Warmup

By default, the server runs warmup requests to initialize CUDA graphs and caches:
bool
default:"false"
Skip the warmup phase on server startup.
string
default:"null"
Specify custom warmup functions (comma-separated) to run before server starts. Example: --warmups=warmup_name1,warmup_name2

Health Endpoint

Check server health:

Environment Variables

SGLang respects several environment variables:
  • CUDA_VISIBLE_DEVICES - Control which GPUs are used
  • NCCL_SOCKET_IFNAME - Network interface for multi-node communication
  • SGLANG_USE_MODELSCOPE - Download models from ModelScope instead of HuggingFace
  • HF_TOKEN - HuggingFace authentication token for gated models

Python API

You can also launch the server programmatically:

See Also