Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tiny model creation script #22202

Merged
merged 5 commits into from
Mar 16, 2023
Merged
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
27 changes: 20 additions & 7 deletions utils/create_dummy_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@
import argparse
import collections.abc
import copy
import importlib
import inspect
import json
import os
import shutil
import sys
import tempfile
import traceback
from pathlib import Path

from check_config_docstrings import get_checkpoint_from_config_class
from datasets import load_dataset
from get_test_info import get_model_to_tester_mapping, get_tester_classes_for_model
from huggingface_hub import Repository, create_repo, upload_folder

from transformers import (
Expand Down Expand Up @@ -58,7 +57,6 @@
logging.disable_progress_bar()
logger = logging.get_logger(__name__)

sys.path.append(".")
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"

if not is_torch_available():
Expand All @@ -67,6 +65,7 @@
if not is_tf_available():
raise ValueError("Please install TensorFlow.")


FRAMEWORKS = ["pytorch", "tensorflow"]
INVALID_ARCH = []
TARGET_VOCAB_SIZE = 1024
Expand Down Expand Up @@ -94,8 +93,12 @@
"TFCamembertModel",
"TFCamembertForCausalLM",
"DecisionTransformerModel",
"GraphormerModel",
"InformerModel",
"JukeboxModel",
"MarianForCausalLM",
"MaskFormerSwinModel",
"MaskFormerSwinBackbone",
"MT5Model",
"MT5ForConditionalGeneration",
"TFMT5ForConditionalGeneration",
Expand Down Expand Up @@ -126,6 +129,7 @@
"XLMRobertaForQuestionAnswering",
"TFXLMRobertaForSequenceClassification",
"TFXLMRobertaForMaskedLM",
"TFXLMRobertaForCausalLM",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot this one is a previous PR

"TFXLMRobertaForQuestionAnswering",
"TFXLMRobertaModel",
"TFXLMRobertaForMultipleChoice",
Expand Down Expand Up @@ -355,7 +359,7 @@ def build_processor(config_class, processor_class, allow_no_checkpoint=False):
return processor


def get_tiny_config(config_class, **model_tester_kwargs):
def get_tiny_config(config_class, model_class=None, **model_tester_kwargs):
"""Retrieve a tiny configuration from `config_class` using each model's `ModelTester`.

Args:
Expand All @@ -378,9 +382,18 @@ def get_tiny_config(config_class, **model_tester_kwargs):
module_name = model_type_to_module_name(model_type)
if not modeling_name.startswith(module_name):
raise ValueError(f"{modeling_name} doesn't start with {module_name}!")
module = importlib.import_module(f".models.{module_name}.test_modeling_{modeling_name}", package="tests")
camel_case_model_name = config_class.__name__.split("Config")[0]
model_tester_class = getattr(module, f"{camel_case_model_name}ModelTester", None)
test_file = os.path.join("tests", "models", module_name, f"test_modeling_{modeling_name}.py")
models_to_model_testers = get_model_to_tester_mapping(test_file)
# Find the model tester class
model_tester_class = None
tester_classes = []
if model_class is not None:
tester_classes = get_tester_classes_for_model(test_file, model_class)
else:
for _tester_classes in models_to_model_testers.values():
tester_classes.extend(_tester_classes)
if len(tester_classes) > 0:
model_tester_class = sorted(tester_classes, key=lambda x: x.__name__)[0]
except ModuleNotFoundError:
error = f"Tiny config not created for {model_type} - cannot find the testing module from the model name."
raise ValueError(error)
Expand Down