Optimize import times a bit#7171
Merged
rapids-bot[bot] merged 6 commits intorapidsai:branch-25.10from Sep 4, 2025
Merged
Conversation
The import time for `_sklearn_compat.py` was non-negligible in the list of imports we control. Most of that file was unused in cuml, culling out the compat bits we don't need saved 0.08 s on my machine.
After this commit, `import cuml` should only import core bits of sklearn like `import sklearn.base`. Anything algorithm specific is delayed until first use, speeding import time.
a251b2f to
859a026
Compare
jcrist
commented
Sep 3, 2025
csadorf
reviewed
Sep 4, 2025
csadorf
approved these changes
Sep 4, 2025
Member
Author
|
/merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An offline conversation sent me down an import time inspection rabbit hole, this PR is the result. I don't think any of the changes here are bad, but also am not sure they're meaningful. Just pushing it up for discussion.
cumlhas some dependencies with non-negligible import times. These include:cupycudfsklearnnumpypandasIn terms of total import time contribution,
cudf+pandasare the biggest offenders here. With some work we could delay ourcudf&pandasimports until use and shave off ~40% of our import time. If most users aren't usingcudfthis might be a meaningful body of work to pursue.The other imports are pretty core to how
cumlworks and can't really be avoided in any workflow - delaying imports just moves costs from import until use but doesn't reduce it.This PR instead focuses on limiting the number of things imported from
sklearnupon animport cumlcall. This drops ~10% of our import time off, bringing us to just under1 son my machine.Changes can be summarized as:
_sklearn_compat.pyto just what we actually use. This drops a bunch of sklearn imports, and is the most meaningful contribution to the import time improvements.cuml.pipeline/cuml.model_selectionimports until use.Could go either way on merging this, just pushing it up for discussion.