Element 0 of tensors does not require grad and does not have a grad_fn

Detaching tensors doesn’t fix this issue, but would cut the computation graph so that Autograd never reaches the inplace operation causing the error.
To fix the inplace error: remove all inplace operations and replace them with their out-of-place equivalents.