Hey, have you verified the correctness of your code?
Two things:

I don’t the difference between .detach_() and .detach().
It seems like it’s also correct even if you don’t use tmp.detach_(), because tmp was created as a new Variable as @Ilya_Kostrikov suggested