Back to DrivenData | Blog

Cuda Issue Main.py Submissions

Hi,

I have made several submissions, and keep running into the same error.

RuntimeError: Expected object of device type cuda but got device type cpu for argument #1 ‘self’ in call to _thnn_conv2d_forward
ERROR conda.cli.main_run:execute(33): Subprocess for ‘conda run [‘python’, ‘main.py’]’ command failed. (See above for error)

Here is the traceback in my scripts:

File “/codeexecution/main.py”, line 127, in main
make_predictions(model, test_metadata, bands, predictions_dir)
File “/codeexecution/main.py”, line 78, in make_predictions
preds = model.forward(x)

I am using a model from the segmentation models pytorch library rather than the pytorch lightning code example given in the competition. I have tried several different things to force the model to the cuda device but it doesn’t seem to work. I have tried model.cuda(), model.to(‘cuda’), and model = model.cuda(), but they all yield the same error.

Any recommendations for how I can get the submission to work? I tested the main.py file in google colab and it worked fine.

Thanks!

Is it possible that the model is on GPU but the features x are on CPU? You could try x.cuda().

1 Like

That worked thank you very much!