Skip to course content
Free PyTorch course

Advanced Deep Learning with PyTorch

Welcome to Deep Learning with PyTorch

Before the first model, one question decides whether the rest of the course runs on your machine: what hardware do you actually have? The answer changes speed. It never changes correctness.

Check the environment before you need it

PyTorch runs on CPU everywhere. It can also use an NVIDIA GPU through CUDA, or Apple silicon through MPS. Every example in this course is sized to finish on a CPU in seconds, so an accelerator is a convenience, not a prerequisite.

Run this now. If it prints a version number, you are ready.

import torch

# The one command to run before anything else in this course.
print("torch version :", torch.__version__)
print("CPU is always available. Accelerator, if any:")
print("  CUDA (NVIDIA)      :", torch.cuda.is_available())
print("  MPS  (Apple silicon):", torch.backends.mps.is_available())

# Everything in this course runs on CPU. An accelerator makes it faster,
# never more correct, so nothing here requires one.
device = "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
print("this course will use:", device)

The device line at the end is the pattern you will reuse: pick the best available backend, fall back to CPU, and never hard-code a device that a reader might not have.

The mistake this prevents

Writing .cuda() directly into a lesson script. It works on the author's machine and crashes on everyone else's. Select the device once, at the top, and move tensors to that variable instead.

Takeaway

Confirm the environment before the first experiment. A setup problem discovered in Module 6 costs far more than one discovered now.