Solved by aauker in post #4 
              
              
                Ah, I see.  When you write something like XYZ[0] = ... , this is still an in-place operation. 
My recommendation to follow a scheme of conditionally changing values in your loss function (I assume from a network output of XYZ) is to initialize new tensors for each index: 
Here’s an example for a ten…