How to tile a tensor without occupying new GPU memory

If the size of tensor is wery large, such as 40000*64. I want to tile the 0 dim with 100 times, if I use repeat, the menory of GPU will grow a lot. How can I do it without occupying new GPU memory, just use expand?

import torch
a=torch.rand(40000,64).cuda()
a=a.unsqueeze(1).repeat(1,100,1).view(-1,64)

The the memory will up to 1500M, it is to higher!

1 Like