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
1872bde7
Unverified
Commit
1872bde7
authored
May 08, 2024
by
NielsRogge
Committed by
GitHub
May 08, 2024
Browse files
[BitsandBytes] Verify if GPU is available (#30533)
Change order
parent
998dbe06
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
6 deletions
+5
-6
src/transformers/quantizers/quantizer_bnb_4bit.py
src/transformers/quantizers/quantizer_bnb_4bit.py
+2
-3
src/transformers/quantizers/quantizer_bnb_8bit.py
src/transformers/quantizers/quantizer_bnb_8bit.py
+3
-3
No files found.
src/transformers/quantizers/quantizer_bnb_4bit.py
View file @
1872bde7
...
@@ -58,6 +58,8 @@ class Bnb4BitHfQuantizer(HfQuantizer):
...
@@ -58,6 +58,8 @@ class Bnb4BitHfQuantizer(HfQuantizer):
self
.
modules_to_not_convert
=
self
.
quantization_config
.
llm_int8_skip_modules
self
.
modules_to_not_convert
=
self
.
quantization_config
.
llm_int8_skip_modules
def
validate_environment
(
self
,
*
args
,
**
kwargs
):
def
validate_environment
(
self
,
*
args
,
**
kwargs
):
if
not
torch
.
cuda
.
is_available
():
raise
RuntimeError
(
"No GPU found. A GPU is needed for quantization."
)
if
not
(
is_accelerate_available
()
and
is_bitsandbytes_available
()):
if
not
(
is_accelerate_available
()
and
is_bitsandbytes_available
()):
raise
ImportError
(
raise
ImportError
(
"Using `bitsandbytes` 8-bit quantization requires Accelerate: `pip install accelerate` "
"Using `bitsandbytes` 8-bit quantization requires Accelerate: `pip install accelerate` "
...
@@ -70,9 +72,6 @@ class Bnb4BitHfQuantizer(HfQuantizer):
...
@@ -70,9 +72,6 @@ class Bnb4BitHfQuantizer(HfQuantizer):
" sure the weights are in PyTorch format."
" sure the weights are in PyTorch format."
)
)
if
not
torch
.
cuda
.
is_available
():
raise
RuntimeError
(
"No GPU found. A GPU is needed for quantization."
)
device_map
=
kwargs
.
get
(
"device_map"
,
None
)
device_map
=
kwargs
.
get
(
"device_map"
,
None
)
if
(
if
(
device_map
is
not
None
device_map
is
not
None
...
...
src/transformers/quantizers/quantizer_bnb_8bit.py
View file @
1872bde7
...
@@ -58,6 +58,9 @@ class Bnb8BitHfQuantizer(HfQuantizer):
...
@@ -58,6 +58,9 @@ class Bnb8BitHfQuantizer(HfQuantizer):
self
.
modules_to_not_convert
=
self
.
quantization_config
.
llm_int8_skip_modules
self
.
modules_to_not_convert
=
self
.
quantization_config
.
llm_int8_skip_modules
def
validate_environment
(
self
,
*
args
,
**
kwargs
):
def
validate_environment
(
self
,
*
args
,
**
kwargs
):
if
not
torch
.
cuda
.
is_available
():
raise
RuntimeError
(
"No GPU found. A GPU is needed for quantization."
)
if
not
(
is_accelerate_available
()
and
is_bitsandbytes_available
()):
if
not
(
is_accelerate_available
()
and
is_bitsandbytes_available
()):
raise
ImportError
(
raise
ImportError
(
"Using `bitsandbytes` 8-bit quantization requires Accelerate: `pip install accelerate` "
"Using `bitsandbytes` 8-bit quantization requires Accelerate: `pip install accelerate` "
...
@@ -70,9 +73,6 @@ class Bnb8BitHfQuantizer(HfQuantizer):
...
@@ -70,9 +73,6 @@ class Bnb8BitHfQuantizer(HfQuantizer):
" sure the weights are in PyTorch format."
" sure the weights are in PyTorch format."
)
)
if
not
torch
.
cuda
.
is_available
():
raise
RuntimeError
(
"No GPU found. A GPU is needed for quantization."
)
device_map
=
kwargs
.
get
(
"device_map"
,
None
)
device_map
=
kwargs
.
get
(
"device_map"
,
None
)
if
(
if
(
device_map
is
not
None
device_map
is
not
None
...
...
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