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
abd4cbd7
Unverified
Commit
abd4cbd7
authored
Dec 01, 2023
by
Marc Sun
Committed by
GitHub
Dec 01, 2023
Browse files
Better error message for bitsandbytes import (#27764)
* better error message * fix logic * fix log
parent
7b6324e1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
6 deletions
+5
-6
src/transformers/modeling_utils.py
src/transformers/modeling_utils.py
+5
-6
No files found.
src/transformers/modeling_utils.py
View file @
abd4cbd7
...
...
@@ -1010,7 +1010,7 @@ class ModuleUtilsMixin:
else
:
raise
ValueError
(
"bitsandbytes is not installed but it seems that the model has been loaded in 4bit precision, something went wrong"
" make sure to install bitsandbytes with `pip install bitsandbytes`."
" make sure to install bitsandbytes with `pip install bitsandbytes`.
You also need a GPU.
"
)
for
param
in
total_parameters
:
...
...
@@ -2746,11 +2746,13 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix
)
if
load_in_8bit
or
load_in_4bit
:
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
()):
raise
ImportError
(
"Using `load_in_8bit=True` requires Accelerate: `pip install accelerate` and the latest version of"
" bitsandbytes `pip install -i https://test.pypi.org/simple/ bitsandbytes` or"
" pip install bitsandbytes`
"
"
`
pip install bitsandbytes`
.
"
)
if
torch_dtype
is
None
:
...
...
@@ -2764,10 +2766,7 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix
torch_dtype
=
torch
.
float16
if
device_map
is
None
:
if
torch
.
cuda
.
is_available
():
device_map
=
{
""
:
torch
.
cuda
.
current_device
()}
else
:
raise
RuntimeError
(
"No GPU found. A GPU is needed for quantization."
)
logger
.
info
(
"The device_map was not initialized. "
"Setting device_map to {'':torch.cuda.current_device()}. "
...
...
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