diff --git a/beginner_source/blitz/tensor_tutorial.py b/beginner_source/blitz/tensor_tutorial.py index ac54945bc3a..30e2aac9f5f 100644 --- a/beginner_source/blitz/tensor_tutorial.py +++ b/beginner_source/blitz/tensor_tutorial.py @@ -105,9 +105,9 @@ # # We move our tensor to the GPU if available -if torch.cuda.is_available(): - tensor = tensor.to('cuda') - print(f"Device tensor is stored on: {tensor.device}") +device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else 'cpu' +tensor = tensor.to(device) +print(f"Device tensor is stored on: {tensor.device}") ######################################################################