The user wants a GPU scheduling policy designed for Machine Learning (ML) workloads.
The key requirements are:
- Target: ML workloads (which have specific characteristics like long-running, bursty, preemption-sensitive, varying resource needs).
- Constraints: Quotas (fairness/accounting) and Priorities (urgency/importance).
1. Analyze the Problem Space:
2. Core Scheduling Approaches (The "How"):
- Static Partitioning: Divide GPUs physically. Too rigid.
- Time-Slicing: Context switch. Bad for ML (performance degradation, memory overhead).
- MPS (Multi-Process Service): Good for utilization, bad for isolation (memory faults crash everyone).
- MIG (Multi-Instance GPU): Hardware partitioning. Best for isolation, but rigid sizes.
- Software Scheduling (Kubernetes/YARN/Slurm): The meta-scheduler. This is usually what people mean by "scheduling policy."
3. Designing the Policy (The "Architecture"):
I need to propose a system that sits on top of a resource manager (like Kubernetes).
4. Structuring the Response:
I will structure this as a technical design document.
- Title: High-Level Design.
- Objectives: What are we optimizing for?
- Core Concepts: Define Quotas, Priorities, Fairness.
- The Policy Mechanism:
-
- Multi-Level Queue Structure.
-
- Weighted Fair Queuing (The algorithm).
-
- Preemption Strategies (Crucial for ML).
- Handling ML Specifics:
- Gang Scheduling.
- Fragmentation.
- Checkpointing.
- Implementation Example: Kubernetes context.
5. Refining the Logic (Self-Correction during drafting):
- Critique: Just using Round Robin isn't enough because distributed training needs all GPUs at once.
- Correction: Must include "Gang Scheduling" or "All-or-Nothing" semantics.
- Critique: Simple quotas block high-priority jobs if quota is full.
- Correction: Introduce "Resource Reclamation" (Lending). If Team A isn't using their quota, Team B can borrow it, but Team A gets it back instantly when needed.
- Critique: Killing a training job running for 3 days is painful.
- Correction: Suggest "Graceful Preemption" using signals (SIGTERM) to trigger a checkpoint before SIGKILL.
6. Drafting the Policy Details:
- Quota Model: Hierarchical (Org -> Team -> User). Hard Quota (Guaranteed) vs. Soft Quota (Burst).
- Priority: Numeric score.
- Scoring Function:
Score = (PriorityWeight * JobPriority) + (FairnessWeight * (1 / UsageRatio)).
- Actually, a two-pass approach is better: Filter by priority first, then sort by fairness? Or strictly strictly Priority > Quota?
- Decision: Strict Priority within Guaranteed Quota, Fairness within Best-Effort. But if High Priority hits Quota Limit, they must preempt Low Priority.
7. Final Polish:
Make it readable. Use diagrams (ASCII art) or bulleted lists. Ensure terms like "Fragmentation," "Gang Scheduling," and "DRF" are used correctly. Focus on Kubernetes since it's the industry standard.
(Self-Correction on GPU Sharing):
Should I mention MPS/MIG?
- MIG: Mention as an optimization for splitting A100/H100s.
- MPS: Mention with caution due to isolation.
- Time-slicing: Mention as a fallback.
8. Summary of the Proposed Policy: "Priority-Aware DRF with Graceful Preemption"
- Inputs: Job (GPU needs, Priority, User/Team).
- State: Cluster Usage, Quota DB.
- Logic:
- Filter: Can fit? Gang scheduling ok?
- Priority Check: Is this High Priority?
- Quota Check: Do they have guaranteed quota left?
- Preemption: If no space, identify victims (Low priority + Over Quota).
- Selection: Pick node to minimize fragmentation.
Let's write it out.
Outline for Output:
- Design Goals: Utilization, Fairness, Low Latency (Inference), High Throughput (Training).
- Resource Model: Definition of Quotas and Priority Classes.
- The Scheduling Algorithm (The Core):
- Step 1: Admission & Quota Validation.
- Step 2: The "Gang" Constraint.
- Step 3: Bin Packing (Anti-fragmentation).
- The Preemption Policy (The Safety Valve):
- Victim Selection.
- Graceful Shutdown (Checkpointing).
- Advanced Features:
- Quota Lending (Overcommit).
- Load Awareness (Topology).
- Architecture Diagram (Mental model).
This looks solid. I will generate the response based on this structure.
Designing a GPU scheduling policy for Machine Learning (ML) workloads requires balancing three conflicting goals: utilization (keep GPUs busy), fairness (respect quotas), and performance (minimize latency for high-priority jobs).
Unlike CPU scheduling, ML workloads are often "monolithic" (an entire training job needs N GPUs simultaneously to function) and state-sensitive (killing a job after 23 hours of training is catastrophic).
Below is a comprehensive design for a Priority-Aware, Cost-Efficient GPU Scheduler.
1. Core Abstractions
To implement quotas and priorities, we first define the workloads and resources.
- Pod/Job: The unit of work.
- Resource Request: Number of GPUs, Memory, Topology requirements (e.g., NVLink).
- Priority Class: (e.g.,
Production, High, Medium, Low/Preemptible).
- Quota Scope: The team or project ID the job belongs to.
- GPU Node: A physical machine.
- Allocatable Resources: Total GPUs.
- Shared Memory: Determines if we use MIG (Multi-Instance GPU) or MPS (Multi-Process Service) for fractional sharing.
2. The Scheduling Policy Architecture
We will use a Modified Weighted Fair Queuing approach with a Two-Level Queue.
Level 1: Logical Quota Management (The "Admission Controller")
Before a job even reaches the physical nodes, it must pass the Quota check.
- Quota Enforcement: The scheduler checks the Team’s usage.
- Guaranteed Quota: Team A pays for 10 GPUs. They can run 10 GPUs indefinitely.
- Burst Quota: If the cluster is idle, Team A can burst to 20 GPUs.
- Debt Accounting: If Team A is bursting and a paying customer needs resources, Team A becomes "indebted" and their burst jobs become eligible for preemption.
Level 2: Physical Placement (The "Binder")
This is where the actual GPU assignment happens. We will use a policy of "Best-Effort Gang Scheduling."
3. Detailed Policy Mechanisms
A. The "Gang" Scheduling Constraint
ML Training usually requires all GPUs simultaneously. If a job requests 8 GPUs, the scheduler uses an "All-or-Nothing" policy.
- Implementation: The scheduler holds the job in a pending state until 8 GPUs are available on a single node (or across compatible nodes for distributed training). This avoids "deadlock" where half a job is running, eating quota, but doing no work.
B. Priority & Preemption Logic (The Core Loop)
When a High Priority job arrives and no resources are free:
- Filter: Identify running jobs that are Preemptible (Low Priority) or Bursting (exceeding their guaranteed quota).
- Victim Selection: Score potential victims based on:
- Lowest Priority: Kill
Low before Medium.
- Smallest Footprint: Kill the job that frees up just enough GPUs for the incoming job (to minimize wasted compute).
- Progress Check: (Crucial for ML) Ideally, do not kill jobs close to completion.
- Graceful Preemption (Checkpointing):
- Instead of
SIGKILL (immediate termination), the scheduler sends a SIGTERM or a custom API signal to the Job Driver.
- Grace Period: The job has 60-120 seconds to save model weights to disk (checkpoint).
- Force Kill: If the timer expires, the job is killed.
C. Fragmentation Management (Bin Packing)
To ensure large training jobs can fit, we need to minimize fragmentation.
- Policy: Most Requested Fit First.
- Instead of spreading small jobs across empty nodes, pack them tightly onto the fullest node. This leaves whole nodes empty for large distributed training runs.
4. Handling Different ML Phases
Different ML phases have different tolerances for latency and preemption.
| Phase | Sensitivity | Scheduling Policy |
|---|
| Inference | Latency Sensitive | Dedicated / Static Partitioning. Bind specific GPUs to inference pods. No preemption allowed. |
| Training | Throughput Sensitive | Gang Scheduling + Checkpointing. Allow preemption, but enforce "Graceful Shutdown" to save state. |
| Notebooks | Interactive | Time-Slicing. If idle, grant access. Implement an "Idle Watchdog" to kill notebooks after 30m of inactivity to free quota. |
| Hyperparameter Tuning | Parallel / Short | Fractional Sharing (MIG). Slice GPUs into smaller instances to run many small trials in parallel. |
5. Advanced Feature: "Reallocatable" Quotas
To maximize utilization while respecting priorities, implement a Lending System.
- Reserved: Team A has 10 GPUs. They are using 4.
- Lending: The system marks 6 GPUs as "Lent" to a global pool of Low-Priority jobs (e.g., Team B's experiments).
- Reclamation: Team A suddenly submits a big job needing 10 GPUs.
- Immediate Recall: The scheduler immediately preempts Team B's jobs running on the "Lent" GPUs to return them to Team A.
6. Summary of the Algorithm (Pseudocode)
def schedule(new_job):
# 1. Check Quota
if not has_quota(new_job.team) and not is_cluster_idle():
reject(new_job, "Quota Exceeded")
# 2. Find Resources (Gang Scheduling)
free_gpus = find_free_gpus(new_job.requirements)
if len(free_gpus) >= new_job.gpu_count:
allocate(new_job, free_gpus)
return
# 3. If full, try Preemption
candidates = find_preemptible_jobs()
# Sort by Priority (Asc), then Progress (Asc - kill youngest first)
candidates.sort(key=lambda x: (x.priority, x.progress))
for victim in candidates:
if can_fit_after_eviction(new_job, victim):
signal_checkpoint(victim) # Graceful shutdown signal
wait(60) # Wait for checkpoint
kill(victim)
allocate(new_job)
return
# 4. If no preemption possible, Queue the job
queue(new_job)
7. Implementation Recommendations
- Kubernetes: Use the Volcano or YuniKorn scheduler. They support "Gang Scheduling" and "Preemption" natively.
- Bin Packing: Configure the scheduler
MostRequestedPriority to reduce fragmentation.
- Topology: If using distributed training, ensure the scheduler is "Topology Aware" (places GPUs on the same switch/rack to minimize network latency).