What are the (dis) advantages of persistent_workers

Just wanted to throw out my own use-case and why it is valuable (and a time-saver) for me to actually have persistent_workers set to False.

The reason is that I have an “active learning” process where the dataset labels can change every epoch.

All of the samples themselves are cached locally in shared memory, but the LABELS are cleaned up as active learning proceeds so these labels need to be pulled down from an external database. This pulling of the new labels occurs once per epoch, and is a relatively fast operation, a call to the database. This call is triggered by calling a function on the Dataset owned by the DataLoader.

By setting persistent_workers to False, it guarantees that a NEW instance of the Dataset is pickled out to every worker at the start of the epoch, based on the current instance of the Dataset in the DataLoader, with the updated labels from the database.

This would not be possible with persistent_workers set to True (at least without digging into the internals, which I’d rather not do).