AssertionError: Invalid device id

Hi Everyone,

Can anyone suggest reasons for this kind of error and possible solution:

raise AssertionError(“Invalid device id”)
AssertionError: Invalid device id

Hi,

The problem is that the current cuda device id is not valid.
What does torch.cuda.device_count() returns? If it returns 0 that means that no device are available.

1 Like

Thank you so much for reply!

My GPU is working, I am trying this project on my personal computer (which has one GPU) as well as with Server’s GPUs.

1 Like

But what does torch.cuda.device_count() returns? You need a recent enough nvidia gpu for them to be usable.

On my system it returns 1 and on Server it is 8.

1 Like

What are the device ids you give to your DataParallel?

DataParallel is written as:

model = torch.nn.DataParallel(model, device_ids=args.gpus).cuda()
cudnn.benchmark = True

What does args.gpus contains? In particular for your system with a single gpu, it should only contain [0] and so no DataParallel should be used in that case.

My dataset is Videos so I am running on server which has to use at least 4 gpus.

if args.gpus is not None:
devices = [args.gpus[i] for i in range(args.workers)]
else:
devices = list(range(args.workers))