AI Operations

Slurm for GPU Clusters: Scheduling Training Jobs on HPC-Style Infrastructure

Slurm schedules GPU training jobs by detecting, allocating and tracking GPUs as Generic Resources (GRES). A correctly configured cluster keeps healthy nodes available, allocates the requested GPU type and count, and enforces device access and resource limits.

This guide covers six steps for configuring and verifying GPU scheduling on an installed Slurm cluster with NVIDIA GPU nodes.

Step 1: Enable GPU Scheduling in Slurm

Slurm enables no generic resources by default. Configure GresTypes and per-node Gres= entries in slurm.conf to declare the GPUs available for scheduling.

The AutoDetect option in gres.conf detects GPU details, but slurm.conf still needs Gres= to specify the expected count.

  • AutoDetect=nvml detects NVIDIA GPUs through NVML.
  • AutoDetect=nvidia, introduced in Slurm 24.11, requires no NVML library but cannot detect MIG instances or NVLinks.
  • File= entries in gres.conf must appear in increasing numerical order.

The selection plugin determines allocation granularity:

  • select/linear allocates whole nodes.
  • select/cons_tres allocates consumable resources such as CPUs, cores and sockets, and manages GPUs as trackable resources. The --gpu* options require this plugin.

Slurm places nodes in DRAIN when detected resources fall below configured counts or autodetected GPU properties conflict with the configuration. To expose only some installed GPUs, configure them manually in gres.conf without autodetection.

GPU affinity operates at socket boundaries. Cores values must align with Slurm's socket topology; arbitrary core-level GPU scheduling is not supported.

Use slurmd -C to inspect detected resources and slurmd -G to test GRES configuration. Scheduler selection also depends on fabric, storage and power, as discussed in GPU server cluster design.

Verification: Confirm the node stays out of DRAIN and slurmd -G reports the intended GPUs.

Step 2: Request GPUs at Submit Time

Slurm allocates no GRES unless a job requests them. Jobs can use --gres or the --gpu* options:

RequestAllocation
--gres=gpu:a100:4Four A100 GPUs per allocated node
--gpus=4Four GPUs across the job allocation
--gpus-per-node=4Four GPUs per allocated node

The --gpu* options require select/cons_tres.

Typed and untyped requests must remain consistent between jobs and steps. For example, a job requesting gpu:a100:4 cannot create a step requesting the untyped gpu:2.

Job steps normally inherit the job's allocated GRES, although they can request different counts. Resources implicitly assigned through exclusive node access are an exception.

Verification: Confirm the job receives the requested GPU type and count, with consistent GRES types across steps.

Step 3: Verify Which GPUs Each Job Sees

Slurm sets CUDA_VISIBLE_DEVICES for each job step to identify its allocated GPUs. The variable is set when tasks launch on compute nodes, not globally by salloc. With sbatch, its initial value reflects the allocation's first node.

GPU visibility does not guarantee isolation. CUDA_VISIBLE_DEVICES controls CUDA enumeration, while Linux device cgroups can restrict access to GPU device files. Both should be verified.

Prolog and Epilog execute outside the job's device cgroup, so GPU indices may differ. For example, a GPU identified as /dev/nvidia1 by a Prolog may appear as GPU 0 inside the constrained job.

NVML, used by nvidia-smi, numbers GPUs by PCI bus ID. Set CUDA_DEVICE_ORDER=PCI_BUS_ID to use PCI-bus ordering in CUDA instead of the default FASTEST_FIRST, as explained in NVIDIA's CUDA documentation.

Linux device-file indices use minor-number assignments that do not necessarily match NVML indices. Their mapping can change after reboots or hardware changes, so verify it after boot.

Suspended jobs retain their allocated GPUs and do not release that capacity for queued training jobs.

Verification: Check GPU visibility, access restrictions and the mapping between CUDA, NVML and physical devices.

Step 4: Schedule Multi-Node Training with Backfill

Slurm loads backfill scheduling by default. Backfill starts lower-priority jobs when doing so will not delay higher-priority jobs, improving utilization compared with strict priority scheduling. For efficiency, it reserves whole nodes even when jobs require only part of their resources.

Backfill requires realistic walltime estimates:

  • DefaultTime sets a partition's default walltime.
  • MaxTime sets its maximum walltime.
  • OverTimeLimit controls additional time allowed before terminating a job that exceeds its walltime limit.

Excessive walltime estimates reduce backfill opportunities.

Jobs submitted to multiple partitions can receive separate reservations. The bf_one_resv_per_job option limits each job to one reservation but may prevent its earliest possible start across partitions.

Use squeue --start to estimate when pending jobs will begin. Reserved nodes appear in the Planned state.

For topology-aware scheduling, max_switch_wait controls how long a job can wait for its desired number of leaf switches. The default is 300 seconds.

Verification: Submit a multi-node job and confirm its estimated start time and reservations reflect realistic walltime requirements.

Step 5: Choose Whole GPUs, MIG, MPS or Sharding

Slurm supports whole-GPU allocation and three sharing mechanisms: Multi-Instance GPU (MIG), CUDA Multi-Process Service (MPS) and sharding. They differ in isolation, allocation and accounting.

