-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Make Monai (Random) Transforms work in a multi-threaded environment #7582
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
Comments
What is the reason for storing the randomization information for a sample in an instance variable on the transform? Compared to having the randomize() method return that information as an object? |
With Pytorch 2.6 free-threading support (Python 3.13t) is enabled on Linux x64, and Numpy has preliminary support since version 2.1, so the AFAIK main dependencies for Monai could now be used in free-threading python. Is there any roadmap/timeline for supporting free-threaded python within MONAI already? I understand there are a lot of other things you are working on, I'm just interested in what the thoughts of the MONAI core team are on this. I see two ways to support this, and I would especially appreciate feedback on the first option, especially if there are hurdles I overlooked 1. Minimum changesTry to work around the current limitations of the Randomizable class an try to establish support with minimum changes:
Pros:
Cons:
Note: Possibly this could also be implemented in a Dataloader, but then the dataloader has strong coupling to the compose/transform it uses. 2. Refactor the TransformsRefactor the Randomizable interface to enable the use of multiple threads without copying/cloning. Pros:
Cons:
Thank you for your input and your great work on MONAI! |
With PEP 703 being accepted and implementation of it underway python/cpython#108219 I think it would be great to prepare the Monai transforms early for execution on multiple threads. Especially with the large tensor sizes and the advantages of running transforms on GPU, I'm hoping for free-threading to have a big benefit in (3D) medical imaging AI.
I think the biggest issue here would be the Randomizable transforms, which currently can't be executed inside a threaded environment.
AFAIK, the free-threading is pushed by Meta, and I'm therefore expecting pytorch to be compatible with it relatively early, since one of the talks on no-gil python talked about testing it with a pytorch DL project internally at Meta.
This might be a great opportunity to work on #6854 as well, which might eventually require breaking changes in the Randomizable API as well.
The text was updated successfully, but these errors were encountered: