• 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 116 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 2.2K 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 7 views
0 votes
1 answer 50 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
1 vote
1 answer 874 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 274 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
0 votes
1 answer 363 views
Problem : I want to remote debug my windows 7 64bit machine, which runs the remote debugging tools. I am compiling the code in my local computer and then I copy it to my remote machine and run it with a remote debugger. It used to work until few days back also I don't recall ... 0 skipped ========== May be the change is the main reason and a "BeginBuild has not yet been called" is just a symptom?
asked Jan 25, 2020 jwilliam 3.9k points
0 votes
1 answer 2 views
0 votes
1 answer 153 views
Problem : Looking for solution of following doubt if one for loop is nested within another, then the counter variables for the two loops should be
asked Nov 12, 2019 peterlaw 6.9k points