CriterionMIGMPSSharding
AllocationHardware-partitioned GPU instance; up to seven on an A100Configured share of GPU execution resourcesScheduler-defined GPU share
IsolationHardware isolation with cgroup supportShared GPU; different users' MPS servers are serialized by the standard control daemonNo process fencing
SetupSlurm 21.08+; instances partitioned beforehandselect/cons_tres; MPS servers managed through Prologselect/cons_tres
LimitsNo NVML-based gpumem or gpuutil accounting for MIG instancesRequests use one GPU per node by default; no frequency setting or proportional performance guaranteeNo frequency setting; shard counts do not enforce compute or memory limits

MIG creates hardware-isolated GPU instances that Slurm schedules as individual GPUs. Slurm cannot dynamically create these partitions.

MPS allows CUDA processes to share GPU execution resources. Configured percentages constrain execution resources but do not guarantee equivalent memory, throughput or performance. The Slurm distribution provides an MPS Prolog example at etc/prolog.example.

Sharding allows multiple jobs to use one GPU without process isolation, making it better suited to known, homogeneous workloads.

These approaches involve different isolation and density tradeoffs, discussed further in fractional GPU allocation.

A physical GPU cannot simultaneously be allocated as gres/gpu and gres/mps or gres/shard. MPS and sharding allow multiple jobs to share a GPU within configured resource counts.

For NVIDIA GPUs using AutoDetect=nvml, AccountingStorageTRES=gres/gpu automatically enables gres/gpumem and gres/gpuutil accounting. This mechanism does not support MIG utilization accounting.

Verification: Confirm jobs request the correct GRES and that allocation, isolation and accounting behave as configured.

Step 6: Bound GPU Use with Accounts and QoS

Slurm's Quality of Service (QoS) controls three aspects of scheduling:

  1. Priority: QoS affects job priority when multifactor scheduling is active and PriorityWeightQOS > 0.
  2. Preemption: With PreemptType=preempt/qos, QoS determines which jobs may preempt others.
  3. Resource limits: QoS restricts jobs and trackable resources (TRES), including GPUs.

Slurm generally evaluates limits in this order:

Partition QoS → Job QoS → User association → Account association → Cluster association → Partition limits.

Exceptions include group limits and partition walltime and node-count restrictions. Applicable QoS flags can override some partition limits.

Jobs exceeding applicable limits usually remain pending. DenyOnLimit rejects individually over-limit submissions and treats group limits as maximum limits for that check.

Partition QoS normally overrides job QoS unless Flags=OverPartQOS is set. Group limits apply across partitions sharing a QoS. For example, GrpTRES=cpu=20 assigned to two partitions permits 20 CPUs total, not 20 per partition.

Typed GPU Limit Bypass

Slurm documents a limitation with typed GRES limits: MaxTRESPerUser=gres/gpu:tesla=1 does not restrict a generic request such as --gres=gpu:2.

A job-submit plugin can require typed GPU requests to prevent this bypass.

For enforcement and accounting:

  • Include generic and typed resources in AccountingStorageTRES, with appropriate TRESBillingWeights.
  • Configure AccountingStorageEnforce to enforce association and QoS requirements. The safe option helps ensure jobs subject to TRES-minute limits can complete.
  • Reducing limits does not terminate running jobs; updated limits affect subsequent scheduling and submissions.

Verification: Confirm over-limit jobs pend or are rejected, and generic requests cannot bypass typed GPU limits.

Mixed GPU Models in One Cluster

Typed GRES distinguish GPU models. Nodes can advertise gpu:a100 or gpu:a10, allowing jobs to request the required type.

For multi-node training jobs requiring homogeneous GPUs, assign node features by GPU model and use --constraint to select compatible hosts.

Another approach, described in a Stack Overflow discussion by damienfrancois, submits separate model-specific jobs with singleton dependencies and cancels the alternative when one starts. This requires explicit cancellation logic; singleton dependencies alone do not implement a first-job-wins policy.

Typed GRES specify the requested GPU model, while node constraints restrict eligible hosts.

Slurm on Kubernetes: Slinky

Slinky integrates Slurm with Kubernetes for environments running both HPC-style training jobs and containerized workloads.

Developed by SchedMD and supported by NVIDIA, it provides two main components:

  • slurm-operator: Runs and manages Slurm clusters on Kubernetes, including Slurm daemons.
  • slurm-bridge: Uses Slurm to schedule selected Kubernetes workloads, allowing Slurm and Kubernetes workloads to share cluster infrastructure.

Slinky is useful when Kubernetes already orchestrates containerized workloads, but GPU training jobs require Slurm's scheduling, accounting or resource-allocation capabilities.

Verification Checklist

After configuring Slurm, confirm:

  1. Node health: sinfo shows nodes in an appropriate state, such as idle or mixed, rather than DRAIN.
  2. GPU detection: slurmd -G matches intended GPU resources, accounting for excluded GPUs or MIG instances.
  3. Visibility and isolation: CUDA_VISIBLE_DEVICES shows allocated GPUs, and device cgroups restrict unallocated devices where enabled.
  4. Device mapping: CUDA, NVML and Linux device indices are reconciled after boot.
  5. Prolog logging: GPU indices recorded outside job cgroups map correctly to job-visible devices.
  6. Backfill: squeue --start reports expected start times and reservations reflect realistic walltime limits.
  7. Resource enforcement: Generic GPU requests cannot bypass typed-GRES limits.
  8. Walltime configuration: DefaultTime and MaxTime reflect realistic training-job durations.

Repeat these checks after Slurm upgrades, GPU driver changes, node reboots or edits to slurm.conf and gres.conf.

Zettabyte's zWARE provides GPU scheduling, monitoring, diagnostics, recovery and cluster-wide visibility through its GPU infrastructure management software layer.