Training a computer vision model on Isambard-AI
4,083 X-rays and four GPUs.
Can we teach a computer
to spot a fracture?
Why HPC? → Isambard-AI → The data
1 GPU → 4 GPUs → Good practice
We won’t cover batch jobs (see Introduction to HPC) or training across several nodes
Why can’t I just use my laptop?
To train a model, we show it thousands of examples many times over, adjusting millions of weights as we go.
Most of that work is multiplying large grids of numbers.
CPU A few fast, flexible cores
GPU Thousands of simpler cores, all doing the same sum at once
Time Each training run takes hours or days
Memory “CUDA out of memory”
Number of runs You want to try lots of settings or much more data
Has anyone waited more than an hour for a model to train?
How do I get a GPU?
apps.isambard.ac.uk/aip2-jupyter
| Field | Choose |
|---|---|
| Project | the course project |
| Job duration | until the end of the course |
| Number of GH200s | 1 |
| Partition | leave empty |
| Reservation | interactive |
When your time runs out, the session ends straight away, with no warning. Save regularly.
In JupyterLab, go to File → New → Terminal
Terminal
Open hpc-for-ai.ipynb and check the kernel in the top right says “Python (HPC for AI part 1)”
nvidia-smi Run it in a terminal to see each GPU, its memory and what’s running on it
GPU dashboard Click the GPU icon in the left sidebar and open Utilization and Memory
hpc-for-ai.ipynb
Python doesn’t wait for the GPU: it carries on as soon as it has sent the work. synchronize() waits until the GPU has finished.
$PROJECTDIR |
shared with the project | dataset, weights, kernel |
$SCRATCHDIR |
your working space | your data split and models |
$HOME |
limited to 100 GiB | your notebook |
None of these are backed up
nvidia-smi in a terminal. How much memory does your GPU have?size to 16384 in the matrix multiplication cell and run it again. How do the CPU and GPU times change?What does our data look like?
1 in 6
images show a fracture
Abedeen et al. (2023) Scientific Data 10, 521
Training 70% Validation 15% Test 15%
hpc-for-ai.ipynb
Training The model learns from these
Validation Checked after each epoch
Test Kept aside until the end
With medical images, all the images of one patient should go in the same set.
If they don’t, the model can learn to recognise the patient instead of the fracture.
FracAtlas has no patient IDs, and some body parts were X-rayed from more than one angle.
In your own work, split by patient.
fracatlas-split/
├── train/
│ ├── fractured/ → symbolic links to the shared images
│ └── not_fractured/
├── val/
└── test/
The links point to the original images, so the split takes up almost no space
Add a new cell to the notebook:
hardware column)?Can a computer learn to spot a fracture?
We start with a model that has already been trained on over a million everyday photos, then fine-tune it on our X-rays
ImageNet photos → YOLOv8n-cls → X-rays
Epochs How many times the model sees every image
Image size 512 × 512 pixels
Batch Images per update
Workers CPU processes loading images
hpc-for-ai.ipynb
Open the GPU dashboard before you run this cell
82%
accuracy from always saying “not fractured”, while missing every fracture
| Score | For fractured |
|---|---|
| Precision | When it says “fractured”, how often is it right? |
| Recall | What proportion of the real fractures did it find? |
If we’re deciding which X-rays to look at first, recall (sensitivity) matters most. Missing a fracture is worse than a false alarm.
Look at your classification report and confusion matrix:
fractured? What does it mean in plain English?Is more GPUs always faster?
PyTorch’s Distributed Data Parallel (DDP) runs a separate process for each GPU
Ultralytics writes a short training script and runs four copies of it with torch.distributed.run
notebook → rank 0
rank 1 rank 2 rank 3
Look for the DDP: line in the output, and the four processes in nvidia-smi
hpc-for-ai.ipynb
Watch the dashboard: are all four GPUs working?
Starting up Launching four processes and connecting the GPUs
Sharing gradients The GPUs have to stop and share after every batch
Loading data The CPU has to keep four GPUs supplied instead of one
With a small model and dataset, these costs cancel out much of the benefit.
With large models that take days to train, extra GPUs can make a big difference.
Fill this in with the numbers from the demo
| Run | Minutes | Speed-up | Fractured recall |
|---|---|---|---|
| 1 GPU | 1.0 | ||
| 4 GPUs |
What do you think would happen with a much bigger model?
How do I use a shared supercomputer well?
Save regularly Sessions end with no warning
Check your time Run squeue in a terminal (the command is in the notes)
Stop your server File → Hub Control Panel → Stop My Server
Back up your work Nothing on Isambard-AI is backed up
Check the dashboard. If your GPUs are often idle, more GPUs won’t help.
Start small, with one GPU and a few epochs.
Only ask for what you need. If your job uses one GPU, ask for one GH200.
Good for exploring and learning
But they have a time limit and need your browser open
Better for real training runs
They run on their own, and you can queue up lots at once
Please stop your server
File → Hub Control Panel → Stop My Server
Jean Golding Institute © CC-BY 4.0