-
Notifications
You must be signed in to change notification settings - Fork 6
Lazy load ML dependencies in the __init__ #346
Lazy load ML dependencies in the __init__ #346
Conversation
LAY-3689 Lazilly load sdk dependencies that are not always needed
Description part of https://github.com/layerai/roadmap/issues/19 Currently An inspiration can be taken in what we did last time we wanted to speed up the SDK - https://github.com/layerai/monorepo/pull/3146/files Acceptance Criteria
|
60bf650 to
2cbb8ba
Compare
| requests = ">=2.23.0" | ||
| nvsmi = "^0.4.2" | ||
| psutil = ">=5.4.8" # Google Colab comes with 5.4.8 by default. If it gets upgraded an error message is shown saying the runtime needs to be restarted. | ||
| lazy-loader = {git = "https://github.com/layerai/lazy_loader.git", rev = "26aa52ab057afb0c3f85ffc64f220eae0e9a222c"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to fork, because lazy_loader only installs to python >= 3.8, but there were no blockers to lower the requirement.
2cbb8ba to
f6bf9b2
Compare
volkangurel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the forked dependency, but looks like a good improvement so let's merge this in and we can iterate.
It is a problem, indeed. Publishing to pip does not support direct dependencies. Proposed lowering minimum supported Python version to 3.7 in the upstream repo scientific-python/lazy-loader#14 |
Lazy load ML dependencies (
torch,keras,xgboost) in the__init__to lower the import times when the libs are not used. Also,pandasandpyarrowimports were moved from the module tops into the methods.Before the change (with
torchinstalled):python -c "import layer" 3.52s user 0.77s system 128% cpu 3.325 totalAfter the change:
python -c "import layer" 1.95s user 0.44s system 214% cpu 1.114 totalIMHO there're still to much being done in the
__init__and could be improved further, but that's a good start. Some data on what's going on (using importtime_output_wrapper to format the output):python -m importtime_output_wrapper -m layer --depth 8 --width 600 --time cumulative --format waterfall 1> imports.logAlso closes LAY-3341.