Skip to content

Memory leaks (when early break from iterator) #393

@shekhovt

Description

@shekhovt

It is eating up host memory indefinitely, much more than the unpacked dataset would take.

Duplicate of #345 , the explanation and a better workaround are proposed there.

MWE:

import torch
#------------------
import ffcv
from ffcv.loader import OrderOption
from ffcv.fields.decoders import IntDecoder
from ffcv.transforms import ToTensor, Squeeze, ToTorchImage
from ffcv.fields.rgb_image import CenterCropRGBImageDecoder
# -----------------

dev = torch.device('cpu')

train_set = '/local/temporary/data/imagenet/imagenet_pytorch/train-res=256-cls=10.beton'
input_size = 128

def train_pipelines():
    image_pipeline= [
            CenterCropRGBImageDecoder((input_size, input_size), ratio = 1),
            ToTensor(),
            ToTorchImage(),
        ]
    
    label_pipeline = [
            IntDecoder(),
            ToTensor(),
            Squeeze(),
        ]
    
    # Pipeline for each data field
    tr_pipelines = {
        'image': image_pipeline,
        'label': label_pipeline
    }
    return tr_pipelines 

num_workers = 4
batch_size = 128
train_loader = ffcv.loader.Loader(train_set, batch_size=batch_size, num_workers=num_workers, order=OrderOption.RANDOM, pipelines=train_pipelines(), drop_last=True)

epochs = 1000

print('single loader')
for e in range(epochs):
    x = 0
    for data, target in train_loader:
        x += data.to(dev).sum().cpu().detach().item()
        break
    print(e, x)
image

The problem is apparently with the break out of the loader loop. For some intermediate tasks we need just a few batches. There must be a way to cleanup?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions