There really is a bug in einsum in PyTorch 0.4 (that I used unsqueeze_ where I should have used unsqueeze) and so it inplace-modifies the arguments in some circumstances. Note that x = x + ... is not an inplace modification and perfectly legitimate. (The .data stuff is bogus, but I think Santosh is aware of that, too.)
Best regards
Thomas