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
2a787201
Unverified
Commit
2a787201
authored
Jul 28, 2023
by
YQ
Committed by
GitHub
Jul 28, 2023
Browse files
override .cuda() to check if model is already quantized (#25166)
parent
c1dba111
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
0 deletions
+10
-0
src/transformers/modeling_utils.py
src/transformers/modeling_utils.py
+10
-0
No files found.
src/transformers/modeling_utils.py
View file @
2a787201
...
...
@@ -1912,6 +1912,16 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix
mem
=
mem
+
mem_bufs
return
mem
def
cuda
(
self
,
*
args
,
**
kwargs
):
# Checks if the model has been loaded in 8-bit
if
getattr
(
self
,
"is_quantized"
,
False
):
raise
ValueError
(
"Calling `cuda()` is not supported for `4-bit` or `8-bit` quantized models. Please use the model as it is, since the"
" model has already been set to the correct devices and casted to the correct `dtype`."
)
else
:
return
super
().
cuda
(
*
args
,
**
kwargs
)
def
to
(
self
,
*
args
,
**
kwargs
):
# Checks if the model has been loaded in 8-bit
if
getattr
(
self
,
"is_quantized"
,
False
):
...
...
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