Module 3 · GPUs and Kubernetes for AI · Chapter 10 · Free
Scheduling and sharing GPUs: MIG, time-slicing and quotas
- A whole GPU per small workload wastes the scarcest resource in the building.
- Sharing trades isolation for utilisation: MIG isolates in hardware, time-slicing has no memory isolation, MPS isolates weakly.
- Quotas and priority classes decide who gets GPUs, and who yields when the cluster is full.
The picture: a GPU is a workshop. Wall off rooms, take turns on the bench, or hand over the building.
- The four ways to allocate a GPU, and the isolation each really gives.
- The noisy neighbour failure shape of each mechanism.
- A worked sharing plan for one 80 GB card across three workloads.
- Quotas, priority and preemption, set so batch yields to serving.
Copperline is a made up B2B SaaS company. Its data science team and its support copilot share one GPU cluster informally: no quotas, no rules, just goodwill.
- At 2 p.m., a training run starts on the same card the copilot serves from.
- The copilot's latency roughly doubles (illustrative), and Ana, the support lead, hears about it from customers first.
- The training job did nothing wrong. Nobody told it the card was shared, or that serving came first.
Priya Nair, the staff platform engineer, decides sharing needs mechanism, not manners.
- Why whole GPU allocation wastes small workloads.
- MIG: hardware partitions with real isolation.
- Time-slicing and MPS: turns and shared contexts.
- Choosing per workload: isolation versus utilisation.
- Quotas, priority and preemption in Kubernetes.
- A worked 80 GB plan, then the matching lab.
Next: why one workload per GPU is so expensive.
Step 1: A whole GPU per small workload wastes the card
Kubernetes treats a GPU as indivisible. A pod requests one GPU and gets the entire card, however little it uses.
- The waste: a small model using 12 GB of an 80 GB card strands the other 68 GB. No other pod can touch it.
- The queue: the next workload waits for a free card, not for free memory, so users queue while utilisation looks low.
- The bill: Greg, the finance partner, pays for whole cards. Stranded memory is money spent on capacity nobody can use. Chapter 9 covers sizing each workload first.
Think of renting a whole warehouse for one bicycle. Where the picture breaks down:
- A GPU needs a named mechanism to subdivide it safely.
- Some loads really do fill the warehouse: large training runs should keep the whole card.
Next: the strongest split, partitions cut in hardware.
Step 2: MIG, hardware partitions with real isolation
MIG, Multi-Instance GPU, is a well known feature on supported NVIDIA cards. It partitions one GPU into separate instances, each with dedicated memory and compute.
- Isolation: memory and compute are separated in hardware. One instance cannot consume another's memory.
- Fault behaviour: a crash or memory blowout in one instance stays inside it. Neighbours keep serving.
- The cost: partitions come in fixed sizes. A workload that outgrows its partition cannot borrow idle space next door.
- The fit: production serving and mixed tenants, where predictable latency beats squeezing out every gigabyte.
In Kubernetes, the device plugin advertises each partition as its own resource, so a pod requests a partition the way it once requested a card.
Next: the looser mechanisms: turns and a shared context.
Step 3: Time-slicing and MPS, sharing without walls
Time-slicing lets several pods share one GPU by taking turns. The device plugin advertises the same GPU several times over, using a replica count an operator sets in its config.
- Isolation: none for memory. Every pod sees the whole card's memory, and one pod can take most of it.
- Failure shape: the noisy neighbour is a memory hog. One pod grows, another hits out of memory errors.
- The fit: trusted, bursty, small work: dev notebooks, experiments, tools that can retry.
MPS, the Multi-Process Service, sits between the two. Several processes share one GPU context at once, rather than taking turns.
- At a glance: MPS can raise utilisation for many small processes, with per client memory limits in some setups.
- The catch: isolation is weaker than MIG. One bad process can hurt the others.
- The fit: trusted workloads from one team, not tenants who must never affect each other.
Think of a kitchen. MIG is separate flats. Time-slicing is one kitchen used in turns. MPS is one kitchen, several cooks at once. Where the picture breaks down:
- Cooks can coordinate. GPU processes cannot, so collisions surface as errors, not apologies.
- MIG partition sizes are likewise fixed until an operator reconfigures the card.
Next: the four options side by side.
Step 4: Choose by workload
- Whole GPU: full memory and compute, total isolation. Fits training and any job that fills the card. Failure shape: cost and queues, not neighbours.
- MIG: strong isolation, fixed sizes, some stranded space. Fits serving, latency sensitive work, and tenants you do not fully trust.
- Time-slicing: best utilisation, no memory isolation. Fits trusted dev and retryable batch. Failure shape: one hog starves the rest.
- MPS: high concurrency, weaker isolation. Fits one team's small trusted processes. Failure shape: a fault in the shared context can spread.
One line: isolation buys predictable latency and safe tenants, and costs utilisation. Utilisation buys density, and costs the noisy neighbour page.
Predict first:
Time-slicing shares one memory pool with no isolation. The notebook's growth leaves too little for the copilot, whose requests then fail. Kubernetes does not preempt a running pod just because GPU memory ran out.
Next: the cluster level controls above any single card.
Step 5: Quotas, priority and preemption
Sharing decides what happens on one card. Quotas decide who may claim cards.
- Resource quotas: a
ResourceQuotacaps the total GPU count a namespace can request, counting whole GPUs or MIG partitions as advertised. - Limit ranges: a
LimitRangesets per pod maximums, so one pod cannot request every GPU in its namespace. - Priority classes: give serving a high
PriorityClassand batch a low one. When the cluster is full, the scheduler preempts low priority pods to place serving. - Preemption in practice: the batch job is evicted and requeues. That is the design working, so batch jobs must checkpoint and tolerate being killed.
# Illustrative: cap a namespace and rank serving above batch
apiVersion: v1
kind: ResourceQuota
metadata:
name: gpu-quota
namespace: data-science
spec:
hard:
requests.nvidia.com/gpu: "2"
---
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: serving-high
value: 100000
preemptionPolicy: PreemptLowerPriority
Priya caps data science at two GPUs, gives the copilot the high priority class, and training the low one. The 2 p.m. run now queues or yields.
Next: the picture, one card shared three ways.
Step 6: The picture, one GPU shared three ways
Press Next to walk a GPU request through the scheduler.
- A pod requests a GPU resource: a whole card, a MIG partition, or a shared slot.
- The quota caps the team's claims. Priority decides who wins when the cluster is full.
- The copilot lands on a MIG partition: hardware isolation, steady latency.
- Notebooks share a card in turns. Density is high, with no memory walls between them.
- The fine-tune takes a whole card at low priority, and yields by preemption when serving needs room.
Next: one card, three workloads, two plans, arithmetic shown.
Step 7: Worked example, one 80 GB card, three workloads
All figures here are illustrative. One 80 GB card, like an H100 SXM, hosts three workloads: the copilot (24 GB), an embeddings batch job (9 GB), and a dev notebook (7 GB). Total real use: 24 + 9 + 7 = 40 GB.
1. Whole GPU each. Three workloads claim three cards: 3 × 80 = 240 GB claimed for 40 GB used.
2. The MIG plan. Partition the card into slices of 40, 20 and 20 GB: 40 + 20 + 20 = 80 GB. The copilot takes the 40 GB slice, stranding 40 - 24 = 16 GB. Embeddings strand 20 - 9 = 11 GB. The notebook strands 20 - 7 = 13 GB. Total stranded: 16 + 11 + 13 = 40 GB, but every workload is hardware isolated.
3. The time-slicing plan. All three share one pool: 40 GB used, 80 - 40 = 40 GB free for bursts. Nothing is stranded.
4. The risk difference. Under time-slicing, if the notebook grows by 45 GB, it wants 7 + 45 = 52 GB, leaving 80 - 52 - 24 - 9 = -5 GB: someone fails. Under MIG, the notebook hits its own 20 GB wall and fails alone.
5. Priya's call. The copilot goes on MIG. The notebook and embeddings time-slice a second card, where a failure is a retry, not an incident.
Same workloads. The plans differ in where the waste sits and who feels a failure.
Next: the lab: you make the call for six workloads.
Step 8: Hands-on lab, match the workload to the mechanism
Why: teams get asked "can we just share a GPU?" weekly. The answer depends on isolation, trust and failure cost.
Lab: Copperline's three workloads share one GPU cluster on goodwill, and the cold open shows how that ends at 2 p.m. This lab runs in your browser and needs JavaScript enabled.
- Serving and untrusted work landed on isolation. Dev and retryable batch landed on sharing.
- No workload picked MPS: it fits best when one trusted team runs many small processes at once.
Next: a field note, then the mix-ups.
In production practice, GPU sharing is often adopted in stages: whole cards first, then time-slicing for dev, then MIG where isolation justifies fixed partitions. Treat that as a pattern, not a rule. The step teams most regret skipping is the quota: an uncapped cluster is claimed by whoever submits first.
Mix-ups to avoid
- "Time-slicing gives each pod its share of memory." It does not. It shares turns and one memory pool. Keep serving off it.
- "MIG slices can grow when a neighbour is idle." Sizes are fixed until the card is reconfigured. Size them from Chapter 9's math.
- "A quota stops noisy neighbours." A quota caps namespace claims. It does nothing about memory clashes inside one shared card.
- "High priority means batch never runs." Priority only bites when the cluster is full. Batch uses idle capacity the rest of the time.
- "MPS is just MIG with a different name." MPS shares a context with weaker isolation. MIG partitions in hardware.
Chapter quiz
Five questions. Score 70% to pass.
Review this chapter in 5 minutes
Watch the whole chapter recapped: MIG hardware partitions, time-slicing and MPS, quotas and priority, and a worked 80 GB sharing plan.
- Whole GPU per small workload strands most of the card.
- MIG: fixed hardware partitions, isolated memory and compute, fits serving and tenants.
- Time-slicing: turns on one card, no memory isolation, fits trusted dev and batch.
- MPS: one shared context, weaker isolation, fits one team's small trusted processes.
- Worked plan: 40 GB real use on one 80 GB card. MIG strands 40 GB but isolates; time-slicing strands nothing but risks a -5 GB clash.
- Quotas cap namespaces, priority ranks workloads, preemption makes batch yield.
Decision rule: if a workload is untrusted or latency sensitive, isolate it with MIG or a whole GPU; if it is trusted and can retry, share it.
Review
Glossary
- MIG
- Multi-Instance GPU: hardware partitions of one GPU, each with isolated memory and compute.
- Time-slicing
- Several pods share one GPU by taking turns, with no memory isolation. Example: eight notebooks on one card.
- MPS
- Multi-Process Service: processes share one GPU context at once, with weaker isolation than MIG.
- Device plugin
- The Kubernetes component that advertises GPU resources to the scheduler.
- Resource quota
- A per namespace cap on total resources, including GPU count. Example: at most two GPUs.
- Limit range
- Per pod defaults and maximums inside a namespace. Example: no pod may request over one GPU.
- Priority class
- A ranking the scheduler uses when capacity is scarce. Example: serving-high over batch-low.
- Preemption
- Evicting lower priority pods so higher priority pods can be placed.
- Noisy neighbour
- A co-located workload whose resource use harms yours. Example: a notebook filling shared GPU memory.
- Stranded capacity
- Resource claimed but unused by its owner and unusable by others. Example: 68 GB idle in a whole GPU allocation.
Next: "Kubernetes for AI workloads: operators, node pools and gang scheduling".