How to compute the size of Pytorch tensors
It is fairly simple to compute the in memory size of Pytorch tensors with two handy methods: numel and element_size:
import torch
def get_size(t: torch.Tensor):
return t.numel() * t.element_size()
That’s it!