Can't pickle local object ''SubPolicy.__init__.<locals>.<lambda>'’
KaiOtter opened this issue · 6 comments
Hi, I meet a problem when I run AutoAugment and I can't find any solution by google.
My environment is different from the tested one. Well, I will feel lucky if it is not a complex compatibility issue.
My environment is as below:
python: 3.7
pytorch: 1.10
Pillow: 5.4.1
File "/home/dc2-user/anaconda3/envs/kaidi_env/lib/python3.7/site-packages/torch/utils/data/dataloader.py",
line 469, in init
w.start()
File "/home/dc2-user/anaconda3/envs/kaidi_env/lib/python3.7/multiprocessing/process.py", line 112, in start
self._popen = self._Popen(self)
File "/home/dc2-user/anaconda3/envs/kaidi_env/lib/python3.7/multiprocessing/context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "/home/dc2-user/anaconda3/envs/kaidi_env/lib/python3.7/multiprocessing/context.py", line 284, in _Popen
return Popen(process_obj)
File "/home/dc2-user/anaconda3/envs/kaidi_env/lib/python3.7/multiprocessing/popen_spawn_posix.py", line 32,
in init
super().init(process_obj)
File "/home/dc2-user/anaconda3/envs/kaidi_env/lib/python3.7/multiprocessing/popen_fork.py", line 20, in init
self._launch(process_obj)
File "/home/dc2-user/anaconda3/envs/kaidi_env/lib/python3.7/multiprocessing/popen_spawn_posix.py", line 47,
in _launch
reduction.dump(process_obj, fp)
File "/home/dc2-user/anaconda3/envs/kaidi_env/lib/python3.7/multiprocessing/reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object "SubPolicy.init.<locals>.<lambda>"
I have found a solution for that. This bug comes from python multiprocessing file which cannot be changed. But there is an alternative version, multiprocess, from https://github.com/uqfoundation/multiprocess, you can install it using pip here: https://pypi.org/project/multiprocess/#files
After installation, you can replace import multiprocessing
with import multiprocess as multiprocessing,
so you import the new package under same name, without affecting anything else.
Hi, @triangleCZH I'm using PyTorch Dataloader with Python3.7 and meet the same bug, but the multiprocessing
model was used in torch.utils.data.dataloader
, is there anyway that I don't need to modify the source code?
I use conda environment , so I don't fear to change pytorch source code , it could be rebulid very easily and fast
Easy fix is to use dill (https://stackoverflow.com/a/37002397) instead of pickle. The Sub-policies from this repo cannot be pickled currently as they define functions inside the class.
I've created a new PR which fixes this issue. It's the only way I could get it to work on DDP training.
I've created a new PR which fixes this issue. It's the only way I could get it to work on DDP training.
what is the 'PR'? Could you tell detaily how to fix this issue?please