If the parameter value is needed for the gradient computation, an inplace operation is disallowed, as explained in the error message.
In such a case, remove the inplace operation and use the out-of-place one:
x = x + 2

Also, don’t use the .data attribute, as it might yield unwanted side effects.