You can have a construct like this:
if torch.cuda.is_available():
  device = 'cuda'
else:
  device = 'cpu'
model.to(device)

To move between CPU and GPU, use the .to(device) function with the appropriate value for device