Enable Faster Training by Pinning Data to Memory?

Is there a reason that the DataLoader sets pin_memory=false?

loader = DataLoader(
            dataset,
            batch_size=c.eval_batch_size if is_val else c.batch_size,
            shuffle=False,
            collate_fn=dataset.collate_fn,
            drop_last=False,
            sampler=sampler,
            num_workers=c.num_val_loader_workers
            if is_val else c.num_loader_workers,
            pin_memory=False)
    return loader

As I understand it, pin_memory speeds up transfers from host to device. Perhaps it’s because it has been determined that this is not a bottleneck in the training?

This is one of the pytorch core developers.

try to use pin_memory, but if you are seeing system freeze or swap being used a lot, disable it.

So this is not the case for my training. But consider it for your own.

1 Like

Thanks @erogol! Makes sense!