Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Placement | Deciding which models run on which nodes, and how many replicas of each. |
| Bin packing | Fitting items of different sizes into as few fixed-size boxes as possible. Here: replicas into 8-GPU nodes. |
| Fragmentation | Free GPUs scattered across nodes in pieces too small for the next replica. |
| Hysteresis | Only acting when a change is clearly worth it, so the system does not flip back and forth on noise. |
| Gang scheduling | Placing all pods of a group together or none of them (21.c). |
| Queue (in Kueue / KAI) | A named share of cluster capacity that a team’s workloads are admitted from. |
| Preemption | Stopping a lower-priority workload to make room for a higher-priority one. |
1. Problem → Why → Optimization#
GIVEN N nodes with GPUs of several types and topologies
M models, each with GPU needs (21.b) and traffic that changes all day
tenant quotas and priorities (21.f)
DECIDE which models run where, and how many replicas of each
CONSTRAINTS a replica needs a fixed number of GPUs of the right type in one NVLink domain
moving a replica costs minutes (weights load, compile, warm up: 20.h)
demand moves continuouslyThis is bin packing with expensive moves and a moving target. The expensive moves are what make it different from ordinary Kubernetes scheduling, where moving a stateless web pod costs seconds.
The optimization: concentrate traffic on few, well-batched replicas; tier the long tail of models; pack nodes instead of spreading; standardise replica sizes; cache weights on nodes so moves get cheap; and limit churn.
2. Why does it exist?#
The default Kubernetes scheduler places one pod at a time on any node with enough free resources. For inference it misses most of what matters:
✗ it does not know that moving a model costs minutes
✗ it does not know traffic per model, so it cannot size replica counts
✗ its default scoring (NodeResourcesFit with LeastAllocated) prefers EMPTIER nodes:
it spreads, which fragments GPUs
✗ it does not know which nodes already hold a model's weights
✗ it places pods one by one, so a multi-pod instance can be half-placed (no gang)
✗ it has no notion of team queues, fair share or borrowing idle quotaSpreading also hurts throughput: splitting one model’s traffic over more replicas than it needs lowers each replica’s batch size and its tokens per GPU (14.m). For inference you usually want to concentrate traffic on fewer, fuller replicas.
3. Simple analogy#
Allocating rooms in a conference centre. Large events need whole halls; small meetings need one room. If you seat each small meeting in a different hall “to spread the load”, no hall is left free when a large event books. And moving an event already set up costs hours of work, so you only do it when the gain is clear.
4. Tiny example: tiering a real traffic mix#
Measure requests per model per hour over a week. In nearly every multi-model platform a handful of models take most of the traffic:
Model req/hour tier placement
chat-large 42,000 hot 6 dedicated replicas
chat-small 18,000 hot 3 dedicated
code-assist 9,500 hot 2 dedicated
summarize 2,100 warm 1 dedicated, shares a node
translate 340 warm shared pool, always resident
legal-v2 45 cold loaded on demand
…40 more < 50 cold shared pool, LRU swapping (20.i)
COLD-TIER SLO: "the first request to a cold model may take up to 90 seconds"Publishing a different SLO for cold models is what makes the long tail affordable. Without it every model must stay resident, and 45 rarely used models hold more GPUs than the 5 busy ones. Whether swapping works for a given model is arithmetic on its load time and request rate (20.i).
5. Technical explanation#
The placement objective#
MINIMISE GPUs allocated
SUBJECT TO every model meets its SLO at its demand
tenant quotas are respected
placement changes are few
replicas(model) = ceil(demand(model) / capacity_per_replica(model) / target_utilisation)
(capacity per replica is MEASURED for that model, 22.g)A scoring function for “this replica on this node”:
score(model, node) =
+ w1 × weights already cached on the node fast start
+ w2 × NVLink domain fits the TP degree performance
+ w3 × GPU type is the model's preference cost per token (21.l)
+ w4 × node is already partly used pack, do not spread
− w5 × fragmentation this placement creates
− w6 × known noisy neighbour on the nodew1 is worth more than people expect. A node that already holds the weights turns a
six-minute start into a 40-second one, which changes which placement moves are affordable at all.
Strategies#
| Strategy | How | Use when |
|---|---|---|
| Static | A plan written by hand | A few high-traffic models |
| Demand-proportional | Recompute replica counts hourly from the formula above; apply gradually | The usual answer for a medium platform |
| Bin packing with hysteresis | Solve the packing; apply a change only if the gain beats a threshold | Many models, steady demand |
| Tiered | Hot dedicated, warm shared and resident, cold swapped | 50+ models with skewed traffic |
The scheduler layer in 2026#
You rarely write a scheduler. You choose one, or several, and configure it:
| Tool | What it adds | Status (Nov 2026) |
|---|---|---|
| kube-scheduler | Plugins; switch scoring to MostAllocated to pack; DRA device selection (21.c) | Kubernetes 1.37; built-in Workload API and gang scheduling beta, off by default |
| Kueue | Queues and quotas per team (ClusterQueue, LocalQueue), borrowing, fair sharing, preemption, topology-aware scheduling, MultiKueue across clusters; manages Deployments, StatefulSets and LeaderWorkerSets as well as batch jobs | v0.20.5, Kubernetes SIG project |
| KAI Scheduler | Hierarchical queues with fair share, gang scheduling, bin packing or spread, topology-aware scheduling, fractional GPUs (21.d); integrated with Dynamo’s Grove | v0.19.0; open-sourced by NVIDIA from Run:ai in 2025, CNCF Sandbox |
| Volcano | Batch scheduler with gang scheduling, queues and many job types | v1.16.0, CNCF |
| Framework controllers | llm-d, Dynamo, AIBrix, KServe size and roll out pools (21.j) | See 21.j |
A common split: Kueue or KAI decides whether and when a workload gets capacity (quota, priority, gang admission), kube-scheduler or KAI decides where, and a placement controller of your own decides how many replicas of which model.
Fragmentation and how to prevent it#
node0: [8-GPU model ] full
node1: [4-GPU][2][1][1] full
node2: [4-GPU][2] [2 free] a 4-GPU replica cannot fit
node3: [1][1][1][1][1] [3 free]
Free: 5 GPUs. Largest free block on one node: 3. An 8-GPU replica cannot be placed.Mitigations, cheapest first:
- Pack instead of spread. Best-fit placement keeps whole nodes free. In Kubernetes, use
MostAllocatedscoring or a scheduler with bin packing (KAI, Volcano). - Standardise replica sizes on 1, 2, 4 or 8 GPUs. This also matches what NVLink topology and attention-head counts want for tensor parallelism (14.c).
- Specialise node pools: some for 8-GPU replicas, some for small ones.
- Place the largest first when you plan from scratch.
- Defragment in low-traffic windows, one replica at a time (21.l). Expensive; make it rare.
Implementing the placement controller#
OPTION A a controller that adjusts Deployment replica counts and node affinities
OPTION B a custom scheduler plugin implementing the score above
OPTION C an external controller that computes the desired placement, writes it as
replica counts, affinities and queue assignments, and lets Kubernetes enact it
→ the pragmatic choice: decoupled and testable// Sketch of the controller loop (option C).
func reconcile(ctx context.Context) {
demand := metrics.DemandPerModel(time.Hour)
capacity := registry.MeasuredCapacityPerReplica() // per model, from benchmarks
desired := map[string]int{}
for model, d := range demand {
desired[model] = int(math.Ceil(d / capacity[model] / tier(model).TargetUtil))
}
plan := pack(desired, cluster.Nodes(), score) // best fit, largest first
changes := 0
for _, c := range diff(k8s.CurrentPlacement(ctx), plan) {
if c.Benefit < hysteresisThreshold {
continue // not worth a five-minute move
}
if changes++; changes > maxChangesPerHour {
break // limit churn
}
enact(ctx, c) // one replica at a time, wait for ready
}
}The benefit threshold and the churn limit are what stop the controller thrashing. Without them, ordinary demand noise causes continuous replacement, and every replacement is minutes of lost capacity.
6. Under the hood: why packing beats spreading#
Replicas come and go on a 16-node cluster of 8-GPU nodes. Each step, a replica either scales down or a new one asks for a size. We count how often an 8-GPU replica is refused even though 8 or more GPUs are free in total.
// packing.go — replicas come and go on a 16-node cluster of 8-GPU nodes.
// How often does an 8-GPU replica fail to place although 8 or more GPUs are free?
package main
import (
"fmt"
"math/rand/v2"
)
const nodes, perNode = 16, 8
type policy func(free []int, need int) int // returns a node index, or -1
// spread: the emptiest node that fits (the Kubernetes default leans this way).
func spread(free []int, need int) int {
best := -1
for i, f := range free {
if f >= need && (best < 0 || f > free[best]) {
best = i
}
}
return best
}
// pack: the fullest node that still fits (best fit).
func pack(free []int, need int) int {
best := -1
for i, f := range free {
if f >= need && (best < 0 || f < free[best]) {
best = i
}
}
return best
}
func simulate(name string, sizes []int, place policy) {
r := rand.New(rand.NewPCG(7, 7))
free := make([]int, nodes)
for i := range free {
free[i] = perNode
}
type replica struct{ node, gpus int }
var running []replica
bigTries, bigStranded := 0, 0
for step := 0; step < 20000; step++ {
if len(running) > 0 && r.Float64() < 0.5 { // a replica scales down
k := r.IntN(len(running))
free[running[k].node] += running[k].gpus
running = append(running[:k], running[k+1:]...)
continue
}
need := sizes[r.IntN(len(sizes))]
n := place(free, need)
total := 0
for _, f := range free {
total += f
}
if need == perNode {
bigTries++
if n < 0 && total >= perNode {
bigStranded++ // enough GPUs exist, but not on one node
}
}
if n >= 0 {
free[n] -= need
running = append(running, replica{n, need})
}
}
fmt.Printf("%-24s 8-GPU replica blocked by fragmentation: %4.1f%% of attempts\n",
name, 100*float64(bigStranded)/float64(bigTries))
}
func main() {
odd := []int{1, 2, 3, 5, 6, 8}
pow2 := []int{1, 2, 4, 8}
simulate("odd sizes, spread", odd, spread)
simulate("odd sizes, pack", odd, pack)
simulate("powers of two, spread", pow2, spread)
simulate("powers of two, pack", pow2, pack)
}Output:
odd sizes, spread 8-GPU replica blocked by fragmentation: 20.2% of attempts
odd sizes, pack 8-GPU replica blocked by fragmentation: 11.2% of attempts
powers of two, spread 8-GPU replica blocked by fragmentation: 20.4% of attempts
powers of two, pack 8-GPU replica blocked by fragmentation: 7.2% of attemptsHow to read it:
- Packing roughly halves fragmentation whatever the sizes. It is the bigger lever.
- Powers of two help only together with packing. Spreading scatters small replicas so widely that tidy sizes cannot save you.
- The exact percentages depend on the size mix and churn rate in this toy model; the ordering is what carries over.
7. Performance implications#
- Concentrated replicas batch better. Four replicas at batch 32 usually produce more tokens per GPU than eight at batch 16 (14.m), as long as the latency SLO holds.
- Every move is lost capacity. A replica that takes five minutes to load and warm is five minutes of GPUs serving nothing. Node weight caches and fast loaders (20.g) shrink this cost.
- Topology-aware placement keeps tensor-parallel groups on NVLink and prefill/decode pairs in the same rack (9.d, 14.j).
- GPU type matters. Matching decode-heavy models to high-bandwidth GPUs and prefill-heavy ones to high-FLOP GPUs changes cost per token (21.l).
8. Production implications#
- Measure per-model traffic first. The distribution decides the strategy.
- Tier your models and publish a separate SLO for the cold tier.
- Pack, do not spread, and standardise on 1, 2, 4 or 8 GPUs per replica.
- Cache weights on nodes so placement changes are cheap enough to make.
- Add hysteresis and a churn limit to anything that moves replicas automatically.
- Use a queueing scheduler (Kueue or KAI) when several teams share the cluster, so quotas, borrowing and preemption are explicit (21.f).
- Rebalance in low-traffic windows, never at peak.
9. Common mistakes#
- Leaving the default spreading behaviour for GPU pods. Fragmentation and smaller batches.
- Treating every model the same. The long tail holds most of the GPUs.
- No hysteresis. The controller thrashes on demand noise.
- Odd replica sizes (3, 5, 6, 7 GPUs).
- No node weight cache. Every move costs minutes.
- Ignoring NVLink and rack topology when placing multi-GPU and multi-node replicas.
- Rebalancing at peak traffic.
- No pin list in the shared pool, so a busy model gets evicted and thrashes (20.i).
- Running two schedulers on the same nodes without coordination, so each places pods into capacity the other thinks is free.
10. Hands-on exercise#
- Measure the distribution. For a real or synthetic multi-model workload, plot requests per model. What fraction of models carries 95% of traffic? Design the tiers.
- Run
packing.go. Change the scale-down probability from 0.5 to 0.3 (a fuller cluster) and to 0.7. How does the gap between pack and spread change? Add a policy that places 8-GPU replicas first on reserved nodes. - Build the controller in simulation. Implement the section 5 loop with a week of synthetic demand. Measure GPUs used, SLO misses and number of moves, with and without hysteresis.
- Configure a real scheduler. In a test cluster, install Kueue or KAI Scheduler, create two team queues with quotas and borrowing, and show a high-priority serving workload preempting a batch job.
11. Interview questions#
- Why is the default Kubernetes scheduler not enough for model placement?
- Why is spreading the wrong default for inference replicas?
- Design a scoring function for placing a replica on a node.
- What is hot/warm/cold tiering and why does it matter?
- How does GPU fragmentation arise, and what are the cheapest fixes?
- What stops a placement controller thrashing?
- Compare Kueue, KAI Scheduler and Volcano. Where does each fit in an inference platform?
12. Further reading#
Checked on 12 November 2026.