Solved by ptrblck in post #2 
              
              
                I haven’t tested your code, but note that self.y.detach() is not an inplace operation so you might need to either reassign the detached tensor via self.y = self.y.detach() or use the inplace method self.y.detach_().