[tests] relocate core integration tests (#11146)
* relocate core integration tests * add sys.path context manager * cleanup * try * try2 * fix path * doc * style * add dep * add 2 more deps
This commit is contained in:
@@ -525,7 +525,7 @@ Here is an example of running ``run_translation.py`` under DeepSpeed deploying a
|
|||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
deepspeed examples/seq2seq/run_translation.py \
|
deepspeed examples/seq2seq/run_translation.py \
|
||||||
--deepspeed examples/tests/deepspeed/ds_config.json \
|
--deepspeed tests/deepspeed/ds_config.json \
|
||||||
--model_name_or_path t5-small --per_device_train_batch_size 1 \
|
--model_name_or_path t5-small --per_device_train_batch_size 1 \
|
||||||
--output_dir output_dir --overwrite_output_dir --fp16 \
|
--output_dir output_dir --overwrite_output_dir --fp16 \
|
||||||
--do_train --max_train_samples 500 --num_train_epochs 1 \
|
--do_train --max_train_samples 500 --num_train_epochs 1 \
|
||||||
@@ -550,7 +550,7 @@ To deploy DeepSpeed with one GPU adjust the :class:`~transformers.Trainer` comma
|
|||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
deepspeed --num_gpus=1 examples/seq2seq/run_translation.py \
|
deepspeed --num_gpus=1 examples/seq2seq/run_translation.py \
|
||||||
--deepspeed examples/tests/deepspeed/ds_config.json \
|
--deepspeed tests/deepspeed/ds_config.json \
|
||||||
--model_name_or_path t5-small --per_device_train_batch_size 1 \
|
--model_name_or_path t5-small --per_device_train_batch_size 1 \
|
||||||
--output_dir output_dir --overwrite_output_dir --fp16 \
|
--output_dir output_dir --overwrite_output_dir --fp16 \
|
||||||
--do_train --max_train_samples 500 --num_train_epochs 1 \
|
--do_train --max_train_samples 500 --num_train_epochs 1 \
|
||||||
|
|||||||
@@ -795,6 +795,23 @@ leave any data in there.
|
|||||||
otherwise.
|
otherwise.
|
||||||
|
|
||||||
|
|
||||||
|
Temporary sys.path override
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
If you need to temporary override ``sys.path`` to import from another test for example, you can use the
|
||||||
|
``ExtendSysPath`` context manager. Example:
|
||||||
|
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
import os
|
||||||
|
from transformers.testing_utils import ExtendSysPath
|
||||||
|
bindir = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
with ExtendSysPath(f"{bindir}/.."):
|
||||||
|
from test_trainer import TrainerIntegrationCommon # noqa
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Skipping tests
|
Skipping tests
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|||||||
11
setup.py
11
setup.py
@@ -85,6 +85,7 @@ if stale_egg_info.exists():
|
|||||||
# 1. all dependencies should be listed here with their version requirements if any
|
# 1. all dependencies should be listed here with their version requirements if any
|
||||||
# 2. once modified, run: `make deps_table_update` to update src/transformers/dependency_versions_table.py
|
# 2. once modified, run: `make deps_table_update` to update src/transformers/dependency_versions_table.py
|
||||||
_deps = [
|
_deps = [
|
||||||
|
"Pillow",
|
||||||
"black>=20.8b1",
|
"black>=20.8b1",
|
||||||
"cookiecutter==1.7.2",
|
"cookiecutter==1.7.2",
|
||||||
"dataclasses",
|
"dataclasses",
|
||||||
@@ -102,13 +103,13 @@ _deps = [
|
|||||||
"jax>=0.2.8",
|
"jax>=0.2.8",
|
||||||
"jaxlib>=0.1.59",
|
"jaxlib>=0.1.59",
|
||||||
"keras2onnx",
|
"keras2onnx",
|
||||||
|
"nltk",
|
||||||
"numpy>=1.17",
|
"numpy>=1.17",
|
||||||
"onnxconverter-common",
|
"onnxconverter-common",
|
||||||
"onnxruntime-tools>=1.4.2",
|
"onnxruntime-tools>=1.4.2",
|
||||||
"onnxruntime>=1.4.0",
|
"onnxruntime>=1.4.0",
|
||||||
"packaging",
|
"packaging",
|
||||||
"parameterized",
|
"parameterized",
|
||||||
"Pillow",
|
|
||||||
"protobuf",
|
"protobuf",
|
||||||
"psutil",
|
"psutil",
|
||||||
"pydantic",
|
"pydantic",
|
||||||
@@ -119,15 +120,18 @@ _deps = [
|
|||||||
"recommonmark",
|
"recommonmark",
|
||||||
"regex!=2019.12.17",
|
"regex!=2019.12.17",
|
||||||
"requests",
|
"requests",
|
||||||
|
"rouge-score",
|
||||||
|
"sacrebleu>=1.4.12",
|
||||||
"sacremoses",
|
"sacremoses",
|
||||||
|
"sagemaker>=2.31.0",
|
||||||
"scikit-learn",
|
"scikit-learn",
|
||||||
"sentencepiece==0.1.91",
|
"sentencepiece==0.1.91",
|
||||||
"soundfile",
|
"soundfile",
|
||||||
"sphinx-copybutton",
|
"sphinx-copybutton",
|
||||||
"sphinx-markdown-tables",
|
"sphinx-markdown-tables",
|
||||||
"sphinx-rtd-theme==0.4.3", # sphinx-rtd-theme==0.5.0 introduced big changes in the style.
|
"sphinx-rtd-theme==0.4.3", # sphinx-rtd-theme==0.5.0 introduced big changes in the style.
|
||||||
"sphinxext-opengraph==0.4.1",
|
|
||||||
"sphinx==3.2.1",
|
"sphinx==3.2.1",
|
||||||
|
"sphinxext-opengraph==0.4.1",
|
||||||
"starlette",
|
"starlette",
|
||||||
"tensorflow-cpu>=2.3",
|
"tensorflow-cpu>=2.3",
|
||||||
"tensorflow>=2.3",
|
"tensorflow>=2.3",
|
||||||
@@ -139,7 +143,6 @@ _deps = [
|
|||||||
"unidic>=1.0.2",
|
"unidic>=1.0.2",
|
||||||
"unidic_lite>=1.0.7",
|
"unidic_lite>=1.0.7",
|
||||||
"uvicorn",
|
"uvicorn",
|
||||||
"sagemaker>=2.31.0",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -238,7 +241,7 @@ extras["vision"] = deps_list("Pillow")
|
|||||||
extras["sentencepiece"] = deps_list("sentencepiece", "protobuf")
|
extras["sentencepiece"] = deps_list("sentencepiece", "protobuf")
|
||||||
extras["testing"] = (
|
extras["testing"] = (
|
||||||
deps_list(
|
deps_list(
|
||||||
"pytest", "pytest-xdist", "timeout-decorator", "parameterized", "psutil", "datasets", "pytest-sugar", "black"
|
"pytest", "pytest-xdist", "timeout-decorator", "parameterized", "psutil", "datasets", "pytest-sugar", "black", "sacrebleu", "rouge-score", "nltk"
|
||||||
)
|
)
|
||||||
+ extras["retrieval"]
|
+ extras["retrieval"]
|
||||||
+ extras["modelcreation"]
|
+ extras["modelcreation"]
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
# 1. modify the `_deps` dict in setup.py
|
# 1. modify the `_deps` dict in setup.py
|
||||||
# 2. run `make deps_table_update``
|
# 2. run `make deps_table_update``
|
||||||
deps = {
|
deps = {
|
||||||
|
"Pillow": "Pillow",
|
||||||
"black": "black>=20.8b1",
|
"black": "black>=20.8b1",
|
||||||
"cookiecutter": "cookiecutter==1.7.2",
|
"cookiecutter": "cookiecutter==1.7.2",
|
||||||
"dataclasses": "dataclasses",
|
"dataclasses": "dataclasses",
|
||||||
@@ -19,13 +20,13 @@ deps = {
|
|||||||
"jax": "jax>=0.2.8",
|
"jax": "jax>=0.2.8",
|
||||||
"jaxlib": "jaxlib>=0.1.59",
|
"jaxlib": "jaxlib>=0.1.59",
|
||||||
"keras2onnx": "keras2onnx",
|
"keras2onnx": "keras2onnx",
|
||||||
|
"nltk": "nltk",
|
||||||
"numpy": "numpy>=1.17",
|
"numpy": "numpy>=1.17",
|
||||||
"onnxconverter-common": "onnxconverter-common",
|
"onnxconverter-common": "onnxconverter-common",
|
||||||
"onnxruntime-tools": "onnxruntime-tools>=1.4.2",
|
"onnxruntime-tools": "onnxruntime-tools>=1.4.2",
|
||||||
"onnxruntime": "onnxruntime>=1.4.0",
|
"onnxruntime": "onnxruntime>=1.4.0",
|
||||||
"packaging": "packaging",
|
"packaging": "packaging",
|
||||||
"parameterized": "parameterized",
|
"parameterized": "parameterized",
|
||||||
"Pillow": "Pillow",
|
|
||||||
"protobuf": "protobuf",
|
"protobuf": "protobuf",
|
||||||
"psutil": "psutil",
|
"psutil": "psutil",
|
||||||
"pydantic": "pydantic",
|
"pydantic": "pydantic",
|
||||||
@@ -36,15 +37,18 @@ deps = {
|
|||||||
"recommonmark": "recommonmark",
|
"recommonmark": "recommonmark",
|
||||||
"regex": "regex!=2019.12.17",
|
"regex": "regex!=2019.12.17",
|
||||||
"requests": "requests",
|
"requests": "requests",
|
||||||
|
"rouge-score": "rouge-score",
|
||||||
|
"sacrebleu": "sacrebleu>=1.4.12",
|
||||||
"sacremoses": "sacremoses",
|
"sacremoses": "sacremoses",
|
||||||
|
"sagemaker": "sagemaker>=2.31.0",
|
||||||
"scikit-learn": "scikit-learn",
|
"scikit-learn": "scikit-learn",
|
||||||
"sentencepiece": "sentencepiece==0.1.91",
|
"sentencepiece": "sentencepiece==0.1.91",
|
||||||
"soundfile": "soundfile",
|
"soundfile": "soundfile",
|
||||||
"sphinx-copybutton": "sphinx-copybutton",
|
"sphinx-copybutton": "sphinx-copybutton",
|
||||||
"sphinx-markdown-tables": "sphinx-markdown-tables",
|
"sphinx-markdown-tables": "sphinx-markdown-tables",
|
||||||
"sphinx-rtd-theme": "sphinx-rtd-theme==0.4.3",
|
"sphinx-rtd-theme": "sphinx-rtd-theme==0.4.3",
|
||||||
"sphinxext-opengraph": "sphinxext-opengraph==0.4.1",
|
|
||||||
"sphinx": "sphinx==3.2.1",
|
"sphinx": "sphinx==3.2.1",
|
||||||
|
"sphinxext-opengraph": "sphinxext-opengraph==0.4.1",
|
||||||
"starlette": "starlette",
|
"starlette": "starlette",
|
||||||
"tensorflow-cpu": "tensorflow-cpu>=2.3",
|
"tensorflow-cpu": "tensorflow-cpu>=2.3",
|
||||||
"tensorflow": "tensorflow>=2.3",
|
"tensorflow": "tensorflow>=2.3",
|
||||||
@@ -56,5 +60,4 @@ deps = {
|
|||||||
"unidic": "unidic>=1.0.2",
|
"unidic": "unidic>=1.0.2",
|
||||||
"unidic_lite": "unidic_lite>=1.0.7",
|
"unidic_lite": "unidic_lite>=1.0.7",
|
||||||
"uvicorn": "uvicorn",
|
"uvicorn": "uvicorn",
|
||||||
"sagemaker": "sagemaker>=2.31.0",
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import unittest
|
|||||||
from distutils.util import strtobool
|
from distutils.util import strtobool
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Iterator, Union
|
||||||
|
|
||||||
from .file_utils import (
|
from .file_utils import (
|
||||||
is_datasets_available,
|
is_datasets_available,
|
||||||
@@ -621,6 +622,27 @@ class CaptureLogger:
|
|||||||
return f"captured: {self.out}\n"
|
return f"captured: {self.out}\n"
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
# adapted from https://stackoverflow.com/a/64789046/9201239
|
||||||
|
def ExtendSysPath(path: Union[str, os.PathLike]) -> Iterator[None]:
|
||||||
|
"""
|
||||||
|
Temporary add given path to `sys.path`.
|
||||||
|
|
||||||
|
Usage ::
|
||||||
|
|
||||||
|
with ExtendSysPath('/path/to/dir'):
|
||||||
|
mymodule = importlib.import_module('mymodule')
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
path = os.fspath(path)
|
||||||
|
try:
|
||||||
|
sys.path.insert(0, path)
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
sys.path.remove(path)
|
||||||
|
|
||||||
|
|
||||||
class TestCasePlus(unittest.TestCase):
|
class TestCasePlus(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
This class extends `unittest.TestCase` with additional features.
|
This class extends `unittest.TestCase` with additional features.
|
||||||
|
|||||||
@@ -16,16 +16,16 @@ import dataclasses
|
|||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import unittest
|
import unittest
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
from parameterized import parameterized
|
from parameterized import parameterized
|
||||||
from transformers import TrainingArguments
|
from transformers import TrainingArguments, is_torch_available
|
||||||
from transformers.file_utils import WEIGHTS_NAME
|
from transformers.file_utils import WEIGHTS_NAME
|
||||||
from transformers.integrations import is_deepspeed_available
|
from transformers.integrations import is_deepspeed_available
|
||||||
from transformers.testing_utils import (
|
from transformers.testing_utils import (
|
||||||
CaptureLogger,
|
CaptureLogger,
|
||||||
|
ExtendSysPath,
|
||||||
TestCasePlus,
|
TestCasePlus,
|
||||||
execute_subprocess_async,
|
execute_subprocess_async,
|
||||||
get_gpu_count,
|
get_gpu_count,
|
||||||
@@ -38,8 +38,11 @@ from transformers.trainer_utils import set_seed
|
|||||||
|
|
||||||
|
|
||||||
bindir = os.path.abspath(os.path.dirname(__file__))
|
bindir = os.path.abspath(os.path.dirname(__file__))
|
||||||
sys.path.append(f"{bindir}/../../../tests")
|
with ExtendSysPath(f"{bindir}/.."):
|
||||||
from test_trainer import TrainerIntegrationCommon, get_regression_trainer # noqa
|
from test_trainer import TrainerIntegrationCommon # noqa
|
||||||
|
|
||||||
|
if is_torch_available():
|
||||||
|
from test_trainer import get_regression_trainer # noqa
|
||||||
|
|
||||||
|
|
||||||
set_seed(42)
|
set_seed(42)
|
||||||
@@ -21,6 +21,7 @@ from unittest.mock import patch
|
|||||||
from transformers.file_utils import is_apex_available
|
from transformers.file_utils import is_apex_available
|
||||||
from transformers.integrations import is_fairscale_available
|
from transformers.integrations import is_fairscale_available
|
||||||
from transformers.testing_utils import (
|
from transformers.testing_utils import (
|
||||||
|
ExtendSysPath,
|
||||||
TestCasePlus,
|
TestCasePlus,
|
||||||
execute_subprocess_async,
|
execute_subprocess_async,
|
||||||
get_gpu_count,
|
get_gpu_count,
|
||||||
@@ -34,7 +35,7 @@ from transformers.trainer_utils import set_seed
|
|||||||
|
|
||||||
|
|
||||||
bindir = os.path.abspath(os.path.dirname(__file__))
|
bindir = os.path.abspath(os.path.dirname(__file__))
|
||||||
sys.path.append(f"{bindir}/../../seq2seq")
|
with ExtendSysPath(f"{bindir}/../../examples/seq2seq"):
|
||||||
from run_translation import main # noqa
|
from run_translation import main # noqa
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user