From 0e8e5359fb67243f7e531ead04f48c60a7306f39 Mon Sep 17 00:00:00 2001 From: "Yao, Matrix" Date: Thu, 25 Sep 2025 22:05:00 +0000 Subject: [PATCH 1/3] fix peft cpu ut failure Signed-off-by: Yao, Matrix --- bitsandbytes/nn/modules.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bitsandbytes/nn/modules.py b/bitsandbytes/nn/modules.py index 1adf75e79..bfd12d15e 100644 --- a/bitsandbytes/nn/modules.py +++ b/bitsandbytes/nn/modules.py @@ -679,6 +679,7 @@ def to(self: T, tensor: Tensor, non_blocking: bool = ...) -> T: ... def to(self, *args, **kwargs): device, dtype, non_blocking, convert_to_format = torch._C._nn._parse_to(*args, **kwargs) + if device is not None and device.type != "meta" and self.data.device.type == "cpu": if device.type != "cpu" or self.data.dtype != torch.int8: return self._quantize(device) @@ -690,8 +691,8 @@ def to(self, *args, **kwargs): requires_grad=self.requires_grad, has_fp16_weights=self.has_fp16_weights, ) - new_param.CB = self.CB - new_param.SCB = self.SCB + new_param.CB = self.CB.to(device=device) if self.CB != None else self.CB + new_param.SCB = self.SCB.to(device=device) if self.SCB != None else self.SCB return new_param From 9ff90e11e29e827b1a0f7be5bef6bc97412c2ce7 Mon Sep 17 00:00:00 2001 From: Yao Matrix Date: Fri, 26 Sep 2025 08:26:36 -0700 Subject: [PATCH 2/3] Update modules.py --- bitsandbytes/nn/modules.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bitsandbytes/nn/modules.py b/bitsandbytes/nn/modules.py index bfd12d15e..67efcde2c 100644 --- a/bitsandbytes/nn/modules.py +++ b/bitsandbytes/nn/modules.py @@ -679,7 +679,6 @@ def to(self: T, tensor: Tensor, non_blocking: bool = ...) -> T: ... def to(self, *args, **kwargs): device, dtype, non_blocking, convert_to_format = torch._C._nn._parse_to(*args, **kwargs) - if device is not None and device.type != "meta" and self.data.device.type == "cpu": if device.type != "cpu" or self.data.dtype != torch.int8: return self._quantize(device) From 052fed064a437a959f93f3aa7c5cf30d5c5c69b5 Mon Sep 17 00:00:00 2001 From: "Yao, Matrix" Date: Mon, 29 Sep 2025 16:07:47 +0000 Subject: [PATCH 3/3] fix ruff Signed-off-by: Yao, Matrix --- bitsandbytes/nn/modules.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bitsandbytes/nn/modules.py b/bitsandbytes/nn/modules.py index 67efcde2c..835e002ed 100644 --- a/bitsandbytes/nn/modules.py +++ b/bitsandbytes/nn/modules.py @@ -690,8 +690,8 @@ def to(self, *args, **kwargs): requires_grad=self.requires_grad, has_fp16_weights=self.has_fp16_weights, ) - new_param.CB = self.CB.to(device=device) if self.CB != None else self.CB - new_param.SCB = self.SCB.to(device=device) if self.SCB != None else self.SCB + new_param.CB = self.CB.to(device=device) if self.CB is not None else self.CB + new_param.SCB = self.SCB.to(device=device) if self.SCB is not None else self.SCB return new_param