• Register
0 votes
249 views

Problem :

I am trying to compute a loss on the jacobian of the network but encountered following error 
one of the variables needed for gradient computation has been modified by an inplace operation
6 5 3
6,930 points

1 Answer

0 votes

Solution :

Please note grad_output.zero_() is in-place and so is grad_output[:, i-1] = 0. In-place means "modify a tensor instead of returning a new one, which has the modifications applied".  An example which uses the zero out the 1st column as follows :

e.g.
import torch
t = torch.randn(3, 3)
ixs = torch.arange(3, dtype=torch.int64)
zeroed = torch.where(ixs[None, :] == 1, torch.tensor(0.), t)

zeroed
tensor([[-0.6616,  0.0000,  0.7329],
        [ 0.8961,  0.0000, -0.1978],
        [ 0.0798,  0.0000, -1.2041]])

t
tensor([[-0.6616, -1.6422,  0.7329],
        [ 0.8961, -0.9623, -0.1978],
        [ 0.0798, -0.7733, -1.2041]])

Notice how the t retains values it had before and also zeroed has the values which you want.

9 7 4
38,600 points

Related questions

0 votes
1 answer 89 views
89 views
Problem : I am facing following c# socket issue the i/o operation has been aborted because of either a thread exit or an application request
asked Nov 16, 2019 peterlaw 6.9k points
0 votes
1 answer 1.7K views
1.7K views
Problem : I am trying to convert my list into an array using Python, But I got below error ValueError: only one element tensors can be converted to Python scalars.
asked Oct 22, 2019 peterlaw 6.9k points
0 votes
1 answer 47 views
47 views
Problem : I have my web application which is throwing the below error while running in IE: “Illegal operation attempted on a registry key that has been marked for deletion” It works really fine in my Chrome but unfortunately gives the above error in production ... information on my error. And it confuses me as why this is only occurring when trying to use the IE. Any pointers?
asked Jan 6 alecxe 7.5k points
0 votes
1 answer 195 views
195 views
Problem : I am currently facing an issue with MySQL! I am the cPanel user, and I am looking for the solution on my issue. It seems this is more specific than other people with the same error codes issues. Please find below my code for the reference: DELIMITER $$ ... from the code: MySQL said: Documentation #1227 - Access denied; you need (at least one of) the SUPER privilege(s) for this operation
asked Nov 21, 2019 peterlaw 6.9k points