What does an LLM server do?

Introduction

Project introduction

What does an LLM server do?

A language model writes its answer one token at a time. First it reads the whole prompt in one pass, called the prefill, which produces the first token. Then it runs one decode step per token, each feeding in only the newest token. To avoid recomputing the past on every step, it keeps the keys and values of earlier tokens in a KV cache.

A server has many users at once. Running one model step for many requests costs barely more than running it for one, so servers batch. The hard part is the scheduler, which decides before every step which requests run, which new ones may join, and what to do when memory runs out.

Why the scheduler matters

Requests arrive at random times and their answers range from a few tokens to hundreds. A batch that waits for its longest request leaves slots empty while other users wait. Continuous batching, introduced by Orca, lets requests join and leave at every step, and is how servers such as vLLM and Hugging Face TGI work today.

In this project you build those pieces and measure them the way serving papers do, with time to first token, time per output token, throughput, and their 99th percentiles. Then you push the server hard and watch a scheduler that is great for throughput make every streaming user wait, and you fix it.

Who runs in each model step

3 batch slots
slot 1
A
slot 2
B
slot 3
C
waiting0
prefill + first token decode, one token empty slot0 empty slots so far
Requestsarrive at any time
Schedulerplans every step
Model stepprefill and decode
Tokensstream to users

What you will build

01

Prefill, decode, and batching

A KV cache step in PyTorch, and a scheduler that plans every model step.

02

Metrics users feel

Time to first token, time per output token, gaps between tokens, and throughput.

03

KV cache memory

Size the cache, hand it out in fixed-size blocks, and see what happens when it runs out.

Start with the KV cache

Write one decode step of attention that reuses cached keys and values.

Continue to Problem 1