Apply part of Tensor on Function to avoid out of memory

The following code dies because of out of memory.

images # Variable of size 2000 * 3 * 224 * 224 (N * C * H * W)
l = vgg.feature_layer # feature layer of vgg (3 * 244 * 244 -> 14 * 14 * 512)
f = l(images) # out of memory!!!!

Batch size (2000) seems to big, so I modified like

f = tr.cat([ l(im) for im in images.split(10)]) # now batch size is 10, still out of memory!!!

I reduced the batch size like above, But still out of memory issue occurs.

How can I avoid it ???
My friend told me to use DataSet and DataLoader.
But I want to find a simple way

It depends if you are training or testing.
In training, the internal layer outputs and other gradient biffers occupy space.
During testing, you could use torch.no_grad() to reduce memory consumption. Possibly try with this.