Hi,
The errors means that you changed inplace a Tensor whose value was needed to compute some gradients.
Given the line that cause the error, this is most likely the -= operation that is the issue.
Can you try replacing it with an out of place version like td = td - xx ?