Mini sglang (the project calls itself Mini-SGLang) is a lightweight LLM inference framework derived from SGLang. It is about 5,000 lines of Python and keeps the mechanisms that make modern serving fast: radix-tree KV cache reuse, chunked prefill, overlap scheduling, tensor parallelism and optimised attention kernels. In practice you get a serving engine you can read from end to end, which makes it a good way to learn what a runtime actually schedules. What it cannot tell you is where your own workload spends its time. Only a profile tells you that.
Inside Mini-SGLang: processes, request states and kernels
Its authors built Mini-SGLang because SGLang’s codebase had grown to nearly 300k lines of Python. The project had two stated aims: to provide learning material and to make research prototyping fast. The engine still supports both online and offline inference, and it serves an OpenAI-compatible /v1/chat/completions endpoint.
Under the hood, Mini-SGLang runs as several independent processes that cooperate. The rank 0 scheduler takes messages from the tokenizer, talks to the schedulers on the other tensor-parallel workers and sends results to the detokenizer. There is one scheduler worker per GPU (a TP rank). Each one manages computation and resource allocation on its device, and all of them schedule the request and trigger their local engine to compute the next token. The engine is the per-process worker that owns the model, the context, the KV cache, the attention backend and CUDA graph replay.
The state lives in a few dataclasses. Req is one request, Batch is the set of requests in one model execution, Context holds the global inference state and SamplingParams holds the user’s sampling settings. A request moves through WAITING, PREFILL, DECODE and FINISHED. Work moves through the engine along two paths. The control path tracks which state each request is in. The data path carries input_ids, positions, logits and the KV cache through the batch, model runner and attention backend.
The practical consequence is that every iteration starts with a scheduling decision: which requests go into the batch, and whether this step runs prefill or decode. A fast kernel fed by a poor batch still produces poor throughput.
The kernel side is equally explicit. On NVIDIA Hopper, Mini-SGLang uses FlashAttention-3 for prefill and FlashInfer for decode by default. It can also use the TensorRT-LLM fmha backend and assign different backends to each phase. It uses just-in-time compiled kernels and TVM FFI for Python bindings, which LMSYS says is much faster than the default PyTorch interface. CUDA graph capture and replay is on by default to cut CPU launch overhead in decode, and --cuda-graph-max-bs sets the largest batch that gets captured. For profiling, the code carries fine-grained NVTX annotations.
What a lightweight SGLang runtime schedules: prefill, decode, batching and the KV cache
Prefill is compute-bound, decode is memory-bound
Prefill is the forward pass over the whole input prompt. Decode then produces output tokens one at a time, and each new token depends on the ones before it. These two phases put conflicting demands on the GPU. A systematic characterisation of LLM inference on GPUs measured much higher streaming multiprocessor utilisation in prefill and much higher memory bandwidth utilisation in decode. It concluded that prefill is limited by compute throughput and decode by memory bandwidth. The cause is tensor size and data reuse. Prefill runs large GEMMs with heavy reuse, while decode works on small per-token inputs and keeps re-reading the KV cache.
Which phase dominates latency depends on the input length. In the same study, for Qwen2.5-7B with a fixed 128-token output (measured on vLLM v0.9.2), decode accounted for most of the latency at short inputs. Prefill overtook it at roughly 2k input tokens. Treat that 2k figure as specific to that model and setup, not as a constant. Its value is the reminder that a chat workload and a long-document workload on the same engine can have different bottlenecks.
The phase split also changes how parallelism pays off. The characterisation found that prefill scales with tensor parallelism but decode gains little from it, and is often fastest on a single GPU or with pipeline parallelism, because communication overhead outweighs the small amount of per-step compute. Mini-SGLang supports tensor parallelism across GPUs, set with --tp n. For a decode-heavy workload, adding GPUs through --tp is therefore something to measure before you assume it helps.
Batching, chunked prefill and overlap scheduling
A decode iteration processes only one token per request, so its compute utilisation is low. That is why batching works so well for decode and for overall throughput. The difficulty is that batching interleaves prefill and decode iterations, which makes it hard to get high throughput and low latency at once. Sarathi-Serve introduced chunked prefill to deal with this. It splits a prefill into roughly equal chunks so new requests can join a batch without pausing ongoing decodes. Mini-SGLang turns chunked prefill on by default, which lowers peak memory and prevents out-of-memory errors in long-context serving.
Overlap scheduling deals with host CPU overhead. The CPU does batch scheduling, memory management and token processing. Left unoptimised, that work leaves the GPU idle between steps. Mini-SGLang prepares the next batch on the CPU while the GPU runs the current one, a technique its documentation attributes to NanoFlow. LMSYS credits this mechanism for Mini-SGLang consistently outperforming the Nano-vLLM baseline on Qwen3 models.
The radix KV cache
The KV cache holds the key and value tensors from earlier tokens. It depends only on the prefix, so requests that share a prompt prefix can share the cache. In the SGLang paper’s RadixAttention design, a radix tree maps token sequences to KV tensors stored in pages of one token each. Leaves are evicted in least-recently-used order, and a reference count protects nodes that the running batch is still using. Cached tokens and running requests share one memory pool. When enough requests are waiting, the cache is evicted in favour of a larger batch. On few-shot MMLU, where prompts share examples, the paper reports that sharing the cache allows larger batches and less prefill computation, which lowers first-token latency. On a benchmark with no reuse at all, managing the tree took 0.2 seconds of a 74.3-second run, under 0.3% overhead.
Mini-SGLang enables its radix cache by default, and --cache naive switches it to a simple strategy. How much the cache buys you depends on the cache hit rate. Shared system prompts give it prefixes to reuse. Unrelated one-shot prompts do not.
mini sglang versus full SGLang: when is the minimal version enough?
On the configuration LMSYS tested, the two runtimes perform almost the same. LMSYS replayed 1,000 requests against Qwen3-32B with 4-way tensor parallelism on four H200 GPUs. Throughput, P90 time to first token and time between tokens were nearly identical to SGLang. That is one model, one topology and one trace, so read it as evidence that the core mechanisms are complete, not as a guarantee for every workload.
Full SGLang includes:
- a frontend language for structured LM programs and compressed finite-state machines for fast constrained decoding
- prefill/decode (PD) disaggregation, which separates the two phases so that prefill batches stop interrupting decode
- a cache-aware load balancer across workers, which LMSYS measured in its v0.4 release at up to 1.9x throughput with a 3.8x higher cache hit rate
- data-parallel attention for MLA models such as DeepSeek, which avoids duplicating the KV cache across tensor-parallel ranks
Mini-SGLang’s feature documentation describes online serving, tensor parallelism, chunked prefill, attention backends, CUDA graphs, the radix cache and overlap scheduling.
The minimal version is enough when the goal is to understand a serving engine, to prototype a scheduling or kernel idea in a codebase small enough to change safely, or to serve a dense model on one node. You need the full stack when you run separate prefill and decode fleets, route across many replicas, serve MLA models at high concurrency, or rely on constrained decoding for structured output. Deploying the compact runtime on smaller hardware raises its own questions, which we cover in mini sglang for edge vision-language inference.
Why does GPU utilisation read high while throughput stays low?
The usual GPU utilisation figure measures whether a kernel is running, not how much work the GPU is doing. The figure nvidia-smi reports is the share of the sample period during which at least one kernel was executing, and it can reach 100% from a kernel that only reads and writes memory with zero FLOPs. A 2023 analysis by Arthur Chiao showed nvidia-smi at 100% while DCGM reported SM occupancy below 20% and low floating-point activity. NVIDIA’s DCGM documentation counts warps waiting on memory as active in its SM activity metric. It says a value of 0.8 or more is necessary but not sufficient for effective GPU use, and a value below 0.5 likely means ineffective use.
Two documented causes can make an inference engine look busy while throughput is poor.
The first is memory. Decode attention is limited by DRAM bandwidth: the 2025 “Mind the Memory Gap” study found more than half of attention kernel cycles stalled on data access across every model it tested. We go through the evidence, and what profiling reveals in SGLang deployments, in our article on SGLang profiling and benchmark tools. Kernels stalled on memory still count as active.
The second is the host. In the same study, CPU overhead grew with batch size and reached up to 30% of total execution time in some cases. LMSYS has written that an unoptimised inference engine can spend as much as half its time on CPU overhead. The Blink paper notes that in mainstream serving stacks the scheduler returns to the host after every decode step. Under colocation with CPU-intensive workloads, SGLang, vLLM and TensorRT-LLM kept only 28–54% of their isolated throughput. Overlap scheduling hides CPU work by preparing the next batch while the GPU computes.
How do I profile a mini sglang workload to find the bottleneck?
Profile from the outside in. Measure the end-to-end numbers first, then the timeline, and look at individual kernels only after that. Our parent guide on profiling GPU kernels to find the real bottleneck explains the general workflow of Nsight Systems then Nsight Compute. Here we apply it to an inference runtime.
- Measure under realistic load. Record time to first token, time per output token and throughput while the server receives requests at a controlled rate. SGLang’s
bench_servingdoes exactly this. Read P50 time per output token to diagnose the engine and P99 to check the service-level objective. Mixing the two makes queueing delay look like kernel inefficiency. - Compare against a floor. The 2026 floor-first triage paper uses decode memory-bandwidth utilisation (MBU) as follows: above 70% means the implementation is near its floor, 40–70% suggests recoverable overlap or scheduling losses worth an Nsight Systems pass, and below 40% suggests a system-level defect such as host-bound execution, missing CUDA graph coverage or interference. The authors call these calibration targets, not constants.
- Read the timeline. Run Nsight Systems with the NVTX ranges Mini-SGLang already emits. Periods with no GPU kernel active are CPU time. Look for gaps between decode steps and check whether the overlap scheduler is actually hiding batch preparation.
- Classify kernels with a roofline. A layer with heavy compute and little memory traffic is compute-bound, and the reverse is memory-bound. Expect prefill GEMMs near the compute roof and decode attention near the bandwidth line. For isolated kernel work, SGLang’s
bench_one_batchruns fixed batches without the scheduler. That makes kernels easier to profile but the metrics unrealistic. - Check batch occupancy. Compare running batch size and KV pool usage against capacity. In full SGLang, a token usage above 0.9 indicates good KV cache utilisation.
Symptom-to-constraint checklist
| What the profile shows | Likely constraint | Confirm with |
|---|---|---|
| Gaps between kernels on the timeline, idle GPU between decode steps | Host-bound scheduling or CPU contention | Nsight Systems CPU and GPU rows; repeat with the host isolated |
nvidia-smi at 100% but low DCGM SM occupancy |
GPU not saturated | DCGM SM occupancy and floating-point activity |
| Throughput flattens as batch grows; decode attention sits on the bandwidth line | Memory-bound decode attention | Roofline position of attention kernels in Nsight Compute |
| Time to first token rises with prompt length; high SM use during prefill | Compute-bound prefill | Prefill share of latency across input lengths |
| Small running batches, low KV pool usage | Batching-limited | Batch size and token usage over time |
| Decode MBU below 40% | System-level defect that kernel tuning will not fix | Floor comparison, then the timeline |
What optimisation order gives the largest speedup?
Generic advice only makes sense in the context profiling provides. The sequence below moves from system-level fixes to kernel work.
- Remove system defects. Below 40% decode MBU, per-kernel work will not help. Make sure overlap scheduling and CUDA graphs are active (both are on by default in Mini-SGLang) and that the host is not shared with CPU-heavy work.
- Find the batch size knee. Throughput rises with batch size up to a knee point and then gives diminishing returns as latency climbs. In the “Mind the Memory Gap” study, a profiling-driven advisor picked batch 96 for OPT-1.3B under a strict latency target. It kept 83.13% of maximum-batch throughput while using 16.32% of the KV cache. For offline batch inference, SGLang’s tuning guide calls reaching a large batch size the most important factor.
- Set the memory split. In SGLang,
--mem-fraction-staticsets the share of GPU memory given to model weights plus the KV pool. Lowering it prevents out-of-memory errors but limits concurrency and peak throughput. A smaller--chunked-prefill-sizesaves memory at the cost of slower long-prompt prefill. Raising the CUDA graph batch limit uses more memory, so it has to be traded against the static fraction. Mini-SGLang exposes the CUDA graph limit as--cuda-graph-max-bs. - Match the schedule policy to the traffic. For workloads with many shared prefixes, SGLang’s longest-prefix-match policy (
--schedule-policy lpm) reorders requests to raise cache hits but adds scheduling overhead. The SGLang paper’s ablations show cache-aware scheduling is one of the components needed for its best results. - Pick parallelism by phase. Use tensor parallelism for prefill-heavy workloads, and a single GPU or pipeline parallelism for decode-heavy ones.
- Only then work on kernels and the decode algorithm. Quantisation raises arithmetic intensity and helps memory-bound decode most. Speculative decoding also targets memory-bound decode latency, and we cover lookahead decoding separately.
How much each step gains depends on which constraint your profile shows. Nobody can promise a figure before that measurement exists. TechnoLynx’s GPU performance engineering work profiles and tunes kernels, memory and parallelism to make workloads faster on the target hardware.
Mini sglang is a good place to learn these levers because its whole codebase is about 5,000 lines of Python. What stays open is how your own workload behaves. The MBU bands are calibrated rather than derived, the 2k-token crossover came from one model, and the parity result came from one cluster. Your first trace, not the codebase, decides which lever to pull.
FAQ
What does SGLang stand for?
The SGLang paper defines it as a Structured Generation Language for LLMs. It is a front-end language paired with a runtime, built to exploit the multi-call structure of LM programs.