pytoch dataloader can only join a child process
Nov. 24, 2019, 10:22 p.m.
read: 2696
环境
python版本3.7.0
pytorch版本1.3.1
pycharm远程调试
import torch
from torch import multiprocessing
# DEPENDANCY: This is required for ``DistributedDataParallel``
# https://pytorch.org/docs/stable/nn.html?highlight=distributeddataparallel#torch.nn.parallel.DistributedDataParallel
try:
multiprocessing.set_start_method('spawn')
except RuntimeError:
pass
# DEPENDANCY: This is required for ``from tqdm import tqdm``
# https://github.com/tqdm/tqdm/blob/96d8a3c3642474144f53f74331ef2172d1c39496/tqdm/_tqdm.py#L74
mp_lock = multiprocessing.RLock()
import torch
from torch.utils.data import DataLoader
if __name__ == '__main__':
data_iterator = torch.utils.data.DataLoader([torch.tensor(i) for i in range(10)], num_workers=4)
for batch in data_iterator:
pass
直接运行以上简单代码会报错
解决方案/solution重启pycharm/restart pycharm
如果以上方法行不通 / orstep 1.切换到python3.6环境 / change python version to python3.6
step 2.切换到pytorch 1.1.0/ change pytorch version to 1.1.0