Runtime Error: cuda runtime error (10)

  File "", line 26, in <module>
    MyModel = PretrainedModel(arch_name,hidden_layers, data_dir, epochs, device , learning_rate, manual_seed)
  File "/home/workspace/ImageClassifier/", line 62, in __init__
    self.flower_classifier = FlowerClassifier(self.input_layer_size, self.output_layer_size, self.hidden_layers)
  File "/home/workspace/ImageClassifier/", line 32, in __init__
    self.hidden_layers = nn.ModuleList([nn.Linear(input_size, hidden_layers[0])])
  File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/", line 41, in __init__
    self.weight = Parameter(torch.Tensor(out_features, in_features))
RuntimeError: CUDA error (10): invalid device ordinal```

I got this error when trying to train a model. Does anyone know how to resolve this issue?

RuntimeError: CUDA error (10): invalid device ordinal
is raised if you try to specify a wrong device id as seen e.g. here:

x = torch.randn(1).to("cuda:100")
# RuntimeError: CUDA error: invalid device ordinal

Check which GPU id is used and make sure it’s in [0, nb_gpus-1].