Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtimeError in pytorch 0.4.1 #4

Open
monadyn opened this issue Aug 20, 2018 · 5 comments
Open

runtimeError in pytorch 0.4.1 #4

monadyn opened this issue Aug 20, 2018 · 5 comments

Comments

@monadyn
Copy link

monadyn commented Aug 20, 2018

pytorch 0.4.1

RuntimeError Traceback (most recent call last)
in ()
37 loss = loss_fn(Variable(batch), generator(noise), alphas=alphas)
38 print(" loss is ", batch)
---> 39 loss.backward()
40 print(" backward")
41 optimizer.step()

~/Downloads/venv/lib/python3.6/site-packages/torch/tensor.py in backward(self, gradient, retain_graph, create_graph)
91 products. Defaults to False.
92 """
---> 93 torch.autograd.backward(self, gradient, retain_graph, create_graph)
94
95 def register_hook(self, hook):

~/Downloads/venv/lib/python3.6/site-packages/torch/autograd/init.py in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables)
88 Variable._execution_engine.run_backward(
89 tensors, grad_tensors, retain_graph, create_graph,
---> 90 allow_unreachable=True) # allow_unreachable flag
91
92

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

@adrienchaton
Copy link

adrienchaton commented Sep 7, 2018

Hello,

I also get such "RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation" when backpropagating the SmoothKNN function.
The same code, running on the same GPU, using the MMD as loss criterion does not raise errors.

Did you find a solution ? Were you using SmoothKNN in the "loss_fn" ?

Thanks

@josipd
Copy link
Owner

josipd commented Sep 7, 2018

Thanks for the bug report! Does this also happen for k=1?

@adrienchaton
Copy link

adrienchaton commented Sep 7, 2018

Thank you for the quick reply !

I detail a bit more because I did encounter different behavior for k=1 or k>1 (I tried because it is mentioned that the operation is differently done at k=1)

The backward I am doing is on two objectives, computed for the same optimization step.
_ first one is computed with MMD or SmoothKNN and is called trans_score in my code
_ second one is computed only with torch tensor operations and is called CC_rec_loss

in the beginning, I did (trans_score+CC_rec_loss).backward() and it would lead to different errors
k=1 -> RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation
k>1 (eg.10) -> RuntimeError: Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor for argument #3 'other'

then I tried to backward them separately (but still doing a single optimization step after), first doing the trans_score.backward() alone ; there I get the same error for k=1 or k>1 which is RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

let me know if I may give more informations to help fixing the issue if anything can be done

thanks !

ps: I was also opening an other issue, I guess it relates to that one even though I am not sure he is using SmoothKNN ; still I was telling that the setting works perfect with MMD but not with SmoothKNN (only difference is in setting a True cuda boolean and a k value for SmoothKNN ; about that, MMD does not have a cuda argument but works with GPU whereas SmoothKNN has a cuda argument, that I set to True but there may be an additional issue with cuda tensors mixed with cpu tensors, that I didn't understand cf. in the beginning with k>1)

@adrienchaton
Copy link

Hi !

I continue exerimenting with the MMD criterion, two questions for which you may have some recommendations:
_ the alpha value in the MMD, I guess there is no general rule for optimum choice but what base value would you recommend please ? I read online it may be around 0.05
_ from reading the source of the computation of the MMD test, it involves summing along dimensions, hence such criterion would be equivalent to a size_average=True loss terms from pytorch ?

thanks !

@adrienchaton
Copy link

Dear Josipd,

I have been doing some checks of gradient calculations/propagations and it seems that when I compute a loss criterion using the torch_two_sample.statistics_diff.MMDStatistic in between a generated batch and a batch sampled from a target data distribution, it does not accumulate any gradient in the generative model ..

I have a code where I separately backward my different criterions, all accumulate gradients as expected except the MMD ; I can send you through, I don't understand why it does not work whereas this function should support backpropagation right ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants