Trace a request through SGLang and annotate the radix cache
CPU · your Macreading-code240 minrequiredGoal · Produce a call graph of one SGLang generate request and a worked example of radix cache insert, match and evict for three overlapping prompts.
- 1git clone https://github.com/sgl-project/sglang and check out the latest release tag; record the commit hash.
- 2Start at python/sglang/srt/entrypoints and find the HTTP generate handler; follow into managers/tokenizer_manager.py.
- 3Follow the ZMQ hop to managers/scheduler.py; annotate the main event loop, get_new_batch_prefill and the decode batch path.
- 4Open mem_cache/radix_cache.py; read match_prefix, insert and evict and draw the tree after inserting prompts A, AB and AC token by token.
- 5Find where the scheduler calls the radix cache to compute prefix lengths and how that influences batch ordering.
- 6Locate the attention backend selection and the layer that calls it; record the kernel used for prefill and decode.
- 7Write the call graph with path:line references and the radix tree diagrams in one markdown file.
- Deliverable
- sglang-request-trace.md with the call graph, commit hash and three radix tree diagrams showing node sharing.
- Check
- Your diagram shows prompts AB and AC sharing the node for A, and your eviction walkthrough frees a leaf before an interior node.