LLM Serving Throughput Calculator

easy
Unit 6 · Agents & Inference0/3 to milestone

Back-of-the-envelope capacity planning for an LLM endpoint. For a request with prompt_tokens and output_tokens, given a GPU's prefill speed (tokens/s processed for the prompt) and per-sequence decode speed (tokens/s generated):

  • Time to first token (TTFT) = prompt_tokens / prefill_tps
  • Generation time = output_tokens / decode_tps
  • Latency = TTFT + generation time

Implement request_latency(prompt_tokens, output_tokens, prefill_tps, decode_tps) returning {"ttft", "latency"} in seconds. Then implement gpus_needed(requests_per_sec, prompt_tokens, output_tokens, prefill_tps, decode_tps, concurrent_per_gpu): by Little's law, the average number of in-flight requests is requests_per_sec × latency. Divide by how many requests one GPU serves concurrently and round up.

#inference#capacity-planning2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
LLM Serving Throughput Calculator · TechGradify