How do I train a YOLO model on a cloud GPU?

Deploy a Raw GPU instance, install the ultralytics-opencv-headless package in a Python environment, confirm that PyTorch sees the GPU, then run yolo detect train data=your-data.yaml model=yolo26n.pt epochs=100 imgsz=640 device=0 inside tmux and copy best.pt off before you destroy the instance.
Updated 2026-10-29
This guide follows the official Ultralytics docs (Install, Train mode, CLI, Object detection datasets), all read on 2026-10-29. The latest ultralytics release on PyPI that day was 8.4.192. It is for students and researchers who have outgrown a notebook GPU and want to train a YOLO detection model on a rented NVIDIA GPU such as the RTX 5090 or the other cards listed on /pricing.
What you need
| Item | Official value (read 2026-10-29) | Source |
|---|---|---|
| Package | ultralytics 8.4.192 on PyPI; ultralytics-opencv-headless for servers without a display |
PyPI, Install docs |
| Python / PyTorch | Python>=3.8 with PyTorch>=1.8 | Install docs |
| Licence | AGPL-3.0 | PyPI, GitHub LICENSE |
| Default device | GPU device=0 when available, otherwise CPU |
Train docs |
| Default batch | 16; batch=-1 picks a batch size automatically from the available GPU memory |
Train docs |
| Dataset format | YAML file with path, train, val, names; one .txt label file per image |
Detection datasets docs |
Ultralytics is licensed under AGPL-3.0; commercial use without releasing your code needs an Ultralytics Enterprise License (Ultralytics licence page).
VRAM need depends on model, precision and workflow; see How much VRAM do I need to run an LLM? for the general method. For YOLO training, batch=-1 lets Ultralytics size the batch for the card you rented. CloudGPU instances are single-GPU, so this guide uses device=0.
Step 1: Deploy a Raw GPU and connect
On /deploy, pick an NVIDIA GPU and the Raw GPU option (JupyterLab + CUDA pre-installed, root SSH on a dedicated container). Connect over SSH with the host, port and user shown for your instance, or open a terminal in JupyterLab.
Step 2: Check the GPU, driver and Python
nvidia-smi # GPU name, driver version and the "CUDA Version" the driver supports
nvcc --version # CUDA toolkit compiler, if installed
python3 --version
which tmux rsync
You need Python 3.8 or later. If tmux or rsync is missing, install it with the package manager (you are root on the container).
Step 3: Install Ultralytics in a virtual environment
python3 -m venv ~/yolo-env
source ~/yolo-env/bin/activate
pip install -U pip
pip install -U ultralytics-opencv-headless
According to the official Ultralytics install docs, servers without a display, such as cloud VMs and containers, should use ultralytics-opencv-headless to avoid libGL errors; it has the same API as ultralytics. Plain pip install -U ultralytics also works if you want OpenCV’s GUI extras; the docs note it can raise libGL errors on a server without a display.
If you prefer conda, see How to set up a conda environment on a cloud GPU.
Then confirm that PyTorch was installed with CUDA and sees the card:
python -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available(), torch.cuda.get_device_name(0) if torch.cuda.is_available() else '')"
yolo version
The line should end with True and your GPU name. If it prints False, or training later stops with a CUDA error about the device, install a PyTorch build that matches your driver first and then reinstall the Ultralytics package; the Ultralytics docs recommend this order for a specific PyTorch build. See How to install a specific PyTorch CUDA version on a cloud GPU.
Step 4: Run a short test on COCO8
COCO8 is the Ultralytics sample dataset with the first 8 images of COCO train2017 (4 for training, 4 for validation). It downloads automatically, so it is a simple way to check the whole setup before you upload your own data:
mkdir -p ~/yolo && cd ~/yolo
yolo detect train data=coco8.yaml model=yolo26n.pt epochs=3 imgsz=640 device=0
The pretrained yolo26n.pt weights also download automatically. According to the train docs, metrics, plots and checkpoints are always written to the run directory; look for the run folder path in the training output. In Step 6 you set the folder yourself with project and name.
Step 5: Upload your dataset in YOLO format
The Ultralytics detection docs describe this layout: an images folder and a matching labels folder, each with train and val subfolders, and one .txt label file per image. Each row in a label file is class x_center y_center width height, with box values normalized from 0 to 1 and class numbers starting at 0. Images with no objects need no label file.
my-dataset/
├── images/
│ ├── train/
│ └── val/
└── labels/
├── train/
└── val/
From your own computer, copy the folder to the instance:
rsync -avP -e "ssh -p <ssh-port>" ./my-dataset/ <ssh-user>@<ssh-host>:yolo/my-dataset/
On the instance, create ~/yolo/my-data.yaml with your own class names:
path: /root/yolo/my-dataset # use the output of: echo ~/yolo/my-dataset
train: images/train
val: images/val
names:
0: helmet
1: person
Step 6: Train inside tmux
Start a tmux session so training keeps running if your SSH connection drops:
tmux new -s yolo
source ~/yolo-env/bin/activate
cd ~/yolo
yolo detect train data=my-data.yaml model=yolo26n.pt epochs=100 imgsz=640 batch=-1 device=0 project=runs name=my-run
Detach with Ctrl-b then d; reattach with tmux attach -t yolo. According to the train docs:
batch=-1sizes the batch automatically from the available GPU memory, and a value such asbatch=0.70targets that fraction of GPU memory instead.- If a CUDA out-of-memory error happens in the first epoch, the trainer halves the batch size and retries, up to 3 times, on single-GPU training.
model=yolo26n.ptstarts from pretrained weights; other model files and sizes are listed in the Ultralytics docs.
To watch GPU use while it trains, run nvidia-smi in a second SSH session; see How to check GPU utilization on a cloud GPU.
Step 7: Resume an interrupted run
The train docs say a checkpoint is written at the end of every epoch, and a run can be resumed from its last.pt once at least one epoch has finished. Resuming restores the weights, optimizer state, learning rate scheduler and epoch number:
find ~/yolo/runs -name last.pt
yolo train resume model=<path-to>/weights/last.pt
Step 8: Validate, test and export
The Ultralytics CLI guide uses best.pt from the run folder for the next steps:
yolo detect val model=<run-folder>/weights/best.pt data=my-data.yaml
yolo detect predict model=<run-folder>/weights/best.pt source=path/to/images
yolo export model=<run-folder>/weights/best.pt format=onnx
Check your own setup
These are checks you can run yourself; this page does not assume the result.
- Driver and CUDA:
nvidia-smiprints a table with your GPU name and a CUDA Version. - PyTorch sees the GPU: the Step 3 check prints
Trueand the GPU name. - No libGL error:
python -c "import cv2; print(cv2.__version__)"prints a version. If it fails with alibGLmessage, check that you installedultralytics-opencv-headless. - Training uses the GPU: while training runs,
nvidia-smiin a second session lists apythonoryoloprocess on the GPU.
Before you destroy the instance
According to /terms, data on the instance is permanently deleted when you destroy it. Copy the run folder, including weights/best.pt and weights/last.pt, to your computer first:
rsync -avP -e "ssh -p <ssh-port>" <ssh-user>@<ssh-host>:yolo/runs/ ./yolo-runs/
GPU time is billed per minute, rounded up, with a 1-minute minimum, and billing stops when you destroy the instance; see /terms.
Related guides
- How to install a specific PyTorch CUDA version on a cloud GPU
- How to check GPU utilization on a cloud GPU
- How to set up a conda environment on a cloud GPU
FAQ
How do I train YOLO on a rented GPU server?
Deploy a Raw GPU instance, create a Python virtual environment, run pip install -U ultralytics-opencv-headless, and check that torch.cuda.is_available() prints True. Then run yolo detect train data=your-data.yaml model=yolo26n.pt epochs=100 imgsz=640 device=0 inside tmux so training keeps running if SSH disconnects.
Why do I get a libGL error when I import Ultralytics on a server?
Servers without a display, such as cloud VMs and containers, do not have the OpenCV GUI libraries. According to the official Ultralytics install docs, install ultralytics-opencv-headless instead of ultralytics on these machines; it has the same API without OpenCV’s GUI components.
What batch size should I use for YOLO training on a cloud GPU?
Set batch=-1 and Ultralytics picks a batch size from the available GPU memory, or set a fraction such as batch=0.70. According to the train docs, if a CUDA out-of-memory error happens in the first epoch on a single GPU, the trainer halves the batch size and retries up to 3 times.
How do I resume YOLO training after the instance or SSH session stops?
Ultralytics writes a checkpoint at the end of every epoch. Find last.pt in the run folder and run yolo train resume model=path/to/last.pt. Resuming restores the weights, optimizer state, scheduler and epoch number, and needs at least one finished epoch.
How is the GPU billed while YOLO trains?
GPU time is billed per minute, rounded up, with a 1-minute minimum, and billing stops when you destroy the instance. Copy your run folder with best.pt and last.pt off first, because data on the instance is deleted on destroy. See https://cloudgpu.app/terms for the full billing terms.
Sources
- Ultralytics docs, Install, read 2026-10-29
- Ultralytics docs, Train mode, read 2026-10-29
- Ultralytics docs, CLI guide, read 2026-10-29
- Ultralytics docs, Object detection datasets and COCO8, read 2026-10-29
- PyPI, ultralytics (release 8.4.192, licence AGPL-3.0), read 2026-10-29
- Ultralytics, Licence (AGPL-3.0 and Enterprise License), read 2026-10-29
- CloudGPU /pricing, /deploy, /terms, read 2026-10-29