Input type (CUDAFloatTensor) and weight type (CPUFloatTensor) should be the same

I cloned the repo and have been experimenting using the lesson 8 pascal-multi.ipynb notebook.

***I DID NOT EDIT A LINE OF CODE OTHER THAN INPUT DIRECTORIES, SO PLEASE DO NOT SUGGEST JUST ‘PASSING MODEL TO GPUS’ lol. Whatever error exists exists within the repo, not within a line of code i wrote. because, again, i didn’t add any code. ***

I have cloned all the data sets succesfully and didn’t edit any of the code other than the paths to the input data sets. Finally, i installed fastai using pip install fastai and seem to have confirmed that I am using the correct version of pytorch.

After training the model, this line appears to fail due to a mismatch in weight types and input types :

batch = learn.model(x)

Error thrown :

RuntimeError: Input type (CUDAFloatTensor) and weight type (CPUFloatTensor) should be the same

I sincerely apologize if this is the wrong place to post this, but I thought it could be an important error.

I did another pull, and now the error has changed. It looks like the code base is still under development? The docker container i’m using doesn’t have conda so I did pip install fastai. Is the pip version too under construction to use?

Line it fails on :, 1, cycle_len=3, use_clr=(32,5))

notebook :

new error :
TypeError: eq received an invalid combination of arguments - got (torch.cuda.LongTensor), but expected one of:

  • (int value)
    didn’t match because some of the arguments have invalid types: (!torch.cuda.LongTensor!)
  • (torch.LongTensor other)
    didn’t match because some of the arguments have invalid types: (!torch.cuda.LongTensor!)

For pascal.ipynb change accuracy_np() to accuracy() a few cells earlier to fix that:

def detn_acc(input, target):
    _,c_t = target
    c_i = input[:, 4:]
    return accuracy(c_i, c_t)

The first post’s error - I get that too, but I didn’t have a chance to figure it out yet.

1 Like

thanks so much !

I figured out the errors In the pascal_multi.ipynb notebook. Find almost any cell with .cpu() and change it to .cuda()


Thanks for the hint, @pricel3ss. Both notebooks have now been fixed in the fastai repo.

Thanks for the update, but something is still wrong I think with this notebook.

I took the last version of pascal-multi, did not change any single line of code, and I have very different loss results.
For the “prefocal” model, section “More anchors” (2/3 of the notebook), Jeremy obtains train and validation losses around 10 after 2 cycles. Executing exactly the same code, I obtain train and val losses around 70-80… That’s 8 times more. Can anybody explain this ?

Thanks a lot,