How to Move a Tensor Back to the CPU in PyTorch with .cpu()
Results computed on the GPU often have to come back to the CPU: NumPy, for one, only works with data in the computer's main memory. .cpu() makes that copy. This guide moves a tensor from the GPU of an Apple M1 Pro back to the CPU in PyTorch 2.15.0.
Syntax
tensor.cpu()
| Part | What it means |
|---|---|
tensor | The tensor to bring back, on any device |
.cpu() | Returns a copy of it on the CPU. The original stays where it was |
PyTorch's reference says it "Returns a copy of this object in CPU memory. If this object is already in CPU memory, then no copy is performed and the original object is returned."
The Example
A script makes a tensor on the GPU, brings a copy back to the CPU, and prints where each lives.
Prerequisites
- A uv project with PyTorch and NumPy.
uv add torch numpyadds both; without NumPy, PyTorch 2.15.0 prints a warning each time it starts. This guide uses PyTorch 2.15.0 and NumPy 2.5.5 on Python 3.15.2, with uv 0.13.10, on an Apple M1 Pro.
Step 1: Write the Script
import torch
accelerator = torch.accelerator.current_accelerator(check_available=True)
device = accelerator or torch.device("cpu")
on_gpu = torch.tensor([2.0, 4.0, 6.0], device=device)
back_on_cpu = on_gpu.cpu()
print(on_gpu.device)
print(back_on_cpu.device)
print(back_on_cpu)

The first two lines pick the GPU when PyTorch can use one, and the CPU otherwise: How to Check Whether PyTorch Can Use a GPU (CUDA or Apple MPS) explains them. device=device makes the tensor straight on the GPU, and on_gpu.cpu() copies it back.
Step 2: Run It
uv run python to_cpu.py
mps:0
cpu
tensor([2., 4., 6.])
![The terminal after uv run python to_cpu.py: mps:0, then cpu, then tensor([2., 4., 6.]).](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/ai/pytorch/2026/pytorch-to-cpu-02-output.webp)
The original is still on mps:0, the M1 Pro's GPU, and the copy is on cpu. The copy prints without a device= label, because it's on the CPU. The command works unchanged in PowerShell.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
.numpy() on a tensor on the GPU | TypeError: can't convert mps:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first. | on_gpu.cpu().numpy(), which printed [2. 4.] for a two-value tensor |
Expecting .cpu() to move the tensor itself | on_gpu was still on mps:0 after the call | Keep the copy: back_on_cpu = on_gpu.cpu() |
FAQ
Is .cpu() the same as .to("cpu")?
They do the same here: on_gpu.to("cpu").device printed cpu too. .cpu() is the shorter way to write it.
Do I need .cpu() before printing a tensor?
No. print() shows a GPU tensor as it is, with device='mps:0' after its values. The copy matters for libraries that read the numbers directly, such as NumPy.
Conclusion
on_gpu.cpu() copied a tensor from mps:0, the GPU of an Apple M1 Pro, back to the cpu, while the original stayed on the GPU. NumPy's .numpy() needed that copy first.
Additional Resources
- Tensor.cpu — PyTorch's reference for the method.
- Tensor.to — moving a tensor to any device.
- Tensors tutorial — PyTorch's introduction to tensors, including NumPy.
