SGLang
A language-model serving runtime with scheduling, attention kernels and reusable prefix state. Its RadixAttention idea is especially useful when conversations or related prompts repeatedly share an initial token sequence.
Client / HTTP endpoint
Submits a generation request to the serving endpoint. A request can ask for streamed text, so producing and transmitting a response happens repeatedly before the request finishes.
- Client / HTTP endpoint Tokenizer managerGeneration request
- Tokenizer manager Client / HTTP endpointStream text to client
One pass through the system.
Select a step to highlight the components involved in the diagram.
Why it is built this way.
Cache benefit depends on the workload
A common system prompt or repeated conversation prefix can save computation. Unrelated prompts offer less reusable state; a cache hit is not a replacement for generating the response.
Reuse needs careful memory ownership
Shared prefixes reduce duplicated state but complicate allocation and eviction. Active references must remain valid, and cached state competes with new requests for finite device memory.
Separate processes need separate diagnosis
Slow tokenization, scheduling, GPU execution and detokenization can all delay a stream. A healthy HTTP process alone does not establish that the execution pipeline is making progress.
Read the implementation.
python/sglang/srt/managers/tokenizer_manager.pyTrace request preparation and the ZeroMQ channels connecting input and output managers.
python/sglang/srt/managers/scheduler.pyStart at the scheduler and follow its batching, cache and worker collaborators.
python/sglang/srt/mem_cache/radix_cache.pyInspect prefix matching, tree state and eviction rather than treating the cache as a text lookup.
Go deeper with the official docs
- SGLang paper: runtime and RadixAttention
- Detokenizer process and output IPC
- Model execution implementation
Educational diagrams, synthesized from the linked project documentation. Components and boundaries vary by version and deployment.