From 3d8340d313fe62ce39d892c349a837168944dbef Mon Sep 17 00:00:00 2001 From: Eduardo Patrocinio Date: Wed, 26 Nov 2025 09:41:00 -0500 Subject: [PATCH] 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' --- beginner_source/basics/tensorqs_tutorial.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beginner_source/basics/tensorqs_tutorial.py b/beginner_source/basics/tensorqs_tutorial.py index 30e05cb10d0..3b441645833 100644 --- a/beginner_source/basics/tensorqs_tutorial.py +++ b/beginner_source/basics/tensorqs_tutorial.py @@ -111,8 +111,8 @@ # across devices can be expensive in terms of time and memory! # We move our tensor to the current accelerator if available -if torch.accelerator.is_available(): - tensor = tensor.to(torch.accelerator.current_accelerator()) +if torch.cuda.is_available(): + tensor = tensor.to("cuda") ######################################################################