Skip to content

Commit 73f1ab8

Browse files
Fix compatibility for bitsandbytes>=0.46 (#20956)
* Fix compatibility for bitsandbytes>=0.46 * --upgrade-strategy=eager --------- Co-authored-by: Jirka B <[email protected]>
1 parent afa7d56 commit 73f1ab8

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

.azure/gpu-tests-fabric.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ jobs:
130130
- bash: |
131131
set -e
132132
extra=$(python -c "print({'lightning': 'fabric-'}.get('$(PACKAGE_NAME)', ''))")
133-
pip install -e ".[${extra}dev]" -U --extra-index-url="${TORCH_URL}"
133+
pip install -e ".[${extra}dev]" -U --upgrade-strategy=eager --extra-index-url="${TORCH_URL}"
134134
displayName: "Install package & dependencies"
135135
136136
- bash: |

docs/source-pytorch/common/precision_intermediate.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Under the hood, we use `transformer_engine.pytorch.fp8_autocast <https://docs.nv
165165
Quantization via Bitsandbytes
166166
*****************************
167167

168-
`bitsandbytes <https://github.com/TimDettmers/bitsandbytes>`__ (BNB) is a library that supports quantizing :class:`torch.nn.Linear` weights.
168+
`bitsandbytes <https://github.com/bitsandbytes-foundation/bitsandbytes>`__ (BNB) is a library that supports quantizing :class:`torch.nn.Linear` weights.
169169

170170
Both 4-bit (`paper reference <https://arxiv.org/abs/2305.14314v1>`__) and 8-bit (`paper reference <https://arxiv.org/abs/2110.02861>`__) quantization is supported.
171171
Specifically, we support the following modes:

requirements/fabric/strategies.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
# note: is a bug around 0.10 with `MPS_Accelerator must implement all abstract methods`
77
# shall be resolved by https://github.com/microsoft/DeepSpeed/issues/4372
88
deepspeed >=0.9.3, <=0.9.3; platform_system != "Windows" and platform_system != "Darwin" # strict
9-
# skip bitsandbytes==0.46, due to ValueError: too many values to unpack (expected 2)
10-
bitsandbytes >=0.45.2,!=0.46,<0.47.0; platform_system != "Darwin"
9+
bitsandbytes >=0.45.2,<0.47.0; platform_system != "Darwin"

requirements/pytorch/extra.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ hydra-core >=1.2.0, <1.4.0
88
jsonargparse[signatures,jsonnet] >=4.39.0, <4.41.0
99
rich >=12.3.0, <14.1.0
1010
tensorboardX >=2.2, <2.7.0 # min version is set by torch.onnx missing attribute
11-
# skip bitsandbytes==0.46, due to ValueError: too many values to unpack (expected 2)
12-
bitsandbytes >=0.45.2,!=0.46,<0.47.0; platform_system != "Darwin"
11+
bitsandbytes >=0.45.2,<0.47.0; platform_system != "Darwin"

src/lightning/fabric/plugins/precision/bitsandbytes.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,12 @@ def quantize(
256256
if int8params.has_fp16_weights:
257257
int8params.data = B
258258
else:
259-
if hasattr(bnb.functional, "double_quant"):
259+
# bitsandbytes >= 0.45 supports an improved API
260+
if hasattr(bnb.functional, "int8_vectorwise_quant"):
261+
CB, SCB, _ = bnb.functional.int8_vectorwise_quant(B)
262+
else: # old method is deprecated in 0.45, removed in 0.46+.
260263
CB, _, SCB, _, _ = bnb.functional.double_quant(B)
261-
else: # for bitsandbytes versions ≥0.46
262-
CB, SCB = bnb.functional.int8_double_quant(B)
264+
263265
int8params.data = CB
264266
setattr(int8params, "CB", CB)
265267
setattr(int8params, "SCB", SCB)

0 commit comments

Comments
 (0)