Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
5e5c4d62
Unverified
Commit
5e5c4d62
authored
May 30, 2024
by
Younes Belkada
Committed by
GitHub
May 30, 2024
Browse files
FIX / Quantization: Add extra validation for bnb config (#31135)
add validation for bnb config
parent
2b9e252b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
0 deletions
+11
-0
src/transformers/utils/quantization_config.py
src/transformers/utils/quantization_config.py
+4
-0
tests/quantization/bnb/test_4bit.py
tests/quantization/bnb/test_4bit.py
+7
-0
No files found.
src/transformers/utils/quantization_config.py
View file @
5e5c4d62
...
...
@@ -383,6 +383,10 @@ class BitsAndBytesConfig(QuantizationConfigMixin):
if
bnb_4bit_quant_storage
is
None
:
self
.
bnb_4bit_quant_storage
=
torch
.
uint8
elif
isinstance
(
bnb_4bit_quant_storage
,
str
):
if
bnb_4bit_quant_storage
not
in
[
"float16"
,
"float32"
,
"int8"
,
"uint8"
,
"float64"
,
"bfloat16"
]:
raise
ValueError
(
"`bnb_4bit_quant_storage` must be a valid string (one of 'float16', 'float32', 'int8', 'uint8', 'float64', 'bfloat16') "
)
self
.
bnb_4bit_quant_storage
=
getattr
(
torch
,
bnb_4bit_quant_storage
)
elif
isinstance
(
bnb_4bit_quant_storage
,
torch
.
dtype
):
self
.
bnb_4bit_quant_storage
=
bnb_4bit_quant_storage
...
...
tests/quantization/bnb/test_4bit.py
View file @
5e5c4d62
...
...
@@ -303,6 +303,13 @@ class Bnb4BitTest(Base4bitTest):
model
=
AutoModelForSeq2SeqLM
.
from_pretrained
(
"google-t5/t5-small"
,
load_in_4bit
=
True
,
device_map
=
"auto"
)
self
.
assertTrue
(
model
.
decoder
.
block
[
0
].
layer
[
2
].
DenseReluDense
.
wo
.
weight
.
dtype
==
torch
.
float32
)
def
test_bnb_4bit_wrong_config
(
self
):
r
"""
Test whether creating a bnb config with unsupported values leads to errors.
"""
with
self
.
assertRaises
(
ValueError
):
_
=
BitsAndBytesConfig
(
load_in_4bit
=
True
,
bnb_4bit_quant_storage
=
"add"
)
@
require_bitsandbytes
@
require_accelerate
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment