transformers

Форк
0
/
check_model_tester.py 
63 строки · 2.5 Кб
1
# coding=utf-8
2
# Copyright 2023 The HuggingFace Inc. team.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15

16

17
import glob
18
import os
19

20
from get_test_info import get_tester_classes
21

22

23
if __name__ == "__main__":
24
    failures = []
25

26
    pattern = os.path.join("tests", "models", "**", "test_modeling_*.py")
27
    test_files = glob.glob(pattern)
28
    # TODO: deal with TF/Flax too
29
    test_files = [
30
        x for x in test_files if not (x.startswith("test_modeling_tf_") or x.startswith("test_modeling_flax_"))
31
    ]
32

33
    for test_file in test_files:
34
        tester_classes = get_tester_classes(test_file)
35
        for tester_class in tester_classes:
36
            # A few tester classes don't have `parent` parameter in `__init__`.
37
            # TODO: deal this better
38
            try:
39
                tester = tester_class(parent=None)
40
            except Exception:
41
                continue
42
            if hasattr(tester, "get_config"):
43
                config = tester.get_config()
44
                for k, v in config.to_dict().items():
45
                    if isinstance(v, int):
46
                        target = None
47
                        if k in ["vocab_size"]:
48
                            target = 100
49
                        elif k in ["max_position_embeddings"]:
50
                            target = 128
51
                        elif k in ["hidden_size", "d_model"]:
52
                            target = 40
53
                        elif k == ["num_layers", "num_hidden_layers", "num_encoder_layers", "num_decoder_layers"]:
54
                            target = 5
55
                        if target is not None and v > target:
56
                            failures.append(
57
                                f"{tester_class.__name__} will produce a `config` of type `{config.__class__.__name__}`"
58
                                f' with config["{k}"] = {v} which is too large for testing! Set its value to be smaller'
59
                                f" than {target}."
60
                            )
61

62
    if len(failures) > 0:
63
        raise Exception(f"There were {len(failures)} failures:\n" + "\n".join(failures))
64

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.