Skip to content

Commit 45dcd4d

Browse files
Drop Python 3.9 support (#1795)
1 parent fad47f2 commit 45dcd4d

File tree

17 files changed

+54
-51
lines changed

17 files changed

+54
-51
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.11.2
3+
rev: v0.14.3
44
hooks:
55
- id: ruff
66
args:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The library includes quantization primitives for 8-bit & 4-bit operations, throu
1919
## System Requirements
2020
bitsandbytes has the following minimum requirements for all platforms:
2121

22-
* Python 3.9+
22+
* Python 3.10+
2323
* [PyTorch](https://pytorch.org/get-started/locally/) 2.3+
2424
* _Note: While we aim to provide wide backwards compatibility, we recommend using the latest version of PyTorch for the best experience._
2525

benchmarking/matmul_benchmark.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def test_bench_matmul(batch, seq, model, hidden):
3535
B = torch.empty(hidden, model, dtype=torch.float16, device="cuda")
3636
torch.nn.init.xavier_uniform_(B)
3737

38-
B_fp4, state = F.quantize_fp4(B)
39-
B_fp4_c, state_c = F.quantize_fp4(B, compress_statistics=True)
38+
_B_fp4, _state = F.quantize_fp4(B)
39+
_B_fp4_c, _state_c = F.quantize_fp4(B, compress_statistics=True)
4040

4141
B_nf4, state_nf4 = F.quantize_nf4(B)
4242
B_nf4_c, state_nf4_c = F.quantize_nf4(B, compress_statistics=True)
@@ -117,8 +117,8 @@ def test_bench_matmul(batch, seq, model, hidden):
117117
f"B -> CB + threshold: [{batch},{seq},{model}], [{model},{hidden}]->[{batch},{seq},{hidden}]: {time.time() - t0:.4f}s"
118118
)
119119

120-
CA, SCA, _ = F.int8_vectorwise_quant(A, threshold=0.0)
121-
CB, SCB, _ = F.int8_vectorwise_quant(B)
120+
CA, _SCA, _ = F.int8_vectorwise_quant(A, threshold=0.0)
121+
CB, _SCB, _ = F.int8_vectorwise_quant(B)
122122
torch.cuda.synchronize()
123123
t0 = time.time()
124124
for i in range(iters):

bitsandbytes/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ def _import_backends():
5454
"""
5555
from importlib.metadata import entry_points
5656

57-
if sys.version_info < (3, 10):
58-
extensions = entry_points().get("bitsandbytes.backends", [])
59-
else:
60-
extensions = entry_points(group="bitsandbytes.backends")
57+
extensions = entry_points(group="bitsandbytes.backends")
6158

6259
for ext in extensions:
6360
try:

bitsandbytes/autograd/_functions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from collections.abc import Callable
12
from dataclasses import dataclass
23
from math import prod
3-
from typing import Callable, Optional
4+
from typing import Optional
45
import warnings
56
from warnings import warn
67

@@ -257,7 +258,7 @@ def backward(ctx: torch.autograd.function.FunctionCtx, grad_output: torch.Tensor
257258
return torch.zeros_like(ctx.A), torch.zeros_like(ctx.B), None, bias_grad, None
258259

259260
req_gradA, req_gradB, _, req_gradBias, _ = ctx.needs_input_grad
260-
CAt, subA, A = ctx.tensors
261+
CAt, subA, _A = ctx.tensors
261262
SCAt, idx = ctx.tensor_states
262263
state: MatmulLtState = ctx.state
263264
grad_A = grad_B = grad_bias = None

bitsandbytes/backends/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import torch
55

66
try:
7-
import triton # noqa: F401
87
import triton.language as tl # noqa: F401
98

9+
import triton # noqa: F401
10+
1011
triton_available = True
1112
except ImportError:
1213
triton_available = False

bitsandbytes/functional.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import ctypes as ct
77
import itertools
88
from math import prod
9-
from typing import Any, Optional, Union
9+
from typing import Any, Optional
1010

1111
import numpy as np
1212
import torch
@@ -1413,7 +1413,7 @@ def percentile_clipping(grad: Tensor, gnorm_vec: Tensor, step: int, percentile:
14131413
raise ValueError(f"Gradient type {grad.dtype} not supported!")
14141414

14151415
current_gnorm = torch.sqrt(gnorm_vec[step % 100])
1416-
vals, idx = torch.sort(gnorm_vec)
1416+
vals, _ = torch.sort(gnorm_vec)
14171417
clip_value = torch.sqrt(vals[percentile])
14181418
gnorm_scale = 1.0
14191419

@@ -2059,7 +2059,7 @@ def int8_vectorwise_quant(A: torch.Tensor, threshold=0.0):
20592059

20602060

20612061
def spmm_coo(
2062-
cooA: Union[COOSparseTensor, torch.Tensor],
2062+
cooA: COOSparseTensor | torch.Tensor,
20632063
B: torch.Tensor,
20642064
out: Optional[torch.Tensor] = None,
20652065
):

bitsandbytes/nn/modules.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -310,28 +310,28 @@ def _quantize(self, device):
310310
def cpu(self):
311311
return self.to(device="cpu")
312312

313-
def cuda(self, device: Optional[Union[int, device, str]] = None, non_blocking: bool = False):
313+
def cuda(self, device: Optional[int | device | str] = None, non_blocking: bool = False):
314314
return self.to(device="cuda" if device is None else device, non_blocking=non_blocking)
315315

316-
def xpu(self, device: Optional[Union[int, device, str]] = None, non_blocking: bool = False):
316+
def xpu(self, device: Optional[int | device | str] = None, non_blocking: bool = False):
317317
return self.to(device="xpu" if device is None else device, non_blocking=non_blocking)
318318

319319
@overload
320320
def to(
321321
self: T,
322-
device: Optional[Union[int, device]] = ...,
323-
dtype: Optional[Union[dtype, str]] = ...,
322+
device: Optional[int | device] = ...,
323+
dtype: Optional[dtype | str] = ...,
324324
non_blocking: bool = ...,
325325
) -> T: ...
326326

327327
@overload
328-
def to(self: T, dtype: Union[dtype, str], non_blocking: bool = ...) -> T: ...
328+
def to(self: T, dtype: dtype | str, non_blocking: bool = ...) -> T: ...
329329

330330
@overload
331331
def to(self: T, tensor: Tensor, non_blocking: bool = ...) -> T: ...
332332

333333
def to(self, *args, **kwargs):
334-
device, dtype, non_blocking, convert_to_format = torch._C._nn._parse_to(*args, **kwargs)
334+
device, dtype, non_blocking, _ = torch._C._nn._parse_to(*args, **kwargs)
335335

336336
if device is not None and device.type != "meta" and not self.bnb_quantized:
337337
return self._quantize(device)
@@ -644,10 +644,10 @@ def _quantize(self, device):
644644
def cpu(self):
645645
return self.to(device="cpu")
646646

647-
def cuda(self, device: Optional[Union[int, device, str]] = None, non_blocking: bool = False):
647+
def cuda(self, device: Optional[int | device | str] = None, non_blocking: bool = False):
648648
return self.to(device="cuda" if device is None else device, non_blocking=non_blocking)
649649

650-
def xpu(self, device: Optional[Union[int, device, str]] = None, non_blocking: bool = False):
650+
def xpu(self, device: Optional[int | device | str] = None, non_blocking: bool = False):
651651
return self.to(device="xpu" if device is None else device, non_blocking=non_blocking)
652652

653653
def __deepcopy__(self, memo):
@@ -665,19 +665,19 @@ def __deepcopy__(self, memo):
665665
@overload
666666
def to(
667667
self: T,
668-
device: Optional[Union[int, device]] = ...,
669-
dtype: Optional[Union[dtype, str]] = ...,
668+
device: Optional[int | device] = ...,
669+
dtype: Optional[dtype | str] = ...,
670670
non_blocking: bool = ...,
671671
) -> T: ...
672672

673673
@overload
674-
def to(self: T, dtype: Union[dtype, str], non_blocking: bool = ...) -> T: ...
674+
def to(self: T, dtype: dtype | str, non_blocking: bool = ...) -> T: ...
675675

676676
@overload
677677
def to(self: T, tensor: Tensor, non_blocking: bool = ...) -> T: ...
678678

679679
def to(self, *args, **kwargs):
680-
device, dtype, non_blocking, convert_to_format = torch._C._nn._parse_to(*args, **kwargs)
680+
device, dtype, non_blocking, _ = torch._C._nn._parse_to(*args, **kwargs)
681681

682682
is_quantized = self.data.dtype == torch.int8
683683

@@ -1048,7 +1048,7 @@ def to(self, *args, **kwargs):
10481048
# Call the parent to() method to handle standard parameter/buffer movement
10491049
result = super().to(*args, **kwargs)
10501050

1051-
device, dtype, non_blocking, convert_to_format = torch._C._nn._parse_to(*args, **kwargs)
1051+
device, _, _, _ = torch._C._nn._parse_to(*args, **kwargs)
10521052

10531053
# Handle state tensors if needed.
10541054
if device is not None:

bitsandbytes/optim/optimizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def update_step(self, group, p, gindex, pindex):
507507
step = state["step"]
508508

509509
if config["percentile_clipping"] < 100:
510-
current_gnorm, clip_value, gnorm_scale = F.percentile_clipping(
510+
_current_gnorm, _clip_value, gnorm_scale = F.percentile_clipping(
511511
grad,
512512
state["gnorm_vec"],
513513
step,
@@ -725,7 +725,7 @@ def update_step(self, group, p, gindex, pindex):
725725
step = state["step"]
726726

727727
if config["percentile_clipping"] < 100:
728-
current_gnorm, clip_value, gnorm_scale = F.percentile_clipping(
728+
_current_gnorm, _clip_value, gnorm_scale = F.percentile_clipping(
729729
grad,
730730
state["gnorm_vec"],
731731
step,

bitsandbytes/research/autograd/_functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ def backward(ctx, grad_output):
307307
return torch.zeros_like(ctx.A), torch.zeros_like(ctx.B), None, bias_grad, None
308308

309309
req_gradA, req_gradB, _, req_gradBias, _ = ctx.needs_input_grad
310-
CAt, subA, A = ctx.tensors
311-
SCAt, idx = ctx.tensor_states
310+
_CAt, _subA, A = ctx.tensors
311+
_SCAt, _idx = ctx.tensor_states
312312
state = ctx.state
313313
grad_A = grad_B = grad_bias = None
314314

@@ -320,7 +320,7 @@ def backward(ctx, grad_output):
320320
if len(grad_output.shape) == 3:
321321
grad_output = grad_output.reshape(-1, grad_output.shape[-1]).contiguous()
322322

323-
Cgrad, Cgradt, SCgrad, SCgradt, outlier_cols = F.int8_double_quant(grad_output.to(torch.float16))
323+
_Cgrad, _Cgradt, _SCgrad, _SCgradt, _outlier_cols = F.int8_double_quant(grad_output.to(torch.float16))
324324

325325
if req_gradB:
326326
# print('back A shape', A.shape)

0 commit comments

Comments
 (0)