Skip to main content

Overview

The sglang serve command launches a server for serving language models or diffusion models. The server type is automatically determined based on the model path, or can be explicitly specified using the --model-type flag.

Basic Usage

Required Arguments

string
required
Path or name of the model to serve. Can be:
  • HuggingFace model ID (e.g., meta-llama/Llama-2-7b-hf)
  • Local path to model directory
  • ModelScope model ID (when using SGLANG_USE_MODELSCOPE=1)

Server Type Selection

string
default:"auto"
Override automatic model type detection. Options:
  • auto: Automatically detect model type (default)
  • llm: Force standard language model server
  • diffusion: Force diffusion model server

Model Auto-Detection

SGLang automatically detects whether to launch a standard language model server or a diffusion model server based on:
  1. For local directories: Checks for model_index.json with _diffusers_version field
  2. For remote models: Attempts to download model_index.json from HuggingFace/ModelScope
  3. Falls back to language model server on detection failure

Language Model Server Options

Model and Tokenizer

string
Path to the tokenizer. Defaults to --model-path if not specified.
string
default:"auto"
Tokenizer mode. Options: auto, slow.
boolean
default:"false"
Trust remote code from HuggingFace.
string
default:"auto"
Model loading format. Options: auto, pt, safetensors, npcache, dummy, sharded_state, gguf, bitsandbytes, layered, flash_rl, remote, remote_instance, fastsafetensors, private.
string
Model revision (branch/tag name or commit ID).

HTTP Server

string
default:"127.0.0.1"
Server host address.
integer
default:"30000"
Server port.
string
API key for authentication.

Quantization

string
Quantization method. Options: awq, fp8, mxfp8, gptq, marlin, gptq_marlin, awq_marlin, bitsandbytes, gguf, modelopt, modelopt_fp8, modelopt_fp4, petit_nvfp4, w8a8_int8, w8a8_fp8, moe_wna16, qoq, w4afp8, mxfp4, auto-round, compressed-tensors, modelslim, quark_int4fp8_moe.
string
default:"auto"
Data type for model weights. Options: auto, float16, bfloat16, float32.
string
default:"auto"
Data type for KV cache. Options: auto, fp8_e4m3, fp8_e5m2, bfloat16.

Memory and Scheduling

float
Fraction of GPU memory to use for model weights and KV cache.
integer
Maximum total number of tokens in the batch.
integer
Chunk size for chunked prefill. Default varies by GPU memory (2048-16384).
integer
default:"16384"
Maximum number of tokens in a prefill batch.
string
default:"fcfs"
Scheduling policy. Options: fcfs (first-come-first-serve).

Parallelism

integer
default:"1"
Tensor parallelism size.
integer
default:"1"
Data parallelism size.
integer
default:"1"
Pipeline parallelism size.

Attention Backend

string
Attention backend. Options: triton, torch_native, flex_attention, nsa, cutlass_mla, fa3, fa4, flashinfer, flashmla, trtllm_mla, trtllm_mha, dual_chunk_flash_attn, aiter, wave, intel_amx, ascend, intel_xpu.

LoRA

boolean
Enable LoRA adapters.
integer
Maximum LoRA rank.
string
Paths to LoRA adapters.

Speculative Decoding

string
Speculative decoding algorithm. Options: EAGLE, MEDUSA, STANDALONE, NGRAM.
string
Path to the draft model for speculative decoding.
integer
Number of speculative decoding steps.

Logging

string
default:"info"
Logging level. Options: debug, info, warning, error.
boolean
default:"false"
Log all requests.
boolean
default:"false"
Enable Prometheus metrics.

Diffusion Model Server Options

When serving diffusion models, additional options are available:

Parallelism

integer
default:"1"
Number of GPUs to use.
integer
Sequence parallelism degree.
integer
Ulysses sequence parallelism degree.
integer
Ring sequence parallelism degree.

Attention

string
Attention backend for diffusion models.
string
Cache-DIT configuration for diffusers.

Offloading

boolean
Offload DiT model to CPU.
boolean
Offload VAE to CPU.
boolean
Offload text encoder to CPU.

Backend

string
default:"auto"
Model backend. Options: auto, sglang, diffusers.

Examples

Serve a Language Model

Serve a Diffusion Model

Advanced Configuration

Output

When the server starts successfully, you’ll see output similar to:

Help

To see all available options:
Note: Since the exact help depends on the model type, provide a model path to see specific options: