[INDEX] // ALL_DOCS ›
[TOC] // ON_THIS_PAGE ›
PyTorch GPU tests need a GPU in CI. Machine starts a runner for the job and shuts it down afterwards. Your test suite stays in GitHub Actions.
Before you run
Follow the quickstart to create your team and install the GitHub App on this repository. Start with $10 of free GPU time. No charge, no commitment. Free-tier jobs have a 30-minute limit and run one at a time.
Add a GPU smoke test
Save this as .github/workflows/gpu-test.yml. Run it from the Actions tab first.
It uses an x64 T4 runner and a separate Python environment, so packages installed
on the runner don’t decide which PyTorch you test.
name: PyTorch GPU smoke test
on: workflow_dispatch
permissions:
contents: read
jobs:
gpu-test:
runs-on: machine/id=${{ github.run_id }}-${{ github.run_attempt }}/gpu=t4/tenancy=spot
timeout-minutes: 25
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install PyTorch
run: |
python -m venv .venv
.venv/bin/python -m pip install torch==2.7.1 --index-url https://download.pytorch.org/whl/cu128
- name: Run on the GPU
run: |
nvidia-smi
.venv/bin/python - <<'PY'
import torch
assert torch.cuda.is_available(), 'CUDA is unavailable'
x = torch.arange(16, device='cuda', dtype=torch.float32)
assert (x * 2).sum().item() == 240
print(torch.cuda.get_device_name(0))
PY
That assertion matters. A test that quietly runs on the CPU can pass while the GPU path is broken. Check the device before running your own tests, too.
The PyTorch version here is an explicit example pin. Use your project’s tested version and the matching wheel from the PyTorch installation guide. The wheel includes its CUDA runtime; a CUDA compiler is a separate requirement if your project builds custom extensions.
Run your own tests
Replace the smoke-test step with your project’s dependency installation and
.venv/bin/python -m pytest. Keep the CUDA assertion. Mark expensive tests so
ordinary PRs can run a short set and releases can run the full suite.
Start with manual runs on trusted code. If you add a PR trigger, review who can submit code to it; don’t execute untrusted fork code with secrets or privileged GitHub tokens.
This checks one GPU. Use the multi-GPU guide for distributed tests, or CUDA CI for compiled kernels.