diff --git a/.circleci/config.yml b/.circleci/config.yml index 3c76b63a78a7..b9cf5126878a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -916,7 +916,7 @@ jobs: path: ~/transformers/test_preparation.txt - run: | if [ -f test_list.txt ]; then - python -m pytest -n 1 tests/*layoutlmv2* --dist=loadfile -s --make-reports=tests_layoutlmv2 --durations=100 + python -m pytest -n 1 tests/models/*layoutlmv2* --dist=loadfile -s --make-reports=tests_layoutlmv2 --durations=100 fi - store_artifacts: path: ~/transformers/tests_output.txt diff --git a/.github/workflows/self-scheduled.yml b/.github/workflows/self-scheduled.yml index a5d9701d9f83..3f68a24d9d62 100644 --- a/.github/workflows/self-scheduled.yml +++ b/.github/workflows/self-scheduled.yml @@ -43,13 +43,14 @@ jobs: working-directory: /transformers run: | rm -rf tests/__pycache__ + rm -rf tests/models/__pycache__ rm -rf reports - id: set-matrix name: Identify models to test working-directory: /transformers/tests run: | - echo "::set-output name=matrix::$(python3 -c 'import os; x = list(filter(os.path.isdir, os.listdir(os.getcwd()))); x.sort(); print(x)')" + echo "::set-output name=matrix::$(python3 -c 'import os; tests = os.getcwd(); model_tests = os.listdir(os.path.join(tests, "models")); d1 = sorted(list(filter(os.path.isdir, os.listdir(tests)))); d2 = sorted(list(filter(os.path.isdir, [f"models/{x}" for x in model_tests]))); d1.remove("models"); d = d2 + d1; print(d)')" - name: NVIDIA-SMI run: | @@ -76,7 +77,16 @@ jobs: needs: setup steps: - name: Echo folder ${{ matrix.folders }} - run: echo "${{ matrix.folders }}" + shell: bash + # For folders like `models/bert`, set an env. var. (`matrix_folders`) to `models_bert`, which will be used to + # set the artifact folder names (because the character `/` is not allowed). + run: | + echo "${{ matrix.folders }}" + matrix_folders=${{ matrix.folders }} + echo "$matrix_folders" + matrix_folders=${matrix_folders/'models/'/'models_'} + echo "$matrix_folders" + echo "matrix_folders=$matrix_folders" >> $GITHUB_ENV - name: Update clone working-directory: /transformers @@ -95,7 +105,7 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@v2 with: - name: ${{ matrix.machines }}_run_all_tests_gpu_${{ matrix.folders }}_test_reports + name: ${{ matrix.machines }}_run_all_tests_gpu_${{ env.matrix_folders }}_test_reports path: /transformers/reports/${{ matrix.machines }}_tests_gpu_${{ matrix.folders }} run_examples_gpu: @@ -255,6 +265,8 @@ jobs: CI_SLACK_CHANNEL_ID: ${{ secrets.CI_SLACK_CHANNEL_ID }} CI_SLACK_CHANNEL_ID_DAILY: ${{ secrets.CI_SLACK_CHANNEL_ID_DAILY }} CI_SLACK_CHANNEL_DUMMY_TESTS: ${{ secrets.CI_SLACK_CHANNEL_DUMMY_TESTS }} + # We pass `needs.setup.outputs.matrix` as the argument. A processing in `notification_service.py` to change + # `models/bert` to `models_bert` is required, as the artifact names use `_` instead of `/`. run: | pip install slack_sdk python utils/notification_service.py "${{ needs.setup.outputs.matrix }}" diff --git a/src/transformers/commands/add_new_model.py b/src/transformers/commands/add_new_model.py index 276032eefe63..83f0188afafb 100644 --- a/src/transformers/commands/add_new_model.py +++ b/src/transformers/commands/add_new_model.py @@ -102,10 +102,10 @@ def run(self): 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) + os.makedirs(f"{path_to_transformer_root}/tests/models/{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"): + with open(f"{path_to_transformer_root}/tests/models/{lowercase_model_name}/__init__.py", "w"): pass shutil.move( @@ -136,7 +136,7 @@ def remove_copy_lines(path): shutil.move( f"{directory}/test_modeling_{lowercase_model_name}.py", - f"{path_to_transformer_root}/tests/{lowercase_model_name}/test_modeling_{lowercase_model_name}.py", + f"{path_to_transformer_root}/tests/models/{lowercase_model_name}/test_modeling_{lowercase_model_name}.py", ) else: os.remove(f"{directory}/modeling_{lowercase_model_name}.py") @@ -153,7 +153,7 @@ def remove_copy_lines(path): shutil.move( f"{directory}/test_modeling_tf_{lowercase_model_name}.py", - f"{path_to_transformer_root}/tests/{lowercase_model_name}/test_modeling_tf_{lowercase_model_name}.py", + f"{path_to_transformer_root}/tests/models/{lowercase_model_name}/test_modeling_tf_{lowercase_model_name}.py", ) else: os.remove(f"{directory}/modeling_tf_{lowercase_model_name}.py") @@ -170,7 +170,7 @@ def remove_copy_lines(path): shutil.move( f"{directory}/test_modeling_flax_{lowercase_model_name}.py", - f"{path_to_transformer_root}/tests/{lowercase_model_name}/test_modeling_flax_{lowercase_model_name}.py", + f"{path_to_transformer_root}/tests/models/{lowercase_model_name}/test_modeling_flax_{lowercase_model_name}.py", ) else: os.remove(f"{directory}/modeling_flax_{lowercase_model_name}.py") diff --git a/src/transformers/commands/add_new_model_like.py b/src/transformers/commands/add_new_model_like.py index 30a8229b57ab..625af5001116 100644 --- a/src/transformers/commands/add_new_model_like.py +++ b/src/transformers/commands/add_new_model_like.py @@ -554,7 +554,7 @@ def get_model_files(model_type: str, frameworks: Optional[List[str]] = None) -> ] test_files = filter_framework_files(test_files, frameworks=frameworks) # Add the test directory - test_files = [REPO_PATH / "tests" / module_name / f for f in test_files] + test_files = [REPO_PATH / "tests" / "models" / module_name / f for f in test_files] # Filter by existing files test_files = [f for f in test_files if f.exists()] @@ -1227,7 +1227,7 @@ def disable_fx_test(filename: Path) -> bool: disabled_fx_test = False - tests_folder = REPO_PATH / "tests" / new_model_patterns.model_lower_cased + tests_folder = REPO_PATH / "tests" / "models" / new_model_patterns.model_lower_cased os.makedirs(tests_folder, exist_ok=True) with open(tests_folder / "__init__.py", "w"): pass diff --git a/templates/adding_a_missing_tokenization_test/cookiecutter-template-{{cookiecutter.modelname}}/test_tokenization_{{cookiecutter.lowercase_modelname}}.py b/templates/adding_a_missing_tokenization_test/cookiecutter-template-{{cookiecutter.modelname}}/test_tokenization_{{cookiecutter.lowercase_modelname}}.py index 631886f6b2eb..36e35c04ed33 100644 --- a/templates/adding_a_missing_tokenization_test/cookiecutter-template-{{cookiecutter.modelname}}/test_tokenization_{{cookiecutter.lowercase_modelname}}.py +++ b/templates/adding_a_missing_tokenization_test/cookiecutter-template-{{cookiecutter.modelname}}/test_tokenization_{{cookiecutter.lowercase_modelname}}.py @@ -26,25 +26,25 @@ {% endif -%} {% if cookiecutter.has_fast_class == "True" and cookiecutter.slow_tokenizer_use_sentencepiece == "True" -%} from transformers.testing_utils import require_sentencepiece, require_tokenizers -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_sentencepiece @require_tokenizers {% elif cookiecutter.slow_tokenizer_use_sentencepiece == "True" -%} from transformers.testing_utils import require_sentencepiece -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_sentencepiece {% elif cookiecutter.has_fast_class == "True" -%} from transformers.testing_utils import require_tokenizers -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_tokenizers {% else -%} -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin {% endif -%} diff --git a/templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/test_modeling_flax_{{cookiecutter.lowercase_modelname}}.py b/templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/test_modeling_flax_{{cookiecutter.lowercase_modelname}}.py index 69b0a7fae201..37b22a75c3e9 100644 --- a/templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/test_modeling_flax_{{cookiecutter.lowercase_modelname}}.py +++ b/templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/test_modeling_flax_{{cookiecutter.lowercase_modelname}}.py @@ -20,8 +20,8 @@ from transformers import is_flax_available, {{cookiecutter.camelcase_modelname}}Config from transformers.testing_utils import require_flax, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor if is_flax_available(): import numpy as np @@ -345,8 +345,8 @@ def test_inference_masked_lm(self): ) from transformers.testing_utils import require_sentencepiece, require_flax, require_tokenizers, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor if is_flax_available(): diff --git a/templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/test_modeling_tf_{{cookiecutter.lowercase_modelname}}.py b/templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/test_modeling_tf_{{cookiecutter.lowercase_modelname}}.py index 0f4d7824c164..48cd1239eaed 100644 --- a/templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/test_modeling_tf_{{cookiecutter.lowercase_modelname}}.py +++ b/templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/test_modeling_tf_{{cookiecutter.lowercase_modelname}}.py @@ -20,8 +20,8 @@ from transformers import is_tf_available, {{cookiecutter.camelcase_modelname}}Config from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_tf_available(): @@ -711,8 +711,8 @@ def test_inference_masked_lm(self): ) from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor if is_tf_available(): 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 e15adc91e30c..7becb5155183 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 @@ -18,13 +18,13 @@ {% if cookiecutter.is_encoder_decoder_model == "False" -%} import unittest -from ..test_modeling_common import floats_tensor +from ...test_modeling_common import floats_tensor from transformers import is_torch_available from transformers.testing_utils import require_torch, slow, torch_device from transformers import {{cookiecutter.camelcase_modelname}}Config -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): @@ -489,9 +489,9 @@ def test_inference_masked_lm(self): from transformers.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 ..generation.test_generation_utils import GenerationTesterMixin -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/deepspeed/test_model_zoo.py b/tests/deepspeed/test_model_zoo.py index 905d40eadd5d..94559604935a 100644 --- a/tests/deepspeed/test_model_zoo.py +++ b/tests/deepspeed/test_model_zoo.py @@ -24,6 +24,7 @@ TestCasePlus, execute_subprocess_async, get_gpu_count, + get_tests_dir, require_deepspeed, require_torch_gpu, slow, @@ -70,8 +71,8 @@ XLNET_TINY = "sshleifer/tiny-xlnet-base-cased" BERT_TINY = "hf-internal-testing/tiny-bert" -FIXTURE_DIRECTORY = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures") -ROOT_DIRECTORY = os.path.join(dirname(dirname(dirname(os.path.abspath(__file__))))) +FIXTURE_DIRECTORY = get_tests_dir("fixtures") +ROOT_DIRECTORY = os.path.join(dirname(get_tests_dir())) # TODO: to add: # albert diff --git a/tests/albert/__init__.py b/tests/models/__init__.py similarity index 100% rename from tests/albert/__init__.py rename to tests/models/__init__.py diff --git a/tests/auto/__init__.py b/tests/models/albert/__init__.py similarity index 100% rename from tests/auto/__init__.py rename to tests/models/albert/__init__.py diff --git a/tests/albert/test_modeling_albert.py b/tests/models/albert/test_modeling_albert.py similarity index 98% rename from tests/albert/test_modeling_albert.py rename to tests/models/albert/test_modeling_albert.py index 125ba314ddc3..77496699d427 100644 --- a/tests/albert/test_modeling_albert.py +++ b/tests/models/albert/test_modeling_albert.py @@ -20,8 +20,8 @@ from transformers.models.auto import get_values from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/albert/test_modeling_flax_albert.py b/tests/models/albert/test_modeling_flax_albert.py similarity index 98% rename from tests/albert/test_modeling_flax_albert.py rename to tests/models/albert/test_modeling_flax_albert.py index 11e971684e43..802952e52cbd 100644 --- a/tests/albert/test_modeling_flax_albert.py +++ b/tests/models/albert/test_modeling_flax_albert.py @@ -19,7 +19,7 @@ from transformers import AlbertConfig, is_flax_available from transformers.testing_utils import require_flax, slow -from ..test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask +from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask if is_flax_available(): diff --git a/tests/albert/test_modeling_tf_albert.py b/tests/models/albert/test_modeling_tf_albert.py similarity index 98% rename from tests/albert/test_modeling_tf_albert.py rename to tests/models/albert/test_modeling_tf_albert.py index 7eacc1f32a47..ad10228a5182 100644 --- a/tests/albert/test_modeling_tf_albert.py +++ b/tests/models/albert/test_modeling_tf_albert.py @@ -20,8 +20,8 @@ from transformers.models.auto import get_values from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/albert/test_tokenization_albert.py b/tests/models/albert/test_tokenization_albert.py similarity index 96% rename from tests/albert/test_tokenization_albert.py rename to tests/models/albert/test_tokenization_albert.py index 2421da49274c..5459917775d9 100644 --- a/tests/albert/test_tokenization_albert.py +++ b/tests/models/albert/test_tokenization_albert.py @@ -13,17 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import unittest -from os.path import dirname from transformers import AlbertTokenizer, AlbertTokenizerFast -from transformers.testing_utils import require_sentencepiece, require_tokenizers, slow +from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/spiece.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/spiece.model") @require_sentencepiece diff --git a/tests/bart/__init__.py b/tests/models/auto/__init__.py similarity index 100% rename from tests/bart/__init__.py rename to tests/models/auto/__init__.py diff --git a/tests/auto/test_configuration_auto.py b/tests/models/auto/test_configuration_auto.py similarity index 94% rename from tests/auto/test_configuration_auto.py rename to tests/models/auto/test_configuration_auto.py index f07bb428347a..eeb10ad2d315 100644 --- a/tests/auto/test_configuration_auto.py +++ b/tests/models/auto/test_configuration_auto.py @@ -14,7 +14,6 @@ # limitations under the License. import importlib -import os import sys import tempfile import unittest @@ -24,15 +23,15 @@ from transformers.models.auto.configuration_auto import CONFIG_MAPPING, AutoConfig from transformers.models.bert.configuration_bert import BertConfig from transformers.models.roberta.configuration_roberta import RobertaConfig -from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER +from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, get_tests_dir -sys.path.append(str(Path(__file__).parent.parent.parent / "utils")) +sys.path.append(str(Path(__file__).parent.parent.parent.parent / "utils")) from test_module.custom_configuration import CustomConfig # noqa E402 -SAMPLE_ROBERTA_CONFIG = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../fixtures/dummy-config.json") +SAMPLE_ROBERTA_CONFIG = get_tests_dir("fixtures/dummy-config.json") class AutoConfigTest(unittest.TestCase): diff --git a/tests/auto/test_feature_extraction_auto.py b/tests/models/auto/test_feature_extraction_auto.py similarity index 90% rename from tests/auto/test_feature_extraction_auto.py rename to tests/models/auto/test_feature_extraction_auto.py index b0c11c517ab7..e9d044e8daac 100644 --- a/tests/auto/test_feature_extraction_auto.py +++ b/tests/models/auto/test_feature_extraction_auto.py @@ -14,7 +14,6 @@ # limitations under the License. import json -import os import sys import tempfile import unittest @@ -28,20 +27,18 @@ Wav2Vec2Config, Wav2Vec2FeatureExtractor, ) -from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER +from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, get_tests_dir -sys.path.append(str(Path(__file__).parent.parent.parent / "utils")) +sys.path.append(str(Path(__file__).parent.parent.parent.parent / "utils")) from test_module.custom_configuration import CustomConfig # noqa E402 from test_module.custom_feature_extraction import CustomFeatureExtractor # noqa E402 -SAMPLE_FEATURE_EXTRACTION_CONFIG_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../fixtures") -SAMPLE_FEATURE_EXTRACTION_CONFIG = os.path.join( - os.path.dirname(os.path.abspath(__file__)), "../fixtures/dummy_feature_extractor_config.json" -) -SAMPLE_CONFIG = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../fixtures/dummy-config.json") +SAMPLE_FEATURE_EXTRACTION_CONFIG_DIR = get_tests_dir("fixtures") +SAMPLE_FEATURE_EXTRACTION_CONFIG = get_tests_dir("fixtures/dummy_feature_extractor_config.json") +SAMPLE_CONFIG = get_tests_dir("fixtures/dummy-config.json") class AutoFeatureExtractorTest(unittest.TestCase): diff --git a/tests/auto/test_modeling_auto.py b/tests/models/auto/test_modeling_auto.py similarity index 99% rename from tests/auto/test_modeling_auto.py rename to tests/models/auto/test_modeling_auto.py index 02ecb08e1e2f..3731d70f5bb5 100644 --- a/tests/auto/test_modeling_auto.py +++ b/tests/models/auto/test_modeling_auto.py @@ -32,7 +32,7 @@ from ..bert.test_modeling_bert import BertModelTester -sys.path.append(str(Path(__file__).parent.parent.parent / "utils")) +sys.path.append(str(Path(__file__).parent.parent.parent.parent / "utils")) from test_module.custom_configuration import CustomConfig # noqa E402 diff --git a/tests/auto/test_modeling_flax_auto.py b/tests/models/auto/test_modeling_flax_auto.py similarity index 100% rename from tests/auto/test_modeling_flax_auto.py rename to tests/models/auto/test_modeling_flax_auto.py diff --git a/tests/auto/test_modeling_tf_auto.py b/tests/models/auto/test_modeling_tf_auto.py similarity index 100% rename from tests/auto/test_modeling_tf_auto.py rename to tests/models/auto/test_modeling_tf_auto.py diff --git a/tests/auto/test_modeling_tf_pytorch.py b/tests/models/auto/test_modeling_tf_pytorch.py similarity index 100% rename from tests/auto/test_modeling_tf_pytorch.py rename to tests/models/auto/test_modeling_tf_pytorch.py diff --git a/tests/auto/test_processor_auto.py b/tests/models/auto/test_processor_auto.py similarity index 96% rename from tests/auto/test_processor_auto.py rename to tests/models/auto/test_processor_auto.py index 02fa8696c4a1..26122e6164ab 100644 --- a/tests/auto/test_processor_auto.py +++ b/tests/models/auto/test_processor_auto.py @@ -36,12 +36,12 @@ Wav2Vec2FeatureExtractor, Wav2Vec2Processor, ) -from transformers.testing_utils import PASS, USER, is_staging_test +from transformers.testing_utils import PASS, USER, get_tests_dir, is_staging_test from transformers.tokenization_utils import TOKENIZER_CONFIG_FILE from transformers.utils import FEATURE_EXTRACTOR_NAME, is_tokenizers_available -sys.path.append(str(Path(__file__).parent.parent.parent / "utils")) +sys.path.append(str(Path(__file__).parent.parent.parent.parent / "utils")) from test_module.custom_configuration import CustomConfig # noqa E402 from test_module.custom_feature_extraction import CustomFeatureExtractor # noqa E402 @@ -49,12 +49,9 @@ from test_module.custom_tokenization import CustomTokenizer # noqa E402 -SAMPLE_PROCESSOR_CONFIG = os.path.join( - os.path.dirname(os.path.abspath(__file__)), "../fixtures/dummy_feature_extractor_config.json" -) -SAMPLE_VOCAB = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../fixtures/vocab.json") - -SAMPLE_PROCESSOR_CONFIG_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../fixtures") +SAMPLE_PROCESSOR_CONFIG = get_tests_dir("fixtures/dummy_feature_extractor_config.json") +SAMPLE_VOCAB = get_tests_dir("fixtures/vocab.json") +SAMPLE_PROCESSOR_CONFIG_DIR = get_tests_dir("fixtures") class AutoFeatureExtractorTest(unittest.TestCase): diff --git a/tests/auto/test_tokenization_auto.py b/tests/models/auto/test_tokenization_auto.py similarity index 99% rename from tests/auto/test_tokenization_auto.py rename to tests/models/auto/test_tokenization_auto.py index 57041e583029..1e1abb924584 100644 --- a/tests/auto/test_tokenization_auto.py +++ b/tests/models/auto/test_tokenization_auto.py @@ -53,7 +53,7 @@ ) -sys.path.append(str(Path(__file__).parent.parent / "utils")) +sys.path.append(str(Path(__file__).parent.parent.parent.parent / "utils")) from test_module.custom_configuration import CustomConfig # noqa E402 from test_module.custom_tokenization import CustomTokenizer # noqa E402 diff --git a/tests/barthez/__init__.py b/tests/models/bart/__init__.py similarity index 100% rename from tests/barthez/__init__.py rename to tests/models/bart/__init__.py diff --git a/tests/bart/test_modeling_bart.py b/tests/models/bart/test_modeling_bart.py similarity index 99% rename from tests/bart/test_modeling_bart.py rename to tests/models/bart/test_modeling_bart.py index db443164c58e..18fc66a4f563 100644 --- a/tests/bart/test_modeling_bart.py +++ b/tests/models/bart/test_modeling_bart.py @@ -25,9 +25,9 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device from transformers.utils import cached_property -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/bart/test_modeling_flax_bart.py b/tests/models/bart/test_modeling_flax_bart.py similarity index 99% rename from tests/bart/test_modeling_flax_bart.py rename to tests/models/bart/test_modeling_flax_bart.py index 219d41cae2b6..ef4f9d38525f 100644 --- a/tests/bart/test_modeling_flax_bart.py +++ b/tests/models/bart/test_modeling_flax_bart.py @@ -19,8 +19,8 @@ from transformers import BartConfig, BartTokenizer, is_flax_available from transformers.testing_utils import require_flax, slow -from ..generation.test_generation_flax_utils import FlaxGenerationTesterMixin -from ..test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...generation.test_generation_flax_utils import FlaxGenerationTesterMixin +from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_flax_available(): diff --git a/tests/bart/test_modeling_tf_bart.py b/tests/models/bart/test_modeling_tf_bart.py similarity index 99% rename from tests/bart/test_modeling_tf_bart.py rename to tests/models/bart/test_modeling_tf_bart.py index 070d16e56b14..29c61a1e40e7 100644 --- a/tests/bart/test_modeling_tf_bart.py +++ b/tests/models/bart/test_modeling_tf_bart.py @@ -21,9 +21,9 @@ from transformers.testing_utils import require_tf, slow from transformers.utils import cached_property -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor -from ..utils.test_modeling_tf_core import TFCoreModelTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...utils.test_modeling_tf_core import TFCoreModelTesterMixin if is_tf_available(): diff --git a/tests/bart/test_tokenization_bart.py b/tests/models/bart/test_tokenization_bart.py similarity index 98% rename from tests/bart/test_tokenization_bart.py rename to tests/models/bart/test_tokenization_bart.py index 66e5e0b9e3ff..b8e216e69ba2 100644 --- a/tests/bart/test_tokenization_bart.py +++ b/tests/models/bart/test_tokenization_bart.py @@ -20,7 +20,7 @@ from transformers.testing_utils import require_tokenizers, require_torch from transformers.utils import cached_property -from ..test_tokenization_common import TokenizerTesterMixin, filter_roberta_detectors +from ...test_tokenization_common import TokenizerTesterMixin, filter_roberta_detectors @require_tokenizers diff --git a/tests/bartpho/__init__.py b/tests/models/barthez/__init__.py similarity index 100% rename from tests/bartpho/__init__.py rename to tests/models/barthez/__init__.py diff --git a/tests/barthez/test_tokenization_barthez.py b/tests/models/barthez/test_tokenization_barthez.py similarity index 98% rename from tests/barthez/test_tokenization_barthez.py rename to tests/models/barthez/test_tokenization_barthez.py index 2738ec6e306f..38acf046b4f3 100644 --- a/tests/barthez/test_tokenization_barthez.py +++ b/tests/models/barthez/test_tokenization_barthez.py @@ -18,7 +18,7 @@ from transformers import BarthezTokenizer, BarthezTokenizerFast, BatchEncoding from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_tokenizers diff --git a/tests/beit/__init__.py b/tests/models/bartpho/__init__.py similarity index 100% rename from tests/beit/__init__.py rename to tests/models/bartpho/__init__.py diff --git a/tests/bartpho/test_tokenization_bartpho.py b/tests/models/bartpho/test_tokenization_bartpho.py similarity index 92% rename from tests/bartpho/test_tokenization_bartpho.py rename to tests/models/bartpho/test_tokenization_bartpho.py index 3e35ad15c1ee..fc5ebfd19c4a 100644 --- a/tests/bartpho/test_tokenization_bartpho.py +++ b/tests/models/bartpho/test_tokenization_bartpho.py @@ -15,14 +15,14 @@ import os import unittest -from os.path import dirname from transformers.models.bartpho.tokenization_bartpho import VOCAB_FILES_NAMES, BartphoTokenizer +from transformers.testing_utils import get_tests_dir -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece_bpe.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece_bpe.model") class BartphoTokenizerTest(TokenizerTesterMixin, unittest.TestCase): diff --git a/tests/bert/__init__.py b/tests/models/beit/__init__.py similarity index 100% rename from tests/bert/__init__.py rename to tests/models/beit/__init__.py diff --git a/tests/beit/test_feature_extraction_beit.py b/tests/models/beit/test_feature_extraction_beit.py similarity index 99% rename from tests/beit/test_feature_extraction_beit.py rename to tests/models/beit/test_feature_extraction_beit.py index 71d78a266081..a9338aea1fc1 100644 --- a/tests/beit/test_feature_extraction_beit.py +++ b/tests/models/beit/test_feature_extraction_beit.py @@ -22,7 +22,7 @@ from transformers.testing_utils import require_torch, require_vision from transformers.utils import is_torch_available, is_vision_available -from ..test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs +from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs if is_torch_available(): diff --git a/tests/beit/test_modeling_beit.py b/tests/models/beit/test_modeling_beit.py similarity index 99% rename from tests/beit/test_modeling_beit.py rename to tests/models/beit/test_modeling_beit.py index ee75019435ea..8c9202c34b10 100644 --- a/tests/beit/test_modeling_beit.py +++ b/tests/models/beit/test_modeling_beit.py @@ -26,8 +26,8 @@ from transformers.testing_utils import require_torch, require_vision, slow, torch_device from transformers.utils import cached_property, is_torch_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/beit/test_modeling_flax_beit.py b/tests/models/beit/test_modeling_flax_beit.py similarity index 98% rename from tests/beit/test_modeling_flax_beit.py rename to tests/models/beit/test_modeling_flax_beit.py index a8a53eda6e9a..50996dedc7af 100644 --- a/tests/beit/test_modeling_flax_beit.py +++ b/tests/models/beit/test_modeling_flax_beit.py @@ -21,8 +21,8 @@ from transformers.testing_utils import require_flax, require_vision, slow from transformers.utils import cached_property, is_flax_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor if is_flax_available(): diff --git a/tests/bert_generation/__init__.py b/tests/models/bert/__init__.py similarity index 100% rename from tests/bert_generation/__init__.py rename to tests/models/bert/__init__.py diff --git a/tests/bert/test_modeling_bert.py b/tests/models/bert/test_modeling_bert.py old mode 100755 new mode 100644 similarity index 99% rename from tests/bert/test_modeling_bert.py rename to tests/models/bert/test_modeling_bert.py index efef037627fa..ca4223aacd42 --- a/tests/bert/test_modeling_bert.py +++ b/tests/models/bert/test_modeling_bert.py @@ -20,9 +20,9 @@ from transformers.models.auto import get_values from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/bert/test_modeling_flax_bert.py b/tests/models/bert/test_modeling_flax_bert.py similarity index 98% rename from tests/bert/test_modeling_flax_bert.py rename to tests/models/bert/test_modeling_flax_bert.py index 8914170c18fe..5516c4d6fe67 100644 --- a/tests/bert/test_modeling_flax_bert.py +++ b/tests/models/bert/test_modeling_flax_bert.py @@ -19,7 +19,7 @@ from transformers import BertConfig, is_flax_available from transformers.testing_utils import require_flax, slow -from ..test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_flax_available(): diff --git a/tests/bert/test_modeling_tf_bert.py b/tests/models/bert/test_modeling_tf_bert.py similarity index 99% rename from tests/bert/test_modeling_tf_bert.py rename to tests/models/bert/test_modeling_tf_bert.py index 8c709e093801..e83ae9f71802 100644 --- a/tests/bert/test_modeling_tf_bert.py +++ b/tests/models/bert/test_modeling_tf_bert.py @@ -20,9 +20,9 @@ from transformers.models.auto import get_values from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask -from ..utils.test_modeling_tf_core import TFCoreModelTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...utils.test_modeling_tf_core import TFCoreModelTesterMixin if is_tf_available(): diff --git a/tests/bert/test_tokenization_bert.py b/tests/models/bert/test_tokenization_bert.py similarity index 99% rename from tests/bert/test_tokenization_bert.py rename to tests/models/bert/test_tokenization_bert.py index f53482eef756..fcb69914b94d 100644 --- a/tests/bert/test_tokenization_bert.py +++ b/tests/models/bert/test_tokenization_bert.py @@ -29,7 +29,7 @@ ) from transformers.testing_utils import require_tokenizers, slow -from ..test_tokenization_common import TokenizerTesterMixin, filter_non_english +from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english @require_tokenizers diff --git a/tests/bert_japanese/__init__.py b/tests/models/bert_generation/__init__.py similarity index 100% rename from tests/bert_japanese/__init__.py rename to tests/models/bert_generation/__init__.py diff --git a/tests/bert_generation/test_modeling_bert_generation.py b/tests/models/bert_generation/test_modeling_bert_generation.py old mode 100755 new mode 100644 similarity index 98% rename from tests/bert_generation/test_modeling_bert_generation.py rename to tests/models/bert_generation/test_modeling_bert_generation.py index 73cd77ac0f33..f5cbd61a1d60 --- a/tests/bert_generation/test_modeling_bert_generation.py +++ b/tests/models/bert_generation/test_modeling_bert_generation.py @@ -19,9 +19,9 @@ from transformers import BertGenerationConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/bert_generation/test_tokenization_bert_generation.py b/tests/models/bert_generation/test_tokenization_bert_generation.py similarity index 96% rename from tests/bert_generation/test_tokenization_bert_generation.py rename to tests/models/bert_generation/test_tokenization_bert_generation.py index d21589526bab..155f383a4600 100644 --- a/tests/bert_generation/test_tokenization_bert_generation.py +++ b/tests/models/bert_generation/test_tokenization_bert_generation.py @@ -13,20 +13,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import unittest -from os.path import dirname from transformers import BertGenerationTokenizer -from transformers.testing_utils import require_sentencepiece, require_torch, slow +from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_torch, slow from transformers.utils import cached_property -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin SPIECE_UNDERLINE = "▁" -SAMPLE_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece.model") @require_sentencepiece diff --git a/tests/bertweet/__init__.py b/tests/models/bert_japanese/__init__.py similarity index 100% rename from tests/bertweet/__init__.py rename to tests/models/bert_japanese/__init__.py diff --git a/tests/bert_japanese/test_tokenization_bert_japanese.py b/tests/models/bert_japanese/test_tokenization_bert_japanese.py similarity index 99% rename from tests/bert_japanese/test_tokenization_bert_japanese.py rename to tests/models/bert_japanese/test_tokenization_bert_japanese.py index 47a7d2ea036d..59605bac1412 100644 --- a/tests/bert_japanese/test_tokenization_bert_japanese.py +++ b/tests/models/bert_japanese/test_tokenization_bert_japanese.py @@ -29,7 +29,7 @@ ) from transformers.testing_utils import custom_tokenizers -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @custom_tokenizers diff --git a/tests/big_bird/__init__.py b/tests/models/bertweet/__init__.py similarity index 100% rename from tests/big_bird/__init__.py rename to tests/models/bertweet/__init__.py diff --git a/tests/bertweet/test_tokenization_bertweet.py b/tests/models/bertweet/test_tokenization_bertweet.py similarity index 97% rename from tests/bertweet/test_tokenization_bertweet.py rename to tests/models/bertweet/test_tokenization_bertweet.py index edeb8ae81a9d..5f82fba51675 100644 --- a/tests/bertweet/test_tokenization_bertweet.py +++ b/tests/models/bertweet/test_tokenization_bertweet.py @@ -18,7 +18,7 @@ from transformers.models.bertweet.tokenization_bertweet import VOCAB_FILES_NAMES, BertweetTokenizer -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin class BertweetTokenizationTest(TokenizerTesterMixin, unittest.TestCase): diff --git a/tests/bigbird_pegasus/__init__.py b/tests/models/big_bird/__init__.py similarity index 100% rename from tests/bigbird_pegasus/__init__.py rename to tests/models/big_bird/__init__.py diff --git a/tests/big_bird/test_modeling_big_bird.py b/tests/models/big_bird/test_modeling_big_bird.py similarity index 99% rename from tests/big_bird/test_modeling_big_bird.py rename to tests/models/big_bird/test_modeling_big_bird.py index 24b88fd42372..90e6bbb90e17 100644 --- a/tests/big_bird/test_modeling_big_bird.py +++ b/tests/models/big_bird/test_modeling_big_bird.py @@ -22,8 +22,8 @@ from transformers.models.big_bird.tokenization_big_bird import BigBirdTokenizer from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/big_bird/test_modeling_flax_big_bird.py b/tests/models/big_bird/test_modeling_flax_big_bird.py similarity index 98% rename from tests/big_bird/test_modeling_flax_big_bird.py rename to tests/models/big_bird/test_modeling_flax_big_bird.py index f8f154190f1d..5c5452441e0b 100644 --- a/tests/big_bird/test_modeling_flax_big_bird.py +++ b/tests/models/big_bird/test_modeling_flax_big_bird.py @@ -19,7 +19,7 @@ from transformers import BigBirdConfig, is_flax_available from transformers.testing_utils import require_flax, slow -from ..test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask +from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask if is_flax_available(): diff --git a/tests/big_bird/test_tokenization_big_bird.py b/tests/models/big_bird/test_tokenization_big_bird.py similarity index 97% rename from tests/big_bird/test_tokenization_big_bird.py rename to tests/models/big_bird/test_tokenization_big_bird.py index d1d0daeda7e9..29c28d5877d2 100644 --- a/tests/big_bird/test_tokenization_big_bird.py +++ b/tests/models/big_bird/test_tokenization_big_bird.py @@ -13,20 +13,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import unittest -from os.path import dirname from transformers import BigBirdTokenizer, BigBirdTokenizerFast -from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow +from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, require_torch, slow from transformers.utils import cached_property -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin SPIECE_UNDERLINE = "▁" -SAMPLE_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece.model") @require_sentencepiece diff --git a/tests/blenderbot/__init__.py b/tests/models/bigbird_pegasus/__init__.py similarity index 100% rename from tests/blenderbot/__init__.py rename to tests/models/bigbird_pegasus/__init__.py diff --git a/tests/bigbird_pegasus/test_modeling_bigbird_pegasus.py b/tests/models/bigbird_pegasus/test_modeling_bigbird_pegasus.py similarity index 99% rename from tests/bigbird_pegasus/test_modeling_bigbird_pegasus.py rename to tests/models/bigbird_pegasus/test_modeling_bigbird_pegasus.py index eebdb0a91c11..31f109fbcf61 100644 --- a/tests/bigbird_pegasus/test_modeling_bigbird_pegasus.py +++ b/tests/models/bigbird_pegasus/test_modeling_bigbird_pegasus.py @@ -22,9 +22,9 @@ from transformers import BigBirdPegasusConfig, is_torch_available from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/blenderbot_small/__init__.py b/tests/models/blenderbot/__init__.py similarity index 100% rename from tests/blenderbot_small/__init__.py rename to tests/models/blenderbot/__init__.py diff --git a/tests/blenderbot/test_modeling_blenderbot.py b/tests/models/blenderbot/test_modeling_blenderbot.py similarity index 99% rename from tests/blenderbot/test_modeling_blenderbot.py rename to tests/models/blenderbot/test_modeling_blenderbot.py index 4a8070bfa79c..6bf71384671c 100644 --- a/tests/blenderbot/test_modeling_blenderbot.py +++ b/tests/models/blenderbot/test_modeling_blenderbot.py @@ -21,9 +21,9 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device from transformers.utils import cached_property -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/blenderbot/test_modeling_flax_blenderbot.py b/tests/models/blenderbot/test_modeling_flax_blenderbot.py similarity index 99% rename from tests/blenderbot/test_modeling_flax_blenderbot.py rename to tests/models/blenderbot/test_modeling_flax_blenderbot.py index cf6b8b9083b2..fad60bcced9d 100644 --- a/tests/blenderbot/test_modeling_flax_blenderbot.py +++ b/tests/models/blenderbot/test_modeling_flax_blenderbot.py @@ -20,8 +20,8 @@ from transformers import BlenderbotConfig, is_flax_available from transformers.testing_utils import jax_device, require_flax, slow -from ..generation.test_generation_flax_utils import FlaxGenerationTesterMixin -from ..test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor +from ...generation.test_generation_flax_utils import FlaxGenerationTesterMixin +from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor if is_flax_available(): diff --git a/tests/blenderbot/test_modeling_tf_blenderbot.py b/tests/models/blenderbot/test_modeling_tf_blenderbot.py similarity index 99% rename from tests/blenderbot/test_modeling_tf_blenderbot.py rename to tests/models/blenderbot/test_modeling_tf_blenderbot.py index e9e9816b1782..a8ca54558f06 100644 --- a/tests/blenderbot/test_modeling_tf_blenderbot.py +++ b/tests/models/blenderbot/test_modeling_tf_blenderbot.py @@ -20,8 +20,8 @@ from transformers.testing_utils import require_tf, require_tokenizers, slow from transformers.utils import cached_property -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor if is_tf_available(): diff --git a/tests/blenderbot/test_tokenization_blenderbot.py b/tests/models/blenderbot/test_tokenization_blenderbot.py similarity index 100% rename from tests/blenderbot/test_tokenization_blenderbot.py rename to tests/models/blenderbot/test_tokenization_blenderbot.py diff --git a/tests/bort/__init__.py b/tests/models/blenderbot_small/__init__.py similarity index 100% rename from tests/bort/__init__.py rename to tests/models/blenderbot_small/__init__.py diff --git a/tests/blenderbot_small/test_modeling_blenderbot_small.py b/tests/models/blenderbot_small/test_modeling_blenderbot_small.py similarity index 99% rename from tests/blenderbot_small/test_modeling_blenderbot_small.py rename to tests/models/blenderbot_small/test_modeling_blenderbot_small.py index 7e8ce4b624e0..b046fa97d9e9 100644 --- a/tests/blenderbot_small/test_modeling_blenderbot_small.py +++ b/tests/models/blenderbot_small/test_modeling_blenderbot_small.py @@ -21,9 +21,9 @@ from transformers.testing_utils import require_torch, slow, torch_device from transformers.utils import cached_property -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/blenderbot_small/test_modeling_flax_blenderbot_small.py b/tests/models/blenderbot_small/test_modeling_flax_blenderbot_small.py similarity index 99% rename from tests/blenderbot_small/test_modeling_flax_blenderbot_small.py rename to tests/models/blenderbot_small/test_modeling_flax_blenderbot_small.py index 6f674624265f..3cbacfc8d892 100644 --- a/tests/blenderbot_small/test_modeling_flax_blenderbot_small.py +++ b/tests/models/blenderbot_small/test_modeling_flax_blenderbot_small.py @@ -20,8 +20,8 @@ from transformers import BlenderbotSmallConfig, is_flax_available from transformers.testing_utils import require_flax, slow -from ..generation.test_generation_flax_utils import FlaxGenerationTesterMixin -from ..test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor +from ...generation.test_generation_flax_utils import FlaxGenerationTesterMixin +from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor if is_flax_available(): diff --git a/tests/blenderbot_small/test_modeling_tf_blenderbot_small.py b/tests/models/blenderbot_small/test_modeling_tf_blenderbot_small.py similarity index 99% rename from tests/blenderbot_small/test_modeling_tf_blenderbot_small.py rename to tests/models/blenderbot_small/test_modeling_tf_blenderbot_small.py index 33c5b286c9cf..a830e6c0b6c8 100644 --- a/tests/blenderbot_small/test_modeling_tf_blenderbot_small.py +++ b/tests/models/blenderbot_small/test_modeling_tf_blenderbot_small.py @@ -20,8 +20,8 @@ from transformers.testing_utils import require_tf, require_tokenizers, slow from transformers.utils import cached_property -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor if is_tf_available(): diff --git a/tests/blenderbot_small/test_tokenization_blenderbot_small.py b/tests/models/blenderbot_small/test_tokenization_blenderbot_small.py similarity index 98% rename from tests/blenderbot_small/test_tokenization_blenderbot_small.py rename to tests/models/blenderbot_small/test_tokenization_blenderbot_small.py index 38c3f8391d22..7ea7f09b5764 100644 --- a/tests/blenderbot_small/test_tokenization_blenderbot_small.py +++ b/tests/models/blenderbot_small/test_tokenization_blenderbot_small.py @@ -23,7 +23,7 @@ BlenderbotSmallTokenizer, ) -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin class BlenderbotSmallTokenizerTest(TokenizerTesterMixin, unittest.TestCase): diff --git a/tests/byt5/__init__.py b/tests/models/bort/__init__.py similarity index 100% rename from tests/byt5/__init__.py rename to tests/models/bort/__init__.py diff --git a/tests/bort/test_modeling_bort.py b/tests/models/bort/test_modeling_bort.py similarity index 100% rename from tests/bort/test_modeling_bort.py rename to tests/models/bort/test_modeling_bort.py diff --git a/tests/bort/test_modeling_tf_bort.py b/tests/models/bort/test_modeling_tf_bort.py similarity index 100% rename from tests/bort/test_modeling_tf_bort.py rename to tests/models/bort/test_modeling_tf_bort.py diff --git a/tests/camembert/__init__.py b/tests/models/byt5/__init__.py similarity index 100% rename from tests/camembert/__init__.py rename to tests/models/byt5/__init__.py diff --git a/tests/byt5/test_tokenization_byt5.py b/tests/models/byt5/test_tokenization_byt5.py similarity index 99% rename from tests/byt5/test_tokenization_byt5.py rename to tests/models/byt5/test_tokenization_byt5.py index 7e4f97d3741b..70cfa40ef919 100644 --- a/tests/byt5/test_tokenization_byt5.py +++ b/tests/models/byt5/test_tokenization_byt5.py @@ -24,7 +24,7 @@ from transformers import AddedToken, BatchEncoding, ByT5Tokenizer from transformers.utils import cached_property, is_tf_available, is_torch_available -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin if is_torch_available(): diff --git a/tests/canine/__init__.py b/tests/models/camembert/__init__.py similarity index 100% rename from tests/canine/__init__.py rename to tests/models/camembert/__init__.py diff --git a/tests/camembert/test_modeling_camembert.py b/tests/models/camembert/test_modeling_camembert.py similarity index 100% rename from tests/camembert/test_modeling_camembert.py rename to tests/models/camembert/test_modeling_camembert.py diff --git a/tests/camembert/test_modeling_tf_camembert.py b/tests/models/camembert/test_modeling_tf_camembert.py similarity index 100% rename from tests/camembert/test_modeling_tf_camembert.py rename to tests/models/camembert/test_modeling_tf_camembert.py diff --git a/tests/camembert/test_tokenization_camembert.py b/tests/models/camembert/test_tokenization_camembert.py similarity index 93% rename from tests/camembert/test_tokenization_camembert.py rename to tests/models/camembert/test_tokenization_camembert.py index a2274e3b05bb..aff186d73cb0 100644 --- a/tests/camembert/test_tokenization_camembert.py +++ b/tests/models/camembert/test_tokenization_camembert.py @@ -13,19 +13,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import unittest -from os.path import dirname from transformers import CamembertTokenizer, CamembertTokenizerFast -from transformers.testing_utils import require_sentencepiece, require_tokenizers, slow +from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow from transformers.utils import is_torch_available -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece.model") -SAMPLE_BPE_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece_bpe.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece.model") +SAMPLE_BPE_VOCAB = get_tests_dir("fixtures/test_sentencepiece_bpe.model") FRAMEWORK = "pt" if is_torch_available() else "tf" diff --git a/tests/clip/__init__.py b/tests/models/canine/__init__.py similarity index 100% rename from tests/clip/__init__.py rename to tests/models/canine/__init__.py diff --git a/tests/canine/test_modeling_canine.py b/tests/models/canine/test_modeling_canine.py similarity index 99% rename from tests/canine/test_modeling_canine.py rename to tests/models/canine/test_modeling_canine.py index 5e3c37b37ede..483dd095a18b 100644 --- a/tests/canine/test_modeling_canine.py +++ b/tests/models/canine/test_modeling_canine.py @@ -21,8 +21,8 @@ from transformers import CanineConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, _config_zero_init, global_rng, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, _config_zero_init, global_rng, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/canine/test_tokenization_canine.py b/tests/models/canine/test_tokenization_canine.py similarity index 99% rename from tests/canine/test_tokenization_canine.py rename to tests/models/canine/test_tokenization_canine.py index 0a949e6d78fd..0e016d523b5c 100644 --- a/tests/canine/test_tokenization_canine.py +++ b/tests/models/canine/test_tokenization_canine.py @@ -24,7 +24,7 @@ from transformers.tokenization_utils import AddedToken from transformers.utils import cached_property -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin class CanineTokenizationTest(TokenizerTesterMixin, unittest.TestCase): diff --git a/tests/convbert/__init__.py b/tests/models/clip/__init__.py similarity index 100% rename from tests/convbert/__init__.py rename to tests/models/clip/__init__.py diff --git a/tests/clip/test_feature_extraction_clip.py b/tests/models/clip/test_feature_extraction_clip.py similarity index 99% rename from tests/clip/test_feature_extraction_clip.py rename to tests/models/clip/test_feature_extraction_clip.py index 85cb54510c8c..a3f0817ea0b2 100644 --- a/tests/clip/test_feature_extraction_clip.py +++ b/tests/models/clip/test_feature_extraction_clip.py @@ -21,7 +21,7 @@ from transformers.testing_utils import require_torch, require_vision from transformers.utils import is_torch_available, is_vision_available -from ..test_feature_extraction_common import FeatureExtractionSavingTestMixin +from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin if is_torch_available(): diff --git a/tests/clip/test_modeling_clip.py b/tests/models/clip/test_modeling_clip.py similarity index 99% rename from tests/clip/test_modeling_clip.py rename to tests/models/clip/test_modeling_clip.py index 88649b31455c..7ae1146159e6 100644 --- a/tests/clip/test_modeling_clip.py +++ b/tests/models/clip/test_modeling_clip.py @@ -35,8 +35,8 @@ ) from transformers.utils import is_torch_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ( +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ( ModelTesterMixin, _config_zero_init, floats_tensor, diff --git a/tests/clip/test_modeling_flax_clip.py b/tests/models/clip/test_modeling_flax_clip.py similarity index 99% rename from tests/clip/test_modeling_flax_clip.py rename to tests/models/clip/test_modeling_flax_clip.py index adad20befa72..b8a1030ad1b0 100644 --- a/tests/clip/test_modeling_flax_clip.py +++ b/tests/models/clip/test_modeling_flax_clip.py @@ -8,7 +8,7 @@ from transformers import CLIPConfig, CLIPTextConfig, CLIPVisionConfig, is_flax_available, is_torch_available from transformers.testing_utils import is_pt_flax_cross_test, require_flax, slow -from ..test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_flax_available(): diff --git a/tests/clip/test_modeling_tf_clip.py b/tests/models/clip/test_modeling_tf_clip.py similarity index 99% rename from tests/clip/test_modeling_tf_clip.py rename to tests/models/clip/test_modeling_tf_clip.py index 7ba935240622..ea572e6a2a51 100644 --- a/tests/clip/test_modeling_tf_clip.py +++ b/tests/models/clip/test_modeling_tf_clip.py @@ -26,8 +26,8 @@ from transformers.testing_utils import require_tf, require_vision, slow from transformers.utils import is_tf_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/clip/test_processor_clip.py b/tests/models/clip/test_processor_clip.py similarity index 100% rename from tests/clip/test_processor_clip.py rename to tests/models/clip/test_processor_clip.py diff --git a/tests/clip/test_tokenization_clip.py b/tests/models/clip/test_tokenization_clip.py similarity index 99% rename from tests/clip/test_tokenization_clip.py rename to tests/models/clip/test_tokenization_clip.py index 2ad48ca710a1..e9ba304b475d 100644 --- a/tests/clip/test_tokenization_clip.py +++ b/tests/models/clip/test_tokenization_clip.py @@ -22,7 +22,7 @@ from transformers.models.clip.tokenization_clip import VOCAB_FILES_NAMES from transformers.testing_utils import require_ftfy, require_tokenizers -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_tokenizers diff --git a/tests/convnext/__init__.py b/tests/models/convbert/__init__.py similarity index 100% rename from tests/convnext/__init__.py rename to tests/models/convbert/__init__.py diff --git a/tests/convbert/test_modeling_convbert.py b/tests/models/convbert/test_modeling_convbert.py similarity index 99% rename from tests/convbert/test_modeling_convbert.py rename to tests/models/convbert/test_modeling_convbert.py index a6b41b02d2da..d3eb0aec4cfc 100644 --- a/tests/convbert/test_modeling_convbert.py +++ b/tests/models/convbert/test_modeling_convbert.py @@ -21,8 +21,8 @@ from transformers.models.auto import get_values from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/convbert/test_modeling_tf_convbert.py b/tests/models/convbert/test_modeling_tf_convbert.py similarity index 99% rename from tests/convbert/test_modeling_tf_convbert.py rename to tests/models/convbert/test_modeling_tf_convbert.py index 2ae29c3e4a5a..ae675b878ed1 100644 --- a/tests/convbert/test_modeling_tf_convbert.py +++ b/tests/models/convbert/test_modeling_tf_convbert.py @@ -19,8 +19,8 @@ from transformers import ConvBertConfig, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/cpm/__init__.py b/tests/models/convnext/__init__.py similarity index 100% rename from tests/cpm/__init__.py rename to tests/models/convnext/__init__.py diff --git a/tests/convnext/test_feature_extraction_convnext.py b/tests/models/convnext/test_feature_extraction_convnext.py similarity index 98% rename from tests/convnext/test_feature_extraction_convnext.py rename to tests/models/convnext/test_feature_extraction_convnext.py index 8127d468b377..f02341972ba0 100644 --- a/tests/convnext/test_feature_extraction_convnext.py +++ b/tests/models/convnext/test_feature_extraction_convnext.py @@ -21,7 +21,7 @@ from transformers.testing_utils import require_torch, require_vision from transformers.utils import is_torch_available, is_vision_available -from ..test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs +from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs if is_torch_available(): diff --git a/tests/convnext/test_modeling_convnext.py b/tests/models/convnext/test_modeling_convnext.py similarity index 98% rename from tests/convnext/test_modeling_convnext.py rename to tests/models/convnext/test_modeling_convnext.py index 68a42f38af2d..f12a21bfe64c 100644 --- a/tests/convnext/test_modeling_convnext.py +++ b/tests/models/convnext/test_modeling_convnext.py @@ -22,8 +22,8 @@ from transformers.testing_utils import require_torch, require_vision, slow, torch_device from transformers.utils import cached_property, is_torch_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/convnext/test_modeling_tf_convnext.py b/tests/models/convnext/test_modeling_tf_convnext.py similarity index 98% rename from tests/convnext/test_modeling_tf_convnext.py rename to tests/models/convnext/test_modeling_tf_convnext.py index 579c27dd27a6..7b86a99fd435 100644 --- a/tests/convnext/test_modeling_tf_convnext.py +++ b/tests/models/convnext/test_modeling_tf_convnext.py @@ -22,8 +22,8 @@ from transformers.testing_utils import require_tf, require_vision, slow from transformers.utils import cached_property, is_tf_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor if is_tf_available(): diff --git a/tests/ctrl/__init__.py b/tests/models/cpm/__init__.py similarity index 100% rename from tests/ctrl/__init__.py rename to tests/models/cpm/__init__.py diff --git a/tests/cpm/test_tokenization_cpm.py b/tests/models/cpm/test_tokenization_cpm.py similarity index 100% rename from tests/cpm/test_tokenization_cpm.py rename to tests/models/cpm/test_tokenization_cpm.py diff --git a/tests/data2vec/__init__.py b/tests/models/ctrl/__init__.py similarity index 100% rename from tests/data2vec/__init__.py rename to tests/models/ctrl/__init__.py diff --git a/tests/ctrl/test_modeling_ctrl.py b/tests/models/ctrl/test_modeling_ctrl.py similarity index 97% rename from tests/ctrl/test_modeling_ctrl.py rename to tests/models/ctrl/test_modeling_ctrl.py index af754399b81a..0256a5718b5e 100644 --- a/tests/ctrl/test_modeling_ctrl.py +++ b/tests/models/ctrl/test_modeling_ctrl.py @@ -18,9 +18,9 @@ from transformers import CTRLConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/ctrl/test_modeling_tf_ctrl.py b/tests/models/ctrl/test_modeling_tf_ctrl.py similarity index 98% rename from tests/ctrl/test_modeling_tf_ctrl.py rename to tests/models/ctrl/test_modeling_tf_ctrl.py index d17a97a3ad83..d3e82e57c9f2 100644 --- a/tests/ctrl/test_modeling_tf_ctrl.py +++ b/tests/models/ctrl/test_modeling_tf_ctrl.py @@ -19,8 +19,8 @@ from transformers import CTRLConfig, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/ctrl/test_tokenization_ctrl.py b/tests/models/ctrl/test_tokenization_ctrl.py similarity index 97% rename from tests/ctrl/test_tokenization_ctrl.py rename to tests/models/ctrl/test_tokenization_ctrl.py index 54eb8d218683..0bd4d8c8065c 100644 --- a/tests/ctrl/test_tokenization_ctrl.py +++ b/tests/models/ctrl/test_tokenization_ctrl.py @@ -19,7 +19,7 @@ from transformers.models.ctrl.tokenization_ctrl import VOCAB_FILES_NAMES, CTRLTokenizer -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin class CTRLTokenizationTest(TokenizerTesterMixin, unittest.TestCase): diff --git a/tests/deberta/__init__.py b/tests/models/data2vec/__init__.py similarity index 100% rename from tests/deberta/__init__.py rename to tests/models/data2vec/__init__.py diff --git a/tests/data2vec/test_modeling_data2vec_audio.py b/tests/models/data2vec/test_modeling_data2vec_audio.py similarity index 99% rename from tests/data2vec/test_modeling_data2vec_audio.py rename to tests/models/data2vec/test_modeling_data2vec_audio.py index cec29518b2cb..87885268b261 100644 --- a/tests/data2vec/test_modeling_data2vec_audio.py +++ b/tests/models/data2vec/test_modeling_data2vec_audio.py @@ -24,8 +24,8 @@ from transformers import Data2VecAudioConfig, is_torch_available from transformers.testing_utils import is_pt_flax_cross_test, require_soundfile, require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, _config_zero_init +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, _config_zero_init if is_torch_available(): diff --git a/tests/data2vec/test_modeling_data2vec_text.py b/tests/models/data2vec/test_modeling_data2vec_text.py similarity index 99% rename from tests/data2vec/test_modeling_data2vec_text.py rename to tests/models/data2vec/test_modeling_data2vec_text.py index 8b27cefb74bd..f37d64044a02 100644 --- a/tests/data2vec/test_modeling_data2vec_text.py +++ b/tests/models/data2vec/test_modeling_data2vec_text.py @@ -20,9 +20,9 @@ from transformers import Data2VecTextConfig, is_torch_available from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin if is_torch_available(): diff --git a/tests/data2vec/test_modeling_data2vec_vision.py b/tests/models/data2vec/test_modeling_data2vec_vision.py similarity index 99% rename from tests/data2vec/test_modeling_data2vec_vision.py rename to tests/models/data2vec/test_modeling_data2vec_vision.py index 6005e9b37959..2dc9f1e45e52 100644 --- a/tests/data2vec/test_modeling_data2vec_vision.py +++ b/tests/models/data2vec/test_modeling_data2vec_vision.py @@ -23,8 +23,8 @@ from transformers.testing_utils import require_torch, require_vision, slow, torch_device from transformers.utils import cached_property, is_torch_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/deberta_v2/__init__.py b/tests/models/deberta/__init__.py similarity index 100% rename from tests/deberta_v2/__init__.py rename to tests/models/deberta/__init__.py diff --git a/tests/deberta/test_modeling_deberta.py b/tests/models/deberta/test_modeling_deberta.py similarity index 98% rename from tests/deberta/test_modeling_deberta.py rename to tests/models/deberta/test_modeling_deberta.py index 1902f9389d8d..8d2e2dd020aa 100644 --- a/tests/deberta/test_modeling_deberta.py +++ b/tests/models/deberta/test_modeling_deberta.py @@ -17,8 +17,8 @@ from transformers import DebertaConfig, is_torch_available from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/deberta/test_modeling_tf_deberta.py b/tests/models/deberta/test_modeling_tf_deberta.py similarity index 98% rename from tests/deberta/test_modeling_tf_deberta.py rename to tests/models/deberta/test_modeling_tf_deberta.py index 7e2a3c3110ee..c2584db30f19 100644 --- a/tests/deberta/test_modeling_tf_deberta.py +++ b/tests/models/deberta/test_modeling_tf_deberta.py @@ -19,8 +19,8 @@ from transformers import DebertaConfig, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/deberta/test_tokenization_deberta.py b/tests/models/deberta/test_tokenization_deberta.py similarity index 99% rename from tests/deberta/test_tokenization_deberta.py rename to tests/models/deberta/test_tokenization_deberta.py index 229ea2261813..dcbef8eae573 100644 --- a/tests/deberta/test_tokenization_deberta.py +++ b/tests/models/deberta/test_tokenization_deberta.py @@ -22,7 +22,7 @@ from transformers.models.deberta.tokenization_deberta import VOCAB_FILES_NAMES from transformers.testing_utils import slow -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin class DebertaTokenizationTest(TokenizerTesterMixin, unittest.TestCase): diff --git a/tests/decision_transformer/__init__.py b/tests/models/deberta_v2/__init__.py similarity index 100% rename from tests/decision_transformer/__init__.py rename to tests/models/deberta_v2/__init__.py diff --git a/tests/deberta_v2/test_modeling_deberta_v2.py b/tests/models/deberta_v2/test_modeling_deberta_v2.py similarity index 98% rename from tests/deberta_v2/test_modeling_deberta_v2.py rename to tests/models/deberta_v2/test_modeling_deberta_v2.py index 48f3a673b693..17cdf3ea8f93 100644 --- a/tests/deberta_v2/test_modeling_deberta_v2.py +++ b/tests/models/deberta_v2/test_modeling_deberta_v2.py @@ -17,8 +17,8 @@ from transformers import DebertaV2Config, is_torch_available from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/deberta_v2/test_modeling_tf_deberta_v2.py b/tests/models/deberta_v2/test_modeling_tf_deberta_v2.py similarity index 98% rename from tests/deberta_v2/test_modeling_tf_deberta_v2.py rename to tests/models/deberta_v2/test_modeling_tf_deberta_v2.py index 4fd967c2fa6e..b2cc8896e46e 100644 --- a/tests/deberta_v2/test_modeling_tf_deberta_v2.py +++ b/tests/models/deberta_v2/test_modeling_tf_deberta_v2.py @@ -19,8 +19,8 @@ from transformers import DebertaV2Config, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/deberta_v2/test_tokenization_deberta_v2.py b/tests/models/deberta_v2/test_tokenization_deberta_v2.py similarity index 97% rename from tests/deberta_v2/test_tokenization_deberta_v2.py rename to tests/models/deberta_v2/test_tokenization_deberta_v2.py index ee52c8706af9..c84034c7f0bc 100644 --- a/tests/deberta_v2/test_tokenization_deberta_v2.py +++ b/tests/models/deberta_v2/test_tokenization_deberta_v2.py @@ -13,17 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import unittest -from os.path import dirname from transformers import DebertaV2Tokenizer, DebertaV2TokenizerFast -from transformers.testing_utils import require_sentencepiece, require_tokenizers, slow +from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/spiece.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/spiece.model") @require_sentencepiece diff --git a/tests/deit/__init__.py b/tests/models/decision_transformer/__init__.py similarity index 100% rename from tests/deit/__init__.py rename to tests/models/decision_transformer/__init__.py diff --git a/tests/decision_transformer/test_modeling_decision_transformer.py b/tests/models/decision_transformer/test_modeling_decision_transformer.py similarity index 97% rename from tests/decision_transformer/test_modeling_decision_transformer.py rename to tests/models/decision_transformer/test_modeling_decision_transformer.py index 0843ce630ee3..9124c64fa1d4 100644 --- a/tests/decision_transformer/test_modeling_decision_transformer.py +++ b/tests/models/decision_transformer/test_modeling_decision_transformer.py @@ -21,9 +21,9 @@ from transformers import DecisionTransformerConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/detr/__init__.py b/tests/models/deit/__init__.py similarity index 100% rename from tests/detr/__init__.py rename to tests/models/deit/__init__.py diff --git a/tests/deit/test_feature_extraction_deit.py b/tests/models/deit/test_feature_extraction_deit.py similarity index 98% rename from tests/deit/test_feature_extraction_deit.py rename to tests/models/deit/test_feature_extraction_deit.py index 8eaa8313499c..92a477f182fc 100644 --- a/tests/deit/test_feature_extraction_deit.py +++ b/tests/models/deit/test_feature_extraction_deit.py @@ -21,7 +21,7 @@ from transformers.testing_utils import require_torch, require_vision from transformers.utils import is_torch_available, is_vision_available -from ..test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs +from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs if is_torch_available(): diff --git a/tests/deit/test_modeling_deit.py b/tests/models/deit/test_modeling_deit.py similarity index 99% rename from tests/deit/test_modeling_deit.py rename to tests/models/deit/test_modeling_deit.py index 5876b051fe72..4559fa0c7127 100644 --- a/tests/deit/test_modeling_deit.py +++ b/tests/models/deit/test_modeling_deit.py @@ -24,8 +24,8 @@ from transformers.testing_utils import require_torch, require_vision, slow, torch_device from transformers.utils import cached_property, is_torch_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/distilbert/__init__.py b/tests/models/detr/__init__.py similarity index 100% rename from tests/distilbert/__init__.py rename to tests/models/detr/__init__.py diff --git a/tests/detr/test_feature_extraction_detr.py b/tests/models/detr/test_feature_extraction_detr.py similarity index 99% rename from tests/detr/test_feature_extraction_detr.py rename to tests/models/detr/test_feature_extraction_detr.py index 0f88d57c7347..58bde80fbbb1 100644 --- a/tests/detr/test_feature_extraction_detr.py +++ b/tests/models/detr/test_feature_extraction_detr.py @@ -23,7 +23,7 @@ from transformers.testing_utils import require_torch, require_vision, slow from transformers.utils import is_torch_available, is_vision_available -from ..test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs +from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs if is_torch_available(): diff --git a/tests/detr/test_modeling_detr.py b/tests/models/detr/test_modeling_detr.py similarity index 99% rename from tests/detr/test_modeling_detr.py rename to tests/models/detr/test_modeling_detr.py index 45fb37019939..7b0b7eeb7545 100644 --- a/tests/detr/test_modeling_detr.py +++ b/tests/models/detr/test_modeling_detr.py @@ -23,9 +23,9 @@ from transformers.testing_utils import require_timm, require_vision, slow, torch_device from transformers.utils import cached_property -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor if is_timm_available(): diff --git a/tests/dit/__init__.py b/tests/models/distilbert/__init__.py similarity index 100% rename from tests/dit/__init__.py rename to tests/models/distilbert/__init__.py diff --git a/tests/distilbert/test_modeling_distilbert.py b/tests/models/distilbert/test_modeling_distilbert.py similarity index 98% rename from tests/distilbert/test_modeling_distilbert.py rename to tests/models/distilbert/test_modeling_distilbert.py index 2dfd31ac064b..9b4606b484ee 100644 --- a/tests/distilbert/test_modeling_distilbert.py +++ b/tests/models/distilbert/test_modeling_distilbert.py @@ -19,8 +19,8 @@ from transformers import DistilBertConfig, is_torch_available from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/distilbert/test_modeling_flax_distilbert.py b/tests/models/distilbert/test_modeling_flax_distilbert.py similarity index 98% rename from tests/distilbert/test_modeling_flax_distilbert.py rename to tests/models/distilbert/test_modeling_flax_distilbert.py index 2ad10c07859e..e0f609b4ddf3 100644 --- a/tests/distilbert/test_modeling_flax_distilbert.py +++ b/tests/models/distilbert/test_modeling_flax_distilbert.py @@ -19,7 +19,7 @@ from transformers import DistilBertConfig, is_flax_available from transformers.testing_utils import require_flax, slow -from ..test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask +from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask if is_flax_available(): diff --git a/tests/distilbert/test_modeling_tf_distilbert.py b/tests/models/distilbert/test_modeling_tf_distilbert.py similarity index 98% rename from tests/distilbert/test_modeling_tf_distilbert.py rename to tests/models/distilbert/test_modeling_tf_distilbert.py index 5266723f1f86..e52532d5618a 100644 --- a/tests/distilbert/test_modeling_tf_distilbert.py +++ b/tests/models/distilbert/test_modeling_tf_distilbert.py @@ -19,8 +19,8 @@ from transformers import DistilBertConfig, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/distilbert/test_tokenization_distilbert.py b/tests/models/distilbert/test_tokenization_distilbert.py similarity index 100% rename from tests/distilbert/test_tokenization_distilbert.py rename to tests/models/distilbert/test_tokenization_distilbert.py diff --git a/tests/dpr/__init__.py b/tests/models/dit/__init__.py similarity index 100% rename from tests/dpr/__init__.py rename to tests/models/dit/__init__.py diff --git a/tests/dit/test_modeling_dit.py b/tests/models/dit/test_modeling_dit.py similarity index 100% rename from tests/dit/test_modeling_dit.py rename to tests/models/dit/test_modeling_dit.py diff --git a/tests/dpt/__init__.py b/tests/models/dpr/__init__.py similarity index 100% rename from tests/dpt/__init__.py rename to tests/models/dpr/__init__.py diff --git a/tests/dpr/test_modeling_dpr.py b/tests/models/dpr/test_modeling_dpr.py similarity index 98% rename from tests/dpr/test_modeling_dpr.py rename to tests/models/dpr/test_modeling_dpr.py index 7aef57f753aa..708f1d53c3a4 100644 --- a/tests/dpr/test_modeling_dpr.py +++ b/tests/models/dpr/test_modeling_dpr.py @@ -20,8 +20,8 @@ from transformers import DPRConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/dpr/test_modeling_tf_dpr.py b/tests/models/dpr/test_modeling_tf_dpr.py similarity index 98% rename from tests/dpr/test_modeling_tf_dpr.py rename to tests/models/dpr/test_modeling_tf_dpr.py index ffce36efc3a6..86ef3837f1fa 100644 --- a/tests/dpr/test_modeling_tf_dpr.py +++ b/tests/models/dpr/test_modeling_tf_dpr.py @@ -18,8 +18,8 @@ from transformers import is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/dpr/test_tokenization_dpr.py b/tests/models/dpr/test_tokenization_dpr.py similarity index 100% rename from tests/dpr/test_tokenization_dpr.py rename to tests/models/dpr/test_tokenization_dpr.py diff --git a/tests/electra/__init__.py b/tests/models/dpt/__init__.py similarity index 100% rename from tests/electra/__init__.py rename to tests/models/dpt/__init__.py diff --git a/tests/dpt/test_feature_extraction_dpt.py b/tests/models/dpt/test_feature_extraction_dpt.py similarity index 98% rename from tests/dpt/test_feature_extraction_dpt.py rename to tests/models/dpt/test_feature_extraction_dpt.py index 83abb59eec4f..a0cf1cba23af 100644 --- a/tests/dpt/test_feature_extraction_dpt.py +++ b/tests/models/dpt/test_feature_extraction_dpt.py @@ -21,7 +21,7 @@ from transformers.file_utils import is_torch_available, is_vision_available from transformers.testing_utils import require_torch, require_vision -from ..test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs +from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs if is_torch_available(): diff --git a/tests/dpt/test_modeling_dpt.py b/tests/models/dpt/test_modeling_dpt.py similarity index 98% rename from tests/dpt/test_modeling_dpt.py rename to tests/models/dpt/test_modeling_dpt.py index f908bd8dc1e3..3266ea78a71a 100644 --- a/tests/dpt/test_modeling_dpt.py +++ b/tests/models/dpt/test_modeling_dpt.py @@ -23,8 +23,8 @@ from transformers.models.auto import get_values from transformers.testing_utils import require_torch, require_vision, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/encoder_decoder/__init__.py b/tests/models/electra/__init__.py similarity index 100% rename from tests/encoder_decoder/__init__.py rename to tests/models/electra/__init__.py diff --git a/tests/electra/test_modeling_electra.py b/tests/models/electra/test_modeling_electra.py similarity index 99% rename from tests/electra/test_modeling_electra.py rename to tests/models/electra/test_modeling_electra.py index 4a6a1b1357e4..9a6ba063ea3d 100644 --- a/tests/electra/test_modeling_electra.py +++ b/tests/models/electra/test_modeling_electra.py @@ -20,8 +20,8 @@ from transformers.models.auto import get_values from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/electra/test_modeling_flax_electra.py b/tests/models/electra/test_modeling_flax_electra.py similarity index 98% rename from tests/electra/test_modeling_flax_electra.py rename to tests/models/electra/test_modeling_flax_electra.py index b7726dc1e8f7..cd1a795a19ef 100644 --- a/tests/electra/test_modeling_flax_electra.py +++ b/tests/models/electra/test_modeling_flax_electra.py @@ -5,7 +5,7 @@ from transformers import ElectraConfig, is_flax_available from transformers.testing_utils import require_flax, slow -from ..test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask +from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask if is_flax_available(): diff --git a/tests/electra/test_modeling_tf_electra.py b/tests/models/electra/test_modeling_tf_electra.py similarity index 99% rename from tests/electra/test_modeling_tf_electra.py rename to tests/models/electra/test_modeling_tf_electra.py index ff2acd37e69f..0c0c4f77ab32 100644 --- a/tests/electra/test_modeling_tf_electra.py +++ b/tests/models/electra/test_modeling_tf_electra.py @@ -19,8 +19,8 @@ from transformers import ElectraConfig, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/flaubert/__init__.py b/tests/models/encoder_decoder/__init__.py similarity index 100% rename from tests/flaubert/__init__.py rename to tests/models/encoder_decoder/__init__.py diff --git a/tests/encoder_decoder/test_modeling_encoder_decoder.py b/tests/models/encoder_decoder/test_modeling_encoder_decoder.py similarity index 99% rename from tests/encoder_decoder/test_modeling_encoder_decoder.py rename to tests/models/encoder_decoder/test_modeling_encoder_decoder.py index 8412ccb3894a..b356b3ee0ba1 100644 --- a/tests/encoder_decoder/test_modeling_encoder_decoder.py +++ b/tests/models/encoder_decoder/test_modeling_encoder_decoder.py @@ -20,13 +20,13 @@ from transformers import is_torch_available from transformers.testing_utils import require_torch, slow, torch_device +from ...test_modeling_common import ids_tensor from ..bart.test_modeling_bart import BartStandaloneDecoderModelTester from ..bert.test_modeling_bert import BertModelTester from ..bert_generation.test_modeling_bert_generation import BertGenerationEncoderTester from ..gpt2.test_modeling_gpt2 import GPT2ModelTester from ..prophetnet.test_modeling_prophetnet import ProphetNetStandaloneDecoderModelTester from ..roberta.test_modeling_roberta import RobertaModelTester -from ..test_modeling_common import ids_tensor if is_torch_available(): diff --git a/tests/encoder_decoder/test_modeling_flax_encoder_decoder.py b/tests/models/encoder_decoder/test_modeling_flax_encoder_decoder.py similarity index 99% rename from tests/encoder_decoder/test_modeling_flax_encoder_decoder.py rename to tests/models/encoder_decoder/test_modeling_flax_encoder_decoder.py index cdc0cc119759..ce7a79ead2fe 100644 --- a/tests/encoder_decoder/test_modeling_flax_encoder_decoder.py +++ b/tests/models/encoder_decoder/test_modeling_flax_encoder_decoder.py @@ -22,10 +22,10 @@ from transformers import is_flax_available, is_torch_available from transformers.testing_utils import is_pt_flax_cross_test, require_flax, slow, torch_device +from ...test_modeling_flax_common import ids_tensor from ..bart.test_modeling_flax_bart import FlaxBartStandaloneDecoderModelTester from ..bert.test_modeling_flax_bert import FlaxBertModelTester from ..gpt2.test_modeling_flax_gpt2 import FlaxGPT2ModelTester -from ..test_modeling_flax_common import ids_tensor if is_flax_available(): diff --git a/tests/encoder_decoder/test_modeling_tf_encoder_decoder.py b/tests/models/encoder_decoder/test_modeling_tf_encoder_decoder.py similarity index 99% rename from tests/encoder_decoder/test_modeling_tf_encoder_decoder.py rename to tests/models/encoder_decoder/test_modeling_tf_encoder_decoder.py index bedd72fe247b..74eb59b4e016 100644 --- a/tests/encoder_decoder/test_modeling_tf_encoder_decoder.py +++ b/tests/models/encoder_decoder/test_modeling_tf_encoder_decoder.py @@ -24,11 +24,11 @@ from transformers import is_tf_available, is_torch_available from transformers.testing_utils import is_pt_tf_cross_test, require_tf, require_torch, slow, torch_device +from ...test_modeling_tf_common import ids_tensor from ..bert.test_modeling_tf_bert import TFBertModelTester from ..gpt2.test_modeling_tf_gpt2 import TFGPT2ModelTester from ..rembert.test_modeling_tf_rembert import TFRemBertModelTester from ..roberta.test_modeling_tf_roberta import TFRobertaModelTester -from ..test_modeling_tf_common import ids_tensor if is_tf_available(): diff --git a/tests/fnet/__init__.py b/tests/models/flaubert/__init__.py similarity index 100% rename from tests/fnet/__init__.py rename to tests/models/flaubert/__init__.py diff --git a/tests/flaubert/test_modeling_flaubert.py b/tests/models/flaubert/test_modeling_flaubert.py similarity index 99% rename from tests/flaubert/test_modeling_flaubert.py rename to tests/models/flaubert/test_modeling_flaubert.py index 4c01abd459e8..da29cac6dd58 100644 --- a/tests/flaubert/test_modeling_flaubert.py +++ b/tests/models/flaubert/test_modeling_flaubert.py @@ -19,8 +19,8 @@ from transformers import FlaubertConfig, is_torch_available from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/flaubert/test_modeling_tf_flaubert.py b/tests/models/flaubert/test_modeling_tf_flaubert.py similarity index 98% rename from tests/flaubert/test_modeling_tf_flaubert.py rename to tests/models/flaubert/test_modeling_tf_flaubert.py index 86bcd6ea6484..09ba6f45d8d0 100644 --- a/tests/flaubert/test_modeling_tf_flaubert.py +++ b/tests/models/flaubert/test_modeling_tf_flaubert.py @@ -18,8 +18,8 @@ from transformers import is_tf_available from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/fsmt/__init__.py b/tests/models/fnet/__init__.py similarity index 100% rename from tests/fsmt/__init__.py rename to tests/models/fnet/__init__.py diff --git a/tests/fnet/test_modeling_fnet.py b/tests/models/fnet/test_modeling_fnet.py similarity index 99% rename from tests/fnet/test_modeling_fnet.py rename to tests/models/fnet/test_modeling_fnet.py index b175bf3a5403..0abf51fb5d75 100644 --- a/tests/fnet/test_modeling_fnet.py +++ b/tests/models/fnet/test_modeling_fnet.py @@ -22,8 +22,8 @@ from transformers.models.auto import get_values from transformers.testing_utils import require_tokenizers, require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/fnet/test_tokenization_fnet.py b/tests/models/fnet/test_tokenization_fnet.py similarity index 98% rename from tests/fnet/test_tokenization_fnet.py rename to tests/models/fnet/test_tokenization_fnet.py index a620ccf1f3b1..0058155bdb6d 100644 --- a/tests/fnet/test_tokenization_fnet.py +++ b/tests/models/fnet/test_tokenization_fnet.py @@ -13,17 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import unittest from transformers import FNetTokenizer, FNetTokenizerFast -from transformers.testing_utils import require_sentencepiece, require_tokenizers, slow, tooslow +from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow, tooslow from transformers.tokenization_utils import AddedToken -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_VOCAB = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../fixtures/spiece.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/spiece.model") @require_sentencepiece diff --git a/tests/funnel/__init__.py b/tests/models/fsmt/__init__.py similarity index 100% rename from tests/funnel/__init__.py rename to tests/models/fsmt/__init__.py diff --git a/tests/fsmt/test_modeling_fsmt.py b/tests/models/fsmt/test_modeling_fsmt.py similarity index 99% rename from tests/fsmt/test_modeling_fsmt.py rename to tests/models/fsmt/test_modeling_fsmt.py index c452a5729b10..9e487b609aae 100644 --- a/tests/fsmt/test_modeling_fsmt.py +++ b/tests/models/fsmt/test_modeling_fsmt.py @@ -23,9 +23,9 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device from transformers.utils import cached_property -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/fsmt/test_tokenization_fsmt.py b/tests/models/fsmt/test_tokenization_fsmt.py similarity index 99% rename from tests/fsmt/test_tokenization_fsmt.py rename to tests/models/fsmt/test_tokenization_fsmt.py index f5e3d4b6cf75..7407c2fbc867 100644 --- a/tests/fsmt/test_tokenization_fsmt.py +++ b/tests/models/fsmt/test_tokenization_fsmt.py @@ -22,7 +22,7 @@ from transformers.testing_utils import slow from transformers.utils import cached_property -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin # using a different tiny model than the one used for default params defined in init to ensure proper testing diff --git a/tests/glpn/__init__.py b/tests/models/funnel/__init__.py similarity index 100% rename from tests/glpn/__init__.py rename to tests/models/funnel/__init__.py diff --git a/tests/funnel/test_modeling_funnel.py b/tests/models/funnel/test_modeling_funnel.py similarity index 99% rename from tests/funnel/test_modeling_funnel.py rename to tests/models/funnel/test_modeling_funnel.py index 73f5ec4b1778..c0520203a97f 100644 --- a/tests/funnel/test_modeling_funnel.py +++ b/tests/models/funnel/test_modeling_funnel.py @@ -20,8 +20,8 @@ from transformers.models.auto import get_values from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/funnel/test_modeling_tf_funnel.py b/tests/models/funnel/test_modeling_tf_funnel.py similarity index 99% rename from tests/funnel/test_modeling_tf_funnel.py rename to tests/models/funnel/test_modeling_tf_funnel.py index c3ae3788d61e..422985f7a6fb 100644 --- a/tests/funnel/test_modeling_tf_funnel.py +++ b/tests/models/funnel/test_modeling_tf_funnel.py @@ -19,8 +19,8 @@ from transformers import FunnelConfig, is_tf_available from transformers.testing_utils import require_tf -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/funnel/test_tokenization_funnel.py b/tests/models/funnel/test_tokenization_funnel.py similarity index 97% rename from tests/funnel/test_tokenization_funnel.py rename to tests/models/funnel/test_tokenization_funnel.py index 592f19b41141..e46928a538fd 100644 --- a/tests/funnel/test_tokenization_funnel.py +++ b/tests/models/funnel/test_tokenization_funnel.py @@ -21,7 +21,7 @@ from transformers.models.funnel.tokenization_funnel import VOCAB_FILES_NAMES from transformers.testing_utils import require_tokenizers -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_tokenizers diff --git a/tests/gpt2/__init__.py b/tests/models/glpn/__init__.py similarity index 100% rename from tests/gpt2/__init__.py rename to tests/models/glpn/__init__.py diff --git a/tests/glpn/test_feature_extraction_glpn.py b/tests/models/glpn/test_feature_extraction_glpn.py similarity index 97% rename from tests/glpn/test_feature_extraction_glpn.py rename to tests/models/glpn/test_feature_extraction_glpn.py index c903491ce103..4e7f2bdf5c78 100644 --- a/tests/glpn/test_feature_extraction_glpn.py +++ b/tests/models/glpn/test_feature_extraction_glpn.py @@ -21,7 +21,7 @@ from transformers.testing_utils import require_torch, require_vision from transformers.utils import is_torch_available, is_vision_available -from ..test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs +from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs if is_torch_available(): diff --git a/tests/glpn/test_modeling_glpn.py b/tests/models/glpn/test_modeling_glpn.py similarity index 99% rename from tests/glpn/test_modeling_glpn.py rename to tests/models/glpn/test_modeling_glpn.py index 323215d78b02..7d34a7f4f30d 100644 --- a/tests/glpn/test_modeling_glpn.py +++ b/tests/models/glpn/test_modeling_glpn.py @@ -22,8 +22,8 @@ from transformers.models.auto import get_values from transformers.testing_utils import require_torch, require_vision, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/gpt_neo/__init__.py b/tests/models/gpt2/__init__.py similarity index 100% rename from tests/gpt_neo/__init__.py rename to tests/models/gpt2/__init__.py diff --git a/tests/gpt2/test_modeling_flax_gpt2.py b/tests/models/gpt2/test_modeling_flax_gpt2.py similarity index 98% rename from tests/gpt2/test_modeling_flax_gpt2.py rename to tests/models/gpt2/test_modeling_flax_gpt2.py index 7be52b5a1151..a86377e42f7c 100644 --- a/tests/gpt2/test_modeling_flax_gpt2.py +++ b/tests/models/gpt2/test_modeling_flax_gpt2.py @@ -22,8 +22,8 @@ from transformers import GPT2Config, GPT2Tokenizer, is_flax_available, is_torch_available from transformers.testing_utils import is_pt_flax_cross_test, require_flax, slow -from ..generation.test_generation_flax_utils import FlaxGenerationTesterMixin -from ..test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...generation.test_generation_flax_utils import FlaxGenerationTesterMixin +from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_flax_available(): diff --git a/tests/gpt2/test_modeling_gpt2.py b/tests/models/gpt2/test_modeling_gpt2.py similarity index 99% rename from tests/gpt2/test_modeling_gpt2.py rename to tests/models/gpt2/test_modeling_gpt2.py index cea36400b2b8..c474f519d000 100644 --- a/tests/gpt2/test_modeling_gpt2.py +++ b/tests/models/gpt2/test_modeling_gpt2.py @@ -21,9 +21,9 @@ from transformers import GPT2Config, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/gpt2/test_modeling_tf_gpt2.py b/tests/models/gpt2/test_modeling_tf_gpt2.py similarity index 99% rename from tests/gpt2/test_modeling_tf_gpt2.py rename to tests/models/gpt2/test_modeling_tf_gpt2.py index 2092fb8feb37..9790b1c76626 100644 --- a/tests/gpt2/test_modeling_tf_gpt2.py +++ b/tests/models/gpt2/test_modeling_tf_gpt2.py @@ -18,9 +18,9 @@ from transformers import GPT2Config, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask -from ..utils.test_modeling_tf_core import TFCoreModelTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...utils.test_modeling_tf_core import TFCoreModelTesterMixin if is_tf_available(): diff --git a/tests/gpt2/test_tokenization_gpt2.py b/tests/models/gpt2/test_tokenization_gpt2.py similarity index 99% rename from tests/gpt2/test_tokenization_gpt2.py rename to tests/models/gpt2/test_tokenization_gpt2.py index 96f18e166c14..b14c113edbc2 100644 --- a/tests/gpt2/test_tokenization_gpt2.py +++ b/tests/models/gpt2/test_tokenization_gpt2.py @@ -22,7 +22,7 @@ from transformers.models.gpt2.tokenization_gpt2 import VOCAB_FILES_NAMES from transformers.testing_utils import require_tokenizers -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_tokenizers diff --git a/tests/gptj/__init__.py b/tests/models/gpt_neo/__init__.py similarity index 100% rename from tests/gptj/__init__.py rename to tests/models/gpt_neo/__init__.py diff --git a/tests/gpt_neo/test_modeling_flax_gpt_neo.py b/tests/models/gpt_neo/test_modeling_flax_gpt_neo.py similarity index 98% rename from tests/gpt_neo/test_modeling_flax_gpt_neo.py rename to tests/models/gpt_neo/test_modeling_flax_gpt_neo.py index 580138a7b31e..74659c56a8e4 100644 --- a/tests/gpt_neo/test_modeling_flax_gpt_neo.py +++ b/tests/models/gpt_neo/test_modeling_flax_gpt_neo.py @@ -22,8 +22,8 @@ from transformers import GPT2Tokenizer, GPTNeoConfig, is_flax_available, is_torch_available from transformers.testing_utils import is_pt_flax_cross_test, require_flax, slow -from ..generation.test_generation_flax_utils import FlaxGenerationTesterMixin -from ..test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask +from ...generation.test_generation_flax_utils import FlaxGenerationTesterMixin +from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask if is_flax_available(): diff --git a/tests/gpt_neo/test_modeling_gpt_neo.py b/tests/models/gpt_neo/test_modeling_gpt_neo.py similarity index 99% rename from tests/gpt_neo/test_modeling_gpt_neo.py rename to tests/models/gpt_neo/test_modeling_gpt_neo.py index 4135d7857cd1..f8607cf1edb9 100644 --- a/tests/gpt_neo/test_modeling_gpt_neo.py +++ b/tests/models/gpt_neo/test_modeling_gpt_neo.py @@ -21,9 +21,9 @@ from transformers.testing_utils import require_torch, slow, torch_device from transformers.utils import cached_property -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/herbert/__init__.py b/tests/models/gptj/__init__.py similarity index 100% rename from tests/herbert/__init__.py rename to tests/models/gptj/__init__.py diff --git a/tests/gptj/test_modeling_flax_gptj.py b/tests/models/gptj/test_modeling_flax_gptj.py similarity index 98% rename from tests/gptj/test_modeling_flax_gptj.py rename to tests/models/gptj/test_modeling_flax_gptj.py index 3a6d71b7bfb1..0b98ed5670d3 100644 --- a/tests/gptj/test_modeling_flax_gptj.py +++ b/tests/models/gptj/test_modeling_flax_gptj.py @@ -22,8 +22,8 @@ from transformers import GPT2Tokenizer, GPTJConfig, is_flax_available, is_torch_available from transformers.testing_utils import is_pt_flax_cross_test, require_flax, tooslow -from ..generation.test_generation_flax_utils import FlaxGenerationTesterMixin -from ..test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask +from ...generation.test_generation_flax_utils import FlaxGenerationTesterMixin +from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask if is_flax_available(): diff --git a/tests/gptj/test_modeling_gptj.py b/tests/models/gptj/test_modeling_gptj.py similarity index 99% rename from tests/gptj/test_modeling_gptj.py rename to tests/models/gptj/test_modeling_gptj.py index 0cabb2342b12..23ca46eb8280 100644 --- a/tests/gptj/test_modeling_gptj.py +++ b/tests/models/gptj/test_modeling_gptj.py @@ -20,9 +20,9 @@ from transformers import GPTJConfig, is_torch_available from transformers.testing_utils import require_torch, slow, tooslow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/gptj/test_modeling_tf_gptj.py b/tests/models/gptj/test_modeling_tf_gptj.py similarity index 99% rename from tests/gptj/test_modeling_tf_gptj.py rename to tests/models/gptj/test_modeling_tf_gptj.py index 63feffb8c62e..0d9af0b65087 100644 --- a/tests/gptj/test_modeling_tf_gptj.py +++ b/tests/models/gptj/test_modeling_tf_gptj.py @@ -19,9 +19,9 @@ from transformers import AutoTokenizer, GPTJConfig, is_tf_available from transformers.testing_utils import require_tf, slow, tooslow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask -from ..utils.test_modeling_tf_core import TFCoreModelTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...utils.test_modeling_tf_core import TFCoreModelTesterMixin if is_tf_available(): diff --git a/tests/hubert/__init__.py b/tests/models/herbert/__init__.py similarity index 100% rename from tests/hubert/__init__.py rename to tests/models/herbert/__init__.py diff --git a/tests/herbert/test_tokenization_herbert.py b/tests/models/herbert/test_tokenization_herbert.py similarity index 98% rename from tests/herbert/test_tokenization_herbert.py rename to tests/models/herbert/test_tokenization_herbert.py index d4a30e241d7c..3e8d3ac6ea29 100644 --- a/tests/herbert/test_tokenization_herbert.py +++ b/tests/models/herbert/test_tokenization_herbert.py @@ -22,7 +22,7 @@ from transformers.models.herbert.tokenization_herbert import VOCAB_FILES_NAMES from transformers.testing_utils import get_tests_dir, require_tokenizers, slow -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_tokenizers diff --git a/tests/ibert/__init__.py b/tests/models/hubert/__init__.py similarity index 100% rename from tests/ibert/__init__.py rename to tests/models/hubert/__init__.py diff --git a/tests/hubert/test_modeling_hubert.py b/tests/models/hubert/test_modeling_hubert.py similarity index 99% rename from tests/hubert/test_modeling_hubert.py rename to tests/models/hubert/test_modeling_hubert.py index 878fedb6e64f..0055b8346a4b 100644 --- a/tests/hubert/test_modeling_hubert.py +++ b/tests/models/hubert/test_modeling_hubert.py @@ -23,8 +23,8 @@ from transformers import HubertConfig, is_torch_available from transformers.testing_utils import require_soundfile, require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ( +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ( ModelTesterMixin, _config_zero_init, floats_tensor, diff --git a/tests/hubert/test_modeling_tf_hubert.py b/tests/models/hubert/test_modeling_tf_hubert.py similarity index 99% rename from tests/hubert/test_modeling_tf_hubert.py rename to tests/models/hubert/test_modeling_tf_hubert.py index 5331395b89ca..156535d7a2b8 100644 --- a/tests/hubert/test_modeling_tf_hubert.py +++ b/tests/models/hubert/test_modeling_tf_hubert.py @@ -25,8 +25,8 @@ from transformers import is_tf_available from transformers.testing_utils import require_soundfile, require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor if is_tf_available(): diff --git a/tests/imagegpt/__init__.py b/tests/models/ibert/__init__.py similarity index 100% rename from tests/imagegpt/__init__.py rename to tests/models/ibert/__init__.py diff --git a/tests/ibert/test_modeling_ibert.py b/tests/models/ibert/test_modeling_ibert.py old mode 100755 new mode 100644 similarity index 99% rename from tests/ibert/test_modeling_ibert.py rename to tests/models/ibert/test_modeling_ibert.py index 41819d973be6..f8e7b2da2b9e --- a/tests/ibert/test_modeling_ibert.py +++ b/tests/models/ibert/test_modeling_ibert.py @@ -20,8 +20,8 @@ from transformers import IBertConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/layoutlm/__init__.py b/tests/models/imagegpt/__init__.py similarity index 100% rename from tests/layoutlm/__init__.py rename to tests/models/imagegpt/__init__.py diff --git a/tests/imagegpt/test_feature_extraction_imagegpt.py b/tests/models/imagegpt/test_feature_extraction_imagegpt.py similarity index 98% rename from tests/imagegpt/test_feature_extraction_imagegpt.py rename to tests/models/imagegpt/test_feature_extraction_imagegpt.py index 4d1ca087d80b..1dd3786759fd 100644 --- a/tests/imagegpt/test_feature_extraction_imagegpt.py +++ b/tests/models/imagegpt/test_feature_extraction_imagegpt.py @@ -25,7 +25,7 @@ from transformers.testing_utils import require_torch, require_vision, slow from transformers.utils import is_torch_available, is_vision_available -from ..test_feature_extraction_common import FeatureExtractionSavingTestMixin +from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin if is_torch_available(): diff --git a/tests/imagegpt/test_modeling_imagegpt.py b/tests/models/imagegpt/test_modeling_imagegpt.py similarity index 99% rename from tests/imagegpt/test_modeling_imagegpt.py rename to tests/models/imagegpt/test_modeling_imagegpt.py index c570e6192779..57b406f646bc 100644 --- a/tests/imagegpt/test_modeling_imagegpt.py +++ b/tests/models/imagegpt/test_modeling_imagegpt.py @@ -24,9 +24,9 @@ from transformers.testing_utils import require_torch, require_vision, slow, torch_device from transformers.utils import cached_property, is_torch_available, is_vision_available -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ( +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ( ModelTesterMixin, _config_zero_init, floats_tensor, diff --git a/tests/layoutlmv2/__init__.py b/tests/models/layoutlm/__init__.py similarity index 100% rename from tests/layoutlmv2/__init__.py rename to tests/models/layoutlm/__init__.py diff --git a/tests/layoutlm/test_modeling_layoutlm.py b/tests/models/layoutlm/test_modeling_layoutlm.py similarity index 99% rename from tests/layoutlm/test_modeling_layoutlm.py rename to tests/models/layoutlm/test_modeling_layoutlm.py index faf4458cc81e..ec2190598e56 100644 --- a/tests/layoutlm/test_modeling_layoutlm.py +++ b/tests/models/layoutlm/test_modeling_layoutlm.py @@ -19,8 +19,8 @@ from transformers import LayoutLMConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/layoutlm/test_modeling_tf_layoutlm.py b/tests/models/layoutlm/test_modeling_tf_layoutlm.py similarity index 98% rename from tests/layoutlm/test_modeling_tf_layoutlm.py rename to tests/models/layoutlm/test_modeling_tf_layoutlm.py index 90e2b4fcf169..fb230aab56e8 100644 --- a/tests/layoutlm/test_modeling_tf_layoutlm.py +++ b/tests/models/layoutlm/test_modeling_tf_layoutlm.py @@ -20,8 +20,8 @@ from transformers import LayoutLMConfig, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/layoutlm/test_tokenization_layoutlm.py b/tests/models/layoutlm/test_tokenization_layoutlm.py similarity index 97% rename from tests/layoutlm/test_tokenization_layoutlm.py rename to tests/models/layoutlm/test_tokenization_layoutlm.py index dab51216586b..3663355ee507 100644 --- a/tests/layoutlm/test_tokenization_layoutlm.py +++ b/tests/models/layoutlm/test_tokenization_layoutlm.py @@ -21,7 +21,7 @@ from transformers.models.layoutlm.tokenization_layoutlm import VOCAB_FILES_NAMES from transformers.testing_utils import require_tokenizers -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_tokenizers diff --git a/tests/layoutxlm/__init__.py b/tests/models/layoutlmv2/__init__.py similarity index 100% rename from tests/layoutxlm/__init__.py rename to tests/models/layoutlmv2/__init__.py diff --git a/tests/layoutlmv2/test_feature_extraction_layoutlmv2.py b/tests/models/layoutlmv2/test_feature_extraction_layoutlmv2.py similarity index 99% rename from tests/layoutlmv2/test_feature_extraction_layoutlmv2.py rename to tests/models/layoutlmv2/test_feature_extraction_layoutlmv2.py index ca3bbf1cdc9d..59c30d779c5f 100644 --- a/tests/layoutlmv2/test_feature_extraction_layoutlmv2.py +++ b/tests/models/layoutlmv2/test_feature_extraction_layoutlmv2.py @@ -21,7 +21,7 @@ from transformers.testing_utils import require_pytesseract, require_torch from transformers.utils import is_pytesseract_available, is_torch_available -from ..test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs +from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs if is_torch_available(): diff --git a/tests/layoutlmv2/test_modeling_layoutlmv2.py b/tests/models/layoutlmv2/test_modeling_layoutlmv2.py similarity index 99% rename from tests/layoutlmv2/test_modeling_layoutlmv2.py rename to tests/models/layoutlmv2/test_modeling_layoutlmv2.py index 708a433989ae..bfcd729df153 100644 --- a/tests/layoutlmv2/test_modeling_layoutlmv2.py +++ b/tests/models/layoutlmv2/test_modeling_layoutlmv2.py @@ -23,8 +23,8 @@ from transformers.testing_utils import require_detectron2, require_torch, slow, torch_device from transformers.utils import is_detectron2_available, is_torch_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, _config_zero_init, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, _config_zero_init, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/layoutlmv2/test_processor_layoutlmv2.py b/tests/models/layoutlmv2/test_processor_layoutlmv2.py similarity index 100% rename from tests/layoutlmv2/test_processor_layoutlmv2.py rename to tests/models/layoutlmv2/test_processor_layoutlmv2.py diff --git a/tests/layoutlmv2/test_tokenization_layoutlmv2.py b/tests/models/layoutlmv2/test_tokenization_layoutlmv2.py similarity index 99% rename from tests/layoutlmv2/test_tokenization_layoutlmv2.py rename to tests/models/layoutlmv2/test_tokenization_layoutlmv2.py index 249660d4a3f2..1c3f8190c162 100644 --- a/tests/layoutlmv2/test_tokenization_layoutlmv2.py +++ b/tests/models/layoutlmv2/test_tokenization_layoutlmv2.py @@ -33,7 +33,7 @@ ) from transformers.testing_utils import is_pt_tf_cross_test, require_pandas, require_tokenizers, require_torch, slow -from ..test_tokenization_common import ( +from ...test_tokenization_common import ( SMALL_TRAINING_CORPUS, TokenizerTesterMixin, filter_non_english, diff --git a/tests/led/__init__.py b/tests/models/layoutxlm/__init__.py similarity index 100% rename from tests/led/__init__.py rename to tests/models/layoutxlm/__init__.py diff --git a/tests/layoutxlm/test_processor_layoutxlm.py b/tests/models/layoutxlm/test_processor_layoutxlm.py similarity index 99% rename from tests/layoutxlm/test_processor_layoutxlm.py rename to tests/models/layoutxlm/test_processor_layoutxlm.py index 3964765e3206..d208097e6c80 100644 --- a/tests/layoutxlm/test_processor_layoutxlm.py +++ b/tests/models/layoutxlm/test_processor_layoutxlm.py @@ -17,12 +17,12 @@ import shutil import tempfile import unittest -from os.path import dirname from typing import List from transformers import PreTrainedTokenizer, PreTrainedTokenizerBase, PreTrainedTokenizerFast from transformers.models.layoutxlm import LayoutXLMTokenizer, LayoutXLMTokenizerFast from transformers.testing_utils import ( + get_tests_dir, require_pytesseract, require_sentencepiece, require_tokenizers, @@ -38,7 +38,7 @@ from transformers import LayoutLMv2FeatureExtractor, LayoutXLMProcessor -SAMPLE_SP = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece.model") +SAMPLE_SP = get_tests_dir("fixtures/test_sentencepiece.model") @require_pytesseract diff --git a/tests/layoutxlm/test_tokenization_layoutxlm.py b/tests/models/layoutxlm/test_tokenization_layoutxlm.py similarity index 99% rename from tests/layoutxlm/test_tokenization_layoutxlm.py rename to tests/models/layoutxlm/test_tokenization_layoutxlm.py index 09ca5061fcc5..561e87e77234 100644 --- a/tests/layoutxlm/test_tokenization_layoutxlm.py +++ b/tests/models/layoutxlm/test_tokenization_layoutxlm.py @@ -14,7 +14,6 @@ # limitations under the License. import inspect -import os import shutil import tempfile import unittest @@ -23,6 +22,7 @@ from transformers import AddedToken, LayoutXLMTokenizerFast, SpecialTokensMixin, is_tf_available, is_torch_available from transformers.models.layoutxlm.tokenization_layoutxlm import LayoutXLMTokenizer from transformers.testing_utils import ( + get_tests_dir, is_pt_tf_cross_test, require_pandas, require_scatter, @@ -32,7 +32,7 @@ slow, ) -from ..test_tokenization_common import ( +from ...test_tokenization_common import ( SMALL_TRAINING_CORPUS, TokenizerTesterMixin, filter_non_english, @@ -40,7 +40,7 @@ ) -SAMPLE_VOCAB = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../fixtures/test_sentencepiece.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece.model") @require_sentencepiece diff --git a/tests/longformer/__init__.py b/tests/models/led/__init__.py similarity index 100% rename from tests/longformer/__init__.py rename to tests/models/led/__init__.py diff --git a/tests/led/test_modeling_led.py b/tests/models/led/test_modeling_led.py similarity index 99% rename from tests/led/test_modeling_led.py rename to tests/models/led/test_modeling_led.py index 758834d7fe92..9d3d090ab17d 100644 --- a/tests/led/test_modeling_led.py +++ b/tests/models/led/test_modeling_led.py @@ -24,9 +24,9 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device from transformers.utils import cached_property -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/led/test_modeling_tf_led.py b/tests/models/led/test_modeling_tf_led.py similarity index 99% rename from tests/led/test_modeling_tf_led.py rename to tests/models/led/test_modeling_tf_led.py index df115010f33e..8075d071e662 100644 --- a/tests/led/test_modeling_tf_led.py +++ b/tests/models/led/test_modeling_tf_led.py @@ -19,8 +19,8 @@ from transformers import LEDConfig, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor if is_tf_available(): diff --git a/tests/luke/__init__.py b/tests/models/longformer/__init__.py similarity index 100% rename from tests/luke/__init__.py rename to tests/models/longformer/__init__.py diff --git a/tests/longformer/test_modeling_longformer.py b/tests/models/longformer/test_modeling_longformer.py similarity index 99% rename from tests/longformer/test_modeling_longformer.py rename to tests/models/longformer/test_modeling_longformer.py index 6b3a8752ed4e..fd10b14eaead 100644 --- a/tests/longformer/test_modeling_longformer.py +++ b/tests/models/longformer/test_modeling_longformer.py @@ -19,8 +19,8 @@ from transformers import LongformerConfig, is_torch_available from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/longformer/test_modeling_tf_longformer.py b/tests/models/longformer/test_modeling_tf_longformer.py similarity index 99% rename from tests/longformer/test_modeling_tf_longformer.py rename to tests/models/longformer/test_modeling_tf_longformer.py index d48368267722..12c19e566e95 100644 --- a/tests/longformer/test_modeling_tf_longformer.py +++ b/tests/models/longformer/test_modeling_tf_longformer.py @@ -19,8 +19,8 @@ from transformers import is_tf_available from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/lxmert/__init__.py b/tests/models/luke/__init__.py similarity index 100% rename from tests/lxmert/__init__.py rename to tests/models/luke/__init__.py diff --git a/tests/luke/test_modeling_luke.py b/tests/models/luke/test_modeling_luke.py similarity index 99% rename from tests/luke/test_modeling_luke.py rename to tests/models/luke/test_modeling_luke.py index 99a34cc81c0a..0661748da5a0 100644 --- a/tests/luke/test_modeling_luke.py +++ b/tests/models/luke/test_modeling_luke.py @@ -18,8 +18,8 @@ from transformers import LukeConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/luke/test_tokenization_luke.py b/tests/models/luke/test_tokenization_luke.py similarity index 98% rename from tests/luke/test_tokenization_luke.py rename to tests/models/luke/test_tokenization_luke.py index 456246384c05..81dce277a385 100644 --- a/tests/luke/test_tokenization_luke.py +++ b/tests/models/luke/test_tokenization_luke.py @@ -13,20 +13,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import unittest -from os.path import dirname from typing import Tuple from transformers import AddedToken, LukeTokenizer -from transformers.testing_utils import require_torch, slow +from transformers.testing_utils import get_tests_dir, require_torch, slow -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/vocab.json") -SAMPLE_MERGE_FILE = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/merges.txt") -SAMPLE_ENTITY_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_entity_vocab.json") +SAMPLE_VOCAB = get_tests_dir("fixtures/vocab.json") +SAMPLE_MERGE_FILE = get_tests_dir("fixtures/merges.txt") +SAMPLE_ENTITY_VOCAB = get_tests_dir("fixtures/test_entity_vocab.json") class LukeTokenizerTest(TokenizerTesterMixin, unittest.TestCase): diff --git a/tests/m2m_100/__init__.py b/tests/models/lxmert/__init__.py similarity index 100% rename from tests/m2m_100/__init__.py rename to tests/models/lxmert/__init__.py diff --git a/tests/lxmert/test_modeling_lxmert.py b/tests/models/lxmert/test_modeling_lxmert.py similarity index 99% rename from tests/lxmert/test_modeling_lxmert.py rename to tests/models/lxmert/test_modeling_lxmert.py index f1209d132dc6..7061aaa7d379 100644 --- a/tests/lxmert/test_modeling_lxmert.py +++ b/tests/models/lxmert/test_modeling_lxmert.py @@ -23,8 +23,8 @@ from transformers.models.auto import get_values from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/lxmert/test_modeling_tf_lxmert.py b/tests/models/lxmert/test_modeling_tf_lxmert.py similarity index 99% rename from tests/lxmert/test_modeling_tf_lxmert.py rename to tests/models/lxmert/test_modeling_tf_lxmert.py index 19226545a9b9..7594f889189c 100644 --- a/tests/lxmert/test_modeling_tf_lxmert.py +++ b/tests/models/lxmert/test_modeling_tf_lxmert.py @@ -22,8 +22,8 @@ from transformers import LxmertConfig, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/lxmert/test_tokenization_lxmert.py b/tests/models/lxmert/test_tokenization_lxmert.py similarity index 97% rename from tests/lxmert/test_tokenization_lxmert.py rename to tests/models/lxmert/test_tokenization_lxmert.py index 38b76074c6c6..76047b1f44bc 100644 --- a/tests/lxmert/test_tokenization_lxmert.py +++ b/tests/models/lxmert/test_tokenization_lxmert.py @@ -21,7 +21,7 @@ from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES from transformers.testing_utils import require_tokenizers -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_tokenizers diff --git a/tests/marian/__init__.py b/tests/models/m2m_100/__init__.py similarity index 100% rename from tests/marian/__init__.py rename to tests/models/m2m_100/__init__.py diff --git a/tests/m2m_100/test_modeling_m2m_100.py b/tests/models/m2m_100/test_modeling_m2m_100.py similarity index 98% rename from tests/m2m_100/test_modeling_m2m_100.py rename to tests/models/m2m_100/test_modeling_m2m_100.py index 52a677618abd..003c5a57cf67 100644 --- a/tests/m2m_100/test_modeling_m2m_100.py +++ b/tests/models/m2m_100/test_modeling_m2m_100.py @@ -23,9 +23,9 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device from transformers.utils import cached_property -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/m2m_100/test_tokenization_m2m_100.py b/tests/models/m2m_100/test_tokenization_m2m_100.py similarity index 97% rename from tests/m2m_100/test_tokenization_m2m_100.py rename to tests/models/m2m_100/test_tokenization_m2m_100.py index 35652f0cb3a1..729deb6cd486 100644 --- a/tests/m2m_100/test_tokenization_m2m_100.py +++ b/tests/models/m2m_100/test_tokenization_m2m_100.py @@ -12,26 +12,31 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import tempfile import unittest -from os.path import dirname from pathlib import Path from shutil import copyfile from transformers import M2M100Tokenizer, is_torch_available -from transformers.testing_utils import nested_simplify, require_sentencepiece, require_tokenizers, require_torch, slow +from transformers.testing_utils import ( + get_tests_dir, + nested_simplify, + require_sentencepiece, + require_tokenizers, + require_torch, + slow, +) from transformers.utils import is_sentencepiece_available if is_sentencepiece_available(): from transformers.models.m2m_100.tokenization_m2m_100 import save_json, VOCAB_FILES_NAMES -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin if is_sentencepiece_available(): - SAMPLE_SP = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece.model") + SAMPLE_SP = get_tests_dir("fixtures/test_sentencepiece.model") if is_torch_available(): diff --git a/tests/maskformer/__init__.py b/tests/models/marian/__init__.py similarity index 100% rename from tests/maskformer/__init__.py rename to tests/models/marian/__init__.py diff --git a/tests/marian/test_modeling_flax_marian.py b/tests/models/marian/test_modeling_flax_marian.py similarity index 99% rename from tests/marian/test_modeling_flax_marian.py rename to tests/models/marian/test_modeling_flax_marian.py index bfb0d273add1..4180eb565cf5 100644 --- a/tests/marian/test_modeling_flax_marian.py +++ b/tests/models/marian/test_modeling_flax_marian.py @@ -21,8 +21,8 @@ from transformers.testing_utils import require_flax, require_sentencepiece, require_tokenizers, slow from transformers.utils import cached_property -from ..generation.test_generation_flax_utils import FlaxGenerationTesterMixin -from ..test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor +from ...generation.test_generation_flax_utils import FlaxGenerationTesterMixin +from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor if is_flax_available(): diff --git a/tests/marian/test_modeling_marian.py b/tests/models/marian/test_modeling_marian.py similarity index 99% rename from tests/marian/test_modeling_marian.py rename to tests/models/marian/test_modeling_marian.py index 067144d8cdc3..9c119f936af4 100644 --- a/tests/marian/test_modeling_marian.py +++ b/tests/models/marian/test_modeling_marian.py @@ -22,9 +22,9 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device from transformers.utils import cached_property -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/marian/test_modeling_tf_marian.py b/tests/models/marian/test_modeling_tf_marian.py similarity index 99% rename from tests/marian/test_modeling_tf_marian.py rename to tests/models/marian/test_modeling_tf_marian.py index eb4f24700ba1..e62d7f0d35cc 100644 --- a/tests/marian/test_modeling_tf_marian.py +++ b/tests/models/marian/test_modeling_tf_marian.py @@ -22,8 +22,8 @@ from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow from transformers.utils import cached_property -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor if is_tf_available(): diff --git a/tests/marian/test_tokenization_marian.py b/tests/models/marian/test_tokenization_marian.py similarity index 96% rename from tests/marian/test_tokenization_marian.py rename to tests/models/marian/test_tokenization_marian.py index 6b6ee6c9662d..2cbc0b0a3fe7 100644 --- a/tests/marian/test_tokenization_marian.py +++ b/tests/models/marian/test_tokenization_marian.py @@ -13,25 +13,23 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import tempfile import unittest -from os.path import dirname from pathlib import Path from shutil import copyfile from transformers import BatchEncoding, MarianTokenizer -from transformers.testing_utils import require_sentencepiece, slow +from transformers.testing_utils import get_tests_dir, require_sentencepiece, slow from transformers.utils import is_sentencepiece_available, is_tf_available, is_torch_available if is_sentencepiece_available(): from transformers.models.marian.tokenization_marian import VOCAB_FILES_NAMES, save_json -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_SP = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece.model") +SAMPLE_SP = get_tests_dir("fixtures/test_sentencepiece.model") mock_tokenizer_config = {"target_lang": "fi", "source_lang": "en"} zh_code = ">>zh<<" diff --git a/tests/mbart/__init__.py b/tests/models/maskformer/__init__.py similarity index 100% rename from tests/mbart/__init__.py rename to tests/models/maskformer/__init__.py diff --git a/tests/maskformer/test_feature_extraction_maskformer.py b/tests/models/maskformer/test_feature_extraction_maskformer.py similarity index 99% rename from tests/maskformer/test_feature_extraction_maskformer.py rename to tests/models/maskformer/test_feature_extraction_maskformer.py index 259954643fc9..461add8c0355 100644 --- a/tests/maskformer/test_feature_extraction_maskformer.py +++ b/tests/models/maskformer/test_feature_extraction_maskformer.py @@ -21,7 +21,7 @@ from transformers.testing_utils import require_torch, require_vision from transformers.utils import is_torch_available, is_vision_available -from ..test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs +from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs if is_torch_available(): diff --git a/tests/maskformer/test_modeling_maskformer.py b/tests/models/maskformer/test_modeling_maskformer.py similarity index 99% rename from tests/maskformer/test_modeling_maskformer.py rename to tests/models/maskformer/test_modeling_maskformer.py index 43daf85ab101..bbc24719d753 100644 --- a/tests/maskformer/test_modeling_maskformer.py +++ b/tests/models/maskformer/test_modeling_maskformer.py @@ -24,8 +24,8 @@ from transformers.testing_utils import require_torch, require_vision, slow, torch_device from transformers.utils import cached_property -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin if is_torch_available(): diff --git a/tests/mbart50/__init__.py b/tests/models/mbart/__init__.py similarity index 100% rename from tests/mbart50/__init__.py rename to tests/models/mbart/__init__.py diff --git a/tests/mbart/test_modeling_flax_mbart.py b/tests/models/mbart/test_modeling_flax_mbart.py similarity index 99% rename from tests/mbart/test_modeling_flax_mbart.py rename to tests/models/mbart/test_modeling_flax_mbart.py index bd235487d798..1009dc95dd2a 100644 --- a/tests/mbart/test_modeling_flax_mbart.py +++ b/tests/models/mbart/test_modeling_flax_mbart.py @@ -21,8 +21,8 @@ from transformers.testing_utils import require_flax, require_sentencepiece, require_tokenizers, slow from transformers.utils import cached_property -from ..generation.test_generation_flax_utils import FlaxGenerationTesterMixin -from ..test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor +from ...generation.test_generation_flax_utils import FlaxGenerationTesterMixin +from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor if is_flax_available(): diff --git a/tests/mbart/test_modeling_mbart.py b/tests/models/mbart/test_modeling_mbart.py similarity index 99% rename from tests/mbart/test_modeling_mbart.py rename to tests/models/mbart/test_modeling_mbart.py index 2037ee79efb3..3ac2c542da1e 100644 --- a/tests/mbart/test_modeling_mbart.py +++ b/tests/models/mbart/test_modeling_mbart.py @@ -23,9 +23,9 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device from transformers.utils import cached_property -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/mbart/test_modeling_tf_mbart.py b/tests/models/mbart/test_modeling_tf_mbart.py similarity index 99% rename from tests/mbart/test_modeling_tf_mbart.py rename to tests/models/mbart/test_modeling_tf_mbart.py index eec59fe1b5e0..559a44e5db6a 100644 --- a/tests/mbart/test_modeling_tf_mbart.py +++ b/tests/models/mbart/test_modeling_tf_mbart.py @@ -20,8 +20,8 @@ from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow from transformers.utils import cached_property -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor if is_tf_available(): diff --git a/tests/mbart/test_tokenization_mbart.py b/tests/models/mbart/test_tokenization_mbart.py similarity index 97% rename from tests/mbart/test_tokenization_mbart.py rename to tests/models/mbart/test_tokenization_mbart.py index 3b842b60fb12..d24aefb01fd9 100644 --- a/tests/mbart/test_tokenization_mbart.py +++ b/tests/models/mbart/test_tokenization_mbart.py @@ -12,18 +12,23 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import shutil import tempfile import unittest from transformers import SPIECE_UNDERLINE, BatchEncoding, MBartTokenizer, MBartTokenizerFast, is_torch_available -from transformers.testing_utils import nested_simplify, require_sentencepiece, require_tokenizers, require_torch +from transformers.testing_utils import ( + get_tests_dir, + nested_simplify, + require_sentencepiece, + require_tokenizers, + require_torch, +) -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_VOCAB = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../fixtures/test_sentencepiece.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece.model") if is_torch_available(): diff --git a/tests/megatron_bert/__init__.py b/tests/models/mbart50/__init__.py similarity index 100% rename from tests/megatron_bert/__init__.py rename to tests/models/mbart50/__init__.py diff --git a/tests/mbart50/test_tokenization_mbart50.py b/tests/models/mbart50/test_tokenization_mbart50.py similarity index 98% rename from tests/mbart50/test_tokenization_mbart50.py rename to tests/models/mbart50/test_tokenization_mbart50.py index 3e39beb67be8..63adfe8436d5 100644 --- a/tests/mbart50/test_tokenization_mbart50.py +++ b/tests/models/mbart50/test_tokenization_mbart50.py @@ -12,19 +12,24 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import shutil import tempfile import unittest -from os.path import dirname from transformers import SPIECE_UNDERLINE, BatchEncoding, MBart50Tokenizer, MBart50TokenizerFast, is_torch_available -from transformers.testing_utils import nested_simplify, require_sentencepiece, require_tokenizers, require_torch, slow +from transformers.testing_utils import ( + get_tests_dir, + nested_simplify, + require_sentencepiece, + require_tokenizers, + require_torch, + slow, +) -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece.model") if is_torch_available(): from transformers.models.mbart.modeling_mbart import shift_tokens_right diff --git a/tests/megatron_gpt2/__init__.py b/tests/models/megatron_bert/__init__.py similarity index 100% rename from tests/megatron_gpt2/__init__.py rename to tests/models/megatron_bert/__init__.py diff --git a/tests/megatron_bert/test_modeling_megatron_bert.py b/tests/models/megatron_bert/test_modeling_megatron_bert.py similarity index 99% rename from tests/megatron_bert/test_modeling_megatron_bert.py rename to tests/models/megatron_bert/test_modeling_megatron_bert.py index 01b93bf13a22..4ea3ddcb7be0 100644 --- a/tests/megatron_bert/test_modeling_megatron_bert.py +++ b/tests/models/megatron_bert/test_modeling_megatron_bert.py @@ -23,8 +23,8 @@ from transformers.models.auto import get_values from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/mluke/__init__.py b/tests/models/megatron_gpt2/__init__.py similarity index 100% rename from tests/mluke/__init__.py rename to tests/models/megatron_gpt2/__init__.py diff --git a/tests/megatron_gpt2/test_modeling_megatron_gpt2.py b/tests/models/megatron_gpt2/test_modeling_megatron_gpt2.py similarity index 100% rename from tests/megatron_gpt2/test_modeling_megatron_gpt2.py rename to tests/models/megatron_gpt2/test_modeling_megatron_gpt2.py diff --git a/tests/mobilebert/__init__.py b/tests/models/mluke/__init__.py similarity index 100% rename from tests/mobilebert/__init__.py rename to tests/models/mluke/__init__.py diff --git a/tests/mluke/test_tokenization_mluke.py b/tests/models/mluke/test_tokenization_mluke.py similarity index 98% rename from tests/mluke/test_tokenization_mluke.py rename to tests/models/mluke/test_tokenization_mluke.py index c1d5ef639949..66d669924652 100644 --- a/tests/mluke/test_tokenization_mluke.py +++ b/tests/models/mluke/test_tokenization_mluke.py @@ -14,19 +14,17 @@ # limitations under the License. -import os import unittest -from os.path import dirname from typing import Tuple from transformers.models.mluke.tokenization_mluke import MLukeTokenizer -from transformers.testing_utils import require_torch, slow +from transformers.testing_utils import get_tests_dir, require_torch, slow -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece.model") -SAMPLE_ENTITY_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_entity_vocab.json") +SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece.model") +SAMPLE_ENTITY_VOCAB = get_tests_dir("fixtures/test_entity_vocab.json") class MLukeTokenizerTest(TokenizerTesterMixin, unittest.TestCase): diff --git a/tests/mpnet/__init__.py b/tests/models/mobilebert/__init__.py similarity index 100% rename from tests/mpnet/__init__.py rename to tests/models/mobilebert/__init__.py diff --git a/tests/mobilebert/test_modeling_mobilebert.py b/tests/models/mobilebert/test_modeling_mobilebert.py similarity index 99% rename from tests/mobilebert/test_modeling_mobilebert.py rename to tests/models/mobilebert/test_modeling_mobilebert.py index 99e8e683235e..04301962c3cd 100644 --- a/tests/mobilebert/test_modeling_mobilebert.py +++ b/tests/models/mobilebert/test_modeling_mobilebert.py @@ -20,8 +20,8 @@ from transformers.models.auto import get_values from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/mobilebert/test_modeling_tf_mobilebert.py b/tests/models/mobilebert/test_modeling_tf_mobilebert.py similarity index 99% rename from tests/mobilebert/test_modeling_tf_mobilebert.py rename to tests/models/mobilebert/test_modeling_tf_mobilebert.py index c0ddf043562f..9db55cec2d58 100644 --- a/tests/mobilebert/test_modeling_tf_mobilebert.py +++ b/tests/models/mobilebert/test_modeling_tf_mobilebert.py @@ -19,8 +19,8 @@ from transformers import MobileBertConfig, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/mt5/__init__.py b/tests/models/mpnet/__init__.py similarity index 100% rename from tests/mt5/__init__.py rename to tests/models/mpnet/__init__.py diff --git a/tests/mpnet/test_modeling_mpnet.py b/tests/models/mpnet/test_modeling_mpnet.py similarity index 98% rename from tests/mpnet/test_modeling_mpnet.py rename to tests/models/mpnet/test_modeling_mpnet.py index 5417313998bf..1e72870fdadd 100644 --- a/tests/mpnet/test_modeling_mpnet.py +++ b/tests/models/mpnet/test_modeling_mpnet.py @@ -19,8 +19,8 @@ from transformers import MPNetConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/mpnet/test_modeling_tf_mpnet.py b/tests/models/mpnet/test_modeling_tf_mpnet.py similarity index 98% rename from tests/mpnet/test_modeling_tf_mpnet.py rename to tests/models/mpnet/test_modeling_tf_mpnet.py index f9f9e2d51201..a0a4964d57e9 100644 --- a/tests/mpnet/test_modeling_tf_mpnet.py +++ b/tests/models/mpnet/test_modeling_tf_mpnet.py @@ -19,8 +19,8 @@ from transformers import MPNetConfig, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/mpnet/test_tokenization_mpnet.py b/tests/models/mpnet/test_tokenization_mpnet.py similarity index 97% rename from tests/mpnet/test_tokenization_mpnet.py rename to tests/models/mpnet/test_tokenization_mpnet.py index 4cc677397d24..f761b0280953 100644 --- a/tests/mpnet/test_tokenization_mpnet.py +++ b/tests/models/mpnet/test_tokenization_mpnet.py @@ -21,7 +21,7 @@ from transformers.models.mpnet.tokenization_mpnet import VOCAB_FILES_NAMES, MPNetTokenizer from transformers.testing_utils import require_tokenizers, slow -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_tokenizers diff --git a/tests/nystromformer/__init__.py b/tests/models/mt5/__init__.py similarity index 100% rename from tests/nystromformer/__init__.py rename to tests/models/mt5/__init__.py diff --git a/tests/mt5/test_modeling_flax_mt5.py b/tests/models/mt5/test_modeling_flax_mt5.py similarity index 100% rename from tests/mt5/test_modeling_flax_mt5.py rename to tests/models/mt5/test_modeling_flax_mt5.py diff --git a/tests/mt5/test_modeling_mt5.py b/tests/models/mt5/test_modeling_mt5.py similarity index 100% rename from tests/mt5/test_modeling_mt5.py rename to tests/models/mt5/test_modeling_mt5.py diff --git a/tests/mt5/test_modeling_tf_mt5.py b/tests/models/mt5/test_modeling_tf_mt5.py similarity index 100% rename from tests/mt5/test_modeling_tf_mt5.py rename to tests/models/mt5/test_modeling_tf_mt5.py diff --git a/tests/openai/__init__.py b/tests/models/nystromformer/__init__.py similarity index 100% rename from tests/openai/__init__.py rename to tests/models/nystromformer/__init__.py diff --git a/tests/nystromformer/test_modeling_nystromformer.py b/tests/models/nystromformer/test_modeling_nystromformer.py similarity index 98% rename from tests/nystromformer/test_modeling_nystromformer.py rename to tests/models/nystromformer/test_modeling_nystromformer.py index e3e962b31093..b93c074bf683 100644 --- a/tests/nystromformer/test_modeling_nystromformer.py +++ b/tests/models/nystromformer/test_modeling_nystromformer.py @@ -20,8 +20,8 @@ from transformers import AutoTokenizer, NystromformerConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/pegasus/__init__.py b/tests/models/openai/__init__.py similarity index 100% rename from tests/pegasus/__init__.py rename to tests/models/openai/__init__.py diff --git a/tests/openai/test_modeling_openai.py b/tests/models/openai/test_modeling_openai.py similarity index 98% rename from tests/openai/test_modeling_openai.py rename to tests/models/openai/test_modeling_openai.py index 80babf5b517f..2ff935eef590 100644 --- a/tests/openai/test_modeling_openai.py +++ b/tests/models/openai/test_modeling_openai.py @@ -19,9 +19,9 @@ from transformers import is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/openai/test_modeling_tf_openai.py b/tests/models/openai/test_modeling_tf_openai.py similarity index 98% rename from tests/openai/test_modeling_tf_openai.py rename to tests/models/openai/test_modeling_tf_openai.py index f74a85ee60d6..7cdc2a8bb187 100644 --- a/tests/openai/test_modeling_tf_openai.py +++ b/tests/models/openai/test_modeling_tf_openai.py @@ -19,8 +19,8 @@ from transformers import OpenAIGPTConfig, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/openai/test_tokenization_openai.py b/tests/models/openai/test_tokenization_openai.py similarity index 98% rename from tests/openai/test_tokenization_openai.py rename to tests/models/openai/test_tokenization_openai.py index a9ac22c9283d..26030632918b 100644 --- a/tests/openai/test_tokenization_openai.py +++ b/tests/models/openai/test_tokenization_openai.py @@ -22,7 +22,7 @@ from transformers.models.openai.tokenization_openai import VOCAB_FILES_NAMES from transformers.testing_utils import require_ftfy, require_spacy, require_tokenizers -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_tokenizers diff --git a/tests/perceiver/__init__.py b/tests/models/pegasus/__init__.py similarity index 100% rename from tests/perceiver/__init__.py rename to tests/models/pegasus/__init__.py diff --git a/tests/pegasus/test_modeling_flax_pegasus.py b/tests/models/pegasus/test_modeling_flax_pegasus.py similarity index 99% rename from tests/pegasus/test_modeling_flax_pegasus.py rename to tests/models/pegasus/test_modeling_flax_pegasus.py index 8f5c010477eb..61c356bfb0ce 100644 --- a/tests/pegasus/test_modeling_flax_pegasus.py +++ b/tests/models/pegasus/test_modeling_flax_pegasus.py @@ -19,8 +19,8 @@ from transformers import PegasusConfig, PegasusTokenizer, is_flax_available from transformers.testing_utils import require_flax, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor if is_flax_available(): diff --git a/tests/pegasus/test_modeling_pegasus.py b/tests/models/pegasus/test_modeling_pegasus.py similarity index 99% rename from tests/pegasus/test_modeling_pegasus.py rename to tests/models/pegasus/test_modeling_pegasus.py index 090300de0c9b..a05e34e57c07 100644 --- a/tests/pegasus/test_modeling_pegasus.py +++ b/tests/models/pegasus/test_modeling_pegasus.py @@ -21,10 +21,10 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device from transformers.utils import cached_property -from ..generation.test_generation_utils import GenerationTesterMixin +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor from ..mbart.test_modeling_mbart import AbstractSeq2SeqIntegrationTest -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/pegasus/test_modeling_tf_pegasus.py b/tests/models/pegasus/test_modeling_tf_pegasus.py similarity index 99% rename from tests/pegasus/test_modeling_tf_pegasus.py rename to tests/models/pegasus/test_modeling_tf_pegasus.py index dd2b8c7d6194..594323a7dc45 100644 --- a/tests/pegasus/test_modeling_tf_pegasus.py +++ b/tests/models/pegasus/test_modeling_tf_pegasus.py @@ -20,8 +20,8 @@ from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow from transformers.utils import cached_property -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor if is_tf_available(): diff --git a/tests/pegasus/test_tokenization_pegasus.py b/tests/models/pegasus/test_tokenization_pegasus.py similarity index 99% rename from tests/pegasus/test_tokenization_pegasus.py rename to tests/models/pegasus/test_tokenization_pegasus.py index 7634902b584e..3f83e84178e7 100644 --- a/tests/pegasus/test_tokenization_pegasus.py +++ b/tests/models/pegasus/test_tokenization_pegasus.py @@ -18,7 +18,7 @@ from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, require_torch, slow from transformers.utils import cached_property -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece_no_bos.model") diff --git a/tests/phobert/__init__.py b/tests/models/perceiver/__init__.py similarity index 100% rename from tests/phobert/__init__.py rename to tests/models/perceiver/__init__.py diff --git a/tests/perceiver/test_modeling_perceiver.py b/tests/models/perceiver/test_modeling_perceiver.py similarity index 99% rename from tests/perceiver/test_modeling_perceiver.py rename to tests/models/perceiver/test_modeling_perceiver.py index 3f138373caf8..1fc102bc40a8 100644 --- a/tests/perceiver/test_modeling_perceiver.py +++ b/tests/models/perceiver/test_modeling_perceiver.py @@ -30,8 +30,8 @@ from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device from transformers.utils import is_torch_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/perceiver/test_tokenization_perceiver.py b/tests/models/perceiver/test_tokenization_perceiver.py similarity index 99% rename from tests/perceiver/test_tokenization_perceiver.py rename to tests/models/perceiver/test_tokenization_perceiver.py index 0b6b7d4c75a8..ca61e9c856f1 100644 --- a/tests/perceiver/test_tokenization_perceiver.py +++ b/tests/models/perceiver/test_tokenization_perceiver.py @@ -24,7 +24,7 @@ from transformers import AddedToken, BatchEncoding, PerceiverTokenizer from transformers.utils import cached_property, is_tf_available, is_torch_available -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin if is_torch_available(): diff --git a/tests/plbart/__init__.py b/tests/models/phobert/__init__.py similarity index 100% rename from tests/plbart/__init__.py rename to tests/models/phobert/__init__.py diff --git a/tests/phobert/test_tokenization_phobert.py b/tests/models/phobert/test_tokenization_phobert.py similarity index 97% rename from tests/phobert/test_tokenization_phobert.py rename to tests/models/phobert/test_tokenization_phobert.py index 87bdb95c5290..de16c154c925 100644 --- a/tests/phobert/test_tokenization_phobert.py +++ b/tests/models/phobert/test_tokenization_phobert.py @@ -18,7 +18,7 @@ from transformers.models.phobert.tokenization_phobert import VOCAB_FILES_NAMES, PhobertTokenizer -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin class PhobertTokenizationTest(TokenizerTesterMixin, unittest.TestCase): diff --git a/tests/poolformer/__init__.py b/tests/models/plbart/__init__.py similarity index 100% rename from tests/poolformer/__init__.py rename to tests/models/plbart/__init__.py diff --git a/tests/plbart/test_modeling_plbart.py b/tests/models/plbart/test_modeling_plbart.py similarity index 99% rename from tests/plbart/test_modeling_plbart.py rename to tests/models/plbart/test_modeling_plbart.py index 6a307e244e2a..073db546bf1a 100644 --- a/tests/plbart/test_modeling_plbart.py +++ b/tests/models/plbart/test_modeling_plbart.py @@ -23,9 +23,9 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device from transformers.utils import cached_property -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/plbart/test_tokenization_plbart.py b/tests/models/plbart/test_tokenization_plbart.py similarity index 97% rename from tests/plbart/test_tokenization_plbart.py rename to tests/models/plbart/test_tokenization_plbart.py index d83964e86d85..9aed6040f3fd 100644 --- a/tests/plbart/test_tokenization_plbart.py +++ b/tests/models/plbart/test_tokenization_plbart.py @@ -12,17 +12,22 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import tempfile import unittest from transformers import SPIECE_UNDERLINE, BatchEncoding, PLBartTokenizer, is_torch_available -from transformers.testing_utils import nested_simplify, require_sentencepiece, require_tokenizers, require_torch +from transformers.testing_utils import ( + get_tests_dir, + nested_simplify, + require_sentencepiece, + require_tokenizers, + require_torch, +) -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_VOCAB = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../fixtures/test_sentencepiece.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece.model") if is_torch_available(): diff --git a/tests/prophetnet/__init__.py b/tests/models/poolformer/__init__.py similarity index 100% rename from tests/prophetnet/__init__.py rename to tests/models/poolformer/__init__.py diff --git a/tests/poolformer/test_feature_extraction_poolformer.py b/tests/models/poolformer/test_feature_extraction_poolformer.py similarity index 98% rename from tests/poolformer/test_feature_extraction_poolformer.py rename to tests/models/poolformer/test_feature_extraction_poolformer.py index 5fd830a7ffbd..bb65835d5dc1 100644 --- a/tests/poolformer/test_feature_extraction_poolformer.py +++ b/tests/models/poolformer/test_feature_extraction_poolformer.py @@ -20,7 +20,7 @@ from transformers.testing_utils import require_torch, require_vision from transformers.utils import is_torch_available, is_vision_available -from ..test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs +from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs if is_torch_available(): diff --git a/tests/poolformer/test_modeling_poolformer.py b/tests/models/poolformer/test_modeling_poolformer.py similarity index 98% rename from tests/poolformer/test_modeling_poolformer.py rename to tests/models/poolformer/test_modeling_poolformer.py index 1c6ea9b0a24a..9bb8fa2e29cd 100644 --- a/tests/poolformer/test_modeling_poolformer.py +++ b/tests/models/poolformer/test_modeling_poolformer.py @@ -22,8 +22,8 @@ from transformers.models.auto import get_values from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/qdqbert/__init__.py b/tests/models/prophetnet/__init__.py similarity index 100% rename from tests/qdqbert/__init__.py rename to tests/models/prophetnet/__init__.py diff --git a/tests/prophetnet/test_modeling_prophetnet.py b/tests/models/prophetnet/test_modeling_prophetnet.py similarity index 99% rename from tests/prophetnet/test_modeling_prophetnet.py rename to tests/models/prophetnet/test_modeling_prophetnet.py index 17bf4523e756..e17e14072af5 100644 --- a/tests/prophetnet/test_modeling_prophetnet.py +++ b/tests/models/prophetnet/test_modeling_prophetnet.py @@ -20,9 +20,9 @@ from transformers import ProphetNetConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/prophetnet/test_tokenization_prophetnet.py b/tests/models/prophetnet/test_tokenization_prophetnet.py similarity index 99% rename from tests/prophetnet/test_tokenization_prophetnet.py rename to tests/models/prophetnet/test_tokenization_prophetnet.py index 270bbf53fdfc..5b44879d04b5 100644 --- a/tests/prophetnet/test_tokenization_prophetnet.py +++ b/tests/models/prophetnet/test_tokenization_prophetnet.py @@ -28,7 +28,7 @@ from transformers.models.prophetnet.tokenization_prophetnet import VOCAB_FILES_NAMES, ProphetNetTokenizer from transformers.testing_utils import require_torch, slow -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin class ProphetNetTokenizationTest(TokenizerTesterMixin, unittest.TestCase): diff --git a/tests/rag/__init__.py b/tests/models/qdqbert/__init__.py similarity index 100% rename from tests/rag/__init__.py rename to tests/models/qdqbert/__init__.py diff --git a/tests/qdqbert/test_modeling_qdqbert.py b/tests/models/qdqbert/test_modeling_qdqbert.py similarity index 99% rename from tests/qdqbert/test_modeling_qdqbert.py rename to tests/models/qdqbert/test_modeling_qdqbert.py index 5e53e59126c7..82bf5e3e3364 100644 --- a/tests/qdqbert/test_modeling_qdqbert.py +++ b/tests/models/qdqbert/test_modeling_qdqbert.py @@ -21,8 +21,8 @@ from transformers import QDQBertConfig, is_torch_available from transformers.testing_utils import require_pytorch_quantization, require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/realm/__init__.py b/tests/models/rag/__init__.py similarity index 100% rename from tests/realm/__init__.py rename to tests/models/rag/__init__.py diff --git a/tests/rag/test_modeling_rag.py b/tests/models/rag/test_modeling_rag.py similarity index 99% rename from tests/rag/test_modeling_rag.py rename to tests/models/rag/test_modeling_rag.py index 6914318cfac2..80819663a107 100644 --- a/tests/rag/test_modeling_rag.py +++ b/tests/models/rag/test_modeling_rag.py @@ -20,7 +20,6 @@ import shutil import tempfile import unittest -from os.path import dirname from unittest.mock import patch import numpy as np @@ -30,6 +29,7 @@ from transformers.models.dpr.tokenization_dpr import DPRContextEncoderTokenizer, DPRQuestionEncoderTokenizer from transformers.models.roberta.tokenization_roberta import VOCAB_FILES_NAMES as BART_VOCAB_FILES_NAMES from transformers.testing_utils import ( + get_tests_dir, require_sentencepiece, require_tokenizers, require_torch, @@ -46,7 +46,7 @@ TOLERANCE = 1e-3 -T5_SAMPLE_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece.model") +T5_SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece.model") if is_torch_available() and is_datasets_available() and is_faiss_available(): import torch from datasets import Dataset diff --git a/tests/rag/test_modeling_tf_rag.py b/tests/models/rag/test_modeling_tf_rag.py similarity index 100% rename from tests/rag/test_modeling_tf_rag.py rename to tests/models/rag/test_modeling_tf_rag.py diff --git a/tests/rag/test_retrieval_rag.py b/tests/models/rag/test_retrieval_rag.py similarity index 100% rename from tests/rag/test_retrieval_rag.py rename to tests/models/rag/test_retrieval_rag.py diff --git a/tests/rag/test_tokenization_rag.py b/tests/models/rag/test_tokenization_rag.py similarity index 100% rename from tests/rag/test_tokenization_rag.py rename to tests/models/rag/test_tokenization_rag.py diff --git a/tests/reformer/__init__.py b/tests/models/realm/__init__.py similarity index 100% rename from tests/reformer/__init__.py rename to tests/models/realm/__init__.py diff --git a/tests/realm/test_modeling_realm.py b/tests/models/realm/test_modeling_realm.py similarity index 99% rename from tests/realm/test_modeling_realm.py rename to tests/models/realm/test_modeling_realm.py index 02eaa6556e9f..e084cf5a4e18 100644 --- a/tests/realm/test_modeling_realm.py +++ b/tests/models/realm/test_modeling_realm.py @@ -22,8 +22,8 @@ from transformers import RealmConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/realm/test_retrieval_realm.py b/tests/models/realm/test_retrieval_realm.py similarity index 100% rename from tests/realm/test_retrieval_realm.py rename to tests/models/realm/test_retrieval_realm.py diff --git a/tests/realm/test_tokenization_realm.py b/tests/models/realm/test_tokenization_realm.py similarity index 99% rename from tests/realm/test_tokenization_realm.py rename to tests/models/realm/test_tokenization_realm.py index 6bc31eaa5776..a54da2898032 100644 --- a/tests/realm/test_tokenization_realm.py +++ b/tests/models/realm/test_tokenization_realm.py @@ -28,7 +28,7 @@ from transformers.models.realm.tokenization_realm import RealmTokenizer from transformers.testing_utils import require_tokenizers, slow -from ..test_tokenization_common import TokenizerTesterMixin, filter_non_english +from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english @require_tokenizers diff --git a/tests/regnet/__init__.py b/tests/models/reformer/__init__.py similarity index 100% rename from tests/regnet/__init__.py rename to tests/models/reformer/__init__.py diff --git a/tests/reformer/test_modeling_reformer.py b/tests/models/reformer/test_modeling_reformer.py similarity index 99% rename from tests/reformer/test_modeling_reformer.py rename to tests/models/reformer/test_modeling_reformer.py index d0259bacae18..1929867521a3 100644 --- a/tests/reformer/test_modeling_reformer.py +++ b/tests/models/reformer/test_modeling_reformer.py @@ -25,9 +25,9 @@ torch_device, ) -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/reformer/test_tokenization_reformer.py b/tests/models/reformer/test_tokenization_reformer.py similarity index 97% rename from tests/reformer/test_tokenization_reformer.py rename to tests/models/reformer/test_tokenization_reformer.py index 22e6e455e6f9..32f946c49760 100644 --- a/tests/reformer/test_tokenization_reformer.py +++ b/tests/models/reformer/test_tokenization_reformer.py @@ -12,18 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import unittest -from os.path import dirname from transformers import SPIECE_UNDERLINE, ReformerTokenizer, ReformerTokenizerFast -from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow +from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, require_torch, slow from transformers.utils import cached_property -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece.model") @require_sentencepiece diff --git a/tests/rembert/__init__.py b/tests/models/regnet/__init__.py similarity index 100% rename from tests/rembert/__init__.py rename to tests/models/regnet/__init__.py diff --git a/tests/regnet/test_modeling_regnet.py b/tests/models/regnet/test_modeling_regnet.py similarity index 98% rename from tests/regnet/test_modeling_regnet.py rename to tests/models/regnet/test_modeling_regnet.py index 2660108e96ae..02695dbf6434 100644 --- a/tests/regnet/test_modeling_regnet.py +++ b/tests/models/regnet/test_modeling_regnet.py @@ -22,8 +22,8 @@ from transformers.file_utils import cached_property, is_torch_available, is_vision_available from transformers.testing_utils import require_torch, require_vision, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/resnet/__init__.py b/tests/models/rembert/__init__.py similarity index 100% rename from tests/resnet/__init__.py rename to tests/models/rembert/__init__.py diff --git a/tests/rembert/test_modeling_rembert.py b/tests/models/rembert/test_modeling_rembert.py similarity index 99% rename from tests/rembert/test_modeling_rembert.py rename to tests/models/rembert/test_modeling_rembert.py index 94ec90497f4b..a3ffd6dfd5a1 100644 --- a/tests/rembert/test_modeling_rembert.py +++ b/tests/models/rembert/test_modeling_rembert.py @@ -20,8 +20,8 @@ from transformers import is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/rembert/test_modeling_tf_rembert.py b/tests/models/rembert/test_modeling_tf_rembert.py similarity index 99% rename from tests/rembert/test_modeling_tf_rembert.py rename to tests/models/rembert/test_modeling_tf_rembert.py index d5d52062e8c9..6d4cf0a523b9 100644 --- a/tests/rembert/test_modeling_tf_rembert.py +++ b/tests/models/rembert/test_modeling_tf_rembert.py @@ -19,8 +19,8 @@ from transformers import RemBertConfig, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/roberta/__init__.py b/tests/models/resnet/__init__.py similarity index 100% rename from tests/roberta/__init__.py rename to tests/models/resnet/__init__.py diff --git a/tests/resnet/test_modeling_resnet.py b/tests/models/resnet/test_modeling_resnet.py similarity index 98% rename from tests/resnet/test_modeling_resnet.py rename to tests/models/resnet/test_modeling_resnet.py index 7a0d1ee473d7..f289c5c3df84 100644 --- a/tests/resnet/test_modeling_resnet.py +++ b/tests/models/resnet/test_modeling_resnet.py @@ -22,8 +22,8 @@ from transformers.testing_utils import require_torch, require_vision, slow, torch_device from transformers.utils import cached_property, is_torch_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/roformer/__init__.py b/tests/models/roberta/__init__.py similarity index 100% rename from tests/roformer/__init__.py rename to tests/models/roberta/__init__.py diff --git a/tests/roberta/test_modeling_flax_roberta.py b/tests/models/roberta/test_modeling_flax_roberta.py similarity index 98% rename from tests/roberta/test_modeling_flax_roberta.py rename to tests/models/roberta/test_modeling_flax_roberta.py index 54f9ddf965f3..5bd8a56022ce 100644 --- a/tests/roberta/test_modeling_flax_roberta.py +++ b/tests/models/roberta/test_modeling_flax_roberta.py @@ -19,7 +19,7 @@ from transformers import RobertaConfig, is_flax_available from transformers.testing_utils import require_flax, slow -from ..test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_flax_available(): diff --git a/tests/roberta/test_modeling_roberta.py b/tests/models/roberta/test_modeling_roberta.py similarity index 98% rename from tests/roberta/test_modeling_roberta.py rename to tests/models/roberta/test_modeling_roberta.py index ab92c9dfbd65..e0b8b78b3b6c 100644 --- a/tests/roberta/test_modeling_roberta.py +++ b/tests/models/roberta/test_modeling_roberta.py @@ -20,9 +20,9 @@ from transformers import RobertaConfig, is_torch_available from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/roberta/test_modeling_tf_roberta.py b/tests/models/roberta/test_modeling_tf_roberta.py similarity index 99% rename from tests/roberta/test_modeling_tf_roberta.py rename to tests/models/roberta/test_modeling_tf_roberta.py index 9771673d8748..f9408b84171d 100644 --- a/tests/roberta/test_modeling_tf_roberta.py +++ b/tests/models/roberta/test_modeling_tf_roberta.py @@ -19,8 +19,8 @@ from transformers import RobertaConfig, is_tf_available from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/roberta/test_tokenization_roberta.py b/tests/models/roberta/test_tokenization_roberta.py similarity index 99% rename from tests/roberta/test_tokenization_roberta.py rename to tests/models/roberta/test_tokenization_roberta.py index a898d9bf5f5c..46ce5983f081 100644 --- a/tests/roberta/test_tokenization_roberta.py +++ b/tests/models/roberta/test_tokenization_roberta.py @@ -23,7 +23,7 @@ from transformers.models.roberta.tokenization_roberta import VOCAB_FILES_NAMES from transformers.testing_utils import require_tokenizers, slow -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_tokenizers diff --git a/tests/segformer/__init__.py b/tests/models/roformer/__init__.py similarity index 100% rename from tests/segformer/__init__.py rename to tests/models/roformer/__init__.py diff --git a/tests/roformer/test_modeling_flax_roformer.py b/tests/models/roformer/test_modeling_flax_roformer.py similarity index 98% rename from tests/roformer/test_modeling_flax_roformer.py rename to tests/models/roformer/test_modeling_flax_roformer.py index 01b643e897fd..d45c08efdbb3 100644 --- a/tests/roformer/test_modeling_flax_roformer.py +++ b/tests/models/roformer/test_modeling_flax_roformer.py @@ -19,7 +19,7 @@ from transformers import RoFormerConfig, is_flax_available from transformers.testing_utils import require_flax, slow -from ..test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask +from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask if is_flax_available(): diff --git a/tests/roformer/test_modeling_roformer.py b/tests/models/roformer/test_modeling_roformer.py similarity index 99% rename from tests/roformer/test_modeling_roformer.py rename to tests/models/roformer/test_modeling_roformer.py index f5177a91d5a9..b1d7f3d8a67c 100644 --- a/tests/roformer/test_modeling_roformer.py +++ b/tests/models/roformer/test_modeling_roformer.py @@ -20,8 +20,8 @@ from transformers import RoFormerConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/roformer/test_modeling_tf_roformer.py b/tests/models/roformer/test_modeling_tf_roformer.py similarity index 99% rename from tests/roformer/test_modeling_tf_roformer.py rename to tests/models/roformer/test_modeling_tf_roformer.py index 9a23ca3b83d2..d32d30ae8ad9 100644 --- a/tests/roformer/test_modeling_tf_roformer.py +++ b/tests/models/roformer/test_modeling_tf_roformer.py @@ -19,8 +19,8 @@ from transformers import RoFormerConfig, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/roformer/test_tokenization_roformer.py b/tests/models/roformer/test_tokenization_roformer.py similarity index 97% rename from tests/roformer/test_tokenization_roformer.py rename to tests/models/roformer/test_tokenization_roformer.py index e5db42890d99..db31b34de8c9 100644 --- a/tests/roformer/test_tokenization_roformer.py +++ b/tests/models/roformer/test_tokenization_roformer.py @@ -18,7 +18,7 @@ from transformers import RoFormerTokenizer, RoFormerTokenizerFast from transformers.testing_utils import require_rjieba, require_tokenizers -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_rjieba diff --git a/tests/sew/__init__.py b/tests/models/segformer/__init__.py similarity index 100% rename from tests/sew/__init__.py rename to tests/models/segformer/__init__.py diff --git a/tests/segformer/test_feature_extraction_segformer.py b/tests/models/segformer/test_feature_extraction_segformer.py similarity index 99% rename from tests/segformer/test_feature_extraction_segformer.py rename to tests/models/segformer/test_feature_extraction_segformer.py index c34cb6fc0df2..75083012d875 100644 --- a/tests/segformer/test_feature_extraction_segformer.py +++ b/tests/models/segformer/test_feature_extraction_segformer.py @@ -22,7 +22,7 @@ from transformers.testing_utils import require_torch, require_vision from transformers.utils import is_torch_available, is_vision_available -from ..test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs +from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs if is_torch_available(): diff --git a/tests/segformer/test_modeling_segformer.py b/tests/models/segformer/test_modeling_segformer.py similarity index 99% rename from tests/segformer/test_modeling_segformer.py rename to tests/models/segformer/test_modeling_segformer.py index 668298507871..9af59299f8ec 100644 --- a/tests/segformer/test_modeling_segformer.py +++ b/tests/models/segformer/test_modeling_segformer.py @@ -22,8 +22,8 @@ from transformers.models.auto import get_values from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/sew_d/__init__.py b/tests/models/sew/__init__.py similarity index 100% rename from tests/sew_d/__init__.py rename to tests/models/sew/__init__.py diff --git a/tests/sew/test_modeling_sew.py b/tests/models/sew/test_modeling_sew.py similarity index 99% rename from tests/sew/test_modeling_sew.py rename to tests/models/sew/test_modeling_sew.py index 9881f5166db9..9df69f84677e 100644 --- a/tests/sew/test_modeling_sew.py +++ b/tests/models/sew/test_modeling_sew.py @@ -23,8 +23,8 @@ from transformers import SEWConfig, is_torch_available from transformers.testing_utils import require_soundfile, require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ( +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ( ModelTesterMixin, _config_zero_init, floats_tensor, diff --git a/tests/speech_encoder_decoder/__init__.py b/tests/models/sew_d/__init__.py similarity index 100% rename from tests/speech_encoder_decoder/__init__.py rename to tests/models/sew_d/__init__.py diff --git a/tests/sew_d/test_modeling_sew_d.py b/tests/models/sew_d/test_modeling_sew_d.py similarity index 99% rename from tests/sew_d/test_modeling_sew_d.py rename to tests/models/sew_d/test_modeling_sew_d.py index 7c65909c9f4a..334b10abf3ec 100644 --- a/tests/sew_d/test_modeling_sew_d.py +++ b/tests/models/sew_d/test_modeling_sew_d.py @@ -23,8 +23,8 @@ from transformers import SEWDConfig, is_torch_available from transformers.testing_utils import require_soundfile, require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ( +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ( ModelTesterMixin, _config_zero_init, floats_tensor, diff --git a/tests/speech_to_text/__init__.py b/tests/models/speech_encoder_decoder/__init__.py similarity index 100% rename from tests/speech_to_text/__init__.py rename to tests/models/speech_encoder_decoder/__init__.py diff --git a/tests/speech_encoder_decoder/test_modeling_flax_speech_encoder_decoder.py b/tests/models/speech_encoder_decoder/test_modeling_flax_speech_encoder_decoder.py similarity index 99% rename from tests/speech_encoder_decoder/test_modeling_flax_speech_encoder_decoder.py rename to tests/models/speech_encoder_decoder/test_modeling_flax_speech_encoder_decoder.py index c32b4459f106..432d16d3facd 100644 --- a/tests/speech_encoder_decoder/test_modeling_flax_speech_encoder_decoder.py +++ b/tests/models/speech_encoder_decoder/test_modeling_flax_speech_encoder_decoder.py @@ -21,10 +21,10 @@ from transformers import is_flax_available, is_torch_available from transformers.testing_utils import is_pt_flax_cross_test, require_flax, slow, torch_device +from ...test_modeling_flax_common import floats_tensor, ids_tensor, random_attention_mask from ..bart.test_modeling_flax_bart import FlaxBartStandaloneDecoderModelTester from ..bert.test_modeling_flax_bert import FlaxBertModelTester from ..gpt2.test_modeling_flax_gpt2 import FlaxGPT2ModelTester -from ..test_modeling_flax_common import floats_tensor, ids_tensor, random_attention_mask from ..wav2vec2.test_modeling_flax_wav2vec2 import FlaxWav2Vec2ModelTester diff --git a/tests/speech_encoder_decoder/test_modeling_speech_encoder_decoder.py b/tests/models/speech_encoder_decoder/test_modeling_speech_encoder_decoder.py similarity index 99% rename from tests/speech_encoder_decoder/test_modeling_speech_encoder_decoder.py rename to tests/models/speech_encoder_decoder/test_modeling_speech_encoder_decoder.py index bf7428d716c9..2d934744f9e4 100644 --- a/tests/speech_encoder_decoder/test_modeling_speech_encoder_decoder.py +++ b/tests/models/speech_encoder_decoder/test_modeling_speech_encoder_decoder.py @@ -20,10 +20,10 @@ from transformers import is_torch_available from transformers.testing_utils import require_torch, slow, torch_device +from ...test_modeling_common import floats_tensor, ids_tensor, random_attention_mask from ..bert.test_modeling_bert import BertModelTester from ..speech_to_text.test_modeling_speech_to_text import Speech2TextModelTester from ..speech_to_text_2.test_modeling_speech_to_text_2 import Speech2Text2StandaloneDecoderModelTester -from ..test_modeling_common import floats_tensor, ids_tensor, random_attention_mask from ..wav2vec2.test_modeling_wav2vec2 import Wav2Vec2ModelTester diff --git a/tests/speech_to_text_2/__init__.py b/tests/models/speech_to_text/__init__.py similarity index 100% rename from tests/speech_to_text_2/__init__.py rename to tests/models/speech_to_text/__init__.py diff --git a/tests/speech_to_text/test_feature_extraction_speech_to_text.py b/tests/models/speech_to_text/test_feature_extraction_speech_to_text.py similarity index 99% rename from tests/speech_to_text/test_feature_extraction_speech_to_text.py rename to tests/models/speech_to_text/test_feature_extraction_speech_to_text.py index 9d719e4e1bf9..244b748c7139 100644 --- a/tests/speech_to_text/test_feature_extraction_speech_to_text.py +++ b/tests/models/speech_to_text/test_feature_extraction_speech_to_text.py @@ -23,7 +23,7 @@ from transformers import is_speech_available from transformers.testing_utils import require_torch, require_torchaudio -from ..test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin +from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin if is_speech_available(): diff --git a/tests/speech_to_text/test_modeling_speech_to_text.py b/tests/models/speech_to_text/test_modeling_speech_to_text.py similarity index 99% rename from tests/speech_to_text/test_modeling_speech_to_text.py rename to tests/models/speech_to_text/test_modeling_speech_to_text.py index 82b1c74c59dc..08b94b6465d5 100644 --- a/tests/speech_to_text/test_modeling_speech_to_text.py +++ b/tests/models/speech_to_text/test_modeling_speech_to_text.py @@ -32,9 +32,9 @@ ) from transformers.utils import cached_property -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/speech_to_text/test_modeling_tf_speech_to_text.py b/tests/models/speech_to_text/test_modeling_tf_speech_to_text.py similarity index 99% rename from tests/speech_to_text/test_modeling_tf_speech_to_text.py rename to tests/models/speech_to_text/test_modeling_tf_speech_to_text.py index 897c54722a2f..6485690645a9 100644 --- a/tests/speech_to_text/test_modeling_tf_speech_to_text.py +++ b/tests/models/speech_to_text/test_modeling_tf_speech_to_text.py @@ -21,8 +21,8 @@ from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow from transformers.utils import cached_property, is_tf_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor if is_tf_available(): diff --git a/tests/speech_to_text/test_processor_speech_to_text.py b/tests/models/speech_to_text/test_processor_speech_to_text.py similarity index 96% rename from tests/speech_to_text/test_processor_speech_to_text.py rename to tests/models/speech_to_text/test_processor_speech_to_text.py index 05871a2bb068..e6e43f1bb8d7 100644 --- a/tests/speech_to_text/test_processor_speech_to_text.py +++ b/tests/models/speech_to_text/test_processor_speech_to_text.py @@ -12,17 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import shutil import tempfile import unittest -from os.path import dirname from pathlib import Path from shutil import copyfile from transformers import Speech2TextTokenizer, is_speech_available from transformers.models.speech_to_text.tokenization_speech_to_text import VOCAB_FILES_NAMES, save_json -from transformers.testing_utils import require_sentencepiece, require_torch, require_torchaudio +from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_torch, require_torchaudio from transformers.utils import FEATURE_EXTRACTOR_NAME from .test_feature_extraction_speech_to_text import floats_list @@ -32,7 +30,7 @@ from transformers import Speech2TextFeatureExtractor, Speech2TextProcessor -SAMPLE_SP = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece.model") +SAMPLE_SP = get_tests_dir("fixtures/test_sentencepiece.model") @require_torch diff --git a/tests/speech_to_text/test_tokenization_speech_to_text.py b/tests/models/speech_to_text/test_tokenization_speech_to_text.py similarity index 97% rename from tests/speech_to_text/test_tokenization_speech_to_text.py rename to tests/models/speech_to_text/test_tokenization_speech_to_text.py index 43f26092ff61..3b2ef9f456f4 100644 --- a/tests/speech_to_text/test_tokenization_speech_to_text.py +++ b/tests/models/speech_to_text/test_tokenization_speech_to_text.py @@ -12,21 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import unittest -from os.path import dirname from pathlib import Path from shutil import copyfile from transformers import SPIECE_UNDERLINE, is_sentencepiece_available from transformers.models.speech_to_text import Speech2TextTokenizer from transformers.models.speech_to_text.tokenization_speech_to_text import VOCAB_FILES_NAMES, save_json -from transformers.testing_utils import require_sentencepiece, require_tokenizers, slow +from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_SP = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece.model") +SAMPLE_SP = get_tests_dir("fixtures/test_sentencepiece.model") if is_sentencepiece_available(): import sentencepiece as sp diff --git a/tests/splinter/__init__.py b/tests/models/speech_to_text_2/__init__.py similarity index 100% rename from tests/splinter/__init__.py rename to tests/models/speech_to_text_2/__init__.py diff --git a/tests/speech_to_text_2/test_modeling_speech_to_text_2.py b/tests/models/speech_to_text_2/test_modeling_speech_to_text_2.py similarity index 97% rename from tests/speech_to_text_2/test_modeling_speech_to_text_2.py rename to tests/models/speech_to_text_2/test_modeling_speech_to_text_2.py index 861e4acedc6e..88d055067575 100644 --- a/tests/speech_to_text_2/test_modeling_speech_to_text_2.py +++ b/tests/models/speech_to_text_2/test_modeling_speech_to_text_2.py @@ -19,9 +19,9 @@ from transformers import Speech2Text2Config from transformers.testing_utils import is_torch_available, require_torch, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/speech_to_text_2/test_tokenization_speech_to_text_2.py b/tests/models/speech_to_text_2/test_tokenization_speech_to_text_2.py similarity index 98% rename from tests/speech_to_text_2/test_tokenization_speech_to_text_2.py rename to tests/models/speech_to_text_2/test_tokenization_speech_to_text_2.py index 072473851fc3..1000cce28980 100644 --- a/tests/speech_to_text_2/test_tokenization_speech_to_text_2.py +++ b/tests/models/speech_to_text_2/test_tokenization_speech_to_text_2.py @@ -21,7 +21,7 @@ from transformers.models.speech_to_text_2 import Speech2Text2Tokenizer from transformers.models.speech_to_text_2.tokenization_speech_to_text_2 import VOCAB_FILES_NAMES -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin class SpeechToTextTokenizerTest(TokenizerTesterMixin, unittest.TestCase): diff --git a/tests/squeezebert/__init__.py b/tests/models/splinter/__init__.py similarity index 100% rename from tests/squeezebert/__init__.py rename to tests/models/splinter/__init__.py diff --git a/tests/splinter/test_modeling_splinter.py b/tests/models/splinter/test_modeling_splinter.py similarity index 98% rename from tests/splinter/test_modeling_splinter.py rename to tests/models/splinter/test_modeling_splinter.py index 1b6cfeac9537..9b62b822c098 100644 --- a/tests/splinter/test_modeling_splinter.py +++ b/tests/models/splinter/test_modeling_splinter.py @@ -20,8 +20,8 @@ from transformers import is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/swin/__init__.py b/tests/models/squeezebert/__init__.py similarity index 100% rename from tests/swin/__init__.py rename to tests/models/squeezebert/__init__.py diff --git a/tests/squeezebert/test_modeling_squeezebert.py b/tests/models/squeezebert/test_modeling_squeezebert.py similarity index 98% rename from tests/squeezebert/test_modeling_squeezebert.py rename to tests/models/squeezebert/test_modeling_squeezebert.py index c728aa2b0c2c..cffc4570a059 100644 --- a/tests/squeezebert/test_modeling_squeezebert.py +++ b/tests/models/squeezebert/test_modeling_squeezebert.py @@ -19,8 +19,8 @@ from transformers import SqueezeBertConfig, is_torch_available from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/squeezebert/test_tokenization_squeezebert.py b/tests/models/squeezebert/test_tokenization_squeezebert.py similarity index 100% rename from tests/squeezebert/test_tokenization_squeezebert.py rename to tests/models/squeezebert/test_tokenization_squeezebert.py diff --git a/tests/t5/__init__.py b/tests/models/swin/__init__.py similarity index 100% rename from tests/t5/__init__.py rename to tests/models/swin/__init__.py diff --git a/tests/swin/test_modeling_swin.py b/tests/models/swin/test_modeling_swin.py similarity index 99% rename from tests/swin/test_modeling_swin.py rename to tests/models/swin/test_modeling_swin.py index 2147f578e73e..ef7a64e998d7 100644 --- a/tests/swin/test_modeling_swin.py +++ b/tests/models/swin/test_modeling_swin.py @@ -22,8 +22,8 @@ from transformers.testing_utils import require_torch, require_vision, slow, torch_device from transformers.utils import cached_property, is_torch_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/tapas/__init__.py b/tests/models/t5/__init__.py similarity index 100% rename from tests/tapas/__init__.py rename to tests/models/t5/__init__.py diff --git a/tests/t5/test_modeling_flax_t5.py b/tests/models/t5/test_modeling_flax_t5.py similarity index 99% rename from tests/t5/test_modeling_flax_t5.py rename to tests/models/t5/test_modeling_flax_t5.py index f4d8ebbab1ae..7971bb4116df 100644 --- a/tests/t5/test_modeling_flax_t5.py +++ b/tests/models/t5/test_modeling_flax_t5.py @@ -27,9 +27,9 @@ slow, ) -from ..generation.test_generation_flax_utils import FlaxGenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor +from ...generation.test_generation_flax_utils import FlaxGenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor if is_flax_available(): diff --git a/tests/t5/test_modeling_t5.py b/tests/models/t5/test_modeling_t5.py similarity index 99% rename from tests/t5/test_modeling_t5.py rename to tests/models/t5/test_modeling_t5.py index 8380484b0606..d57300418473 100644 --- a/tests/t5/test_modeling_t5.py +++ b/tests/models/t5/test_modeling_t5.py @@ -22,9 +22,9 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device from transformers.utils import cached_property -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/t5/test_modeling_tf_t5.py b/tests/models/t5/test_modeling_tf_t5.py similarity index 99% rename from tests/t5/test_modeling_tf_t5.py rename to tests/models/t5/test_modeling_tf_t5.py index d3008f017de7..1450a8c7710c 100644 --- a/tests/t5/test_modeling_tf_t5.py +++ b/tests/models/t5/test_modeling_tf_t5.py @@ -19,8 +19,8 @@ from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow from transformers.utils import cached_property -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/t5/test_tokenization_t5.py b/tests/models/t5/test_tokenization_t5.py similarity index 99% rename from tests/t5/test_tokenization_t5.py rename to tests/models/t5/test_tokenization_t5.py index 6f5b0f1198a5..1c0fde222cdb 100644 --- a/tests/t5/test_tokenization_t5.py +++ b/tests/models/t5/test_tokenization_t5.py @@ -21,7 +21,7 @@ from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow from transformers.utils import cached_property, is_tf_available, is_torch_available -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece.model") diff --git a/tests/tapex/__init__.py b/tests/models/tapas/__init__.py similarity index 100% rename from tests/tapex/__init__.py rename to tests/models/tapas/__init__.py diff --git a/tests/tapas/test_modeling_tapas.py b/tests/models/tapas/test_modeling_tapas.py similarity index 99% rename from tests/tapas/test_modeling_tapas.py rename to tests/models/tapas/test_modeling_tapas.py index 385af04dedad..31c9b38c8f86 100644 --- a/tests/tapas/test_modeling_tapas.py +++ b/tests/models/tapas/test_modeling_tapas.py @@ -35,8 +35,8 @@ from transformers.testing_utils import require_scatter, require_torch, slow, torch_device from transformers.utils import cached_property -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/tapas/test_modeling_tf_tapas.py b/tests/models/tapas/test_modeling_tf_tapas.py similarity index 99% rename from tests/tapas/test_modeling_tf_tapas.py rename to tests/models/tapas/test_modeling_tf_tapas.py index 9e3cb63f70b5..147eb472702e 100644 --- a/tests/tapas/test_modeling_tf_tapas.py +++ b/tests/models/tapas/test_modeling_tf_tapas.py @@ -37,8 +37,8 @@ from transformers.testing_utils import require_tensorflow_probability, require_tf, slow from transformers.utils import cached_property -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/tapas/test_tokenization_tapas.py b/tests/models/tapas/test_tokenization_tapas.py similarity index 99% rename from tests/tapas/test_tokenization_tapas.py rename to tests/models/tapas/test_tokenization_tapas.py index a5c6da2a41b9..002f8c7e7549 100644 --- a/tests/tapas/test_tokenization_tapas.py +++ b/tests/models/tapas/test_tokenization_tapas.py @@ -41,7 +41,7 @@ slow, ) -from ..test_tokenization_common import TokenizerTesterMixin, filter_non_english, merge_model_tokenizer_mappings +from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english, merge_model_tokenizer_mappings @require_tokenizers diff --git a/tests/transfo_xl/__init__.py b/tests/models/tapex/__init__.py similarity index 100% rename from tests/transfo_xl/__init__.py rename to tests/models/tapex/__init__.py diff --git a/tests/tapex/test_tokenization_tapex.py b/tests/models/tapex/test_tokenization_tapex.py similarity index 99% rename from tests/tapex/test_tokenization_tapex.py rename to tests/models/tapex/test_tokenization_tapex.py index dd9f3d4bcf25..c959b780215b 100644 --- a/tests/tapex/test_tokenization_tapex.py +++ b/tests/models/tapex/test_tokenization_tapex.py @@ -27,7 +27,7 @@ from transformers.models.tapex.tokenization_tapex import VOCAB_FILES_NAMES from transformers.testing_utils import is_pt_tf_cross_test, require_pandas, slow -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_pandas diff --git a/tests/trocr/__init__.py b/tests/models/transfo_xl/__init__.py similarity index 100% rename from tests/trocr/__init__.py rename to tests/models/transfo_xl/__init__.py diff --git a/tests/transfo_xl/test_modeling_tf_transfo_xl.py b/tests/models/transfo_xl/test_modeling_tf_transfo_xl.py similarity index 98% rename from tests/transfo_xl/test_modeling_tf_transfo_xl.py rename to tests/models/transfo_xl/test_modeling_tf_transfo_xl.py index 87aca5097a4f..129b2ac4cf73 100644 --- a/tests/transfo_xl/test_modeling_tf_transfo_xl.py +++ b/tests/models/transfo_xl/test_modeling_tf_transfo_xl.py @@ -20,8 +20,8 @@ from transformers import TransfoXLConfig, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor if is_tf_available(): diff --git a/tests/transfo_xl/test_modeling_transfo_xl.py b/tests/models/transfo_xl/test_modeling_transfo_xl.py similarity index 99% rename from tests/transfo_xl/test_modeling_transfo_xl.py rename to tests/models/transfo_xl/test_modeling_transfo_xl.py index d4dbba448a95..309811efb465 100644 --- a/tests/transfo_xl/test_modeling_transfo_xl.py +++ b/tests/models/transfo_xl/test_modeling_transfo_xl.py @@ -20,9 +20,9 @@ from transformers import TransfoXLConfig, is_torch_available from transformers.testing_utils import require_torch, require_torch_multi_gpu, slow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/transfo_xl/test_tokenization_transfo_xl.py b/tests/models/transfo_xl/test_tokenization_transfo_xl.py similarity index 98% rename from tests/transfo_xl/test_tokenization_transfo_xl.py rename to tests/models/transfo_xl/test_tokenization_transfo_xl.py index 261fcf00445a..3f7065c51b47 100644 --- a/tests/transfo_xl/test_tokenization_transfo_xl.py +++ b/tests/models/transfo_xl/test_tokenization_transfo_xl.py @@ -19,7 +19,7 @@ from transformers.models.transfo_xl.tokenization_transfo_xl import VOCAB_FILES_NAMES, TransfoXLTokenizer -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin class TransfoXLTokenizationTest(TokenizerTesterMixin, unittest.TestCase): diff --git a/tests/unispeech/__init__.py b/tests/models/trocr/__init__.py similarity index 100% rename from tests/unispeech/__init__.py rename to tests/models/trocr/__init__.py diff --git a/tests/trocr/test_modeling_trocr.py b/tests/models/trocr/test_modeling_trocr.py similarity index 97% rename from tests/trocr/test_modeling_trocr.py rename to tests/models/trocr/test_modeling_trocr.py index b15b059f9299..6d8ff0aa606e 100644 --- a/tests/trocr/test_modeling_trocr.py +++ b/tests/models/trocr/test_modeling_trocr.py @@ -19,9 +19,9 @@ from transformers import TrOCRConfig from transformers.testing_utils import is_torch_available, require_torch, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor if is_torch_available(): diff --git a/tests/unispeech_sat/__init__.py b/tests/models/unispeech/__init__.py similarity index 100% rename from tests/unispeech_sat/__init__.py rename to tests/models/unispeech/__init__.py diff --git a/tests/unispeech/test_modeling_unispeech.py b/tests/models/unispeech/test_modeling_unispeech.py similarity index 99% rename from tests/unispeech/test_modeling_unispeech.py rename to tests/models/unispeech/test_modeling_unispeech.py index 3654f28a8f12..228b0dd175f8 100644 --- a/tests/unispeech/test_modeling_unispeech.py +++ b/tests/models/unispeech/test_modeling_unispeech.py @@ -24,8 +24,8 @@ from transformers import UniSpeechConfig, is_torch_available from transformers.testing_utils import require_soundfile, require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ( +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ( ModelTesterMixin, _config_zero_init, floats_tensor, diff --git a/tests/van/__init__.py b/tests/models/unispeech_sat/__init__.py similarity index 100% rename from tests/van/__init__.py rename to tests/models/unispeech_sat/__init__.py diff --git a/tests/unispeech_sat/test_modeling_unispeech_sat.py b/tests/models/unispeech_sat/test_modeling_unispeech_sat.py similarity index 99% rename from tests/unispeech_sat/test_modeling_unispeech_sat.py rename to tests/models/unispeech_sat/test_modeling_unispeech_sat.py index 537892b5bf9c..6ac06e4db9be 100644 --- a/tests/unispeech_sat/test_modeling_unispeech_sat.py +++ b/tests/models/unispeech_sat/test_modeling_unispeech_sat.py @@ -24,8 +24,8 @@ from transformers import UniSpeechSatConfig, is_torch_available from transformers.testing_utils import require_soundfile, require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ( +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ( ModelTesterMixin, _config_zero_init, floats_tensor, diff --git a/tests/vilt/__init__.py b/tests/models/van/__init__.py similarity index 100% rename from tests/vilt/__init__.py rename to tests/models/van/__init__.py diff --git a/tests/van/test_modeling_van.py b/tests/models/van/test_modeling_van.py similarity index 98% rename from tests/van/test_modeling_van.py rename to tests/models/van/test_modeling_van.py index dff60fea38b7..3e5b7fb1dfc7 100644 --- a/tests/van/test_modeling_van.py +++ b/tests/models/van/test_modeling_van.py @@ -23,8 +23,8 @@ from transformers.testing_utils import require_scipy, require_torch, require_vision, slow, torch_device from transformers.utils import cached_property, is_scipy_available, is_torch_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor if is_scipy_available(): diff --git a/tests/vision_encoder_decoder/__init__.py b/tests/models/vilt/__init__.py similarity index 100% rename from tests/vision_encoder_decoder/__init__.py rename to tests/models/vilt/__init__.py diff --git a/tests/vilt/test_feature_extraction_vilt.py b/tests/models/vilt/test_feature_extraction_vilt.py similarity index 98% rename from tests/vilt/test_feature_extraction_vilt.py rename to tests/models/vilt/test_feature_extraction_vilt.py index 7c82e63eaf69..62a9783c815a 100644 --- a/tests/vilt/test_feature_extraction_vilt.py +++ b/tests/models/vilt/test_feature_extraction_vilt.py @@ -21,7 +21,7 @@ from transformers.testing_utils import require_torch, require_vision from transformers.utils import is_torch_available, is_vision_available -from ..test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs +from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs if is_torch_available(): diff --git a/tests/vilt/test_modeling_vilt.py b/tests/models/vilt/test_modeling_vilt.py similarity index 99% rename from tests/vilt/test_modeling_vilt.py rename to tests/models/vilt/test_modeling_vilt.py index 2ddf9c3455d0..0c6783c439a3 100644 --- a/tests/vilt/test_modeling_vilt.py +++ b/tests/models/vilt/test_modeling_vilt.py @@ -24,8 +24,8 @@ from transformers.testing_utils import require_torch, require_vision, slow, torch_device from transformers.utils import cached_property -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/vision_text_dual_encoder/__init__.py b/tests/models/vision_encoder_decoder/__init__.py similarity index 100% rename from tests/vision_text_dual_encoder/__init__.py rename to tests/models/vision_encoder_decoder/__init__.py diff --git a/tests/vision_encoder_decoder/test_modeling_flax_vision_encoder_decoder.py b/tests/models/vision_encoder_decoder/test_modeling_flax_vision_encoder_decoder.py similarity index 99% rename from tests/vision_encoder_decoder/test_modeling_flax_vision_encoder_decoder.py rename to tests/models/vision_encoder_decoder/test_modeling_flax_vision_encoder_decoder.py index 163b8ddaa231..f874ad1c6337 100644 --- a/tests/vision_encoder_decoder/test_modeling_flax_vision_encoder_decoder.py +++ b/tests/models/vision_encoder_decoder/test_modeling_flax_vision_encoder_decoder.py @@ -22,8 +22,8 @@ from transformers import is_flax_available, is_torch_available, is_vision_available from transformers.testing_utils import is_pt_flax_cross_test, require_flax, require_vision, slow, torch_device +from ...test_modeling_flax_common import floats_tensor, ids_tensor from ..gpt2.test_modeling_flax_gpt2 import FlaxGPT2ModelTester -from ..test_modeling_flax_common import floats_tensor, ids_tensor from ..vit.test_modeling_flax_vit import FlaxViTModelTester diff --git a/tests/vision_encoder_decoder/test_modeling_tf_vision_encoder_decoder.py b/tests/models/vision_encoder_decoder/test_modeling_tf_vision_encoder_decoder.py similarity index 99% rename from tests/vision_encoder_decoder/test_modeling_tf_vision_encoder_decoder.py rename to tests/models/vision_encoder_decoder/test_modeling_tf_vision_encoder_decoder.py index 158aa4e5f076..9edbd3f802fb 100644 --- a/tests/vision_encoder_decoder/test_modeling_tf_vision_encoder_decoder.py +++ b/tests/models/vision_encoder_decoder/test_modeling_tf_vision_encoder_decoder.py @@ -32,8 +32,8 @@ torch_device, ) +from ...test_modeling_tf_common import floats_tensor, ids_tensor from ..gpt2.test_modeling_tf_gpt2 import TFGPT2ModelTester -from ..test_modeling_tf_common import floats_tensor, ids_tensor from ..vit.test_modeling_tf_vit import TFViTModelTester diff --git a/tests/vision_encoder_decoder/test_modeling_vision_encoder_decoder.py b/tests/models/vision_encoder_decoder/test_modeling_vision_encoder_decoder.py similarity index 99% rename from tests/vision_encoder_decoder/test_modeling_vision_encoder_decoder.py rename to tests/models/vision_encoder_decoder/test_modeling_vision_encoder_decoder.py index b867778ec965..f8ac8f1cdf1c 100644 --- a/tests/vision_encoder_decoder/test_modeling_vision_encoder_decoder.py +++ b/tests/models/vision_encoder_decoder/test_modeling_vision_encoder_decoder.py @@ -23,11 +23,11 @@ from transformers.testing_utils import require_torch, require_vision, slow, torch_device from transformers.utils import cached_property, is_torch_available, is_vision_available +from ...test_modeling_common import floats_tensor, ids_tensor, random_attention_mask from ..bart.test_modeling_bart import BartModelTester from ..bert.test_modeling_bert import BertModelTester from ..deit.test_modeling_deit import DeiTModelTester from ..swin.test_modeling_swin import SwinModelTester -from ..test_modeling_common import floats_tensor, ids_tensor, random_attention_mask from ..trocr.test_modeling_trocr import TrOCRStandaloneDecoderModelTester from ..vit.test_modeling_vit import ViTModelTester diff --git a/tests/visual_bert/__init__.py b/tests/models/vision_text_dual_encoder/__init__.py similarity index 100% rename from tests/visual_bert/__init__.py rename to tests/models/vision_text_dual_encoder/__init__.py diff --git a/tests/vision_text_dual_encoder/test_modeling_flax_vision_text_dual_encoder.py b/tests/models/vision_text_dual_encoder/test_modeling_flax_vision_text_dual_encoder.py similarity index 99% rename from tests/vision_text_dual_encoder/test_modeling_flax_vision_text_dual_encoder.py rename to tests/models/vision_text_dual_encoder/test_modeling_flax_vision_text_dual_encoder.py index 27893a3d3ba0..cb476c128aa6 100644 --- a/tests/vision_text_dual_encoder/test_modeling_flax_vision_text_dual_encoder.py +++ b/tests/models/vision_text_dual_encoder/test_modeling_flax_vision_text_dual_encoder.py @@ -31,9 +31,9 @@ ) from transformers.utils import is_flax_available, is_torch_available, is_vision_available +from ...test_modeling_flax_common import floats_tensor, ids_tensor, random_attention_mask from ..bert.test_modeling_flax_bert import FlaxBertModelTester from ..clip.test_modeling_flax_clip import FlaxCLIPVisionModelTester -from ..test_modeling_flax_common import floats_tensor, ids_tensor, random_attention_mask from ..vit.test_modeling_flax_vit import FlaxViTModelTester diff --git a/tests/vision_text_dual_encoder/test_modeling_vision_text_dual_encoder.py b/tests/models/vision_text_dual_encoder/test_modeling_vision_text_dual_encoder.py similarity index 99% rename from tests/vision_text_dual_encoder/test_modeling_vision_text_dual_encoder.py rename to tests/models/vision_text_dual_encoder/test_modeling_vision_text_dual_encoder.py index a5fd8eb9113c..18182047d664 100644 --- a/tests/vision_text_dual_encoder/test_modeling_vision_text_dual_encoder.py +++ b/tests/models/vision_text_dual_encoder/test_modeling_vision_text_dual_encoder.py @@ -24,11 +24,11 @@ from transformers.testing_utils import is_pt_flax_cross_test, require_torch, require_vision, slow, torch_device from transformers.utils import is_flax_available, is_torch_available, is_vision_available +from ...test_modeling_common import floats_tensor, ids_tensor, random_attention_mask from ..bert.test_modeling_bert import BertModelTester from ..clip.test_modeling_clip import CLIPVisionModelTester from ..deit.test_modeling_deit import DeiTModelTester from ..roberta.test_modeling_roberta import RobertaModelTester -from ..test_modeling_common import floats_tensor, ids_tensor, random_attention_mask from ..vit.test_modeling_vit import ViTModelTester diff --git a/tests/vision_text_dual_encoder/test_processor_vision_text_dual_encoder.py b/tests/models/vision_text_dual_encoder/test_processor_vision_text_dual_encoder.py similarity index 100% rename from tests/vision_text_dual_encoder/test_processor_vision_text_dual_encoder.py rename to tests/models/vision_text_dual_encoder/test_processor_vision_text_dual_encoder.py diff --git a/tests/vit/__init__.py b/tests/models/visual_bert/__init__.py similarity index 100% rename from tests/vit/__init__.py rename to tests/models/visual_bert/__init__.py diff --git a/tests/visual_bert/test_modeling_visual_bert.py b/tests/models/visual_bert/test_modeling_visual_bert.py similarity index 99% rename from tests/visual_bert/test_modeling_visual_bert.py rename to tests/models/visual_bert/test_modeling_visual_bert.py index e84b4d11a14d..99db914072cc 100644 --- a/tests/visual_bert/test_modeling_visual_bert.py +++ b/tests/models/visual_bert/test_modeling_visual_bert.py @@ -20,8 +20,8 @@ from transformers import VisualBertConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/vit_mae/__init__.py b/tests/models/vit/__init__.py similarity index 100% rename from tests/vit_mae/__init__.py rename to tests/models/vit/__init__.py diff --git a/tests/vit/test_feature_extraction_vit.py b/tests/models/vit/test_feature_extraction_vit.py similarity index 98% rename from tests/vit/test_feature_extraction_vit.py rename to tests/models/vit/test_feature_extraction_vit.py index df722d74bb08..2daf6452fff5 100644 --- a/tests/vit/test_feature_extraction_vit.py +++ b/tests/models/vit/test_feature_extraction_vit.py @@ -21,7 +21,7 @@ from transformers.testing_utils import require_torch, require_vision from transformers.utils import is_torch_available, is_vision_available -from ..test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs +from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs if is_torch_available(): diff --git a/tests/vit/test_modeling_flax_vit.py b/tests/models/vit/test_modeling_flax_vit.py similarity index 98% rename from tests/vit/test_modeling_flax_vit.py rename to tests/models/vit/test_modeling_flax_vit.py index 9fc734005f3b..56fe28d41baf 100644 --- a/tests/vit/test_modeling_flax_vit.py +++ b/tests/models/vit/test_modeling_flax_vit.py @@ -20,8 +20,8 @@ from transformers import ViTConfig, is_flax_available from transformers.testing_utils import require_flax, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor if is_flax_available(): diff --git a/tests/vit/test_modeling_tf_vit.py b/tests/models/vit/test_modeling_tf_vit.py similarity index 98% rename from tests/vit/test_modeling_tf_vit.py rename to tests/models/vit/test_modeling_tf_vit.py index e8bbd55cbb15..096558091ac8 100644 --- a/tests/vit/test_modeling_tf_vit.py +++ b/tests/models/vit/test_modeling_tf_vit.py @@ -22,8 +22,8 @@ from transformers.testing_utils import require_tf, require_vision, slow from transformers.utils import cached_property, is_tf_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor if is_tf_available(): diff --git a/tests/vit/test_modeling_vit.py b/tests/models/vit/test_modeling_vit.py similarity index 98% rename from tests/vit/test_modeling_vit.py rename to tests/models/vit/test_modeling_vit.py index 6f88463b0e95..a1379a9d31ec 100644 --- a/tests/vit/test_modeling_vit.py +++ b/tests/models/vit/test_modeling_vit.py @@ -22,8 +22,8 @@ from transformers.testing_utils import require_torch, require_vision, slow, torch_device from transformers.utils import cached_property, is_torch_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/wav2vec2/__init__.py b/tests/models/vit_mae/__init__.py similarity index 100% rename from tests/wav2vec2/__init__.py rename to tests/models/vit_mae/__init__.py diff --git a/tests/vit_mae/test_modeling_tf_vit_mae.py b/tests/models/vit_mae/test_modeling_tf_vit_mae.py similarity index 99% rename from tests/vit_mae/test_modeling_tf_vit_mae.py rename to tests/models/vit_mae/test_modeling_tf_vit_mae.py index 5a95f4635065..dc73b20e7eac 100644 --- a/tests/vit_mae/test_modeling_tf_vit_mae.py +++ b/tests/models/vit_mae/test_modeling_tf_vit_mae.py @@ -30,8 +30,8 @@ from transformers.file_utils import cached_property, is_tf_available, is_vision_available from transformers.testing_utils import require_tf, require_vision, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor if is_tf_available(): diff --git a/tests/vit_mae/test_modeling_vit_mae.py b/tests/models/vit_mae/test_modeling_vit_mae.py similarity index 99% rename from tests/vit_mae/test_modeling_vit_mae.py rename to tests/models/vit_mae/test_modeling_vit_mae.py index fae72a8ad7be..191984d82f55 100644 --- a/tests/vit_mae/test_modeling_vit_mae.py +++ b/tests/models/vit_mae/test_modeling_vit_mae.py @@ -26,8 +26,8 @@ from transformers.testing_utils import require_torch, require_vision, slow, torch_device from transformers.utils import cached_property, is_torch_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor if is_torch_available(): diff --git a/tests/wav2vec2_phoneme/__init__.py b/tests/models/wav2vec2/__init__.py similarity index 100% rename from tests/wav2vec2_phoneme/__init__.py rename to tests/models/wav2vec2/__init__.py diff --git a/tests/wav2vec2/test_feature_extraction_wav2vec2.py b/tests/models/wav2vec2/test_feature_extraction_wav2vec2.py similarity index 99% rename from tests/wav2vec2/test_feature_extraction_wav2vec2.py rename to tests/models/wav2vec2/test_feature_extraction_wav2vec2.py index 67c4e050fdf1..98cf2f1c495b 100644 --- a/tests/wav2vec2/test_feature_extraction_wav2vec2.py +++ b/tests/models/wav2vec2/test_feature_extraction_wav2vec2.py @@ -23,7 +23,7 @@ from transformers import WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST, Wav2Vec2Config, Wav2Vec2FeatureExtractor from transformers.testing_utils import require_torch, slow -from ..test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin +from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin global_rng = random.Random() diff --git a/tests/wav2vec2/test_modeling_flax_wav2vec2.py b/tests/models/wav2vec2/test_modeling_flax_wav2vec2.py similarity index 99% rename from tests/wav2vec2/test_modeling_flax_wav2vec2.py rename to tests/models/wav2vec2/test_modeling_flax_wav2vec2.py index da03c95c060b..a228ebfa1947 100644 --- a/tests/wav2vec2/test_modeling_flax_wav2vec2.py +++ b/tests/models/wav2vec2/test_modeling_flax_wav2vec2.py @@ -30,7 +30,7 @@ slow, ) -from ..test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, random_attention_mask +from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, random_attention_mask if is_flax_available(): diff --git a/tests/wav2vec2/test_modeling_tf_wav2vec2.py b/tests/models/wav2vec2/test_modeling_tf_wav2vec2.py similarity index 99% rename from tests/wav2vec2/test_modeling_tf_wav2vec2.py rename to tests/models/wav2vec2/test_modeling_tf_wav2vec2.py index 6da315e7898b..3187303982e1 100644 --- a/tests/wav2vec2/test_modeling_tf_wav2vec2.py +++ b/tests/models/wav2vec2/test_modeling_tf_wav2vec2.py @@ -29,8 +29,8 @@ from transformers.testing_utils import require_librosa, require_pyctcdecode, require_tf, slow from transformers.utils import is_librosa_available, is_pyctcdecode_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor if is_tf_available(): diff --git a/tests/wav2vec2/test_modeling_wav2vec2.py b/tests/models/wav2vec2/test_modeling_wav2vec2.py similarity index 99% rename from tests/wav2vec2/test_modeling_wav2vec2.py rename to tests/models/wav2vec2/test_modeling_wav2vec2.py index c64b0201eebc..98aebdd72818 100644 --- a/tests/wav2vec2/test_modeling_wav2vec2.py +++ b/tests/models/wav2vec2/test_modeling_wav2vec2.py @@ -33,8 +33,8 @@ torch_device, ) -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ( +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ( ModelTesterMixin, _config_zero_init, floats_tensor, diff --git a/tests/wav2vec2/test_processor_wav2vec2.py b/tests/models/wav2vec2/test_processor_wav2vec2.py similarity index 100% rename from tests/wav2vec2/test_processor_wav2vec2.py rename to tests/models/wav2vec2/test_processor_wav2vec2.py diff --git a/tests/wav2vec2/test_tokenization_wav2vec2.py b/tests/models/wav2vec2/test_tokenization_wav2vec2.py similarity index 99% rename from tests/wav2vec2/test_tokenization_wav2vec2.py rename to tests/models/wav2vec2/test_tokenization_wav2vec2.py index 48072fb81c22..4027e0cefc4d 100644 --- a/tests/wav2vec2/test_tokenization_wav2vec2.py +++ b/tests/models/wav2vec2/test_tokenization_wav2vec2.py @@ -32,7 +32,7 @@ from transformers.models.wav2vec2.tokenization_wav2vec2 import VOCAB_FILES_NAMES, Wav2Vec2CTCTokenizerOutput from transformers.testing_utils import require_torch, slow -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin global_rng = random.Random() diff --git a/tests/wav2vec2_with_lm/__init__.py b/tests/models/wav2vec2_phoneme/__init__.py similarity index 100% rename from tests/wav2vec2_with_lm/__init__.py rename to tests/models/wav2vec2_phoneme/__init__.py diff --git a/tests/wav2vec2_phoneme/test_tokenization_wav2vec2_phoneme.py b/tests/models/wav2vec2_phoneme/test_tokenization_wav2vec2_phoneme.py similarity index 99% rename from tests/wav2vec2_phoneme/test_tokenization_wav2vec2_phoneme.py rename to tests/models/wav2vec2_phoneme/test_tokenization_wav2vec2_phoneme.py index 577471c0fa9e..0411a863bc72 100644 --- a/tests/wav2vec2_phoneme/test_tokenization_wav2vec2_phoneme.py +++ b/tests/models/wav2vec2_phoneme/test_tokenization_wav2vec2_phoneme.py @@ -23,7 +23,7 @@ from transformers.models.wav2vec2_phoneme.tokenization_wav2vec2_phoneme import Wav2Vec2PhonemeCTCTokenizerOutput from transformers.testing_utils import require_phonemizer -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin @require_phonemizer diff --git a/tests/wavlm/__init__.py b/tests/models/wav2vec2_with_lm/__init__.py similarity index 100% rename from tests/wavlm/__init__.py rename to tests/models/wav2vec2_with_lm/__init__.py diff --git a/tests/wav2vec2_with_lm/test_processor_wav2vec2_with_lm.py b/tests/models/wav2vec2_with_lm/test_processor_wav2vec2_with_lm.py similarity index 100% rename from tests/wav2vec2_with_lm/test_processor_wav2vec2_with_lm.py rename to tests/models/wav2vec2_with_lm/test_processor_wav2vec2_with_lm.py diff --git a/tests/xglm/__init__.py b/tests/models/wavlm/__init__.py similarity index 100% rename from tests/xglm/__init__.py rename to tests/models/wavlm/__init__.py diff --git a/tests/wavlm/test_modeling_wavlm.py b/tests/models/wavlm/test_modeling_wavlm.py similarity index 99% rename from tests/wavlm/test_modeling_wavlm.py rename to tests/models/wavlm/test_modeling_wavlm.py index 0bc40ed5f790..297d207af3e5 100644 --- a/tests/wavlm/test_modeling_wavlm.py +++ b/tests/models/wavlm/test_modeling_wavlm.py @@ -23,8 +23,8 @@ from transformers import WavLMConfig, is_torch_available from transformers.testing_utils import require_torch, require_torchaudio, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ( +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ( ModelTesterMixin, _config_zero_init, floats_tensor, diff --git a/tests/xlm/__init__.py b/tests/models/xglm/__init__.py similarity index 100% rename from tests/xlm/__init__.py rename to tests/models/xglm/__init__.py diff --git a/tests/xglm/test_modeling_flax_xglm.py b/tests/models/xglm/test_modeling_flax_xglm.py similarity index 98% rename from tests/xglm/test_modeling_flax_xglm.py rename to tests/models/xglm/test_modeling_flax_xglm.py index 45399d962421..f20a1b378f5f 100644 --- a/tests/xglm/test_modeling_flax_xglm.py +++ b/tests/models/xglm/test_modeling_flax_xglm.py @@ -21,8 +21,8 @@ from transformers import XGLMConfig, XGLMTokenizer, is_flax_available, is_torch_available from transformers.testing_utils import is_pt_flax_cross_test, require_flax, require_sentencepiece, slow -from ..generation.test_generation_flax_utils import FlaxGenerationTesterMixin -from ..test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...generation.test_generation_flax_utils import FlaxGenerationTesterMixin +from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_flax_available(): diff --git a/tests/xglm/test_modeling_xglm.py b/tests/models/xglm/test_modeling_xglm.py similarity index 98% rename from tests/xglm/test_modeling_xglm.py rename to tests/models/xglm/test_modeling_xglm.py index 1f80165a84cf..37301a79eda1 100644 --- a/tests/xglm/test_modeling_xglm.py +++ b/tests/models/xglm/test_modeling_xglm.py @@ -21,9 +21,9 @@ from transformers import XGLMConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/xglm/test_tokenization_xglm.py b/tests/models/xglm/test_tokenization_xglm.py similarity index 96% rename from tests/xglm/test_tokenization_xglm.py rename to tests/models/xglm/test_tokenization_xglm.py index f7b270858252..dd5c9f5e6a0c 100644 --- a/tests/xglm/test_tokenization_xglm.py +++ b/tests/models/xglm/test_tokenization_xglm.py @@ -13,20 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import pickle import shutil import tempfile import unittest from transformers import SPIECE_UNDERLINE, XGLMTokenizer, XGLMTokenizerFast -from transformers.testing_utils import require_sentencepiece, require_tokenizers, slow +from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow from transformers.utils import cached_property -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_VOCAB = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../fixtures/test_sentencepiece.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece.model") @require_sentencepiece diff --git a/tests/xlm_prophetnet/__init__.py b/tests/models/xlm/__init__.py similarity index 100% rename from tests/xlm_prophetnet/__init__.py rename to tests/models/xlm/__init__.py diff --git a/tests/xlm/test_modeling_tf_xlm.py b/tests/models/xlm/test_modeling_tf_xlm.py similarity index 98% rename from tests/xlm/test_modeling_tf_xlm.py rename to tests/models/xlm/test_modeling_tf_xlm.py index 412a8430ad6d..00e77cee64ba 100644 --- a/tests/xlm/test_modeling_tf_xlm.py +++ b/tests/models/xlm/test_modeling_tf_xlm.py @@ -19,8 +19,8 @@ from transformers import is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/xlm/test_modeling_xlm.py b/tests/models/xlm/test_modeling_xlm.py similarity index 98% rename from tests/xlm/test_modeling_xlm.py rename to tests/models/xlm/test_modeling_xlm.py index f33622107296..8f56ed8472ea 100644 --- a/tests/xlm/test_modeling_xlm.py +++ b/tests/models/xlm/test_modeling_xlm.py @@ -18,9 +18,9 @@ from transformers import XLMConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/xlm/test_tokenization_xlm.py b/tests/models/xlm/test_tokenization_xlm.py similarity index 98% rename from tests/xlm/test_tokenization_xlm.py rename to tests/models/xlm/test_tokenization_xlm.py index bd056b69d430..adb4835eda40 100644 --- a/tests/xlm/test_tokenization_xlm.py +++ b/tests/models/xlm/test_tokenization_xlm.py @@ -21,7 +21,7 @@ from transformers.models.xlm.tokenization_xlm import VOCAB_FILES_NAMES, XLMTokenizer from transformers.testing_utils import slow -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin class XLMTokenizationTest(TokenizerTesterMixin, unittest.TestCase): diff --git a/tests/xlm_roberta/__init__.py b/tests/models/xlm_prophetnet/__init__.py similarity index 100% rename from tests/xlm_roberta/__init__.py rename to tests/models/xlm_prophetnet/__init__.py diff --git a/tests/xlm_prophetnet/test_modeling_xlm_prophetnet.py b/tests/models/xlm_prophetnet/test_modeling_xlm_prophetnet.py similarity index 100% rename from tests/xlm_prophetnet/test_modeling_xlm_prophetnet.py rename to tests/models/xlm_prophetnet/test_modeling_xlm_prophetnet.py diff --git a/tests/xlm_prophetnet/test_tokenization_xlm_prophetnet.py b/tests/models/xlm_prophetnet/test_tokenization_xlm_prophetnet.py similarity index 96% rename from tests/xlm_prophetnet/test_tokenization_xlm_prophetnet.py rename to tests/models/xlm_prophetnet/test_tokenization_xlm_prophetnet.py index c8f756876310..d560007fe316 100644 --- a/tests/xlm_prophetnet/test_tokenization_xlm_prophetnet.py +++ b/tests/models/xlm_prophetnet/test_tokenization_xlm_prophetnet.py @@ -13,18 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import unittest -from os.path import dirname from transformers.models.xlm_prophetnet.tokenization_xlm_prophetnet import SPIECE_UNDERLINE, XLMProphetNetTokenizer -from transformers.testing_utils import require_sentencepiece, slow +from transformers.testing_utils import get_tests_dir, require_sentencepiece, slow from transformers.utils import cached_property -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece.model") @require_sentencepiece diff --git a/tests/xlm_roberta_xl/__init__.py b/tests/models/xlm_roberta/__init__.py similarity index 100% rename from tests/xlm_roberta_xl/__init__.py rename to tests/models/xlm_roberta/__init__.py diff --git a/tests/xlm_roberta/test_modeling_flax_xlm_roberta.py b/tests/models/xlm_roberta/test_modeling_flax_xlm_roberta.py similarity index 100% rename from tests/xlm_roberta/test_modeling_flax_xlm_roberta.py rename to tests/models/xlm_roberta/test_modeling_flax_xlm_roberta.py diff --git a/tests/xlm_roberta/test_modeling_tf_xlm_roberta.py b/tests/models/xlm_roberta/test_modeling_tf_xlm_roberta.py similarity index 100% rename from tests/xlm_roberta/test_modeling_tf_xlm_roberta.py rename to tests/models/xlm_roberta/test_modeling_tf_xlm_roberta.py diff --git a/tests/xlm_roberta/test_modeling_xlm_roberta.py b/tests/models/xlm_roberta/test_modeling_xlm_roberta.py similarity index 100% rename from tests/xlm_roberta/test_modeling_xlm_roberta.py rename to tests/models/xlm_roberta/test_modeling_xlm_roberta.py diff --git a/tests/xlm_roberta/test_tokenization_xlm_roberta.py b/tests/models/xlm_roberta/test_tokenization_xlm_roberta.py similarity index 97% rename from tests/xlm_roberta/test_tokenization_xlm_roberta.py rename to tests/models/xlm_roberta/test_tokenization_xlm_roberta.py index 0ba1492efc09..53c5987fb2fb 100644 --- a/tests/xlm_roberta/test_tokenization_xlm_roberta.py +++ b/tests/models/xlm_roberta/test_tokenization_xlm_roberta.py @@ -13,21 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import pickle import shutil import tempfile import unittest -from os.path import dirname from transformers import SPIECE_UNDERLINE, XLMRobertaTokenizer, XLMRobertaTokenizerFast -from transformers.testing_utils import require_sentencepiece, require_tokenizers, slow +from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow from transformers.utils import cached_property -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece.model") @require_sentencepiece diff --git a/tests/xlnet/__init__.py b/tests/models/xlm_roberta_xl/__init__.py similarity index 100% rename from tests/xlnet/__init__.py rename to tests/models/xlm_roberta_xl/__init__.py diff --git a/tests/xlm_roberta_xl/test_modeling_xlm_roberta_xl.py b/tests/models/xlm_roberta_xl/test_modeling_xlm_roberta_xl.py similarity index 98% rename from tests/xlm_roberta_xl/test_modeling_xlm_roberta_xl.py rename to tests/models/xlm_roberta_xl/test_modeling_xlm_roberta_xl.py index a3e7e64481ce..b889753f663c 100644 --- a/tests/xlm_roberta_xl/test_modeling_xlm_roberta_xl.py +++ b/tests/models/xlm_roberta_xl/test_modeling_xlm_roberta_xl.py @@ -19,9 +19,9 @@ from transformers import XLMRobertaXLConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/yolos/__init__.py b/tests/models/xlnet/__init__.py similarity index 100% rename from tests/yolos/__init__.py rename to tests/models/xlnet/__init__.py diff --git a/tests/xlnet/test_modeling_tf_xlnet.py b/tests/models/xlnet/test_modeling_tf_xlnet.py similarity index 99% rename from tests/xlnet/test_modeling_tf_xlnet.py rename to tests/models/xlnet/test_modeling_tf_xlnet.py index 8cf4ca2099bd..dc1ca077952c 100644 --- a/tests/xlnet/test_modeling_tf_xlnet.py +++ b/tests/models/xlnet/test_modeling_tf_xlnet.py @@ -21,8 +21,8 @@ from transformers import XLNetConfig, is_tf_available from transformers.testing_utils import require_tf, slow -from ..test_configuration_common import ConfigTester -from ..test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask if is_tf_available(): diff --git a/tests/xlnet/test_modeling_xlnet.py b/tests/models/xlnet/test_modeling_xlnet.py similarity index 99% rename from tests/xlnet/test_modeling_xlnet.py rename to tests/models/xlnet/test_modeling_xlnet.py index 420d22cc1e20..2c26315ceb96 100644 --- a/tests/xlnet/test_modeling_xlnet.py +++ b/tests/models/xlnet/test_modeling_xlnet.py @@ -19,9 +19,9 @@ from transformers import XLNetConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..generation.test_generation_utils import GenerationTesterMixin -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...generation.test_generation_utils import GenerationTesterMixin +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/xlnet/test_tokenization_xlnet.py b/tests/models/xlnet/test_tokenization_xlnet.py similarity index 97% rename from tests/xlnet/test_tokenization_xlnet.py rename to tests/models/xlnet/test_tokenization_xlnet.py index 707c975201ac..6125a1dffd77 100644 --- a/tests/xlnet/test_tokenization_xlnet.py +++ b/tests/models/xlnet/test_tokenization_xlnet.py @@ -13,17 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import unittest -from os.path import dirname from transformers import SPIECE_UNDERLINE, XLNetTokenizer, XLNetTokenizerFast -from transformers.testing_utils import require_sentencepiece, require_tokenizers, slow +from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow -from ..test_tokenization_common import TokenizerTesterMixin +from ...test_tokenization_common import TokenizerTesterMixin -SAMPLE_VOCAB = os.path.join(dirname(dirname(os.path.abspath(__file__))), "fixtures/test_sentencepiece.model") +SAMPLE_VOCAB = get_tests_dir("fixtures/test_sentencepiece.model") @require_sentencepiece diff --git a/tests/yoso/__init__.py b/tests/models/yolos/__init__.py similarity index 100% rename from tests/yoso/__init__.py rename to tests/models/yolos/__init__.py diff --git a/tests/yolos/test_feature_extraction_yolos.py b/tests/models/yolos/test_feature_extraction_yolos.py similarity index 99% rename from tests/yolos/test_feature_extraction_yolos.py rename to tests/models/yolos/test_feature_extraction_yolos.py index 4fc9217bbe03..8a576a583a9a 100644 --- a/tests/yolos/test_feature_extraction_yolos.py +++ b/tests/models/yolos/test_feature_extraction_yolos.py @@ -23,7 +23,7 @@ from transformers.testing_utils import require_torch, require_vision, slow from transformers.utils import is_torch_available, is_vision_available -from ..test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs +from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin, prepare_image_inputs if is_torch_available(): diff --git a/tests/yolos/test_modeling_yolos.py b/tests/models/yolos/test_modeling_yolos.py similarity index 99% rename from tests/yolos/test_modeling_yolos.py rename to tests/models/yolos/test_modeling_yolos.py index e64795b1ea01..75d399eaa797 100644 --- a/tests/yolos/test_modeling_yolos.py +++ b/tests/models/yolos/test_modeling_yolos.py @@ -22,8 +22,8 @@ from transformers.testing_utils import require_torch, require_vision, slow, torch_device from transformers.utils import cached_property, is_torch_available, is_vision_available -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor if is_torch_available(): diff --git a/tests/models/yoso/__init__.py b/tests/models/yoso/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/yoso/test_modeling_yoso.py b/tests/models/yoso/test_modeling_yoso.py similarity index 98% rename from tests/yoso/test_modeling_yoso.py rename to tests/models/yoso/test_modeling_yoso.py index f6d013b1bf8c..d71b051d0a22 100644 --- a/tests/yoso/test_modeling_yoso.py +++ b/tests/models/yoso/test_modeling_yoso.py @@ -20,8 +20,8 @@ from transformers import YosoConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device -from ..test_configuration_common import ConfigTester -from ..test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_configuration_common import ConfigTester +from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask if is_torch_available(): diff --git a/tests/test_feature_extraction_common.py b/tests/test_feature_extraction_common.py index 3f7abcaa70c2..e95db7eae860 100644 --- a/tests/test_feature_extraction_common.py +++ b/tests/test_feature_extraction_common.py @@ -25,7 +25,7 @@ from huggingface_hub import Repository, delete_repo, login from requests.exceptions import HTTPError from transformers import AutoFeatureExtractor, Wav2Vec2FeatureExtractor -from transformers.testing_utils import PASS, USER, is_staging_test +from transformers.testing_utils import PASS, USER, get_tests_dir, is_staging_test from transformers.utils import is_torch_available, is_vision_available @@ -42,7 +42,7 @@ from PIL import Image -SAMPLE_FEATURE_EXTRACTION_CONFIG_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "fixtures") +SAMPLE_FEATURE_EXTRACTION_CONFIG_DIR = get_tests_dir("fixtures") def prepare_image_inputs(feature_extract_tester, equal_resolution=False, numpify=False, torchify=False): diff --git a/tests/utils/test_convert_slow_tokenizer.py b/tests/utils/test_convert_slow_tokenizer.py index 087fbd5053b2..f7bb60acfdb0 100644 --- a/tests/utils/test_convert_slow_tokenizer.py +++ b/tests/utils/test_convert_slow_tokenizer.py @@ -13,8 +13,8 @@ class FakeOriginalTokenizer: class ConvertSlowTokenizerTest(unittest.TestCase): def test_spm_converter_bytefallback_warning(self): - spm_model_file_without_bytefallback = f"{get_tests_dir()}/fixtures/test_sentencepiece.model" - spm_model_file_with_bytefallback = f"{get_tests_dir()}/fixtures/test_sentencepiece_with_bytefallback.model" + spm_model_file_without_bytefallback = get_tests_dir("fixtures/test_sentencepiece.model") + spm_model_file_with_bytefallback = get_tests_dir("fixtures/test_sentencepiece_with_bytefallback.model") original_tokenizer_without_bytefallback = FakeOriginalTokenizer(vocab_file=spm_model_file_without_bytefallback) diff --git a/utils/check_repo.py b/utils/check_repo.py index 5b977912810c..5afaac02a123 100644 --- a/utils/check_repo.py +++ b/utils/check_repo.py @@ -97,21 +97,21 @@ # Update this list with test files that don't have a tester with a `all_model_classes` variable and which don't # trigger the common tests. TEST_FILES_WITH_NO_COMMON_TESTS = [ - "decision_transformer/test_modeling_decision_transformer.py", - "camembert/test_modeling_camembert.py", - "mt5/test_modeling_flax_mt5.py", - "mbart/test_modeling_mbart.py", - "mt5/test_modeling_mt5.py", - "pegasus/test_modeling_pegasus.py", - "camembert/test_modeling_tf_camembert.py", - "mt5/test_modeling_tf_mt5.py", - "xlm_roberta/test_modeling_tf_xlm_roberta.py", - "xlm_roberta/test_modeling_flax_xlm_roberta.py", - "xlm_prophetnet/test_modeling_xlm_prophetnet.py", - "xlm_roberta/test_modeling_xlm_roberta.py", - "vision_text_dual_encoder/test_modeling_vision_text_dual_encoder.py", - "vision_text_dual_encoder/test_modeling_flax_vision_text_dual_encoder.py", - "decision_transformer/test_modeling_decision_transformer.py", + "models/decision_transformer/test_modeling_decision_transformer.py", + "models/camembert/test_modeling_camembert.py", + "models/mt5/test_modeling_flax_mt5.py", + "models/mbart/test_modeling_mbart.py", + "models/mt5/test_modeling_mt5.py", + "models/pegasus/test_modeling_pegasus.py", + "models/camembert/test_modeling_tf_camembert.py", + "models/mt5/test_modeling_tf_mt5.py", + "models/xlm_roberta/test_modeling_tf_xlm_roberta.py", + "models/xlm_roberta/test_modeling_flax_xlm_roberta.py", + "models/xlm_prophetnet/test_modeling_xlm_prophetnet.py", + "models/xlm_roberta/test_modeling_xlm_roberta.py", + "models/vision_text_dual_encoder/test_modeling_vision_text_dual_encoder.py", + "models/vision_text_dual_encoder/test_modeling_flax_vision_text_dual_encoder.py", + "models/decision_transformer/test_modeling_decision_transformer.py", ] # Update this list for models that are not in any of the auto MODEL_XXX_MAPPING. Being in this list is an exception and @@ -308,7 +308,12 @@ def check_models_are_in_init(): # If some test_modeling files should be ignored when checking models are all tested, they should be added in the # nested list _ignore_files of this function. def get_model_test_files(): - """Get the model test files.""" + """Get the model test files. + + The returned files should NOT contain the `tests` (i.e. `PATH_TO_TESTS` defined in this script). They will be + considered as paths relative to `tests`. A caller has to use `os.path.join(PATH_TO_TESTS, ...)` to access the files. + """ + _ignore_files = [ "test_modeling_common", "test_modeling_encoder_decoder", @@ -319,20 +324,23 @@ def get_model_test_files(): "test_modeling_tf_encoder_decoder", ] test_files = [] - for file_or_dir in os.listdir(PATH_TO_TESTS): - path = os.path.join(PATH_TO_TESTS, file_or_dir) - if os.path.isdir(path): - filenames = [os.path.join(file_or_dir, file) for file in os.listdir(path)] - else: - filenames = [file_or_dir] - - for filename in filenames: - if ( - os.path.isfile(os.path.join(PATH_TO_TESTS, filename)) - and "test_modeling" in filename - and not os.path.splitext(filename)[0] in _ignore_files - ): - test_files.append(filename) + # Check both `PATH_TO_TESTS` and `PATH_TO_TESTS/models` + model_test_root = os.path.join(PATH_TO_TESTS, "models") + model_test_dirs = [] + for x in os.listdir(model_test_root): + x = os.path.join(model_test_root, x) + if os.path.isdir(x): + model_test_dirs.append(x) + + for target_dir in [PATH_TO_TESTS] + model_test_dirs: + for file_or_dir in os.listdir(target_dir): + path = os.path.join(target_dir, file_or_dir) + if os.path.isfile(path): + filename = os.path.split(path)[-1] + if "test_modeling" in filename and not os.path.splitext(filename)[0] in _ignore_files: + file = os.path.join(*path.split(os.sep)[1:]) + test_files.append(file) + return test_files diff --git a/utils/notification_service.py b/utils/notification_service.py index c0f2cdb25fbb..47e85d867e5e 100644 --- a/utils/notification_service.py +++ b/utils/notification_service.py @@ -561,6 +561,8 @@ def add_path(self, path: str, gpu: str = None): arguments = sys.argv[1:][0] try: models = ast.literal_eval(arguments) + # Need to change from elements like `models/bert` to `models_bert` (the ones used as artifact names). + models = [x.replace("models/", "models_") for x in models] except SyntaxError: Message.error_out() raise ValueError("Errored out.") diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index 16bf6348d387..f733f301e8dc 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -275,18 +275,21 @@ def create_reverse_dependency_map(): "modeling_tf_utils.py": ["test_modeling_tf_common.py", "utils/test_modeling_tf_core.py"], "modeling_utils.py": ["test_modeling_common.py", "utils/test_offline.py"], "models/auto/modeling_auto.py": [ - "auto/test_modeling_auto.py", - "auto/test_modeling_tf_pytorch.py", - "bort/test_modeling_bort.py", - "dit/test_modeling_dit.py", + "models/auto/test_modeling_auto.py", + "models/auto/test_modeling_tf_pytorch.py", + "models/bort/test_modeling_bort.py", + "models/dit/test_modeling_dit.py", ], - "models/auto/modeling_flax_auto.py": "auto/test_modeling_flax_auto.py", + "models/auto/modeling_flax_auto.py": "models/auto/test_modeling_flax_auto.py", "models/auto/modeling_tf_auto.py": [ - "auto/test_modeling_tf_auto.py", - "auto/test_modeling_tf_pytorch.py", - "bort/test_modeling_tf_bort.py", + "models/auto/test_modeling_tf_auto.py", + "models/auto/test_modeling_tf_pytorch.py", + "models/bort/test_modeling_tf_bort.py", + ], + "models/gpt2/modeling_gpt2.py": [ + "models/gpt2/test_modeling_gpt2.py", + "models/megatron_gpt2/test_modeling_megatron_gpt2.py", ], - "models/gpt2/modeling_gpt2.py": ["gpt2/test_modeling_gpt2.py", "megatron_gpt2/test_modeling_megatron_gpt2.py"], "optimization.py": "optimization/test_optimization.py", "optimization_tf.py": "optimization/test_optimization_tf.py", "pipelines/base.py": "pipelines/test_pipelines_*.py", @@ -350,7 +353,7 @@ def module_to_test_file(module_fname): elif len(splits) > 0 and splits[0] == "utils": default_test_file = f"tests/utils/test_utils_{module_name}" elif len(splits) > 4 and splits[2] == "models": - default_test_file = f"tests/{splits[3]}/test_{module_name}" + default_test_file = f"tests/models/{splits[3]}/test_{module_name}" elif len(splits) > 2 and splits[2].startswith("generation"): default_test_file = f"tests/generation/test_{module_name}" elif len(splits) > 2 and splits[2].startswith("trainer"):