I am not familiar with how autograd works at the backend. Currently I have to modify the output of my network before passing to a criterion. My network output two things. The code is as follows:

        x_dot_wT, phi_theta = output
        # must clone else modify in place
        f_y = x_dot_wT.clone()
        batch_size = target.size(0)
        idxs = torch.arange(0, batch_size, dtype=torch.long)
        f_y[idxs, target] = ((_lambda * f_y[idxs, target]) + phi_theta[idxs, target]) / (1 + _lambda) 

        loss = criterion(f_y, target)


I conveniently clone x_dot_wT to avoid the “variable is modified in place” error. I wonder if this will affect autograd negatively and cause my gradient to be computed wrongly. Does it?