lschmiddey / deep_tabular_augmentation

MIT License
20 stars 9 forks source link

RuntimeError: Expected all tensors to be on the same device #11

Closed Freemanlabs closed 2 years ago

Freemanlabs commented 2 years ago

On running run.fit(...), I get:

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument mat1 in method wrapper_addmm)

Typically I would know how to resolve this using custom PyTorch. But I don't know how to get pass this using dta.

My model was moved to device like so: model = dta.Autoencoder(...).to(DEVICE), but I don't see where/how to move the data/tensors to device.

Thanks.

lschmiddey commented 2 years ago

Do you use your own dataloader? I think the problem might be that the tensors in your dataloaders are not on the same device as your model is. When using model = dta.Autoencoder(...).to(DEVICE) you only put the model parameters to this device, not your input data. You will just have to either write your own simple dataloader in which you specify the device or just copy and paste mine then put it onto the correct device.

But good point, I will add this functionality directly to my dataloaders once Im back from vacation

Freemanlabs commented 2 years ago

Thanks for your response.

I am using your like so: data = dta.DataBunch(*dta.create_loaders(datasets, bs=1024)) However I don't know how to put this to device.

lschmiddey commented 2 years ago

You can either write your own dataloader and add the .to(device) or copy paste the functions from here: https://github.com/lschmiddey/deep_tabular_augmentation/blob/main/deep_tabular_augmentation/dataloaders.py, add .to(device) and use this then as the way to put everything on the same device.

https://stackoverflow.com/questions/65932328/pytorch-while-loading-batched-data-using-dataloader-how-to-transfer-the-data-t

lschmiddey commented 2 years ago

Hi Freemanlabs!

I just published the latest version (0.5.1) where I included your request to put the dataloader on any device you want. You can have a look at the Notebooks or simply change this part here:

data = dta.DataBunch(*dta.create_loaders(datasets, bs=1024))

to:

data = dta.DataBunch(*dta.create_loaders(datasets, bs=1024, device='cpu'))

You can put any device here you wuold like like cuda:0 or whatever and it should just work :)

lschmiddey commented 2 years ago

dataloaders now run on any device (with version 0.5.1)