Fix model templates (#15806)

* Fix model templates

* Update paths
This commit is contained in:
Lysandre Debut 2022-02-23 18:27:29 -05:00 committed by GitHub
parent 309e87e25e
commit bb7949b35a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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",

View File

@ -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,

View File

@ -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