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
42ad693b
Unverified
Commit
42ad693b
authored
Mar 15, 2023
by
Sylvain Gugger
Committed by
GitHub
Mar 15, 2023
Browse files
Regression pipeline device (#22190)
* Fix regression in pipeline when device=-1 is passed * Add regression test
parent
73768147
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
2 deletions
+10
-2
src/transformers/pipelines/base.py
src/transformers/pipelines/base.py
+2
-2
tests/pipelines/test_pipelines_common.py
tests/pipelines/test_pipelines_common.py
+8
-0
No files found.
src/transformers/pipelines/base.py
View file @
42ad693b
...
@@ -769,8 +769,8 @@ class Pipeline(_ScikitCompat):
...
@@ -769,8 +769,8 @@ class Pipeline(_ScikitCompat):
self
.
modelcard
=
modelcard
self
.
modelcard
=
modelcard
self
.
framework
=
framework
self
.
framework
=
framework
if
self
.
framework
==
"pt"
and
device
is
not
None
:
if
self
.
framework
==
"pt"
and
device
is
not
None
and
not
(
isinstance
(
device
,
int
)
and
device
<
0
)
:
self
.
model
=
self
.
model
.
to
(
device
=
device
)
self
.
model
.
to
(
device
)
if
device
is
None
:
if
device
is
None
:
# `accelerate` device map
# `accelerate` device map
...
...
tests/pipelines/test_pipelines_common.py
View file @
42ad693b
...
@@ -484,6 +484,14 @@ class PipelineUtilsTest(unittest.TestCase):
...
@@ -484,6 +484,14 @@ class PipelineUtilsTest(unittest.TestCase):
outputs
=
list
(
dataset
)
outputs
=
list
(
dataset
)
self
.
assertEqual
(
outputs
,
[[{
"id"
:
2
},
{
"id"
:
3
},
{
"id"
:
4
},
{
"id"
:
5
}]])
self
.
assertEqual
(
outputs
,
[[{
"id"
:
2
},
{
"id"
:
3
},
{
"id"
:
4
},
{
"id"
:
5
}]])
def
test_pipeline_negative_device
(
self
):
# To avoid regressing, pipeline used to accept device=-1
classifier
=
pipeline
(
"text-generation"
,
"hf-internal-testing/tiny-random-bert"
,
device
=-
1
)
expected_output
=
[{
"generated_text"
:
ANY
(
str
)}]
actual_output
=
classifier
(
"Test input."
)
self
.
assertEqual
(
expected_output
,
actual_output
)
@
slow
@
slow
@
require_torch
@
require_torch
def
test_load_default_pipelines_pt
(
self
):
def
test_load_default_pipelines_pt
(
self
):
...
...
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