-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug with some LoRA variants when applied to a BnB NF4 quantized m…
…odel. Note the previous commit which added a unit test to trigger this bug.
- Loading branch information
1 parent
7724bd5
commit fa7c36a
Showing
2 changed files
with
22 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import torch | ||
|
||
try: | ||
from bitsandbytes.nn.modules import Params4bit | ||
|
||
bnb_available: bool = True | ||
except ImportError: | ||
bnb_available: bool = False | ||
|
||
|
||
def get_param_shape(param: torch.Tensor) -> torch.Size: | ||
"""A helper function to get the shape of a parameter that handles `bitsandbytes.nn.Params4Bit` correctly.""" | ||
# Accessing the `.shape` attribute of `bitsandbytes.nn.Params4Bit` will return an incorrect result. Instead, we must | ||
# access the `.quant_state.shape` attribute. | ||
if bnb_available and type(param) is Params4bit: # type: ignore | ||
quant_state = param.quant_state | ||
if quant_state is not None: | ||
return quant_state.shape | ||
return param.shape |