Clone and detach in v0.4.0

Sorry if this repetitive but I still don’t get it. What is wrong with doing clone first and then detach i.e. .clone().detach() ?

Nothing. They will given an equivalent end result.
The minor optimization of doing detach() first is that the clone operation won’t be tracked: if you do clone first, then the autograd info are created for the clone and after the detach, because they are inaccessible, they are deleted. So the end result is the same, but you do a bit more useless work.
In any meaningful workload you shouldn’t see any perf difference though. So no need to worry too much about it :smiley:

3 Likes