Torch.numel behavior with torch.Size as input

The official doc on torch.numel notes that its input must be a torch.Tensor. I tried torch.Size as input and the result might be kind of unexpected.

The code snippet is shown as:

import torch
a = torch.Tensor(3, 4)
print(a.numel(), a.shape.numel())

The returned values of both a.numel() and a.shape.numel() are 12.

But there is no documentation or explanation for the input type torch.Size. Whether it is a potential bug or feature?

1 Like

I also ran into the same issue.
There is an open issue about this on github: Document torch.Size and its methods (like torch.Size.numel) · Issue #61231 · pytorch/pytorch · GitHub