Basically, .detach_() removes the backward edges that go into the present tensor (print .grad_fn before and after .detach() to see it). These are the ones that go into there when you call it. After your slice assignment to a_tmp, you’ll have new ones (print before and after there, too, to see it)