Closed mariaalfaroc closed 1 year ago
Dear @mariaalfaroc, I'm glad you found pysdtw useful!
The issue you encounter comes from the way you initialise your tensors. In the examples, you can see that the tensors are created on CPU, before being sent to the GPU. In your code, you do this in one step, which loses the gradient. I think this is the topic of this question on the pytorch forum: https://discuss.pytorch.org/t/no-gradient-on-cuda/144807
You can fix this in several ways. Similar to the code in the examples folders, first create X on CPU and then send X to GPU. Or, create X directly on GPU with the device keyword.
In other words, this works:
X = torch.rand((10, 5, 7), requires_grad=True)
Y = torch.rand((10, 9, 7))
...
res = sdtw(X.to(device, Y.to(device)))
and this works too:
X = torch.rand((10, 5, 7), device=device, requires_grad=True)
Y = torch.rand((10, 9, 7), device=device)
I think we can close this issue, feel free to re-open it if you have more questions.
Hi,
First of all, thank you so much for this amazing implementation! I am trying to use your code (the example code), but I am getting an error when I moved everything to CUDA.
If I print
X.grad
, the result is empty and I get the following warning message:I'm running the code using Google Colab. Any idea why this is happening? Again thank you so much!