• Register
0 votes

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

Please log in or register to answer this question.

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 :

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

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

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 20 views
Problem: i will be thankful to the person who could help me in solve this problem? only one element tensors can be converted to python scalars.
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
1 answer 2.8K 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 3 views
Problem I'm aware of the gradient descent and the back-propagation algorithm. What I don't get is: when is using a bias important and how do you use it?
asked Mar 9 neeraj 9.6k points
1 vote
1 answer 1.4K views
Problem : I am very new to Pytorch. I am currently trying to train my pytorch model I am using the unet model. I am getting dimension out of range error as shown below: /usr/local/lib/python3.5/dist-packages/torch/nn/functional.py in log_softmax(input, ... .view(-1) targets_flat = targets.view(-1) return self.crossEntropy_loss(probs_flat, targets_flat)` Please let me know how to fix above error.
asked Feb 20, 2020 mphil 2.3k points
0 votes
1 answer 146 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 56 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, 2020 alecxe 7.5k points
0 votes
1 answer 2 views
Problem: anyone can help with this setup error?
asked Mar 30 Jack20 2.7k points
0 votes
1 answer 11 views
0 votes
1 answer 22 views
0 votes
1 answer 2 views
Problem: Hello ... Can anyone tell me that why I got this error? operation cannot be performed because the message has been changed
asked Apr 2 Ifra 24.4k points