CUDA error: invalid device ordinal when using python 3.9
I'm trying to excute a code, but I keep geting this error when compiling this piece of code:
  import tensorflow as tf

  from xba import XBA

  import torch

  torch.tensor([1, 2, 3, 4]).to(device=&quot;cuda:2&quot;)

torch.tensor([1, 2, 3, 4]).to(device=&quot;cuda:2&quot;) generates this error: &quot;
RuntimeError: CUDA error: invalid device ordinal
CUDA kernel errors might be asynchronously reported at some other API call,so the 
stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.

AnyIdea about the origine of the bug, it's just the first line of code!!

&quot;cuda:2&quot;

selects the third GPU in your system.  If you don't have 3 GPUs (at least) in your system, you'll get this error.
Assuming you have at least 1 properly installed and set up CUDA GPU available, try:
&quot;cuda:0&quot;

