I haven’t executed the new code snippet, but it’s expected that detaching the tensor from the computation graph stops the gradient propagation at this point, so I’m unsure why you want to use it there.