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
1ca52567
Commit
1ca52567
authored
Dec 13, 2019
by
Morgan Funtowicz
Browse files
Allow model conversion in the pipeline allocator.
parent
28e64ad5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
1 deletion
+13
-1
transformers/pipelines.py
transformers/pipelines.py
+13
-1
No files found.
transformers/pipelines.py
View file @
1ca52567
...
...
@@ -385,5 +385,17 @@ def pipeline(task: str, model, config: Optional[PretrainedConfig] = None, tokeni
targeted_task
=
SUPPORTED_TASKS
[
task
]
task
,
allocator
=
targeted_task
[
'impl'
],
targeted_task
[
'tf'
]
if
is_tf_available
()
else
targeted_task
[
'pt'
]
model
=
allocator
.
from_pretrained
(
model
)
# Special handling for model conversion
from_tf
=
model
.
endswith
(
'.h5'
)
and
not
is_tf_available
()
from_pt
=
model
.
endswith
(
'.bin'
)
and
not
is_torch_available
()
if
from_tf
:
logger
.
warning
(
'Model might be a TensorFlow model (ending with `.h5`) but TensorFlow is not available. Trying to load the model with PyTorch.'
)
elif
from_pt
:
logger
.
warning
(
'Model might be a PyTorch model (ending with `.bin`) but PyTorch is not available. Trying to load the model with Tensorflow.'
)
if
allocator
.
__name__
.
startswith
(
'TF'
):
model
=
allocator
.
from_pretrained
(
model
,
config
=
config
,
from_pt
=
from_pt
)
else
:
model
=
allocator
.
from_pretrained
(
model
,
config
=
config
,
from_tf
=
from_tf
)
return
task
(
model
,
tokenizer
,
**
kwargs
)
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