Practice in Lab: Project: simulate bounded continuous batching with deadlines →
Project: simulate bounded continuous batching with deadlines
Continuous batching mixes requests with different arrival times, context sizes and output budgets. Request-count limits alone cannot express reserved token capacity, and a queued request can expire before it receives a slot. This project simulates admission, one-token decode rounds, cancellation and completion with a reproducible integer clock. Full reservation simplifies the memory invariant while FIFO head blocking exposes a fairness-throughput tradeoff. No tokenizer, accelerator or model runs here; the review must compare the policy with measurements from a real serving system before claiming latency or capacity results.
active = [{'id':'a','remaining':2},{'id':'b','remaining':1}]
completed = []
for row in active:
row['remaining'] -= 1
if row['remaining']==0:
completed.append(row['id'])
print(completed)Review the design
Review reservations, FIFO blocking, deadline boundaries and cancellation. Real serving requires measured prefill/decode costs, paged memory, admission telemetry and model-specific benchmarks.
Your task
Requests have unique string id and integer arrival>=0, deadline>arrival, prompt>=0, output>=1. Capacities are positive integers. Reserve prompt+full output tokens while active; oversized requests are rejected. At each integer tick cancel pending/active requests with deadline<=tick, admit FIFO by (arrival,id) up to slots and reserved capacity without skipping a waiting head, then generate one token for every active request. Completion time is tick+1, so finishing exactly at deadline is allowed. Jump to the next arrival when idle. Return completed time mapping, sorted cancelled/rejected IDs and per-tick events (tick,admitted,completed,cancelled,active after generation,reserved before generation). This is a deterministic scheduling simulation, not model inference or a throughput benchmark.
The explanation opens here once every check passes.