DataLoader : TypeError: Instance and class checks can only be used with @runtime_checkable protocols

Why the error with DataLoader when I upgrade from python version 3.9 to 3.10 ?

I added @runtime_checkable just before DataLoader class, but it does not help with NameError: name 'runtime_checkable' is not defined

Based on the official Python documentation about @runtime_checkable, the decorator should only be applied on a Protocol class. Since DataLoader is not, it will raise the TypeError that you are seeing if you add @runtime_checkable just before the DataLoader class.

We also landed a new PR that allows subclasses of IterableDataset to be used in DataLoader with Python 3.10. If you download the nightly version of PyTorch from the middle of this page, it should work.

Is there a way to get around this error without installing the nightly version of Pytorch ?

I don’t think it is possible at the moment. We are still working on Python 3.10 support. You can track the issue here:

1 Like

I have used the compiled binary on 25 December, but I am still getting the same error.

Did I miss anything ?

I do not believe that is the nightly version and hence it may not have the latest changes.

Please use the nightly version linked here.

Hi, I am facing the same error. Did you come across any solution ?. If so, please help me.

you can use virtual environment inside PyCharm, but make sure you need to install Python3.9 in your OS system

Python version upgrade from 3.9 to 3.10 is what causing the issue.

Either use python 3.9 for now before next PyTorch release, or use the master branch of PyTorch to compile your code. A patch to fix it has landed.