From 5b317f7ea4fcd012d537f0a1e3c73aef82f9b70a Mon Sep 17 00:00:00 2001 From: Lysandre Debut Date: Thu, 14 Oct 2021 15:30:27 -0400 Subject: [PATCH] Scatter dummies + skip pipeline tests (#13996) * Scatter dummies + skip pipeline tests * Add torch scatter to build docs --- .circleci/config.yml | 1 + src/transformers/__init__.py | 53 +++++++++++------- src/transformers/utils/dummy_pt_objects.py | 52 ------------------ .../utils/dummy_scatter_objects.py | 54 +++++++++++++++++++ tests/test_pipelines_common.py | 7 ++- 5 files changed, 94 insertions(+), 73 deletions(-) create mode 100644 src/transformers/utils/dummy_scatter_objects.py diff --git a/.circleci/config.yml b/.circleci/config.yml index b817d36a6..c1d8e11df 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -753,6 +753,7 @@ jobs: - run: sudo apt-get -y update && sudo apt-get install -y libsndfile1-dev - run: pip install --upgrade pip - run: pip install ."[docs]" + - run: pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.9.0+cpu.html - save_cache: key: v0.4-build_doc-{{ checksum "setup.py" }} paths: diff --git a/src/transformers/__init__.py b/src/transformers/__init__.py index 4628d726c..233c7b7ad 100755 --- a/src/transformers/__init__.py +++ b/src/transformers/__init__.py @@ -44,6 +44,7 @@ from . import dependency_versions_check from .file_utils import ( _LazyModule, is_flax_available, + is_scatter_available, is_sentencepiece_available, is_speech_available, is_tf_available, @@ -488,6 +489,25 @@ else: name for name in dir(dummy_timm_objects) if not name.startswith("_") ] +if is_scatter_available(): + _import_structure["models.tapas"].extend( + [ + "TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST", + "TapasForMaskedLM", + "TapasForQuestionAnswering", + "TapasForSequenceClassification", + "TapasModel", + "TapasPreTrainedModel", + "load_tf_weights_in_tapas", + ] + ) +else: + from .utils import dummy_scatter_objects + + _import_structure["utils.dummy_scatter_objects"] = [ + name for name in dir(dummy_scatter_objects) if not name.startswith("_") + ] + # PyTorch-backed objects if is_torch_available(): _import_structure["benchmark.benchmark"] = ["PyTorchBenchmark"] @@ -1157,17 +1177,6 @@ if is_torch_available(): "load_tf_weights_in_t5", ] ) - _import_structure["models.tapas"].extend( - [ - "TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST", - "TapasForMaskedLM", - "TapasForQuestionAnswering", - "TapasForSequenceClassification", - "TapasModel", - "TapasPreTrainedModel", - "load_tf_weights_in_tapas", - ] - ) _import_structure["models.transfo_xl"].extend( [ "TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST", @@ -2282,6 +2291,19 @@ if TYPE_CHECKING: else: from .utils.dummy_timm_objects import * + if is_scatter_available(): + from .models.tapas import ( + TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST, + TapasForMaskedLM, + TapasForQuestionAnswering, + TapasForSequenceClassification, + TapasModel, + TapasPreTrainedModel, + load_tf_weights_in_tapas, + ) + else: + from .utils.dummy_scatter_objects import * + if is_torch_available(): # Benchmarks from .benchmark.benchmark import PyTorchBenchmark @@ -2847,15 +2869,6 @@ if TYPE_CHECKING: T5PreTrainedModel, load_tf_weights_in_t5, ) - from .models.tapas import ( - TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST, - TapasForMaskedLM, - TapasForQuestionAnswering, - TapasForSequenceClassification, - TapasModel, - TapasPreTrainedModel, - load_tf_weights_in_tapas, - ) from .models.transfo_xl import ( TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST, AdaptiveEmbedding, diff --git a/src/transformers/utils/dummy_pt_objects.py b/src/transformers/utils/dummy_pt_objects.py index 80c91278e..3d0eca764 100644 --- a/src/transformers/utils/dummy_pt_objects.py +++ b/src/transformers/utils/dummy_pt_objects.py @@ -3487,58 +3487,6 @@ def load_tf_weights_in_t5(*args, **kwargs): requires_backends(load_tf_weights_in_t5, ["torch"]) -TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST = None - - -class TapasForMaskedLM: - def __init__(self, *args, **kwargs): - requires_backends(self, ["torch"]) - - @classmethod - def from_pretrained(cls, *args, **kwargs): - requires_backends(cls, ["torch"]) - - -class TapasForQuestionAnswering: - def __init__(self, *args, **kwargs): - requires_backends(self, ["torch"]) - - @classmethod - def from_pretrained(cls, *args, **kwargs): - requires_backends(cls, ["torch"]) - - -class TapasForSequenceClassification: - def __init__(self, *args, **kwargs): - requires_backends(self, ["torch"]) - - @classmethod - def from_pretrained(cls, *args, **kwargs): - requires_backends(cls, ["torch"]) - - -class TapasModel: - def __init__(self, *args, **kwargs): - requires_backends(self, ["torch"]) - - @classmethod - def from_pretrained(cls, *args, **kwargs): - requires_backends(cls, ["torch"]) - - -class TapasPreTrainedModel: - def __init__(self, *args, **kwargs): - requires_backends(self, ["torch"]) - - @classmethod - def from_pretrained(cls, *args, **kwargs): - requires_backends(cls, ["torch"]) - - -def load_tf_weights_in_tapas(*args, **kwargs): - requires_backends(load_tf_weights_in_tapas, ["torch"]) - - TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST = None diff --git a/src/transformers/utils/dummy_scatter_objects.py b/src/transformers/utils/dummy_scatter_objects.py new file mode 100644 index 000000000..639ced6f5 --- /dev/null +++ b/src/transformers/utils/dummy_scatter_objects.py @@ -0,0 +1,54 @@ +# This file is autogenerated by the command `make fix-copies`, do not edit. +from ..file_utils import requires_backends + + +TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TapasForMaskedLM: + def __init__(self, *args, **kwargs): + requires_backends(self, ["scatter"]) + + @classmethod + def from_pretrained(cls, *args, **kwargs): + requires_backends(cls, ["scatter"]) + + +class TapasForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_backends(self, ["scatter"]) + + @classmethod + def from_pretrained(cls, *args, **kwargs): + requires_backends(cls, ["scatter"]) + + +class TapasForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_backends(self, ["scatter"]) + + @classmethod + def from_pretrained(cls, *args, **kwargs): + requires_backends(cls, ["scatter"]) + + +class TapasModel: + def __init__(self, *args, **kwargs): + requires_backends(self, ["scatter"]) + + @classmethod + def from_pretrained(cls, *args, **kwargs): + requires_backends(cls, ["scatter"]) + + +class TapasPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_backends(self, ["scatter"]) + + @classmethod + def from_pretrained(cls, *args, **kwargs): + requires_backends(cls, ["scatter"]) + + +def load_tf_weights_in_tapas(*args, **kwargs): + requires_backends(load_tf_weights_in_tapas, ["scatter"]) diff --git a/tests/test_pipelines_common.py b/tests/test_pipelines_common.py index 55121f38c..d727fdbb7 100644 --- a/tests/test_pipelines_common.py +++ b/tests/test_pipelines_common.py @@ -111,7 +111,12 @@ class PipelineTestCaseMeta(type): tiny_config.is_encoder_decoder = False if ModelClass.__name__.endswith("WithLMHead"): tiny_config.is_decoder = True - model = ModelClass(tiny_config) + try: + model = ModelClass(tiny_config) + except ImportError as e: + self.skipTest( + f"Cannot run with {tiny_config} as the model requires a library that isn't installed: {e}" + ) if hasattr(model, "eval"): model = model.eval() if tokenizer_class is not None: