In addition to @adeelh’s comment, there is another difference: torch.flatten() results in a .reshape(), and the differences between .reshape() and .view() are:
[…]
torch.reshapemay return a copy or a view of the original tensor. You can not count on that to return a view or a copy.Another difference is that reshape() can operate on both contiguous and non-contiguous tensor while view() can only operate on contiguous tensor. Also see here about the meaning of contiguous
For context:
-
The community requested for a
flattenfunction for a while, and after Issue #7743, the feature was implemented in the PR #8578. -
You can see the implementation of flatten here, where a call to
.reshape()can be seen inreturnline.