Requesting and Allocating GPUs
Last updated on 2026-08-27 | Edit this page
Estimated time: 35 minutes
Overview
Questions
- How do you request GPUs in SLURM jobs?
- What are GPU job parameters?
- How do you run interactive GPU sessions?
- How do you allocate multiple GPUs?
Objectives
- Submit GPU jobs with correct parameters
- Launch interactive GPU sessions
- Request multiple GPUs when needed
- Understand GPU partition and time limits
GPU Job Submission Basics
Simple GPU Job
BASH
#!/bin/bash
#SBATCH --job-name=gpu_test
#SBATCH --partition=gpu
#SBATCH --gres=gpu:1
#SBATCH --time=01:00:00
#SBATCH --output=gpu_%j.log
module load miniconda3
conda activate pytorch_env
python3 train_model.py
Key options: - --partition=gpu: Must request GPU
partition - --gres=gpu:1: Number and type of GPUs -
--time=01:00:00: Max 720 hours per job
Interactive GPU Sessions
Memory and Core Allocation
CPU Allocation
For each GPU, allocate 4-8 CPU cores for: - Data loading - Preprocessing - I/O operations
Why CPU Cores Matter for GPU Jobs
Under-allocating CPUs creates a bottleneck: - GPU sits idle waiting for data - Data loading becomes the limiting factor - Job runs slow despite having GPU
Rule of thumb: 4-8 CPU cores per GPU for efficient
data feeding. Monitor GPU utilization with nvidia-smi to
verify CPU isn’t bottlenecking.
Time Limits
GPU partition allows: - Max 720 hours (30 days) per job - Typical: 1-8 hours for training - Recommended: Start with 1 hour for testing
Batch Scripts with Setup
Complete example:
BASH
#!/bin/bash
#SBATCH --job-name=deep_learning
#SBATCH --partition=gpu
#SBATCH --gres=gpu:a100:1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=8
#SBATCH --mem=32G
#SBATCH --time=04:00:00
#SBATCH --output=%x_%j.log
#SBATCH --error=%x_%j.err
# Setup environment
module purge
module load miniconda3 cuda/12.2.1
conda activate pytorch_env
cd /bigdata/lab/<labname>/project
# Check GPU
echo "GPU allocation:"
nvidia-smi
# Run training
python3 train.py --gpu 0 --batch-size 32 --epochs 100
echo "Training complete"
Challenge: Write a GPU Job Script
Write a complete SLURM batch script that meets the following requirements:
-
Job name:
pytorch_training - GPUs: 2 NVIDIA A100s
- Time limit: 4 hours
- Memory: 64 GB
- CPU cores: 8 per task (for data loading)
-
Software: Load the
cuda/12.2.1module and activate yourpytorch_envconda environment -
Command: Run
python3 train.py --distributed - Output: Log file named with the job name and job ID
BASH
#!/bin/bash
#SBATCH --job-name=pytorch_training
#SBATCH --partition=gpu
#SBATCH --gres=gpu:a100:2
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=8
#SBATCH --mem=64G
#SBATCH --time=04:00:00
#SBATCH --output=%x_%j.log
#SBATCH --error=%x_%j.err
# Load required modules
module purge
module load miniconda3 cuda/12.2.1
conda activate pytorch_env
# Verify GPU allocation
echo "Allocated GPUs:"
nvidia-smi
# Run distributed training
python3 train.py --distributed
echo "Training complete"
Key points: - --partition=gpu is required for GPU access
on Sagehen. - --gres=gpu:a100:2 requests exactly 2 A100
GPUs. - --cpus-per-task=8 provides enough CPU cores for
parallel data loading. - --mem=64G allocates 64 GB of
system RAM (separate from GPU memory). - %x expands to the
job name and %j to the job ID in output filenames.
- GPU jobs require: –partition=gpu and –gres=gpu:N
- Request matching CPUs and memory for your GPU
- Max 720 hours per job; typical 1-8 hours
- Interactive sessions available for testing
- Multiple GPUs require distributed training setup
