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
8c14b342
Unverified
Commit
8c14b342
authored
Jul 18, 2022
by
gcheron
Committed by
GitHub
Jul 18, 2022
Browse files
add ONNX support for LeVit (#18154)
Co-authored-by:
Guilhem Chéron
<
guilhemc@authentifier.com
>
parent
c1c79b06
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
2 deletions
+31
-2
docs/source/en/serialization.mdx
docs/source/en/serialization.mdx
+1
-0
src/transformers/models/levit/__init__.py
src/transformers/models/levit/__init__.py
+2
-2
src/transformers/models/levit/configuration_levit.py
src/transformers/models/levit/configuration_levit.py
+24
-0
src/transformers/onnx/features.py
src/transformers/onnx/features.py
+3
-0
tests/onnx/test_onnx_v2.py
tests/onnx/test_onnx_v2.py
+1
-0
No files found.
docs/source/en/serialization.mdx
View file @
8c14b342
...
...
@@ -72,6 +72,7 @@ Ready-made configurations include the following architectures:
- I-BERT
- LayoutLM
- LayoutLMv3
- LeViT
- LongT5
- M2M100
- Marian
...
...
src/transformers/models/levit/__init__.py
View file @
8c14b342
...
...
@@ -20,7 +20,7 @@ from typing import TYPE_CHECKING
from
...utils
import
OptionalDependencyNotAvailable
,
_LazyModule
,
is_torch_available
,
is_vision_available
_import_structure
=
{
"configuration_levit"
:
[
"LEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP"
,
"LevitConfig"
]}
_import_structure
=
{
"configuration_levit"
:
[
"LEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP"
,
"LevitConfig"
,
"LevitOnnxConfig"
]}
try
:
if
not
is_vision_available
():
...
...
@@ -46,7 +46,7 @@ else:
if
TYPE_CHECKING
:
from
.configuration_levit
import
LEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP
,
LevitConfig
from
.configuration_levit
import
LEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP
,
LevitConfig
,
LevitOnnxConfig
try
:
if
not
is_vision_available
():
...
...
src/transformers/models/levit/configuration_levit.py
View file @
8c14b342
...
...
@@ -14,7 +14,13 @@
# limitations under the License.
""" LeViT model configuration"""
from
collections
import
OrderedDict
from
typing
import
Mapping
from
packaging
import
version
from
...configuration_utils
import
PretrainedConfig
from
...onnx
import
OnnxConfig
from
...utils
import
logging
...
...
@@ -120,3 +126,21 @@ class LevitConfig(PretrainedConfig):
[
"Subsample"
,
key_dim
[
0
],
hidden_sizes
[
0
]
//
key_dim
[
0
],
4
,
2
,
2
],
[
"Subsample"
,
key_dim
[
0
],
hidden_sizes
[
1
]
//
key_dim
[
0
],
4
,
2
,
2
],
]
# Copied from transformers.models.vit.configuration_vit.ViTOnnxConfig
class
LevitOnnxConfig
(
OnnxConfig
):
torch_onnx_minimum_version
=
version
.
parse
(
"1.11"
)
@
property
def
inputs
(
self
)
->
Mapping
[
str
,
Mapping
[
int
,
str
]]:
return
OrderedDict
(
[
(
"pixel_values"
,
{
0
:
"batch"
,
1
:
"sequence"
}),
]
)
@
property
def
atol_for_validation
(
self
)
->
float
:
return
1e-4
src/transformers/onnx/features.py
View file @
8c14b342
...
...
@@ -333,6 +333,9 @@ class FeaturesManager:
"token-classification"
,
onnx_config_cls
=
"models.layoutlmv3.LayoutLMv3OnnxConfig"
,
),
"levit"
:
supported_features_mapping
(
"default"
,
"image-classification"
,
onnx_config_cls
=
"models.levit.LevitOnnxConfig"
),
"longt5"
:
supported_features_mapping
(
"default"
,
"default-with-past"
,
...
...
tests/onnx/test_onnx_v2.py
View file @
8c14b342
...
...
@@ -196,6 +196,7 @@ PYTORCH_EXPORT_MODELS = {
(
"xlm-roberta"
,
"xlm-roberta-base"
),
(
"layoutlm"
,
"microsoft/layoutlm-base-uncased"
),
(
"layoutlmv3"
,
"microsoft/layoutlmv3-base"
),
(
"levit"
,
"facebook/levit-128S"
),
(
"vit"
,
"google/vit-base-patch16-224"
),
(
"deit"
,
"facebook/deit-small-patch16-224"
),
(
"beit"
,
"microsoft/beit-base-patch16-224"
),
...
...
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