AnswerDotAI / fsdp_qlora

Training LLMs with QLoRA + FSDP
Apache License 2.0
1.42k stars 188 forks source link

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 geronimi73 opened 6 months ago

geronimi73 commented 6 months ago

Fix RuntimeError in https://github.com/AnswerDotAI/fsdp_qlora/issues/28 once and for all by protecting main code with if __name__ != '__main__': return

Background:

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.