Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/peft/utils/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,23 @@ def dequantize_bnb_weight(weight: torch.nn.Parameter, state=None):
"""Helper function to dequantize 4bit or 8bit bnb weights."""
import bitsandbytes as bnb

if state.SCB is None:
state.SCB = weight.SCB

device = weight.device

cls_name = weight.__class__.__name__
if cls_name == "Params4bit":
dequantized = bnb.functional.dequantize_4bit(weight.data, weight.quant_state)
return dequantized

# 8bit case
if state is None:
raise ValueError(
"No `state` was passed for bnb 8bit quantized weights. Please open an issue on the PEFT repository and "
"report the error: https://github.com/huggingface/peft/issues"
)

if state.SCB is None:
state.SCB = weight.SCB

if hasattr(bnb.functional, "int8_vectorwise_dequant"):
# Use bitsandbytes API if available (requires v0.45.0+)
dequantized = bnb.functional.int8_vectorwise_dequant(weight.data, state.SCB)
Expand Down
Loading