-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
Reconcile PythonLayer with Multi-GPU #2936
Comments
This is not going to work that cleanly. Multi-process means multiple gpu Still amazes me that python doesn't support threading in a reasonable way.
|
Yes, I totally agree with you. On second thought maybe Python's multiprocessing module is not suitable here. |
Joblib allows you to use a threading backend when used in conjunction with Cython and releasing the GIL. Maybe that work be appropriate here? |
A manual little example to workaround GIL http://pieceofpy.com/2010/02/26/boost-python-threads-and-releasing-the-gil/ |
The straightforward (and perhaps naive) workaround seems to be to serialize all calls to any Python code, i.e. only allow having one PythonLayer execution at a time to behave like before. This can be done via a global python lock, perhaps as a static member variable in PythonLayer class. From my perspective, I think serializing python execution is reasonable for CPU Bound PythonLayer since Python interpretation is always serialized in GIL and never actually run in parallel. One may argue for the case of IO Bound PythonLayer (such as using PythonLayer as a data layer), but then I would not even expect to run into this case since people should Any comment? |
In the short term until this gets sorted out, perhaps setting |
But even for the shared case, backward is not working correctly #2923 (comment), as in #2903 I only expected a PythonLayer to be shared when used as a data layer and performs no backward. |
You could also give a fatal message for that case too. I agree that this is tricky and don't have a solution, but failing cleanly is a reasonable placeholder. |
|
@BlGene see @thatguymike and @ronghanghu comments on python multiprocess |
What about to implement a method pyforward and pybackward in Net class C++ definition, such that it just releases GIL by means of a ScopedGILRelease and immediately after calls the forward (or backward) methods. Then, simply expose pyforward and pybackward functions to boost interface. Otherwise, a PyNet C++ class that inherit from Net, and override forward and backward doing simply GIL realease and call super.forward() (or super.backward()). At least for the most used time consuming/commonly used methods is important to release GIL, otherwise making caffe not suited to production multi-threaded python applications. |
@ronghanghu |
I have done a pull request for fix it #4360 |
Each net can run in it's own fork now, there is an example in /python/train.py. #4563 |
I can't understand why this was closed? #4563 doesn't release GIL. It only implements multiple GPU training. I wan't to have multiple workers with shared memory and single GPU thread to stream forward passes only, but everything gets blocked during forward pass. What's wrong with #4360, except code style? |
Sorry, so is there any way to create a custom data layer with multiple GPU? |
Right now PythonLayer cannot be parallelized in MultiGPU, which is a bug. Python Global Interpreter Lock (GIL) only allows one thread at a time to run in the python interpreter. This issue is reported in #2923.
We should find a solution to to this bug, or only allow shared PythonLayer and serializing PythonLayer forward (currently via
share_in_parallel: true
) it in MultiGPU (then we need a backward lock, too? but it is more complicated than that #2923 (comment)) Perhaps we may use multiprocessing module to fix this bug? But on second thought it doesn't seem like a good idea either.The text was updated successfully, but these errors were encountered: