Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with Dataloader in getting started tutorial #607

Closed
lcskrishna opened this issue Aug 25, 2020 · 5 comments
Closed

Issues with Dataloader in getting started tutorial #607

lcskrishna opened this issue Aug 25, 2020 · 5 comments

Comments

@lcskrishna
Copy link

馃悰 Bug

Getting the following error, when running part (6) of the Getting Started tutorial.

To Reproduce

Steps to reproduce the behavior:
Running part (6) of the getting started tutorial.

Here is the error stack that I got it.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/opt/conda/lib/python3.6/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/opt/conda/lib/python3.6/multiprocessing/spawn.py", line 114, in _main
    prepare(preparation_data)
  File "/opt/conda/lib/python3.6/multiprocessing/spawn.py", line 225, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "/opt/conda/lib/python3.6/multiprocessing/spawn.py", line 277, in _fixup_main_from_path
    run_name="__mp_main__")
  File "/opt/conda/lib/python3.6/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/opt/conda/lib/python3.6/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/opt/conda/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/data/work/resnext3d/pt-version/training-scripts/classy-vison-project/custom_train.py", line 75, in <module>
    trainer.train(task)
  File "/opt/conda/lib/python3.6/site-packages/classy_vision/trainer/local_trainer.py", line 27, in train
    super().train(task)
  File "/opt/conda/lib/python3.6/site-packages/classy_vision/trainer/classy_trainer.py", line 45, in train
    task.on_phase_start()
  File "/opt/conda/lib/python3.6/site-packages/classy_vision/tasks/classification_task.py", line 1106, in on_phase_start
    self.advance_phase()
  File "/opt/conda/lib/python3.6/site-packages/classy_vision/tasks/classification_task.py", line 1008, in advance_phase
    self.create_data_iterator()
  File "/opt/conda/lib/python3.6/site-packages/classy_vision/tasks/classification_task.py", line 1061, in create_data_iterator
    self.data_iterator = iter(self.dataloaders[self.phase_type])
  File "/root/.local/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 325, in __iter__
    return _MultiProcessingDataLoaderIter(self)
  File "/root/.local/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 777, in __init__
    w.start()
  File "/opt/conda/lib/python3.6/multiprocessing/process.py", line 105, in start
    self._popen = self._Popen(self)
  File "/opt/conda/lib/python3.6/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/opt/conda/lib/python3.6/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/opt/conda/lib/python3.6/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/opt/conda/lib/python3.6/multiprocessing/popen_spawn_posix.py", line 42, in _launch
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "/opt/conda/lib/python3.6/multiprocessing/spawn.py", line 143, in get_preparation_data
    _check_not_importing_main()
  File "/opt/conda/lib/python3.6/multiprocessing/spawn.py", line 136, in _check_not_importing_main
    is not going to be frozen to produce an executable.''')
RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.
Traceback (most recent call last):
  File "/root/.local/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 822, in _try_get_data
    data = self._data_queue.get(timeout=timeout)
  File "/opt/conda/lib/python3.6/multiprocessing/queues.py", line 104, in get
    if not self._poll(timeout):
  File "/opt/conda/lib/python3.6/multiprocessing/connection.py", line 257, in poll
    return self._poll(timeout)
  File "/opt/conda/lib/python3.6/multiprocessing/connection.py", line 414, in _poll
    r = wait([self], timeout)
  File "/opt/conda/lib/python3.6/multiprocessing/connection.py", line 911, in wait
    ready = selector.select(timeout)
  File "/opt/conda/lib/python3.6/selectors.py", line 376, in select
    fd_event_list = self._poll.poll(timeout)
  File "/root/.local/lib/python3.6/site-packages/torch/utils/data/_utils/signal_handling.py", line 66, in handler
    _error_if_any_worker_fails()
RuntimeError: DataLoader worker (pid 3175) exited unexpectedly with exit code 1. Details are lost due to multiprocessing. Rerunning with num_workers=0 may give better error trace.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "custom_train.py", line 75, in <module>
    trainer.train(task)
  File "/opt/conda/lib/python3.6/site-packages/classy_vision/trainer/local_trainer.py", line 27, in train
    super().train(task)
  File "/opt/conda/lib/python3.6/site-packages/classy_vision/trainer/classy_trainer.py", line 48, in train
    task.step()
  File "/opt/conda/lib/python3.6/site-packages/classy_vision/tasks/classy_task.py", line 160, in step
    self.train_step()
  File "/opt/conda/lib/python3.6/site-packages/classy_vision/tasks/classification_task.py", line 913, in train_step
    sample = next(self.get_data_iterator())
  File "/root/.local/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 400, in __next__
    data = self._next_data()
  File "/root/.local/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 1017, in _next_data
    idx, data = self._get_data()
  File "/root/.local/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 984, in _get_data
    success, data = self._try_get_data()
  File "/root/.local/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 835, in _try_get_data
    raise RuntimeError('DataLoader worker (pid(s) {}) exited unexpectedly'.format(pids_str))
RuntimeError: DataLoader worker (pid(s) 3175) exited unexpectedly

I tried setting the num_workers=0, but i get an issue saying use num_workers>0.
Please let us know a way forward for this issue.

cc: @sunway513

mannatsingh added a commit to mannatsingh/ClassyVision that referenced this issue Aug 25, 2020
Summary:
Classy's default dataloader currently doesn't work when `num_workers` is set to 0. This is extremely useful for debugging dataloader issues like in facebookresearch#597 and facebookresearch#607.

Note that calling `set_dataloader_mp_context(None)` doesn't work since that just sets the mp context to the default value for the environment.

If `num_workers` is set to 0, the default call to `Dataloader` now sets `multiprocessing_context` to `None` so that PyTorch doesn't raise an exception.

Differential Revision: D23310512

fbshipit-source-id: 8a66a51d7c05c781783f73eda1ee97aa9398e6c9
@mannatsingh
Copy link
Contributor

@lcskrishna can you share some details about the environment you are on? The questionnaire we ask while creating a new bug report would be really helpful!

In the mean time, can you try both of the following (independently) -

facebook-github-bot pushed a commit that referenced this issue Aug 25, 2020
Summary:
Pull Request resolved: #608

Classy's default dataloader currently doesn't work when `num_workers` is set to 0. This is extremely useful for debugging dataloader issues like in #597 and #607.

Note that calling `set_dataloader_mp_context(None)` doesn't work since that just sets the mp context to the default value for the environment.

If `num_workers` is set to 0, the default call to `Dataloader` now sets `multiprocessing_context` to `None` so that PyTorch doesn't raise an exception.

Reviewed By: vreis

Differential Revision: D23310512

fbshipit-source-id: f4fa6766855446d2c14db7b7054f0e6bc6233bbe
@lcskrishna
Copy link
Author

@mannatsingh Thanks for the quick fix for num_workers=0. I am trying to run ClassyVision on ROCm with AMD GPUs.
However, here are the results of the above two options after rebasing to the top of #608:

  1. When I use num_workers=0 (works fine).
  2. When I use multi-processing context - Currently only "fork" works, the remaining two options (spawn, forkserver) throwed the same error as above.

@mannatsingh
Copy link
Contributor

@lcskrishna I see! It'll be great to see the how Classy works on AMD GPUs - it's something we haven't tried ourselves.

Looking at pytorch/pytorch#5858 and https://docs.python.org/3/library/multiprocessing.html#multiprocessing.freeze_support, it seems like you are running this on Windows? If that's the case, you are in uncharted territory since Classy was written with only linux support in mind.

Classy should work seamlessly even with a "fork" context though on linux.

@lcskrishna
Copy link
Author

@mannatsingh Thanks for the links to the issue and the documentation. I ran the experiments on Linux., and confirming that "fork" option works fine.

@mannatsingh
Copy link
Contributor

Sounds good. There are environments where spawn and forkserver don't work, but that is a more general issue unrelated to Classy Vision.

Closing this out since we have a resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants