Move computation to a GPU
Consider a model on the GPU and an input on the CPU. Work out where the data needs to be before the calculation.
A computation can run on the computer’s main processor (CPU) or on a supported graphics processor (GPU). Each device has its own working memory. For a model step the input needs to be accessible on the same device as the parameters.
A small example
Suppose the model is already on the GPU and you have just created a fresh input tensor on the CPU. Is the example ready to run? Compare the device of the input with the device of the parameters. Without an available accelerator, you can keep the entire example on the CPU.
What else does training need?
Think of training as two operations. First the model on the GPU reads an input and produces a prediction. Then the program compares that prediction with the correct answer from the training example. The first operation needs the model and input on the same device. The second also needs the target on that device.
A prediction can therefore succeed and the very next line, which computes the loss, can report a device mismatch. At that point check where the target array lives. You can trace the same two operations on a CPU with every input on that device.
Done reading?
Mark the lesson as read to move your track progress forward.
Lesson marked as done.
Now build your own version
Move a training step to your chosen device and verify where the data actually lives. You can complete the CPU path without a graphics card.
What practice includes and how much it costs
MCP includes the full lesson and a local project with starter files. Work through the task with your agent, ask for a hint and run the checks on your computer.
One payment, no auto-renewal · Terms
Progress saved in this browser
Clear your history or open this on your phone, and the marks will be gone. Leave your email and they'll move to your account. No password needed.
Done. moved to your account. You can see your progress on any device. My progress