From edc83e2e6c44bb769661e49ee9537db281a1ef1d Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 2 Jan 2024 15:23:36 +0200 Subject: [PATCH] Don't require scipy for regular use --- bitsandbytes/functional.py | 9 ++++++++- setup.py | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bitsandbytes/functional.py b/bitsandbytes/functional.py index 0b18d9b06..f7eee95f7 100644 --- a/bitsandbytes/functional.py +++ b/bitsandbytes/functional.py @@ -233,8 +233,15 @@ def create_linear_map(signed=True, total_bits=8, add_zero=True): l = values.numel()//2 return torch.Tensor(values[:l].tolist() + [0]*gap + values[l:].tolist()) + def create_normal_map(offset=0.9677083, use_extra_value=True): - from scipy.stats import norm + try: + from scipy.stats import norm + except ImportError as ie: + raise ImportError( + "Scipy is required for `create_normal_map`. " + "Install `bitsandbytes` with the `[test]` extra." + ) from ie if use_extra_value: # one more positive value, this is an asymmetric type diff --git a/setup.py b/setup.py index b55678bf4..92db6cae5 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,10 @@ def read(fname): license="MIT", keywords="gpu optimizers optimization 8-bit quantization compression", url="https://github.com/TimDettmers/bitsandbytes", - install_requires=['scipy'], + install_requires=[], + extras_require={ + 'test': ['scipy'], + }, packages=find_packages(), package_data={"": libs}, install_requires=['torch', 'numpy', 'scipy'],