Simulate static versus continuous batching on CPU
CPU · your Macscript120 minrequiredGoal · A discrete-event simulator that reports GPU slot utilization, mean latency and throughput for static and continuous batching on the same request trace.
- 1Model a GPU step as cost = base + per_token * active_tokens with base 20 ms and per_token 0.1 ms; prefill of n tokens costs n per_token in one step.
- 2Generate 300 requests with Poisson arrivals (rate 4 per second), prompt lengths 32-512 and output lengths 16-256.
- 3Implement static batching with batch size 16 where the batch runs until its longest sequence finishes.
- 4Implement continuous batching with a max of 16 slots that admits waiting requests every step and frees slots on completion.
- 5Record per request queue time, TTFT and end-to-end latency, plus slot utilization (occupied slots divided by 16 per step).
- 6Print a table and plot latency CDFs for both policies; then sweep max slots 4, 16, 64 for continuous batching.
- 7Write three sentences on where the throughput curve bends and why.
- Deliverable
- batching_sim.py and a PNG with the latency CDFs and the throughput-versus-slots plot.
- Check
- Continuous batching achieves at least 2x the output tokens per second of static batching and above 80 percent slot utilization on this trace.