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
15bc776f
Unverified
Commit
15bc776f
authored
Dec 23, 2022
by
Syed Abdul Gaffar Shakhadri
Committed by
GitHub
Dec 23, 2022
Browse files
Add Onnx Config for PoolFormer (#20868)
poolformer onnx Co-authored-by:
syed
<
syed.abdul@sandlogic.com
>
parent
4a4cd6cd
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
2 deletions
+39
-2
docs/source/en/serialization.mdx
docs/source/en/serialization.mdx
+1
-0
src/transformers/models/poolformer/__init__.py
src/transformers/models/poolformer/__init__.py
+12
-2
src/transformers/models/poolformer/configuration_poolformer.py
...ransformers/models/poolformer/configuration_poolformer.py
+22
-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 @
15bc776f
...
...
@@ -102,6 +102,7 @@ Ready-made configurations include the following architectures:
- OWL-ViT
- Perceiver
- PLBart
- PoolFormer
- RemBERT
- ResNet
- RoBERTa
...
...
src/transformers/models/poolformer/__init__.py
View file @
15bc776f
...
...
@@ -21,7 +21,13 @@ from typing import TYPE_CHECKING
from
...utils
import
OptionalDependencyNotAvailable
,
_LazyModule
,
is_torch_available
,
is_vision_available
_import_structure
=
{
"configuration_poolformer"
:
[
"POOLFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"
,
"PoolFormerConfig"
]}
_import_structure
=
{
"configuration_poolformer"
:
[
"POOLFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"
,
"PoolFormerConfig"
,
"PoolFormerOnnxConfig"
,
]
}
try
:
if
not
is_vision_available
():
...
...
@@ -47,7 +53,11 @@ else:
if
TYPE_CHECKING
:
from
.configuration_poolformer
import
POOLFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP
,
PoolFormerConfig
from
.configuration_poolformer
import
(
POOLFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP
,
PoolFormerConfig
,
PoolFormerOnnxConfig
,
)
try
:
if
not
is_vision_available
():
...
...
src/transformers/models/poolformer/configuration_poolformer.py
View file @
15bc776f
...
...
@@ -13,8 +13,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
""" PoolFormer 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
...
...
@@ -125,3 +130,20 @@ class PoolFormerConfig(PretrainedConfig):
self
.
layer_scale_init_value
=
layer_scale_init_value
self
.
initializer_range
=
initializer_range
super
().
__init__
(
**
kwargs
)
class
PoolFormerOnnxConfig
(
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
:
"num_channels"
,
2
:
"height"
,
3
:
"width"
}),
]
)
@
property
def
atol_for_validation
(
self
)
->
float
:
return
2e-3
src/transformers/onnx/features.py
View file @
15bc776f
...
...
@@ -447,6 +447,9 @@ class FeaturesManager:
"sequence-classification"
,
onnx_config_cls
=
"models.perceiver.PerceiverOnnxConfig"
,
),
"poolformer"
:
supported_features_mapping
(
"default"
,
"image-classification"
,
onnx_config_cls
=
"models.poolformer.PoolFormerOnnxConfig"
),
"rembert"
:
supported_features_mapping
(
"default"
,
"masked-lm"
,
...
...
tests/onnx/test_onnx_v2.py
View file @
15bc776f
...
...
@@ -210,6 +210,7 @@ PYTORCH_EXPORT_MODELS = {
(
"owlvit"
,
"google/owlvit-base-patch32"
),
(
"perceiver"
,
"hf-internal-testing/tiny-random-PerceiverModel"
,
(
"masked-lm"
,
"sequence-classification"
)),
(
"perceiver"
,
"hf-internal-testing/tiny-random-PerceiverModel"
,
(
"image-classification"
,)),
(
"poolformer"
,
"sail/poolformer_s12"
),
(
"rembert"
,
"google/rembert"
),
(
"resnet"
,
"microsoft/resnet-50"
),
(
"roberta"
,
"hf-internal-testing/tiny-random-RobertaModel"
),
...
...
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