AttributeError: 'DataLoader' object has no attribute 'persistent_workers'

Hello! Just upgraded from my old version of pytorch to 1.9. I ran some code I am using which involves DataLoaders. In the old version of Pytorch it works as expected. In this one I get this error:

AttributeError: ‘DataLoader’ object has no attribute ‘persistent_workers’

I’ve been searching in the source code for the class to see if there is such an attribute there and there is. dict also proves that there is such an attribute. So what gives?

Any help would be appreciated!

Could you double check the installed PyTorch version via torch.__version__, please, as this attribute should be in 1.9.0 and I can also use it?

It is version 1.9.0 yes I already checked that!

The torch.version command yields the result 1.9.0

Also when I check the attributes of the Dataloader I get this:

{‘dataset’: < object at 0x000001188463B790>, ‘num_workers’: 0, ‘pin_memory’: False, ‘timeout’: 0, ‘worker_init_fn’: None, ‘_DataLoader__multiprocessing_context’: None, ‘_dataset_kind’: 0, ‘batch_size’: 100, ‘drop_last’: False, ‘sampler’: < object at 0x000001188463B700>, ‘batch_sampler’: < object at 0x000001188463B610>, ‘generator’: None, ‘collate_fn’: <function default_collate at 0x000001188A783DC0>, ‘_DataLoader__initialized’: True, ‘_IterableDataset_len_called’: None}

So as you can see there is something wrong here. Not sure why though?

I’m still unsure, what might be causing the issue, as this code snippet works fine for me:

import torch
from import Dataset, DataLoader, TensorDataset

dataset = TensorDataset(torch.randn(100, 1), torch.randn(100, 1))
loader = DataLoader(dataset, batch_size=25, num_workers=2, persistent_workers=True)

for data, target in loader:


torch.Size([25, 1])
torch.Size([25, 1])
torch.Size([25, 1])
torch.Size([25, 1])

Are you seeing the same issue using my code?