.cpu().detach().numpy() vs .data.cpu().numpy()

What is the difference between .cpu().detach().numpy() and .data.cpu().numpy() ?

When should I used one of these over the other?

1 Like

.data is an old api and should not be used anymore.
So the first one is the right way to go.

1 Like

How about .cpu().detach() vs .detach().cpu() ?

The end result is the same.
The second one is going to be imperceptibly faster because you don’t track the gradients for the cpu() op. But nothing else.


Thank you very much. That answers my question exactly.
BTW, I don’t know if it’s allowed or forbid. May I ask you to look at another question I post?