Torch Tensor with same shape but different storage size
I'm working on GANs model, the generator creates a tensor with size (3,128,128) which I dumped with the pseudo-code
import torch
image = Generator(noise).clone()
tensor = image[0].detach().cpu()
torch.save(tensor, save_path)

The problem is that tensor costs more storage than the same tensor size, even they have the same shape and dtype
&gt;&gt;&gt; import sys
&gt;&gt;&gt; import torch
&gt;&gt;&gt; tensor = tensor.load(save_path)
&gt;&gt;&gt; rand_t = torch.randn(tensor.shape)
&gt;&gt;&gt; print(tensor.shape, rand_t.shape)
torch.Size([3, 128, 128]) torch.Size([3, 128, 128])
&gt;&gt;&gt; print(tensor.dtype, rand_t.dtype)
torch.float32 torch.float32
&gt;&gt;&gt; print(sys.getsizeof(tensor.storage()))
9830472
&gt;&gt;&gt; print(sys.getsizeof(rand_t.storage()))
196680

I tried to dump those tensors, the output from the generator took 9.2MB and the random tensor took 197.4kB. I did read the pytorch's documents but found nothing. Please help me to figure out what is the difference between them?

It seems like extracting a sub-tensor directly from the original will bring the whole container with it. The function .clone() can solve it. Example:
&gt;&gt;&gt; import sys
&gt;&gt;&gt; import torch
&gt;&gt;&gt; tensor = torch.randn(10,3,128,128)
&gt;&gt;&gt; sys.getsizeof(tensor.storage())
1966144
&gt;&gt;&gt; sub1 = tensor[0]
&gt;&gt;&gt; sub1.shape
torch.Size([3, 128, 128])
&gt;&gt;&gt; sys.getsizeof(sub1.storage())
1966144
&gt;&gt;&gt; sub2 = tensor[0].clone()
&gt;&gt;&gt; sub2.shape
torch.Size([3, 128, 128])
&gt;&gt;&gt; sys.getsizeof(sub2.storage())
196672

Therefore, in my case, cloning the image individually should solve the problem:
import torch
image = Generator(noise).clone() 
tensor = image[0].detach().clone().cpu() # using clone()
torch.save(tensor, save_path)

