From 5dea36c5e2969aa8823213d6602e058db093ec57 Mon Sep 17 00:00:00 2001 From: Ali Alshaarawy <45029495+ali-alshaar7@users.noreply.github.com> Date: Wed, 2 Oct 2024 12:18:43 -0400 Subject: [PATCH] update BitsandBytes version (#20313) * upggrade requiremnets.txt * update fabric bitsandbytes linear quantization for bnb 0.44.1 * add quant_storage param * exclude macos from bnb upgrade * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- requirements/fabric/strategies.txt | 3 ++- requirements/pytorch/extra.txt | 3 ++- src/lightning/fabric/plugins/precision/bitsandbytes.py | 10 ++++++++-- .../pytorch/plugins/precision/bitsandbytes.py | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/requirements/fabric/strategies.txt b/requirements/fabric/strategies.txt index 4aee89d9f6..394aceb39c 100644 --- a/requirements/fabric/strategies.txt +++ b/requirements/fabric/strategies.txt @@ -6,4 +6,5 @@ # note: is a bug around 0.10 with `MPS_Accelerator must implement all abstract methods` # shall be resolved by https://github.com/microsoft/DeepSpeed/issues/4372 deepspeed >=0.8.2, <=0.9.3; platform_system != "Windows" and platform_system != "Darwin" # strict -bitsandbytes >=0.42.0,<0.43.0 +bitsandbytes >=0.44.0,<0.44.2; sys_platform == 'linux' or sys_platform == 'win32' +bitsandbytes >=0.42.0,<0.43.0 ; sys_platform == 'darwin' diff --git a/requirements/pytorch/extra.txt b/requirements/pytorch/extra.txt index 6962da858c..12bbdf5a70 100644 --- a/requirements/pytorch/extra.txt +++ b/requirements/pytorch/extra.txt @@ -8,4 +8,5 @@ hydra-core >=1.2.0, <1.4.0 jsonargparse[signatures] >=4.27.7, <4.28.0 rich >=12.3.0, <13.6.0 tensorboardX >=2.2, <2.7.0 # min version is set by torch.onnx missing attribute -bitsandbytes >=0.42.0,<0.43.0 +bitsandbytes >=0.44.0,<0.44.2; sys_platform == 'linux' or sys_platform == 'win32' +bitsandbytes >=0.42.0,<0.43.0 ; sys_platform == 'darwin' diff --git a/src/lightning/fabric/plugins/precision/bitsandbytes.py b/src/lightning/fabric/plugins/precision/bitsandbytes.py index 0f524dd67f..3944154528 100644 --- a/src/lightning/fabric/plugins/precision/bitsandbytes.py +++ b/src/lightning/fabric/plugins/precision/bitsandbytes.py @@ -43,7 +43,7 @@ _BITSANDBYTES_AVAILABLE = RequirementCache("bitsandbytes>=0.42.0") class BitsandbytesPrecision(Precision): - """Plugin for quantizing weights with `bitsandbytes `__. + """Plugin for quantizing weights with `bitsandbytes `__. .. warning:: This is an :ref:`experimental ` feature. @@ -184,11 +184,15 @@ def _replace_param( if param.device.type == "meta": if isinstance(param, bnb.nn.Params4bit): return bnb.nn.Params4bit( - data, + data=data, requires_grad=data.requires_grad, quant_state=quant_state, + blocksize=param.blocksize, compress_statistics=param.compress_statistics, quant_type=param.quant_type, + quant_storage=param.quant_storage, + module=param.module, + bnb_quantized=param.bnb_quantized, ) return torch.nn.Parameter(data, requires_grad=data.requires_grad) param.data = data @@ -322,6 +326,7 @@ def _import_bitsandbytes() -> ModuleType: return assert isinstance(self.weight, bnb.nn.Params4bit) self.weight = self.quantize(self.weight, weight, device) + self.weight.bnb_quantized = True @staticmethod def quantize( @@ -337,6 +342,7 @@ def _import_bitsandbytes() -> ModuleType: blocksize=params4bit.blocksize, compress_statistics=params4bit.compress_statistics, quant_type=params4bit.quant_type, + quant_storage=params4bit.quant_storage, ) return _replace_param(params4bit, w_4bit, quant_state) diff --git a/src/lightning/pytorch/plugins/precision/bitsandbytes.py b/src/lightning/pytorch/plugins/precision/bitsandbytes.py index 62acc7bf77..3a2daa828b 100644 --- a/src/lightning/pytorch/plugins/precision/bitsandbytes.py +++ b/src/lightning/pytorch/plugins/precision/bitsandbytes.py @@ -16,7 +16,7 @@ from lightning.pytorch.plugins.precision.precision import Precision class BitsandbytesPrecision(Precision, FabricBNBPrecision): - """Plugin for quantizing weights with `bitsandbytes `__. + """Plugin for quantizing weights with `bitsandbytes `__. .. warning:: This is an :ref:`experimental ` feature.