Pack inference requests within a declared memory budget
Inference throughput can improve with batching, but total batch size is constrained by memory and latency. A serving scheduler must define which request costs count against its budget and how oversized requests are handled. Silent overcommit can turn one large request into a service-wide failure.
This exercise uses declared byte costs and a first-fit-in-order sequential packing policy. It does not estimate GPU memory from token counts or claim to measure a real accelerator. Model weights, temporary activations and allocator overhead require separate budgets. Preserving request order makes the policy easy to replay and test.
sizes=[4,3,5]
capacity=7
print(sum(sizes[:2])<=capacity)
print(sum(sizes)>capacity)Review the design
Admission by declared cost is an executable scheduling policy. Real serving needs measured memory headroom, deadline-aware admission and fairness across request classes; the arithmetic alone does not provide those guarantees.
Your task
Implement budget_batches(sizes,capacity), preserving order and packing consecutive positive integer sizes until the next would exceed positive integer capacity. Reject any individual size>capacity. Return lists of original indices.
The explanation opens here once every check passes.