CUDA multiprocessing in jupyter notebook is possible?

Is it possible to run CUDA multiprocessing in jupyter notebook?

Currently I am implementing A3C in notebook.

For running multiprocessing with CUDA, mp.set_start_method('spawn') is required.(mp is torch.multiprocessing)

and mp.set_start_method('spawn') is required __name__ == "__main__".

I have known __name__ == "__main__" is used in .py not in .ipynb

Is there any way instead of using __name__ == "__main__"?

1 Like

Are you sure the __name__ == "__main__" is required and there’s no easy alternative to use here ? Maybe posting the actual could would help since there might be an easy way to modify it as to not require using set_start_method (E.g. by using DataParallel instead of mp)

That being said, there is a way to run code in a notebook as if it were ran under main:

exec(compile('your code here', '__main__.py', 'exec'))

Though I’m not sure if this will actually produce the expected behavior here and I don’t really have a multiple GPU machine handy right now to test.