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
cfaeb153
Unverified
Commit
cfaeb153
authored
Nov 08, 2022
by
TAGAMI Yukihiro
Committed by
GitHub
Nov 07, 2022
Browse files
use huggingface_hub.model_inifo() to get pipline_tag (#20077)
parent
3222fc64
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
14 deletions
+6
-14
src/transformers/pipelines/__init__.py
src/transformers/pipelines/__init__.py
+6
-14
No files found.
src/transformers/pipelines/__init__.py
View file @
cfaeb153
...
@@ -26,7 +26,7 @@ from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union
...
@@ -26,7 +26,7 @@ from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union
from
numpy
import
isin
from
numpy
import
isin
from
huggingface_hub
.file_download
import
http_get
from
huggingface_hub
import
model_info
from
..configuration_utils
import
PretrainedConfig
from
..configuration_utils
import
PretrainedConfig
from
..dynamic_module_utils
import
get_class_from_dynamic_module
from
..dynamic_module_utils
import
get_class_from_dynamic_module
...
@@ -389,25 +389,17 @@ def get_supported_tasks() -> List[str]:
...
@@ -389,25 +389,17 @@ def get_supported_tasks() -> List[str]:
def
get_task
(
model
:
str
,
use_auth_token
:
Optional
[
str
]
=
None
)
->
str
:
def
get_task
(
model
:
str
,
use_auth_token
:
Optional
[
str
]
=
None
)
->
str
:
tmp
=
io
.
BytesIO
()
headers
=
{}
if
use_auth_token
:
headers
[
"Authorization"
]
=
f
"Bearer
{
use_auth_token
}
"
try
:
try
:
http_get
(
f
"https://huggingface.co/api/models/
{
model
}
"
,
tmp
,
headers
=
headers
)
info
=
model_info
(
model
,
token
=
use_auth_token
)
tmp
.
seek
(
0
)
body
=
tmp
.
read
()
data
=
json
.
loads
(
body
)
except
Exception
as
e
:
except
Exception
as
e
:
raise
RuntimeError
(
f
"Instantiating a pipeline without a task set raised an error:
{
e
}
"
)
raise
RuntimeError
(
f
"Instantiating a pipeline without a task set raised an error:
{
e
}
"
)
if
"
pipeline_tag
"
not
in
data
:
if
not
info
.
pipeline_tag
:
raise
RuntimeError
(
raise
RuntimeError
(
f
"The model
{
model
}
does not seem to have a correct `pipeline_tag` set to infer the task automatically"
f
"The model
{
model
}
does not seem to have a correct `pipeline_tag` set to infer the task automatically"
)
)
if
data
.
get
(
"library_name"
,
"transformers"
)
!=
"transformers"
:
if
getattr
(
info
,
"library_name"
,
"transformers"
)
!=
"transformers"
:
raise
RuntimeError
(
f
"This model is meant to be used with
{
data
[
'
library_name
'
]
}
not with transformers"
)
raise
RuntimeError
(
f
"This model is meant to be used with
{
info
.
library_name
}
not with transformers"
)
task
=
data
[
"
pipeline_tag
"
]
task
=
info
.
pipeline_tag
return
task
return
task
...
...
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