-
Notifications
You must be signed in to change notification settings - Fork 139
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
Import bitsandbytes only if it is used #546
Conversation
b145a36
to
35bc63a
Compare
35bc63a
to
c4da854
Compare
Codecov Report
@@ Coverage Diff @@
## master #546 +/- ##
==========================================
- Coverage 75.96% 75.94% -0.02%
==========================================
Files 81 81
Lines 7979 7978 -1
==========================================
- Hits 6061 6059 -2
- Misses 1918 1919 +1
|
@@ -9,13 +9,11 @@ | |||
import numpy as np | |||
import torch | |||
|
|||
if importlib.util.find_spec("bitsandbytes") is not None: |
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.
importlib.util is no longer used, so its import can be removed
hivemind/compression/quantization.py
Outdated
@@ -132,6 +130,9 @@ class BlockwiseQuantization(Quantization): | |||
def quantize( | |||
self, tensor: torch.Tensor, allow_inplace: bool = False | |||
) -> Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray]]: | |||
# This runs actual import only on the 1st call, copies references after that | |||
from bitsandbytes.functional import quantize_blockwise |
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.
Since this is no longer under a conditional import (and will thus cause ImportError instead of NameError), can we wrap this statement instead of the quantize_blockwise
call below with try-except? The same applies to extract
When bitsandbytes is installed, hivemind always tries to import it even if it doesn't work. This leads to a number of undesirable behaviors: - `import hivemind` fails if bitsandbytes is installed but fails to resolve CUDA dynamic libraries or load its own dynamic libraries. This happens all the time: - on CPU-only hosts with CUDA installed (e.g., Colabs) - on hosts with misconfigured CUDA (e.g., most nora envs) - on macOS (even when the daemon is compiled correctly and it should work), etc. - Users see the irrelevant bitsandbytes welcome message even if they don't use it. This message is currently impossible to suppress. Multiple users has reported that this is not expected when they import hivemind/petals. This PR fixes it, so now hivemind's behavior matches with, e.g., HF transformers (import bitsandbytes only if it's necessary).
When bitsandbytes is installed, hivemind always tries to import it even if it doesn't work. This leads to a number of undesirable behaviors: - `import hivemind` fails if bitsandbytes is installed but fails to resolve CUDA dynamic libraries or load its own dynamic libraries. This happens all the time: - on CPU-only hosts with CUDA installed (e.g., Colabs) - on hosts with misconfigured CUDA (e.g., most nora envs) - on macOS (even when the daemon is compiled correctly and it should work), etc. - Users see the irrelevant bitsandbytes welcome message even if they don't use it. This message is currently impossible to suppress. Multiple users has reported that this is not expected when they import hivemind/petals. This PR fixes it, so now hivemind's behavior matches with, e.g., HF transformers (import bitsandbytes only if it's necessary). (cherry picked from commit e18868f)
When bitsandbytes is installed, hivemind always tries to import it even if it doesn't work. This leads to a number of undesirable behaviors:
import hivemind
fails if bitsandbytes is installed but fails to resolve CUDA dynamic libraries or load its own dynamic libraries. This happens all the time:This PR fixes it, so now hivemind's behavior matches with, e.g., HF transformers (import bitsandbytes only if it's necessary).