ddp_cpu not working in Jupyter/Colab
🐛 Bug
Fitting a trainer instantiated with accelerator='ddp_cpu', num_processes=2 does not work.
torch/multiprocessing/spawn.py in join(self, timeout)
ProcessExitedException: process 1 terminated with exit code 1
Please reproduce using the BoringModel
https://colab.research.google.com/drive/1U66mjbpqMYkp6Lq0Zhi5c0DteSX7QHwJ?usp=sharing
To Reproduce
Pass accelerator='ddp_cpu', num_processes=2 to pl.Trainer, and then do trainer.fit(...).
Expected behavior
Does work.
Environment
* CUDA:
- GPU:
- available: False
- version: 10.1
* Packages:
- numpy: 1.19.5
- pyTorch_debug: False
- pyTorch_version: 1.8.1+cu101
- pytorch-lightning: 1.3.4
- tqdm: 4.41.1
* System:
- OS: Linux
- architecture:
- 64bit
-
- processor: x86_64
- python: 3.7.10
- version: #1 SMP Tue Apr 20 19:55:43 PDT 2021
Additional context
I was trying to develop for dp/ddp2 on my laptop, could not get it to work, messed around and tried to run with ddp_cpu but ran into the following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/arche/miniconda3/envs/vse/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "/home/arche/miniconda3/envs/vse/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
self = reduction.pickle.load(from_parent)
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/torch/nn/parallel/distributed.py", line 632, in __setstate__
self.process_group = _get_default_group()
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/torch/distributed/distributed_c10d.py", line 347, in _get_default_group
raise RuntimeError("Default process group has not been initialized, "
RuntimeError: Default process group has not been initialized, please make sure to call init_process_group.
I did not get the same error with BoringModel (as stated earlier).
sidenote: I wanted to try computing a loss on the whole batch (concatenation of the individual device batches), and I understand that DP/DDP2 is the correct distributed "framework" to do that. As my laptop does not have a single gpu (let alone multiple), it looks like I cannot develop/debug due to 'ddp_cpu' being the only thing I can use.
Hi, this seems to be a problem with ddp_cpu running in colab/jupyter notebooks, because this works fine locally running a regular python script. Have you made the same observation?
Exported the notebook to python, moved things around inside the script (otherwise it complained about starting new processes before the current had finished bootstrapping), and ran it successfully. So I guess this was indeed a colab/notebook issue.
Running my own code in the exact same environment gives me the error trace I pasted in "Additional context", at which point my terminal hangs. Interrupting with Ctrl-C "resumes" the stopping of the script. Here is the full trace:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/arche/miniconda3/envs/vse/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "/home/arche/miniconda3/envs/vse/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
self = reduction.pickle.load(from_parent)
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/torch/nn/parallel/distributed.py", line 632, in __setstate__
self.process_group = _get_default_group()
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/torch/distributed/distributed_c10d.py", line 347, in _get_default_group
raise RuntimeError("Default process group has not been initialized, "
RuntimeError: Default process group has not been initialized, please make sure to call init_process_group.
^C (### TERMINAL HANGED, INTERRUPTED BY CTRL-C ###)
Traceback (most recent call last):
File "src/train_model.py", line 182, in <module>
main()
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/hydra/main.py", line 53, in decorated_main
config_name=config_name,
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/hydra/_internal/utils.py", line 371, in _run_hydra
lambda: hydra.run(
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/hydra/_internal/utils.py", line 212, in run_and_report
return func()
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/hydra/_internal/utils.py", line 374, in <lambda>
overrides=args.overrides,
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/hydra/_internal/hydra.py", line 102, in run
configure_logging=with_log_configuration,
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/hydra/core/utils.py", line 137, in run_job
ret.return_value = task_function(task_cfg)
File "src/train_model.py", line 136, in main
trainer.fit(model, datamodule)
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 458, in fit
self._run(model)
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 756, in _run
self.dispatch()
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 797, in dispatch
self.accelerator.start_training(self)
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/pytorch_lightning/accelerators/accelerator.py", line 96, in start_training
self.training_type_plugin.start_training(trainer)
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/pytorch_lightning/plugins/training_type/ddp_spawn.py", line 122, in start_training
mp.spawn(self.new_process, **self.mp_spawn_kwargs)
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 230, in spawn
return start_processes(fn, args, nprocs, join, daemon, start_method='spawn')
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 188, in start_processes
while not context.join():
File "/home/arche/miniconda3/envs/vse/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 101, in join
timeout=timeout,
File "/home/arche/miniconda3/envs/vse/lib/python3.7/multiprocessing/connection.py", line 921, in wait
ready = selector.select(timeout)
File "/home/arche/miniconda3/envs/vse/lib/python3.7/selectors.py", line 415, in select
fd_event_list = self._selector.poll(timeout)
KeyboardInterrupt
(I tried running the BoringModel with hydra, things worked fine.) Here is my main script: https://pastebin.com/mQvMVarm. (datamodule created at line 33, model at line 81, trainer at line 110)
And here my environment details:
* CUDA:
- GPU:
- available: False
- version: None
* Packages:
- numpy: 1.19.2
- pyTorch_debug: False
- pyTorch_version: 1.8.1
- pytorch-lightning: 1.3.4
- tqdm: 4.59.0
* System:
- OS: Linux
- architecture:
- 64bit
- ELF
- processor:
- python: 3.7.10
- version: #1 SMP Fri May 7 16:38:17 UTC 2021
This issue has been automatically marked as stale because it hasn't had any recent activity. This issue will be closed in 7 days if no further activity occurs. Thank you for your contributions, Pytorch Lightning Team!
Closing, duplicate of #7550