jeanfeydy / geomloss

Geometric loss functions between point clouds, images and volumes
MIT License
586 stars 57 forks source link

Not providing cuda torch tensors gives uninformative error #37

Closed Parskatt closed 4 years ago

Parskatt commented 4 years ago

Issue

Given the program sinkhorn_loss.py:

from geomloss import SamplesLoss
import torch

loss= SamplesLoss(loss="sinkhorn", p=2, blur=.1)

x = torch.linspace(0,1)[:,None]
y = torch.linspace(0,1)[:,None]
l = loss.forward(x,y)

I would expect an exception to either be told to send my tensors to GPU (if that is required), or for the program to attempt to automatically send the tensors to the correct device.

However, what i get is:

$ python sinkhorn_loss.py
$ Illegal instruction (core dumped)

Running the same code, but sending x,y to the GPU first produces no errors and gives the correct result (loss=0).

Suggested Solution

Perform a check in SamplesLoss to see that the input tensors are on the correct device, and either send an exception or transfer them.

NightWinkle commented 4 years ago

Your example is not reproducible, and yields no error on my machine.

Moreover, since by default torch.linspace generates only 100 points, it's likely that with your example, computations run on Torch engine (and not KeOps engine), which mean that this error comes most likely from your configuration.

Sending x and y to GPU is not a requirement since computations can be run on CPU, and sending them automatically would not follow Torch paradigm.

Parskatt commented 4 years ago

You're right, it seems it is actually pytorch that is messing up somewhere, I'll close this.

Parskatt commented 3 years ago

If anyone else gets this issue, this is what causes it: https://github.com/pytorch/pytorch/issues/43300