-
Notifications
You must be signed in to change notification settings - Fork 33.5k
Update tiny model creation script #22202
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
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e3af71c
Update UNCONVERTIBLE_MODEL_ARCHITECTURES
ydshieh af06a17
Deal with 2 model tester classes in single test file
ydshieh 289a6af
Deal with 2 model tester classes in single test file
ydshieh 8ae5481
Deal with 2 model tester classes in single test file
ydshieh 1a0cac7
make style and quality
ydshieh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,6 @@ | |
| import argparse | ||
| import collections.abc | ||
| import copy | ||
| import importlib | ||
| import inspect | ||
| import json | ||
| import os | ||
|
|
@@ -67,6 +66,9 @@ | |
| if not is_tf_available(): | ||
| raise ValueError("Please install TensorFlow.") | ||
|
|
||
| from get_test_info import get_model_to_tester_mapping, get_tester_classes_for_model # noqa E402 | ||
|
|
||
|
|
||
| FRAMEWORKS = ["pytorch", "tensorflow"] | ||
| INVALID_ARCH = [] | ||
| TARGET_VOCAB_SIZE = 1024 | ||
|
|
@@ -94,8 +96,12 @@ | |
| "TFCamembertModel", | ||
| "TFCamembertForCausalLM", | ||
| "DecisionTransformerModel", | ||
| "GraphormerModel", | ||
| "InformerModel", | ||
|
ydshieh marked this conversation as resolved.
|
||
| "JukeboxModel", | ||
| "MarianForCausalLM", | ||
| "MaskFormerSwinModel", | ||
| "MaskFormerSwinBackbone", | ||
|
ydshieh marked this conversation as resolved.
|
||
| "MT5Model", | ||
| "MT5ForConditionalGeneration", | ||
| "TFMT5ForConditionalGeneration", | ||
|
|
@@ -126,6 +132,7 @@ | |
| "XLMRobertaForQuestionAnswering", | ||
| "TFXLMRobertaForSequenceClassification", | ||
| "TFXLMRobertaForMaskedLM", | ||
| "TFXLMRobertaForCausalLM", | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgot this one is a previous PR |
||
| "TFXLMRobertaForQuestionAnswering", | ||
| "TFXLMRobertaModel", | ||
| "TFXLMRobertaForMultipleChoice", | ||
|
|
@@ -355,7 +362,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: | ||
|
|
@@ -378,9 +385,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) | ||
|
ydshieh marked this conversation as resolved.
|
||
| 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] | ||
|
ydshieh marked this conversation as resolved.
|
||
| except ModuleNotFoundError: | ||
| error = f"Tiny config not created for {model_type} - cannot find the testing module from the model name." | ||
| raise ValueError(error) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't this be with the other imports above?
Note: can't comment on the sys.path(".") above but the current folder is always in the path, so it's not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sgugger In a few files under
utilis, if there are statements likeimportlib.import_module("tests/models/..."), it requires addingOtherwise, I get
ModuleNotFoundError: No module named 'tests'.The file
utils/create_dummy_models.pyhad thisimportlib.import_module(...)before this PR, so it requiredsys.path.append("."). I can remove it from this PR.(I think I should try to figure out why we need it in the case mentioned above - but if you happen to know, please teach me a lesson 🙏 )
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it works! Thanks a lot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, that's why it's there then. Could you make sure the comment is added so we now why this sys.path.apoend is there?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's no longer needed for this file
create_dummy_models.py(as I re-used the method in another file), and I removed it.In another file (
get_test_info.py), I have a comment# This is required to make the module import works (when the python process is running from the root of the repo)