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
b4ce313e
Unverified
Commit
b4ce313e
authored
Jan 21, 2022
by
lewtun
Committed by
GitHub
Jan 21, 2022
Browse files
Prepare ONNX export for torch v1.11 (#15270)
* Prepare ONNX export for torch v1.11
parent
126bddd1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
13 deletions
+28
-13
src/transformers/onnx/convert.py
src/transformers/onnx/convert.py
+28
-13
No files found.
src/transformers/onnx/convert.py
View file @
b4ce313e
...
@@ -112,19 +112,34 @@ def export(
...
@@ -112,19 +112,34 @@ def export(
config
.
patch_ops
()
config
.
patch_ops
()
# export can works with named args but the dict containing named args as to be last element of the args tuple
# PyTorch deprecated the `enable_onnx_checker` and `use_external_data_format` arguments in v1.11,
export
(
# so we check the torch version for backwards compatibility
model
,
if
parse
(
torch
.
__version__
)
<=
parse
(
"1.10.99"
):
(
model_inputs
,),
# export can work with named args but the dict containing named args
f
=
output
.
as_posix
(),
# has to be the last element of the args tuple.
input_names
=
list
(
config
.
inputs
.
keys
()),
export
(
output_names
=
onnx_outputs
,
model
,
dynamic_axes
=
{
name
:
axes
for
name
,
axes
in
chain
(
config
.
inputs
.
items
(),
config
.
outputs
.
items
())},
(
model_inputs
,),
do_constant_folding
=
True
,
f
=
output
.
as_posix
(),
use_external_data_format
=
config
.
use_external_data_format
(
model
.
num_parameters
()),
input_names
=
list
(
config
.
inputs
.
keys
()),
enable_onnx_checker
=
True
,
output_names
=
onnx_outputs
,
opset_version
=
opset
,
dynamic_axes
=
{
name
:
axes
for
name
,
axes
in
chain
(
config
.
inputs
.
items
(),
config
.
outputs
.
items
())},
)
do_constant_folding
=
True
,
use_external_data_format
=
config
.
use_external_data_format
(
model
.
num_parameters
()),
enable_onnx_checker
=
True
,
opset_version
=
opset
,
)
else
:
export
(
model
,
(
model_inputs
,),
f
=
output
.
as_posix
(),
input_names
=
list
(
config
.
inputs
.
keys
()),
output_names
=
onnx_outputs
,
dynamic_axes
=
{
name
:
axes
for
name
,
axes
in
chain
(
config
.
inputs
.
items
(),
config
.
outputs
.
items
())},
do_constant_folding
=
True
,
opset_version
=
opset
,
)
config
.
restore_ops
()
config
.
restore_ops
()
...
...
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