How to switch Pytorch between cpu and gpu
ofstack.com › python › 40337Sep 12, 2021 · In pytorch, when gpu on the server is occupied, we often want to debug the code with cpu first, so we need to switch between gpu and cpu. Method 1: x. to (device) Taking device as a variable parameter, argparse is recommended for loading: When using gpu: device='cuda' x.to(device) # x Yes 1 A tensor , spread to cuda Go up When using cpu: