Data not loading when num_workers>0

When I run following code :

trainer = Trainer(callbacks=[early_stop_callback], max_epochs=100, accelerator='cpu')
trainer.fit(model, tr_loader, val_loader)

It runs till sanity checks and then throws runtime-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.

        To fix this issue, refer to the "Safe importing of main module"
        section in https://docs.python.org/3/library/multiprocessing.html

This error goes away when I set num_workers = 0 for DataLoader, pls guide whats happening and how to resolve?

Hey @Sar2580P

You need to basically do what it says there, run your code under this guard:

def main():
    # put your code here


if __name__ == '__main__':
    main()