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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix multiprocess issue (RuntimeError An attempt has been made to start a new process before the current process has finished its bootstrapping phase) #62

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

geronimi73
Copy link
Contributor

Fix RuntimeError in #28 once and for all by protecting main code with if __name__ != '__main__': return

Background:

  • The original issue occurred when the awq package was imported in train.py outside of a function. This was due to peft importing awq if installed, causing problems for users who had autoawq installed (me). The previous PR #30 solved by moving the peft imports inside the functions where the modules are needed.
  • Yesterday @iseesaw reported that he ran into this error too move peft imports to avoid RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase  #30 (comment). Did some digging and found that the multiprocess package is causing the problem. It appears that importing multiprocess changes the way child processes are created, similar to the behavior on Windows (see PyTorch documentation).
  • Although the current train.py does not import multiprocess directly, the HuggingFace datasets package does. If a user modifies the code to import datasets, for example with from datasets import load_dataset, the error occurs.
  • To fix this, this PR protects the main code in train.py with if __name__ != '__main__': return, similar to how it was recommended in the error message.

Error:

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.

This change should prevent the RuntimeError from occurring, regardless of whether the user imports packages that affect process creation.

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

Successfully merging this pull request may close these issues.

1 participant