Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
bb7949b3
Unverified
Commit
bb7949b3
authored
Feb 23, 2022
by
Lysandre Debut
Committed by
GitHub
Feb 23, 2022
Browse files
Fix model templates (#15806)
* Fix model templates * Update paths
parent
309e87e2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
8 deletions
+19
-8
.github/workflows/add-model-like.yml
.github/workflows/add-model-like.yml
+5
-4
.github/workflows/model-templates.yml
.github/workflows/model-templates.yml
+2
-2
src/transformers/commands/add_new_model.py
src/transformers/commands/add_new_model.py
+5
-0
src/transformers/commands/add_new_model_like.py
src/transformers/commands/add_new_model_like.py
+6
-1
templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/test_modeling_{{cookiecutter.lowercase_modelname}}.py
...e}}/test_modeling_{{cookiecutter.lowercase_modelname}}.py
+1
-1
No files found.
.github/workflows/add-model-like.yml
View file @
bb7949b3
...
@@ -12,7 +12,8 @@ on:
...
@@ -12,7 +12,8 @@ on:
types
:
[
opened
,
synchronize
,
reopened
]
types
:
[
opened
,
synchronize
,
reopened
]
jobs
:
jobs
:
run_tests_templates
:
run_tests_templates_like
:
name
:
"
Add
new
model
like
template
tests"
runs-on
:
ubuntu-latest
runs-on
:
ubuntu-latest
steps
:
steps
:
-
uses
:
actions/checkout@v2
-
uses
:
actions/checkout@v2
...
@@ -42,7 +43,7 @@ jobs:
...
@@ -42,7 +43,7 @@ jobs:
-
name
:
Run all PyTorch modeling test
-
name
:
Run all PyTorch modeling test
run
:
|
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
-
name
:
Run style changes
run
:
|
run
:
|
...
@@ -50,11 +51,11 @@ jobs:
...
@@ -50,11 +51,11 @@ jobs:
-
name
:
Failure short reports
-
name
:
Failure short reports
if
:
${{ always() }}
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
-
name
:
Test suite reports artifacts
if
:
${{ always() }}
if
:
${{ always() }}
uses
:
actions/upload-artifact@v2
uses
:
actions/upload-artifact@v2
with
:
with
:
name
:
run_all_tests_new_models_test_reports
name
:
run_all_tests_new_models_test_reports
path
:
reports
path
:
reports
/tests_new_models
.github/workflows/model-templates.yml
View file @
bb7949b3
...
@@ -65,11 +65,11 @@ jobs:
...
@@ -65,11 +65,11 @@ jobs:
-
name
:
Failure short reports
-
name
:
Failure short reports
if
:
${{ always() }}
if
:
${{ always() }}
run
:
cat reports/tests_templates
_
failures_short.txt
run
:
cat reports/tests_templates
/
failures_short.txt
-
name
:
Test suite reports artifacts
-
name
:
Test suite reports artifacts
if
:
${{ always() }}
if
:
${{ always() }}
uses
:
actions/upload-artifact@v2
uses
:
actions/upload-artifact@v2
with
:
with
:
name
:
run_all_tests_templates_test_reports
name
:
run_all_tests_templates_test_reports
path
:
reports
path
:
reports
/tests_templates
src/transformers/commands/add_new_model.py
View file @
bb7949b3
...
@@ -102,6 +102,11 @@ class AddNewModelCommand(BaseTransformersCLICommand):
...
@@ -102,6 +102,11 @@ class AddNewModelCommand(BaseTransformersCLICommand):
model_dir
=
f
"
{
path_to_transformer_root
}
/src/transformers/models/
{
lowercase_model_name
}
"
model_dir
=
f
"
{
path_to_transformer_root
}
/src/transformers/models/
{
lowercase_model_name
}
"
os
.
makedirs
(
model_dir
,
exist_ok
=
True
)
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
(
shutil
.
move
(
f
"
{
directory
}
/__init__.py"
,
f
"
{
directory
}
/__init__.py"
,
...
...
src/transformers/commands/add_new_model_like.py
View file @
bb7949b3
...
@@ -1199,11 +1199,16 @@ def create_new_model_like(
...
@@ -1199,11 +1199,16 @@ def create_new_model_like(
disabled_fx_test
=
False
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
:
for
test_file
in
files_to_adapt
:
new_test_file_name
=
test_file
.
name
.
replace
(
new_test_file_name
=
test_file
.
name
.
replace
(
old_model_patterns
.
model_lower_cased
,
new_model_patterns
.
model_lower_cased
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
(
duplicate_module
(
test_file
,
test_file
,
old_model_patterns
,
old_model_patterns
,
...
...
templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/test_modeling_{{cookiecutter.lowercase_modelname}}.py
View file @
bb7949b3
...
@@ -490,7 +490,7 @@ from transformers.file_utils import cached_property
...
@@ -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
transformers.testing_utils
import
require_sentencepiece
,
require_tokenizers
,
require_torch
,
slow
,
torch_device
from
..test_configuration_common
import
ConfigTester
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
from
..test_modeling_common
import
ModelTesterMixin
,
ids_tensor
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment