bugger.
All challenges/Pythonhardllm-continuous-batching-v1
THE INVESTIGATION

Schedule prefill and decode with a token budget

Simulate continuous batching one tick at a time.

LLM ArchitectureLLM inference

What’s going wrong

Original LLM Architecture lab. Implement the missing behavior in solve(data) and keep the supplied JSON interface. Use Python’s standard library.

requests provides stable input order and each request has a unique id, arrival tick, positive prefill tokens and positive decode tokens. Processing starts at tick zero. Each tick has budget ≥1. First spend one token on each arrived decode-ready request in input order up to budget; then use remaining capacity on arrived requests with pending prefill in input order, allowing chunks. Prefill completion makes a request decode-ready next tick. Return ticks (one {decode:[ids],prefill:[[id,count]]} object per tick, including idle ticks before arrivals) and finished (request→tick of final decode). Stop after all requests finish.

Small, well-formed JSON inputs and standard-library Python arithmetic. Keep full precision during computation. The supplied output wrapper rounds results to six decimal places.

Expected behavior

Simulate continuous batching one tick at a time.

Reproduction

01 Decode overlaps a chunked prefill
{"budget":2,"requests":[{"id":"A","arrival":0,"prefill":1,"decode":3},{"id":"B","arrival":1,"prefill":3,"decode":1}]}
{"ticks":[{"decode":[],"prefill":[["A",1]]},{"decode":["A"],"prefill":[["B",1]]},{"decode":["A"],"prefill":[["B",1]]},{"decode":["A"],"prefill":[["B",1]]},{"decode":["B"],"prefill":[]}],"finished":{"A":3,"B":4}}
02 No requests
{"budget":1,"requests":[]}
{"ticks":[],"finished":{}}
03 Idle ticks before a future arrival
{"budget":1,"requests":[{"id":"A","arrival":3,"prefill":1,"decode":1}]}
{"ticks":[{"decode":[],"prefill":[]},{"decode":[],"prefill":[]},{"decode":[],"prefill":[]},{"decode":[],"prefill":[["A",1]]},{"decode":["A"],"prefill":[]}],"finished":{"A":4}}

Before you begin

  • Python functions, lists and dictionaries

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.