LLM Inference Batch Scheduling: Reducing Padding Waste with Bin Packing
LLM inference batch scheduling is more efficient when requests are grouped by sequence shape instead of being padded into one large, mixed-length batch. A scheduler can reduce wasted compute by combining compatible prompts, limiting padding, and using bin-packing decisions that account for available GPU memory, sequence length, and latency targets.
That optimization is not simply a search for the largest batch size. Larger batches can improve throughput while increasing queue time, memory pressure, and tail latency. Production teams should therefore treat padding waste, prefill and decode behavior, scheduler policy, and service-level objectives as one system. This approach is especially important when several teams share a private GPU cluster and each workload has a different request profile.
Why Variable-Length Requests Create Padding Waste

Transformer inference kernels generally operate on rectangular tensors. When requests in the same batch have different token lengths, shorter sequences are extended with padding tokens so the batch can be processed as one tensor. Those padded positions consume memory bandwidth and compute even though they do not produce useful model output.
Consider a batch containing request lengths of 128, 512, and 2,048 input tokens. If the implementation pads every request to 2,048 tokens, most of the work for the first two requests is structural overhead. The exact cost depends on the model, kernel implementation, precision, attention strategy, and hardware, but the scheduling problem is stable: a batch with very different shapes can have lower effective utilization than a smaller batch of similar-length requests.
Padding waste is a scheduling signal, not just a kernel problem
Kernel optimization can make padded execution faster, but it cannot decide whether two requests should have been batched together. The serving layer knows request arrival time, maximum output tokens, priority, tenant, model version, and deadline. It can use those signals to form batches that fit a target shape before work reaches the GPU.
Separate Prefill and Decode Scheduling Decisions
LLM serving has at least two different compute behaviors. Prefill processes the prompt and is often more compute-intensive. Decode generates output tokens incrementally and is sensitive to memory bandwidth, KV-cache capacity, and interleaving with other requests. A scheduler that uses one policy for both phases may improve one metric while degrading another.
| Scheduling concern | Prefill phase | Decode phase |
|---|---|---|
| Primary pressure | Prompt length and compute demand | KV cache, memory bandwidth, and token-step fairness |
| Useful grouping signal | Similar input-token ranges | Active sequence count and remaining output budget |
| Common risk | Long prompts delay short requests | One large request monopolizes token steps |
| Useful metric | Prompt processing time and queue delay | Inter-token latency, tokens per second, and tail latency |
Continuous batching allows new requests to enter as other sequences finish, which can keep the GPU busier than repeatedly waiting for a fixed batch to complete. However, continuous batching does not remove the need for shape-aware admission. If every incoming request has a very different length or output budget, the scheduler can still create memory fragmentation, excess padding, or unfair queue behavior.
Use Length-Aware Buckets Before Bin Packing
A practical scheduling design usually starts with coarse length buckets. For example, requests can be grouped into short, medium, and long prompt ranges, with additional buckets for expected output length or model-specific constraints. Buckets reduce the search space and provide predictable behavior under load.
Choose bucket boundaries from observed request shapes
Do not choose boundaries only from model context limits. Use production telemetry to examine prompt-token percentiles, output-token distributions, arrival bursts, cancellation rates, and tenant-level service objectives. A bucket that looks efficient on average may be unsuitable if it causes a latency-sensitive tenant to wait behind long-context requests.
- Track input and output token lengths separately.
- Measure padding ratio by model, route, tenant, and batch.
- Record queue time before and after bucket assignment.
- Keep an escape path for unusually long or high-priority requests.
- Revisit bucket boundaries when model versions or traffic patterns change.
Buckets are a policy boundary, not a promise that all requests inside a range are equivalent. A second-stage packing decision can still select the best combination based on available memory, maximum batch tokens, priority, and deadline.
Apply Bin Packing to GPU Memory and Token Budgets
In this context, bin packing means placing requests into scheduling windows or batches while respecting resource limits. The bin can represent a GPU execution slot, a maximum token budget, a KV-cache allocation, or a combination of these constraints. The objective is to reduce unused capacity without violating latency and fairness requirements.
Define the resource dimensions explicitly
A scheduler should not treat sequence count as the only capacity measure. Useful dimensions include input tokens, predicted output tokens, active sequences, KV-cache pages, model precision, adapter requirements, and GPU partition or pool. A request with a short prompt but a long expected generation may consume more decode capacity than its input length suggests.
A simple policy can assign each request a conservative resource estimate, place compatible requests into the current bin, and close the bin when adding another request would cross a token or memory limit. More sophisticated policies can use best-fit or first-fit decreasing heuristics, but a mathematically optimal packing result is not required if the decision takes too long for an online serving path.
Keep the packing window bounded
Waiting indefinitely for a perfect combination defeats the purpose of optimization. Set a short batching window and a maximum queue age. If a request reaches that age, the scheduler should admit it with the best available compatible group or send it to a dedicated lane. The correct balance depends on the product's latency objective, but the design principle is consistent: packing efficiency must remain subordinate to a usable response time.
Balance Throughput, Padding Ratio, and Tail Latency
Batch scheduling should be evaluated with a dashboard of related metrics rather than throughput alone. A higher tokens-per-second number can hide a longer queue, more time-to-first-token delay, or a worse p99 experience for short requests.
| Metric | What it reveals | Why it matters |
|---|---|---|
| Padding ratio | How much scheduled tensor capacity is unused | Shows shape mismatch and avoidable compute |
| Batch token utilization | Useful tokens relative to the configured budget | Shows whether packing is filling the execution window |
| Queue time | How long requests wait before admission | Separates scheduler delay from model execution time |
| Time to first token | Prompt-to-first-output responsiveness | Protects interactive user experience |
| Inter-token latency | Spacing between generated tokens | Shows decode contention and memory pressure |
| p95/p99 latency | Tail behavior under bursts and contention | Prevents average throughput from masking outliers |
Use controlled load tests to compare scheduler policies with the same model, hardware, traffic mix, and service objectives. Test both steady traffic and burst traffic. Include cancellations and long-context requests because they can change queue dynamics and KV-cache pressure.
Design Multi-Tenant Controls for Shared GPU Clusters
In a shared enterprise environment, a packing algorithm needs boundaries that protect tenants and workloads. Without quotas or priority rules, a high-volume route can fill every efficient batch and delay smaller but time-sensitive requests. Without observability by tenant, platform teams may see a healthy aggregate GPU utilization number while a specific business workflow misses its target.
An AI orchestration platform can expose model pools, GPU quotas, priority classes, developer workspaces, and workload metrics as one operating layer. OnePlus Platform is OneSource Cloud's AI orchestration platform for coordinating these types of workloads on dedicated infrastructure. The exact policy should be validated against the organization's models, data controls, and latency objectives rather than copied from a generic cluster template.
Implementation Checklist for Padding-Aware Scheduling
- Capture request shape data, including input tokens, output limits, model, tenant, and priority.
- Measure the current padding ratio and separate prefill, decode, and queue time.
- Define token, memory, KV-cache, and active-sequence budgets for each model pool.
- Create length-aware buckets from observed traffic instead of arbitrary context limits.
- Add bounded best-fit or first-fit packing with a maximum batching wait.
- Protect interactive and regulated workloads with quotas, priority classes, and isolation rules.
- Run load tests covering steady state, bursts, long prompts, cancellations, and mixed tenants.
- Review throughput, padding, p95/p99 latency, time to first token, and GPU memory headroom together.
Frequently Asked Questions
Does continuous batching eliminate tensor padding?
No. Continuous batching changes when sequences enter and leave an active batch, but requests can still have different shapes. Length-aware admission, bucketing, and packing are still useful for controlling padding and memory waste.
Is the largest possible batch always the most efficient?
No. A larger batch may improve raw throughput while increasing queue time, KV-cache pressure, and tail latency. The right batch size is constrained by the workload's latency objective, memory budget, and request distribution.
Should prefill and decode use the same scheduler?
They can share an orchestration layer, but their admission and fairness policies should account for different resource behavior. Prefill is driven more by prompt processing, while decode depends heavily on active sequences, KV cache, and token-step contention.
When does bin packing become too expensive for online scheduling?
When the decision time materially increases queue latency or causes unstable behavior under bursts. Bounded heuristics, coarse buckets, and short batching windows usually provide a practical compromise between packing quality and scheduling overhead.
Summary: Optimize the Scheduling Decision, Not Just the Kernel
LLM inference efficiency depends on how requests are admitted, grouped, and interleaved as much as on the model kernel. Length-aware buckets reduce obvious shape mismatch; bounded bin packing improves resource fit; separate prefill and decode policies protect different latency behaviors. The result should be judged with padding ratio, token utilization, queue time, tail latency, and memory headroom together.
For organizations operating multiple model-serving workloads, a dedicated private AI infrastructure environment can make these policies easier to measure and control across GPU pools. OneSource Cloud can help teams review inference architecture, scheduling constraints, storage and networking dependencies, and day-two operations. Request an architecture review to assess the right batching and orchestration approach for your workload.