Limit DataLoader in loading in advance

I wonder if there is a way to prevent the DataLoader from calling getitem so often, so as to say something like:
Do only load 5 sequences in advance (and not plenty as it does now, which has problems with cuda out of memory).
Has anyone tried this before?

You can change the prefetch_factor, which is defined as:

prefetch_factor (int, optional , keyword-only arg) – Number of samples loaded in advance by each worker. 2 means there will be a total of 2 * num_workers samples prefetched across all workers. (default: 2)

2 Likes