Can I replace torch.Generator() in this code snippet, as my cuda version is not supported

Hi there I am using following code to create data loaders.

g_cuda = torch.Generator(device='cuda')
train_set = DataLoader(train_data, batch_size=args.batch_size, shuffle=True, generator = g_cuda)

and getting this error:
RuntimeError: Device type CUDA is not supported for torch.Generator() api.
What is the solution.


I reproduced your issue, but I did not get any error.

import torch
from torchvision.datasets import MNIST
from torchvision.transforms import ToTensor
from import DataLoader

generator = torch.Generator(device='cuda')
dataset = MNIST(root=".", download=True, transform=ToTensor())
dt = DataLoader(dataset, batch_size=8, generator=generator, shuffle=True)

What torch and torchvision versions are you using?


What is the problem?
I have GPU
also can I replace this

g_cuda = torch.Generator(device='cuda')

I think you need to install cuda versions.

My env:

torchvision: 0.13.0+cu113
torch: 1.12.0+cu113

can you plz elaborate, how to do it?
I am using windows 10.

When you install PyTorch you need to install with CUDA, as your PyTorch install is CPU only (1.12.0+cpu). You can find the install command for your configuration on the get-started page.

Actually CUDA-10.2 PyTorch builds are no longer available for Windows.

Then you need to update your drivers which you can do via the NVIDIA control panel. Once you’ve updated to latest version for your GPU you should be able to run 11.6 (assuming your card can support that). But regardless, update the driver and see what’s the maximum support CUDA version for your card which you can find via nvidia-smi

I have NVIDIA GeForce MX110, can I upgrade it?

Have you tried updating your drivers? It will tell you if you’re up to date or not.