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
e0c50b27
Unverified
Commit
e0c50b27
authored
Jul 31, 2023
by
Younes Belkada
Committed by
GitHub
Jul 31, 2023
Browse files
[`pipeline`] revisit device check for pipeline (#25207)
* revisit device check for pipeline * let's raise an error.
parent
52206066
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
2 deletions
+10
-2
src/transformers/pipelines/base.py
src/transformers/pipelines/base.py
+10
-2
No files found.
src/transformers/pipelines/base.py
View file @
e0c50b27
...
...
@@ -775,12 +775,20 @@ class Pipeline(_ScikitCompat):
self
.
modelcard
=
modelcard
self
.
framework
=
framework
# `accelerate` device map
hf_device_map
=
getattr
(
self
.
model
,
"hf_device_map"
,
None
)
if
hf_device_map
is
not
None
and
device
is
not
None
:
raise
ValueError
(
"The model has been loaded with `accelerate` and therefore cannot be moved to a specific device. Please "
"discard the `device` argument when creating your pipeline object."
)
# We shouldn't call `model.to()` for models loaded with accelerate
if
self
.
framework
==
"pt"
and
device
is
not
None
and
not
(
isinstance
(
device
,
int
)
and
device
<
0
):
self
.
model
.
to
(
device
)
if
device
is
None
:
# `accelerate` device map
hf_device_map
=
getattr
(
self
.
model
,
"hf_device_map"
,
None
)
if
hf_device_map
is
not
None
:
# Take the first device used by `accelerate`.
device
=
next
(
iter
(
hf_device_map
.
values
()))
...
...
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