Description
The Tensors tutorial contains outdated patterns that should be modernized.
Changes needed
Suboptimal / Outdated Patterns
| Issue |
Current Code |
Modern Alternative |
Notes |
| Only checking CUDA ignores other accelerators |
if torch.cuda.is_available(): tensor = tensor.to('cuda') |
device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else 'cpu' |
Since PyTorch 2.4+, torch.accelerator provides a device-agnostic API covering CUDA, MPS, XPU, etc. |
Files
Description
The Tensors tutorial contains outdated patterns that should be modernized.
Changes needed
Suboptimal / Outdated Patterns
if torch.cuda.is_available(): tensor = tensor.to('cuda')device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else 'cpu'Files
beginner_source/blitz/tensor_tutorial.py