44. Install PyTorch and First Tensors
44.4 CPU vs GPU Note
Why. People ask “do I need a GPU?” for these chapters.
What. CPU is enough for tiny demos. GPU helps big images / big batches. You can move a tensor with .to(device) when CUDA exists.
How.
Device snippet
- Pick
cudaif available elsecpu. - Create a tensor on that device.
- Keep whole model + data on the same device.
import torch
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
x = torch.ones(2, 2, device=device)
print(device, x)
India lab reality
Many training rooms are CPU-only. Every copy-run sample in this block is sized for CPU.