Changing default device
recipes/recipes/changing_default_device
Run in Google Colab
Colab
Download Notebook
Notebook
View on GitHub
GitHub
It is common practice to write PyTorch code in a device-agnostic way,
and then switch between CPU and CUDA depending on what hardware is available.
Typically, to do this you might have used if-statements and cuda() calls
to do this: