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
28e64ad5
Commit
28e64ad5
authored
Dec 13, 2019
by
Morgan Funtowicz
Browse files
Raise an exception if the pipeline allocator can't determine the tokenizer from the model.
parent
be5bf7b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
+6
-5
transformers/pipelines.py
transformers/pipelines.py
+6
-5
No files found.
transformers/pipelines.py
View file @
28e64ad5
...
@@ -370,11 +370,12 @@ def pipeline(task: str, model, config: Optional[PretrainedConfig] = None, tokeni
...
@@ -370,11 +370,12 @@ def pipeline(task: str, model, config: Optional[PretrainedConfig] = None, tokeni
Utility factory method to build pipeline.
Utility factory method to build pipeline.
"""
"""
# Try to infer tokenizer from model name (if provided as str)
# Try to infer tokenizer from model name (if provided as str)
if
tokenizer
is
None
and
isinstance
(
model
,
str
):
if
not
isinstance
(
tokenizer
,
PreTrainedTokenizer
):
tokenizer
=
model
if
not
isinstance
(
model
,
str
):
else
:
# Impossible to guest what is the right tokenizer here
# Impossible to guest what is the right tokenizer here
raise
Exception
(
'Tokenizer cannot be None if provided model is a PreTrainedModel instance'
)
raise
Exception
(
'Tokenizer cannot be None if provided model is a PreTrainedModel instance'
)
else
:
tokenizer
=
model
tokenizer
=
tokenizer
if
isinstance
(
tokenizer
,
PreTrainedTokenizer
)
else
AutoTokenizer
.
from_pretrained
(
tokenizer
)
tokenizer
=
tokenizer
if
isinstance
(
tokenizer
,
PreTrainedTokenizer
)
else
AutoTokenizer
.
from_pretrained
(
tokenizer
)
...
...
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