-
Notifications
You must be signed in to change notification settings - Fork 1.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
Lazy import of bitsandbytes #1230
Lazy import of bitsandbytes #1230
Conversation
Previously, we imported from bitsandbytes eagerly if the package was installed. This caused two major issues: - Slow loading time of PEFT (~4 sec) - Errors with multiprocessing because bnb initializes CUDA This commit fixes both issues by importing bitsandbytes lazily. PEFT import time is now reduced to ~2sec. Notes Implementation-wise, I use a combination of local imports and module-level __getattr__. The latter was introduced in Python 3.7 and should therefore be safe to use. As for testing, it is not as straightforward as just adding a new unit test. The issue is that when multiple tests are run, depending on the order, bitsandbytes may already be imported once the new test runs. To avoid this issue, I created a completely separate testing script that is run in CI. If anyone has a better idea, please let me know.
Should not be necessary but better safe than sorry.
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Normal CI doesn't support CUDA, d'uh.
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.
Thank you @BenjaminBossan for fixes the issues as well as making the import faster, LGTM! 🚀
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.
Thanks for making the import faster!
.github/workflows/nightly.yml
Outdated
@@ -34,7 +34,7 @@ jobs: | |||
source activate peft | |||
pip install -e . --no-deps | |||
pip install pytest-reportlog | |||
|
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.
Why this diff is here?
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.
I removed all trailing whitespace from the yml.
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.
Note that I moved the test to the proper unit tests using a trick that Zach showed, so I undid all the changes here (i.e. trailing whitespaces are back).
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.
Thanks for fixing this! Great job :)
Thanks a lot @muellerzr for helping with the test. |
Previously, we imported from bitsandbytes eagerly if the package was installed. This caused two major issues: - Slow loading time of PEFT (~4 sec) - Errors with multiprocessing because bnb initializes CUDA This commit fixes both issues by importing bitsandbytes lazily. PEFT import time is now reduced to ~2sec. Notes Implementation-wise, I use a combination of local imports and module-level __getattr__. The latter was introduced in Python 3.7 and should therefore be safe to use.
Should fix various issues reported here and elsewhere, e.g. #559, huggingface/accelerate#2216.
Description
Previously, we imported from bitsandbytes eagerly if the package was installed. This caused two major issues:
This commit fixes both issues by importing bitsandbytes lazily. PEFT import time is now reduced to ~2sec.
Notes
Implementation-wise, I use a combination of local imports and module-level
__getattr__
. The latter was introduced in Python 3.7 and should therefore be safe to use.As for testing, it is not as straightforward as just adding a new unit test. The issue is that when multiple tests are run, depending on the order, bitsandbytes may already be imported once the new test runs. To avoid this issue, I created a completely separate testing script that is run in CI. It is executed on the nightly multi-GPU CI run. Locally, it passes, 🤞 that it also passes there.
If anyone has a better idea, please let me know.