Skip to content

Commit 4f6ae81

Browse files
committed
Fix torch.accelerator AttributeError in tensorqs_tutorial
The tutorial was using torch.accelerator.is_available() and torch.accelerator.current_accelerator() which causes an AttributeError in PyTorch versions that don't have the accelerator API. Changed to use the more widely compatible torch.cuda.is_available() and tensor.to('cuda') pattern that works across all PyTorch versions. Fixes issue where users get: module 'torch' has no attribute 'accelerator'
1 parent f99e9e8 commit 4f6ae81

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

beginner_source/basics/tensorqs_tutorial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@
111111
# across devices can be expensive in terms of time and memory!
112112

113113
# We move our tensor to the current accelerator if available
114-
if torch.accelerator.is_available():
115-
tensor = tensor.to(torch.accelerator.current_accelerator())
114+
if torch.cuda.is_available():
115+
tensor = tensor.to("cuda")
116116

117117

118118
######################################################################

0 commit comments

Comments
 (0)