In your current code snippet x_detach isn’t defined, so I’m not sure if you just assigned it to x or have indeed detached it.
Note that, in the latter case, the computation graph would be detached and previous layers will not get any gradients, if they depend on x.
I’m not sure what your exact use case is, but are you getting the first error message by using x directly?
If so, could you post an executable code snippet using random input tensors to reproduce this issue?