Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion optimum/utils/normalized_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ class NormalizedConfigManager:
'segformer',
'siglip',
'squeezebert',
'table-transformer',
...
"""

Expand Down Expand Up @@ -303,6 +302,7 @@ class NormalizedConfigManager:
"segformer": NormalizedSegformerConfig,
"speech_to_text": SpeechToTextLikeNormalizedTextConfig,
"splinter": NormalizedTextConfig,
"table-transformer": NormalizedTextConfig,
"t5": T5LikeNormalizedTextConfig,
"trocr": TrOCRLikeNormalizedTextConfig,
"vision-encoder-decoder": NormalizedEncoderDecoderConfig,
Expand Down
39 changes: 39 additions & 0 deletions tests/utils/test_normalized_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# coding=utf-8
# Copyright 2022 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

from transformers import TableTransformerConfig

from optimum.utils.normalized_config import NormalizedConfigManager, NormalizedTextConfig


class NormalizedConfigManagerTest(unittest.TestCase):
def test_table_transformer_is_registered(self):
config_class = NormalizedConfigManager.get_normalized_config_class("table-transformer")
self.assertIs(config_class, NormalizedTextConfig)

def test_table_transformer_normalizes_expected_attributes(self):
# Same situation as DETR (table-transformer is DETR-based): the config
# stores d_model / encoder_attention_heads / encoder_layers, but its own
# attribute_map aliases these to hidden_size / num_attention_heads /
# num_hidden_layers, so plain NormalizedTextConfig needs no custom mapping.
config = TableTransformerConfig()
normalized_config_class = NormalizedConfigManager.get_normalized_config_class("table-transformer")
normalized_config = normalized_config_class(config)

self.assertEqual(normalized_config.hidden_size, config.d_model)
self.assertEqual(normalized_config.num_attention_heads, config.encoder_attention_heads)
self.assertEqual(normalized_config.num_layers, config.encoder_layers)