If your re-write works, I’d just go with that. If you want this operation to be in-place, you’d need to also manually re-write the gradient graphs also as an in-place operation, which is a hard matter.  On in-place use with the autograd framework:

Supporting in-place operations in autograd is a hard matter, and  we discourage their use in most cases . Autograd’s aggressive buffer freeing and reuse makes it very efficient and there are very few occasions when in-place operations actually lower memory usage by any significant amount. Unless you’re operating under heavy memory pressure, you might never need to use them.