diff --git a/.github/workflows/add-model-like.yml b/.github/workflows/add-model-like.yml index e3b654ab383..57ea17ad971 100644 --- a/.github/workflows/add-model-like.yml +++ b/.github/workflows/add-model-like.yml @@ -12,7 +12,8 @@ on: types: [opened, synchronize, reopened] jobs: - run_tests_templates: + run_tests_templates_like: + name: "Add new model like template tests" runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -42,7 +43,7 @@ jobs: - name: Run all PyTorch modeling test run: | - python -m pytest -n 2 --dist=loadfile -s --make-reports=tests_new_models tests/test_modeling_bert_new.py + python -m pytest -n 2 --dist=loadfile -s --make-reports=tests_new_models tests/bert_new/test_modeling_bert_new.py - name: Run style changes run: | @@ -50,11 +51,11 @@ jobs: - name: Failure short reports if: ${{ always() }} - run: cat reports/tests_new_models_failures_short.txt + run: cat reports/tests_new_models/failures_short.txt - name: Test suite reports artifacts if: ${{ always() }} uses: actions/upload-artifact@v2 with: name: run_all_tests_new_models_test_reports - path: reports + path: reports/tests_new_models diff --git a/.github/workflows/model-templates.yml b/.github/workflows/model-templates.yml index 3e3768c2889..1f7daed6ca3 100644 --- a/.github/workflows/model-templates.yml +++ b/.github/workflows/model-templates.yml @@ -65,11 +65,11 @@ jobs: - name: Failure short reports if: ${{ always() }} - run: cat reports/tests_templates_failures_short.txt + run: cat reports/tests_templates/failures_short.txt - name: Test suite reports artifacts if: ${{ always() }} uses: actions/upload-artifact@v2 with: name: run_all_tests_templates_test_reports - path: reports + path: reports/tests_templates diff --git a/src/transformers/commands/add_new_model.py b/src/transformers/commands/add_new_model.py index 558ef6dd483..a5854863d2d 100644 --- a/src/transformers/commands/add_new_model.py +++ b/src/transformers/commands/add_new_model.py @@ -102,6 +102,11 @@ class AddNewModelCommand(BaseTransformersCLICommand): model_dir = f"{path_to_transformer_root}/src/transformers/models/{lowercase_model_name}" os.makedirs(model_dir, exist_ok=True) + os.makedirs(f"{path_to_transformer_root}/tests/{lowercase_model_name}", exist_ok=True) + + # Tests require submodules as they have parent imports + with open(f"{path_to_transformer_root}/tests/{lowercase_model_name}/__init__.py", "w"): + pass shutil.move( f"{directory}/__init__.py", diff --git a/src/transformers/commands/add_new_model_like.py b/src/transformers/commands/add_new_model_like.py index f69fd93ea64..5e5159fec9e 100644 --- a/src/transformers/commands/add_new_model_like.py +++ b/src/transformers/commands/add_new_model_like.py @@ -1199,11 +1199,16 @@ def create_new_model_like( disabled_fx_test = False + tests_folder = REPO_PATH / "tests" / new_model_patterns.model_lower_cased + os.makedirs(tests_folder, exist_ok=True) + with open(tests_folder / "__init__.py", "w"): + pass + for test_file in files_to_adapt: new_test_file_name = test_file.name.replace( old_model_patterns.model_lower_cased, new_model_patterns.model_lower_cased ) - dest_file = test_file.parent / new_test_file_name + dest_file = test_file.parent.parent / new_model_patterns.model_lower_cased / new_test_file_name duplicate_module( test_file, old_model_patterns, diff --git a/templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/test_modeling_{{cookiecutter.lowercase_modelname}}.py b/templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/test_modeling_{{cookiecutter.lowercase_modelname}}.py index 700e380610c..1f4826c1030 100644 --- a/templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/test_modeling_{{cookiecutter.lowercase_modelname}}.py +++ b/templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/test_modeling_{{cookiecutter.lowercase_modelname}}.py @@ -490,7 +490,7 @@ from transformers.file_utils import cached_property from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device from ..test_configuration_common import ConfigTester -from ..test_generation_utils import GenerationTesterMixin +from ..generation.test_generation_utils import GenerationTesterMixin from ..test_modeling_common import ModelTesterMixin, ids_tensor