dashesy:

if x.detach() , being a function that I do not know its implementation, has an overhead or not.


Given that x.data is a property that does function calls in the background to re-wrap the underlying stuff in a new variable, I would not know the overhead of x.data either (but believe both are similar, after looking at the implementation).
The migration guide 9 fairly clearly advises


However, .data can be unsafe in some cases. […] A safer alternative is to use x.detach(), […]


Best regards
Thomas