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
7b685f52
Unverified
Commit
7b685f52
authored
Jun 15, 2020
by
Funtowicz Morgan
Committed by
GitHub
Jun 15, 2020
Browse files
Increase pipeline support for ONNX export. (#5005)
* Increase pipeline support for ONNX export. * Style.
parent
1affde2f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
1 deletion
+15
-1
src/transformers/convert_graph_to_onnx.py
src/transformers/convert_graph_to_onnx.py
+15
-1
No files found.
src/transformers/convert_graph_to_onnx.py
View file @
7b685f52
...
@@ -8,6 +8,19 @@ from transformers.pipelines import Pipeline, pipeline
...
@@ -8,6 +8,19 @@ from transformers.pipelines import Pipeline, pipeline
from
transformers.tokenization_utils
import
BatchEncoding
from
transformers.tokenization_utils
import
BatchEncoding
SUPPORTED_PIPELINES
=
[
"feature-extraction"
,
"ner"
,
"sentiment-analysis"
,
"fill-mask"
,
"question-answering"
,
"text-generation"
,
"translation_en_to_fr"
,
"translation_en_to_de"
,
"translation_en_to_ro"
,
]
class
OnnxConverterArgumentParser
(
ArgumentParser
):
class
OnnxConverterArgumentParser
(
ArgumentParser
):
"""
"""
Wraps all the script arguments supported to export transformers models to ONNX IR
Wraps all the script arguments supported to export transformers models to ONNX IR
...
@@ -16,6 +29,7 @@ class OnnxConverterArgumentParser(ArgumentParser):
...
@@ -16,6 +29,7 @@ class OnnxConverterArgumentParser(ArgumentParser):
def
__init__
(
self
):
def
__init__
(
self
):
super
(
OnnxConverterArgumentParser
,
self
).
__init__
(
"ONNX Converter"
)
super
(
OnnxConverterArgumentParser
,
self
).
__init__
(
"ONNX Converter"
)
self
.
add_argument
(
"--pipeline"
,
type
=
str
,
choices
=
SUPPORTED_PIPELINES
,
default
=
"feature-extraction"
)
self
.
add_argument
(
"--model"
,
type
=
str
,
required
=
True
,
help
=
"Model's id or path (ex: bert-base-cased)"
)
self
.
add_argument
(
"--model"
,
type
=
str
,
required
=
True
,
help
=
"Model's id or path (ex: bert-base-cased)"
)
self
.
add_argument
(
"--tokenizer"
,
type
=
str
,
help
=
"Tokenizer's id or path (ex: bert-base-cased)"
)
self
.
add_argument
(
"--tokenizer"
,
type
=
str
,
help
=
"Tokenizer's id or path (ex: bert-base-cased)"
)
self
.
add_argument
(
"--framework"
,
type
=
str
,
choices
=
[
"pt"
,
"tf"
],
help
=
"Framework for loading the model"
)
self
.
add_argument
(
"--framework"
,
type
=
str
,
choices
=
[
"pt"
,
"tf"
],
help
=
"Framework for loading the model"
)
...
@@ -108,7 +122,7 @@ def load_graph_from_args(framework: str, model: str, tokenizer: Optional[str] =
...
@@ -108,7 +122,7 @@ def load_graph_from_args(framework: str, model: str, tokenizer: Optional[str] =
print
(
"Loading pipeline (model: {}, tokenizer: {})"
.
format
(
model
,
tokenizer
))
print
(
"Loading pipeline (model: {}, tokenizer: {})"
.
format
(
model
,
tokenizer
))
# Allocate tokenizer and model
# Allocate tokenizer and model
return
pipeline
(
"feature-extraction"
,
model
=
model
,
tokenizer
=
tokenizer
,
framework
=
framework
)
return
pipeline
(
args
.
pipeline
,
model
=
model
,
tokenizer
=
tokenizer
,
framework
=
framework
)
def
convert_pytorch
(
nlp
:
Pipeline
,
opset
:
int
,
output
:
str
,
use_external_format
:
bool
):
def
convert_pytorch
(
nlp
:
Pipeline
,
opset
:
int
,
output
:
str
,
use_external_format
:
bool
):
...
...
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