diff --git a/.circleci/config.yml b/.circleci/config.yml index 7ed65de73cb..7f9c4947966 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -248,6 +248,7 @@ jobs: - run: isort --check-only examples templates tests src utils - run: flake8 examples templates tests src utils - run: python utils/check_copies.py + - run: python utils/check_dummies.py - run: python utils/check_repo.py check_repository_consistency: working_directory: ~/transformers diff --git a/Makefile b/Makefile index 9d3f2d5da64..637d1616c32 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ modified_only_fixup: extra_quality_checks: python utils/check_copies.py + python utils/check_dummies.py python utils/check_repo.py # this target runs checks on all files @@ -46,6 +47,7 @@ fixup: modified_only_fixup extra_quality_checks fix-copies: python utils/check_copies.py --fix_and_overwrite + python utils/check_dummies.py --fix_and_overwrite # Run tests for the library diff --git a/src/transformers/__init__.py b/src/transformers/__init__.py index 5c098db03c3..9ab37830cfe 100755 --- a/src/transformers/__init__.py +++ b/src/transformers/__init__.py @@ -73,12 +73,13 @@ from .data import ( SquadFeatures, SquadV1Processor, SquadV2Processor, + glue_compute_metrics, glue_convert_examples_to_features, glue_output_modes, glue_processors, glue_tasks_num_labels, - is_sklearn_available, squad_convert_examples_to_features, + xnli_compute_metrics, xnli_output_modes, xnli_processors, xnli_tasks_num_labels, @@ -102,6 +103,7 @@ from .file_utils import ( is_faiss_available, is_psutil_available, is_py3nvml_available, + is_sklearn_available, is_tf_available, is_torch_available, is_torch_tpu_available, @@ -212,10 +214,6 @@ from .utils import logging logger = logging.get_logger(__name__) # pylint: disable=invalid-name -if is_sklearn_available(): - from .data import glue_compute_metrics, xnli_compute_metrics - - # Modeling if is_torch_available(): # Benchmarks @@ -531,6 +529,8 @@ if is_torch_available(): # Trainer from .trainer import EvalPrediction, Trainer, set_seed, torch_distributed_zero_first +else: + from .utils.dummy_pt_objects import * # TensorFlow if is_tf_available(): @@ -753,6 +753,11 @@ if is_tf_available(): # Trainer from .trainer_tf import TFTrainer +else: + # Import the same objects as dummies to get them in the namespace. + # They will raise an import error if the user tries to instantiate / use them. + from .utils.dummy_tf_objects import * + if not is_tf_available() and not is_torch_available(): logger.warning( diff --git a/src/transformers/data/__init__.py b/src/transformers/data/__init__.py index 8d5f6b85b02..e5099537ed2 100644 --- a/src/transformers/data/__init__.py +++ b/src/transformers/data/__init__.py @@ -2,7 +2,7 @@ # There's no way to ignore "F401 '...' imported but unused" warnings in this # module, but to preserve other warnings. So, don't check this module at all. -from .metrics import is_sklearn_available +from .metrics import glue_compute_metrics, xnli_compute_metrics from .processors import ( DataProcessor, InputExample, @@ -21,7 +21,3 @@ from .processors import ( xnli_processors, xnli_tasks_num_labels, ) - - -if is_sklearn_available(): - from .metrics import glue_compute_metrics, xnli_compute_metrics diff --git a/src/transformers/data/metrics/__init__.py b/src/transformers/data/metrics/__init__.py index 2115752111a..0a7891abd79 100644 --- a/src/transformers/data/metrics/__init__.py +++ b/src/transformers/data/metrics/__init__.py @@ -14,77 +14,75 @@ # See the License for the specific language governing permissions and # limitations under the License. -try: +from ...file_utils import is_sklearn_available, requires_sklearn + + +if is_sklearn_available(): from sklearn.metrics import f1_score, matthews_corrcoef from scipy.stats import pearsonr, spearmanr - _has_sklearn = True -except (AttributeError, ImportError): - _has_sklearn = False + +def simple_accuracy(preds, labels): + requires_sklearn(simple_accuracy) + return (preds == labels).mean() -def is_sklearn_available(): - return _has_sklearn +def acc_and_f1(preds, labels): + requires_sklearn(acc_and_f1) + acc = simple_accuracy(preds, labels) + f1 = f1_score(y_true=labels, y_pred=preds) + return { + "acc": acc, + "f1": f1, + "acc_and_f1": (acc + f1) / 2, + } -if _has_sklearn: +def pearson_and_spearman(preds, labels): + requires_sklearn(pearson_and_spearman) + pearson_corr = pearsonr(preds, labels)[0] + spearman_corr = spearmanr(preds, labels)[0] + return { + "pearson": pearson_corr, + "spearmanr": spearman_corr, + "corr": (pearson_corr + spearman_corr) / 2, + } - def simple_accuracy(preds, labels): - return (preds == labels).mean() - def acc_and_f1(preds, labels): - acc = simple_accuracy(preds, labels) - f1 = f1_score(y_true=labels, y_pred=preds) - return { - "acc": acc, - "f1": f1, - "acc_and_f1": (acc + f1) / 2, - } +def glue_compute_metrics(task_name, preds, labels): + requires_sklearn(glue_compute_metrics) + assert len(preds) == len(labels), f"Predictions and labels have mismatched lengths {len(preds)} and {len(labels)}" + if task_name == "cola": + return {"mcc": matthews_corrcoef(labels, preds)} + elif task_name == "sst-2": + return {"acc": simple_accuracy(preds, labels)} + elif task_name == "mrpc": + return acc_and_f1(preds, labels) + elif task_name == "sts-b": + return pearson_and_spearman(preds, labels) + elif task_name == "qqp": + return acc_and_f1(preds, labels) + elif task_name == "mnli": + return {"mnli/acc": simple_accuracy(preds, labels)} + elif task_name == "mnli-mm": + return {"mnli-mm/acc": simple_accuracy(preds, labels)} + elif task_name == "qnli": + return {"acc": simple_accuracy(preds, labels)} + elif task_name == "rte": + return {"acc": simple_accuracy(preds, labels)} + elif task_name == "wnli": + return {"acc": simple_accuracy(preds, labels)} + elif task_name == "hans": + return {"acc": simple_accuracy(preds, labels)} + else: + raise KeyError(task_name) - def pearson_and_spearman(preds, labels): - pearson_corr = pearsonr(preds, labels)[0] - spearman_corr = spearmanr(preds, labels)[0] - return { - "pearson": pearson_corr, - "spearmanr": spearman_corr, - "corr": (pearson_corr + spearman_corr) / 2, - } - def glue_compute_metrics(task_name, preds, labels): - assert len(preds) == len( - labels - ), f"Predictions and labels have mismatched lengths {len(preds)} and {len(labels)}" - if task_name == "cola": - return {"mcc": matthews_corrcoef(labels, preds)} - elif task_name == "sst-2": - return {"acc": simple_accuracy(preds, labels)} - elif task_name == "mrpc": - return acc_and_f1(preds, labels) - elif task_name == "sts-b": - return pearson_and_spearman(preds, labels) - elif task_name == "qqp": - return acc_and_f1(preds, labels) - elif task_name == "mnli": - return {"mnli/acc": simple_accuracy(preds, labels)} - elif task_name == "mnli-mm": - return {"mnli-mm/acc": simple_accuracy(preds, labels)} - elif task_name == "qnli": - return {"acc": simple_accuracy(preds, labels)} - elif task_name == "rte": - return {"acc": simple_accuracy(preds, labels)} - elif task_name == "wnli": - return {"acc": simple_accuracy(preds, labels)} - elif task_name == "hans": - return {"acc": simple_accuracy(preds, labels)} - else: - raise KeyError(task_name) - - def xnli_compute_metrics(task_name, preds, labels): - assert len(preds) == len( - labels - ), f"Predictions and labels have mismatched lengths {len(preds)} and {len(labels)}" - if task_name == "xnli": - return {"acc": simple_accuracy(preds, labels)} - else: - raise KeyError(task_name) +def xnli_compute_metrics(task_name, preds, labels): + requires_sklearn(xnli_compute_metrics) + assert len(preds) == len(labels), f"Predictions and labels have mismatched lengths {len(preds)} and {len(labels)}" + if task_name == "xnli": + return {"acc": simple_accuracy(preds, labels)} + else: + raise KeyError(task_name) diff --git a/src/transformers/file_utils.py b/src/transformers/file_utils.py index 351d74f91a5..7797d85e014 100644 --- a/src/transformers/file_utils.py +++ b/src/transformers/file_utils.py @@ -133,6 +133,15 @@ try: except ImportError: _faiss_available = False +try: + import sklearn.metrics # noqa: F401 + + import scipy.stats # noqa: F401 + + _has_sklearn = True +except (AttributeError, ImportError): + _has_sklearn = False + default_cache_path = os.path.join(torch_cache_home, "transformers") @@ -194,6 +203,88 @@ def is_faiss_available(): return _faiss_available +def is_sklearn_available(): + return _has_sklearn + + +DATASETS_IMPORT_ERROR = """ +{0} requires the 🤗 Datasets library but it was not found in your enviromnent. You can install it with: +``` +pip install datasets +``` +In a notebook or a colab, you can install it by executing a cell with +``` +!pip install datasets +``` +then restarting your kernel. + +Note that if you have a local folder named `datasets` or a local python file named `datasets.py` in your current +working directory, python may try to import this instead of the 🤗 Datasets library. You should rename this folder or +that python file if that's the case. +""" + + +FAISS_IMPORT_ERROR = """ +{0} requires the faiss library but it was not found in your enviromnent. Checkout the instructions on the +installation page of its repo: https://github.com/facebookresearch/faiss/blob/master/INSTALL.md and follow the ones +that match your enviromnent. +""" + + +PYTORCH_IMPORT_ERROR = """ +{0} requires the PyTorch library but it was not found in your enviromnent. Checkout the instructions on the +installation page: https://pytorch.org/get-started/locally/ and follow the ones that match your enviromnent. +""" + + +SKLEARN_IMPORT_ERROR = """ +{0} requires the scikit-learn library but it was not found in your enviromnent. You can install it with: +``` +pip install -U scikit-learn +``` +In a notebook or a colab, you can install it by executing a cell with +``` +!pip install -U scikit-learn +``` +""" + + +TENSORFLOW_IMPORT_ERROR = """ +{0} requires the TensorFlow library but it was not found in your enviromnent. Checkout the instructions on the +installation page: https://www.tensorflow.org/install and follow the ones that match your enviromnent. +""" + + +def requires_datasets(obj): + name = obj.__name__ if hasattr(obj, "__name__") else obj.__class__.__name__ + if not is_datasets_available(): + raise ImportError(DATASETS_IMPORT_ERROR.format(name)) + + +def requires_faiss(obj): + name = obj.__name__ if hasattr(obj, "__name__") else obj.__class__.__name__ + if not is_faiss_available(): + raise ImportError(FAISS_IMPORT_ERROR.format(name)) + + +def requires_pytorch(obj): + name = obj.__name__ if hasattr(obj, "__name__") else obj.__class__.__name__ + if not is_torch_available(): + raise ImportError(PYTORCH_IMPORT_ERROR.format(name)) + + +def requires_sklearn(obj): + name = obj.__name__ if hasattr(obj, "__name__") else obj.__class__.__name__ + if not is_sklearn_available(): + raise ImportError(SKLEARN_IMPORT_ERROR.format(name)) + + +def requires_tf(obj): + name = obj.__name__ if hasattr(obj, "__name__") else obj.__class__.__name__ + if not is_tf_available(): + raise ImportError(TENSORFLOW_IMPORT_ERROR.format(name)) + + def add_start_docstrings(*docstr): def docstring_decorator(fn): fn.__doc__ = "".join(docstr) + (fn.__doc__ if fn.__doc__ is not None else "") diff --git a/src/transformers/retrieval_rag.py b/src/transformers/retrieval_rag.py index 6ed0639e3ce..c8bacc60927 100644 --- a/src/transformers/retrieval_rag.py +++ b/src/transformers/retrieval_rag.py @@ -22,15 +22,23 @@ from typing import Iterable, List, Optional, Tuple import numpy as np from .configuration_rag import RagConfig -from .file_utils import cached_path, is_datasets_available, is_faiss_available, is_remote_url +from .file_utils import ( + cached_path, + is_datasets_available, + is_faiss_available, + is_remote_url, + requires_datasets, + requires_faiss, +) from .tokenization_rag import RagTokenizer from .tokenization_utils_base import BatchEncoding from .utils import logging -if is_datasets_available() and is_faiss_available(): +if is_datasets_available(): from datasets import load_dataset +if is_faiss_available(): import faiss @@ -273,6 +281,8 @@ class RagRetriever: _init_retrieval = True def __init__(self, config, question_encoder_tokenizer, generator_tokenizer): + requires_datasets(self) + requires_faiss(self) super().__init__() self.index = ( LegacyIndex( @@ -301,6 +311,8 @@ class RagRetriever: @classmethod def from_pretrained(cls, retriever_name_or_path, **kwargs): + requires_datasets(cls) + requires_faiss(cls) config = RagConfig.from_pretrained(retriever_name_or_path, **kwargs) rag_tokenizer = RagTokenizer.from_pretrained(retriever_name_or_path, config=config) question_encoder_tokenizer = rag_tokenizer.question_encoder diff --git a/src/transformers/utils/dummy_pt_objects.py b/src/transformers/utils/dummy_pt_objects.py new file mode 100644 index 00000000000..6040cb0b14d --- /dev/null +++ b/src/transformers/utils/dummy_pt_objects.py @@ -0,0 +1,1807 @@ +# This file is autogenerated by the command `make fix-copies`, do not edit. +from ..file_utils import requires_pytorch + + +class PyTorchBenchmark: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class PyTorchBenchmarkArguments: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class DataCollator: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class DataCollatorForLanguageModeling: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class DataCollatorForNextSentencePrediction: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class DataCollatorForPermutationLanguageModeling: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class DataCollatorForSOP: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class DataCollatorWithPadding: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +def default_data_collator(*args, **kwargs): + requires_pytorch(default_data_collator) + + +class GlueDataset: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class GlueDataTrainingArguments: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class LineByLineTextDataset: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class LineByLineWithSOPTextDataset: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class SquadDataset: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class SquadDataTrainingArguments: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class TextDataset: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class TextDatasetForNextSentencePrediction: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +def top_k_top_p_filtering(*args, **kwargs): + requires_pytorch(top_k_top_p_filtering) + + +ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class AlbertForMaskedLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class AlbertForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class AlbertForPreTraining: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class AlbertForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class AlbertForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class AlbertForTokenClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class AlbertModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class AlbertPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +def load_tf_weights_in_albert(*args, **kwargs): + requires_pytorch(load_tf_weights_in_albert) + + +MODEL_FOR_CAUSAL_LM_MAPPING = None + + +MODEL_FOR_MASKED_LM_MAPPING = None + + +MODEL_FOR_MULTIPLE_CHOICE_MAPPING = None + + +MODEL_FOR_PRETRAINING_MAPPING = None + + +MODEL_FOR_QUESTION_ANSWERING_MAPPING = None + + +MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING = None + + +MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING = None + + +MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING = None + + +MODEL_MAPPING = None + + +MODEL_WITH_LM_HEAD_MAPPING = None + + +class AutoModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class AutoModelForCausalLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class AutoModelForMaskedLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class AutoModelForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class AutoModelForPreTraining: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class AutoModelForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class AutoModelForSeq2SeqLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class AutoModelForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class AutoModelForTokenClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class AutoModelWithLMHead: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +BART_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class BartForConditionalGeneration: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class BartForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class BartForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class BartModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class PretrainedBartModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +BERT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class BertForMaskedLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class BertForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class BertForNextSentencePrediction: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class BertForPreTraining: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class BertForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class BertForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class BertForTokenClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class BertLayer: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class BertLMHeadModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class BertModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class BertPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +def load_tf_weights_in_bert(*args, **kwargs): + requires_pytorch(load_tf_weights_in_bert) + + +class BertGenerationDecoder: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class BertGenerationEncoder: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +def load_tf_weights_in_bert_generation(*args, **kwargs): + requires_pytorch(load_tf_weights_in_bert_generation) + + +CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class CamembertForCausalLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class CamembertForMaskedLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class CamembertForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class CamembertForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class CamembertForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class CamembertForTokenClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class CamembertModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +CTRL_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class CTRLLMHeadModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class CTRLModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class CTRLPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class DebertaForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class DebertaModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class DebertaPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class DistilBertForMaskedLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class DistilBertForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class DistilBertForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class DistilBertForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class DistilBertForTokenClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class DistilBertModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class DistilBertPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class DPRContextEncoder: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class DPRPretrainedContextEncoder: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class DPRPretrainedQuestionEncoder: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class DPRPretrainedReader: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class DPRQuestionEncoder: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class DPRReader: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class ElectraForMaskedLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class ElectraForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class ElectraForPreTraining: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class ElectraForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class ElectraForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class ElectraForTokenClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class ElectraModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class ElectraPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +def load_tf_weights_in_electra(*args, **kwargs): + requires_pytorch(load_tf_weights_in_electra) + + +class EncoderDecoderModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class FlaubertForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class FlaubertForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class FlaubertForQuestionAnsweringSimple: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class FlaubertForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class FlaubertForTokenClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class FlaubertModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class FlaubertWithLMHeadModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class FSMTForConditionalGeneration: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class FSMTModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class PretrainedFSMTModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +FUNNEL_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class FunnelBaseModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class FunnelForMaskedLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class FunnelForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class FunnelForPreTraining: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class FunnelForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class FunnelForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class FunnelForTokenClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class FunnelModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +def load_tf_weights_in_funnel(*args, **kwargs): + requires_pytorch(load_tf_weights_in_funnel) + + +GPT2_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class GPT2DoubleHeadsModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class GPT2LMHeadModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class GPT2Model: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class GPT2PreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +def load_tf_weights_in_gpt2(*args, **kwargs): + requires_pytorch(load_tf_weights_in_gpt2) + + +LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class LayoutLMForMaskedLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class LayoutLMForTokenClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class LayoutLMModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +LONGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class LongformerForMaskedLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class LongformerForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class LongformerForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class LongformerForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class LongformerForTokenClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class LongformerModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class LongformerSelfAttention: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class LxmertEncoder: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class LxmertForPreTraining: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class LxmertForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class LxmertModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class LxmertPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class LxmertVisualFeatureEncoder: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class LxmertXLayer: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class MarianMTModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class MBartForConditionalGeneration: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class MMBTForClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class MMBTModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class ModalEmbeddings: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class MobileBertForMaskedLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class MobileBertForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class MobileBertForNextSentencePrediction: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class MobileBertForPreTraining: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class MobileBertForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class MobileBertForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class MobileBertForTokenClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class MobileBertLayer: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class MobileBertModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class MobileBertPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +def load_tf_weights_in_mobilebert(*args, **kwargs): + requires_pytorch(load_tf_weights_in_mobilebert) + + +OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class OpenAIGPTDoubleHeadsModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class OpenAIGPTLMHeadModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class OpenAIGPTModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class OpenAIGPTPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +def load_tf_weights_in_openai_gpt(*args, **kwargs): + requires_pytorch(load_tf_weights_in_openai_gpt) + + +class PegasusForConditionalGeneration: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class RagModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class RagSequenceForGeneration: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class RagTokenForGeneration: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +REFORMER_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class ReformerAttention: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class ReformerForMaskedLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class ReformerForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class ReformerForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class ReformerLayer: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class ReformerModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class ReformerModelWithLMHead: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +RETRIBERT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class RetriBertModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class RetriBertPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class RobertaForCausalLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class RobertaForMaskedLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class RobertaForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class RobertaForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class RobertaForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class RobertaForTokenClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class RobertaModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +T5_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class T5ForConditionalGeneration: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class T5Model: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class T5PreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +def load_tf_weights_in_t5(*args, **kwargs): + requires_pytorch(load_tf_weights_in_t5) + + +TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class AdaptiveEmbedding: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class TransfoXLLMHeadModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class TransfoXLModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class TransfoXLPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +def load_tf_weights_in_transfo_xl(*args, **kwargs): + requires_pytorch(load_tf_weights_in_transfo_xl) + + +class Conv1D: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class PreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +def apply_chunking_to_forward(*args, **kwargs): + requires_pytorch(apply_chunking_to_forward) + + +def prune_layer(*args, **kwargs): + requires_pytorch(prune_layer) + + +XLM_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class XLMForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLMForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLMForQuestionAnsweringSimple: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLMForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLMForTokenClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLMModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLMPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLMWithLMHeadModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class XLMRobertaForCausalLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class XLMRobertaForMaskedLM: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLMRobertaForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLMRobertaForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLMRobertaForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLMRobertaForTokenClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLMRobertaModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +XLNET_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class XLNetForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLNetForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLNetForQuestionAnsweringSimple: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLNetForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLNetForTokenClassification: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLNetLMHeadModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLNetModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class XLNetPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +def load_tf_weights_in_xlnet(*args, **kwargs): + requires_pytorch(load_tf_weights_in_xlnet) + + +class Adafactor: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class AdamW: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +def get_constant_schedule(*args, **kwargs): + requires_pytorch(get_constant_schedule) + + +def get_constant_schedule_with_warmup(*args, **kwargs): + requires_pytorch(get_constant_schedule_with_warmup) + + +def get_cosine_schedule_with_warmup(*args, **kwargs): + requires_pytorch(get_cosine_schedule_with_warmup) + + +def get_cosine_with_hard_restarts_schedule_with_warmup(*args, **kwargs): + requires_pytorch(get_cosine_with_hard_restarts_schedule_with_warmup) + + +def get_linear_schedule_with_warmup(*args, **kwargs): + requires_pytorch(get_linear_schedule_with_warmup) + + +def get_polynomial_decay_schedule_with_warmup(*args, **kwargs): + requires_pytorch(get_polynomial_decay_schedule_with_warmup) + + +class MarianTokenizer: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) + + +class EvalPrediction: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +class Trainer: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + +def set_seed(*args, **kwargs): + requires_pytorch(set_seed) + + +def torch_distributed_zero_first(*args, **kwargs): + requires_pytorch(torch_distributed_zero_first) diff --git a/src/transformers/utils/dummy_tf_objects.py b/src/transformers/utils/dummy_tf_objects.py new file mode 100644 index 00000000000..28d8c50b6b3 --- /dev/null +++ b/src/transformers/utils/dummy_tf_objects.py @@ -0,0 +1,1291 @@ +# This file is autogenerated by the command `make fix-copies`, do not edit. +from ..file_utils import requires_tf + + +class TensorFlowBenchmarkArguments: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TensorFlowBenchmark: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +def tf_top_k_top_p_filtering(*args, **kwargs): + requires_tf(tf_top_k_top_p_filtering) + + +TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFAlbertForMaskedLM: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFAlbertForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFAlbertForPreTraining: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFAlbertForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFAlbertForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFAlbertForTokenClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFAlbertMainLayer: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFAlbertModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFAlbertPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_MODEL_FOR_CAUSAL_LM_MAPPING = None + + +TF_MODEL_FOR_MASKED_LM_MAPPING = None + + +TF_MODEL_FOR_MULTIPLE_CHOICE_MAPPING = None + + +TF_MODEL_FOR_PRETRAINING_MAPPING = None + + +TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING = None + + +TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING = None + + +TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING = None + + +TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING = None + + +TF_MODEL_MAPPING = None + + +TF_MODEL_WITH_LM_HEAD_MAPPING = None + + +class TFAutoModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFAutoModelForCausalLM: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFAutoModelForMaskedLM: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFAutoModelForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFAutoModelForPreTraining: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFAutoModelForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFAutoModelForSeq2SeqLM: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFAutoModelForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFAutoModelForTokenClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFAutoModelWithLMHead: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFBertEmbeddings: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFBertForMaskedLM: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFBertForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFBertForNextSentencePrediction: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFBertForPreTraining: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFBertForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFBertForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFBertForTokenClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFBertLMHeadModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFBertMainLayer: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFBertModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFBertPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFCamembertForMaskedLM: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFCamembertForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFCamembertForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFCamembertForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFCamembertForTokenClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFCamembertModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFCTRLLMHeadModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFCTRLModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFCTRLPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFDistilBertForMaskedLM: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFDistilBertForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFDistilBertForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFDistilBertForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFDistilBertForTokenClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFDistilBertMainLayer: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFDistilBertModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFDistilBertPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFElectraForMaskedLM: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFElectraForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFElectraForPreTraining: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFElectraForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFElectraForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFElectraForTokenClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFElectraModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFElectraPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFFlaubertForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFFlaubertForQuestionAnsweringSimple: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFFlaubertForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFFlaubertForTokenClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFFlaubertModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFFlaubertWithLMHeadModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_FUNNEL_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFFunnelBaseModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFFunnelForMaskedLM: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFFunnelForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFFunnelForPreTraining: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFFunnelForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFFunnelForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFFunnelForTokenClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFFunnelModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFGPT2DoubleHeadsModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFGPT2LMHeadModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFGPT2MainLayer: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFGPT2Model: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFGPT2PreTrainedModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_LONGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFLongformerForMaskedLM: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFLongformerForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFLongformerModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFLongformerSelfAttention: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFLxmertForPreTraining: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFLxmertMainLayer: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFLxmertModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFLxmertPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFLxmertVisualFeatureEncoder: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFMobileBertForMaskedLM: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFMobileBertForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFMobileBertForNextSentencePrediction: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFMobileBertForPreTraining: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFMobileBertForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFMobileBertForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFMobileBertForTokenClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFMobileBertMainLayer: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFMobileBertModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFMobileBertPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFOpenAIGPTDoubleHeadsModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFOpenAIGPTLMHeadModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFOpenAIGPTMainLayer: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFOpenAIGPTModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFOpenAIGPTPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFRobertaForMaskedLM: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFRobertaForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFRobertaForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFRobertaForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFRobertaForTokenClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFRobertaMainLayer: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFRobertaModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFRobertaPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFT5ForConditionalGeneration: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFT5Model: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFT5PreTrainedModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFAdaptiveEmbedding: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFTransfoXLLMHeadModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFTransfoXLMainLayer: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFTransfoXLModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFTransfoXLPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFSequenceSummary: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFSharedEmbeddings: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +def shape_list(*args, **kwargs): + requires_tf(shape_list) + + +TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFXLMForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLMForQuestionAnsweringSimple: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLMForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLMForTokenClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLMMainLayer: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFXLMModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLMPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLMWithLMHeadModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFXLMRobertaForMaskedLM: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLMRobertaForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLMRobertaForQuestionAnswering: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLMRobertaForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLMRobertaForTokenClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLMRobertaModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +TF_XLNET_PRETRAINED_MODEL_ARCHIVE_LIST = None + + +class TFXLNetForMultipleChoice: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLNetForQuestionAnsweringSimple: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLNetForSequenceClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLNetForTokenClassification: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLNetLMHeadModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLNetMainLayer: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class TFXLNetModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class TFXLNetPreTrainedModel: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) + + +class AdamWeightDecay: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class GradientAccumulator: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +class WarmUp: + def __init__(self, *args, **kwargs): + requires_tf(self) + + +def create_optimizer(*args, **kwargs): + requires_tf(create_optimizer) + + +class TFTrainer: + def __init__(self, *args, **kwargs): + requires_tf(self) diff --git a/utils/check_dummies.py b/utils/check_dummies.py new file mode 100644 index 00000000000..7a18d5e0dbb --- /dev/null +++ b/utils/check_dummies.py @@ -0,0 +1,199 @@ +# coding=utf-8 +# Copyright 2020 The HuggingFace Inc. team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import os +import re + + +# All paths are set with the intent you should run this script from the root of the repo with the command +# python utils/check_dummies.py +PATH_TO_TRANSFORMERS = "src/transformers" + +_re_single_line_import = re.compile(r"\s+from\s+\S*\s+import\s+([^\(\s].*)\n") + +DUMMY_CONSTANT = """ +{0} = None +""" + +DUMMY_PT_PRETRAINED_CLASS = """ +class {0}: + def __init__(self, *args, **kwargs): + requires_pytorch(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_pytorch(self) +""" + +DUMMY_PT_CLASS = """ +class {0}: + def __init__(self, *args, **kwargs): + requires_pytorch(self) +""" + +DUMMY_PT_FUNCTION = """ +def {0}(*args, **kwargs): + requires_pytorch({0}) +""" + +DUMMY_TF_PRETRAINED_CLASS = """ +class {0}: + def __init__(self, *args, **kwargs): + requires_tf(self) + + @classmethod + def from_pretrained(self, *args, **kwargs): + requires_tf(self) +""" + +DUMMY_TF_CLASS = """ +class {0}: + def __init__(self, *args, **kwargs): + requires_tf(self) +""" + +DUMMY_TF_FUNCTION = """ +def {0}(*args, **kwargs): + requires_tf({0}) +""" + + +def read_init(): + """ Read the init and exctracts PyTorch and TensorFlow objects. """ + with open(os.path.join(PATH_TO_TRANSFORMERS, "__init__.py"), "r", encoding="utf-8") as f: + lines = f.readlines() + + line_index = 0 + # Find where the PyTorch imports begin + pt_objects = [] + while not lines[line_index].startswith("if is_torch_available():"): + line_index += 1 + line_index += 1 + + # Until we unindent, add PyTorch objects to the list + while len(lines[line_index]) <= 1 or lines[line_index].startswith(" "): + line = lines[line_index] + search = _re_single_line_import.search(line) + if search is not None: + pt_objects += search.groups()[0].split(", ") + elif line.startswith(" "): + pt_objects.append(line[8:-2]) + line_index += 1 + + # Find where the TF imports begin + tf_objects = [] + while not lines[line_index].startswith("if is_tf_available():"): + line_index += 1 + line_index += 1 + + # Until we unindent, add PyTorch objects to the list + while len(lines[line_index]) <= 1 or lines[line_index].startswith(" "): + line = lines[line_index] + search = _re_single_line_import.search(line) + if search is not None: + tf_objects += search.groups()[0].split(", ") + elif line.startswith(" "): + tf_objects.append(line[8:-2]) + line_index += 1 + return pt_objects, tf_objects + + +def create_dummy_object(name, is_pytorch=True): + """ Create the code for the dummy object corresponding to `name`.""" + _pretrained = [ + "Config" "ForCausalLM", + "ForConditionalGeneration", + "ForMaskedLM", + "ForMultipleChoice", + "ForQuestionAnswering", + "ForSequenceClassification", + "ForTokenClassification", + "Model", + "Tokenizer", + ] + if name.isupper(): + return DUMMY_CONSTANT.format(name) + elif name.islower(): + return (DUMMY_PT_FUNCTION if is_pytorch else DUMMY_TF_FUNCTION).format(name) + else: + is_pretrained = False + for part in _pretrained: + if part in name: + is_pretrained = True + break + if is_pretrained: + template = DUMMY_PT_PRETRAINED_CLASS if is_pytorch else DUMMY_TF_PRETRAINED_CLASS + else: + template = DUMMY_PT_CLASS if is_pytorch else DUMMY_TF_CLASS + return template.format(name) + + +def create_dummy_files(): + """ Create the content of the dummy files. """ + pt_objects, tf_objects = read_init() + + pt_dummies = "# This file is autogenerated by the command `make fix-copies`, do not edit.\n" + pt_dummies += "from ..file_utils import requires_pytorch\n\n" + pt_dummies += "\n".join([create_dummy_object(o) for o in pt_objects]) + + tf_dummies = "# This file is autogenerated by the command `make fix-copies`, do not edit.\n" + tf_dummies += "from ..file_utils import requires_tf\n\n" + tf_dummies += "\n".join([create_dummy_object(o, False) for o in tf_objects]) + + return pt_dummies, tf_dummies + + +def check_dummies(overwrite=False): + """ Check if the dummy files are up to date and maybe `overwrite` with the right content. """ + pt_dummies, tf_dummies = create_dummy_files() + path = os.path.join(PATH_TO_TRANSFORMERS, "utils") + pt_file = os.path.join(path, "dummy_pt_objects.py") + tf_file = os.path.join(path, "dummy_tf_objects.py") + + with open(pt_file, "r", encoding="utf-8") as f: + actual_pt_dummies = f.read() + with open(tf_file, "r", encoding="utf-8") as f: + actual_tf_dummies = f.read() + + if pt_dummies != actual_pt_dummies: + if overwrite: + print("Updating transformers.utils.dummy_pt_objects.py as the main __init__ has new objects.") + with open(pt_file, "w", encoding="utf-8") as f: + f.write(pt_dummies) + else: + raise ValueError( + "The main __init__ has objects that are not present in transformers.utils.dummy_pt_objects.py.", + "Run `make fix-copies` to fix this.", + ) + + if tf_dummies != actual_tf_dummies: + if overwrite: + print("Updating transformers.utils.dummy_tf_objects.py as the main __init__ has new objects.") + with open(tf_file, "w", encoding="utf-8") as f: + f.write(tf_dummies) + else: + raise ValueError( + "The main __init__ has objects that are not present in transformers.utils.dummy_pt_objects.py.", + "Run `make fix-copies` to fix this.", + ) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--fix_and_overwrite", action="store_true", help="Whether to fix inconsistencies.") + args = parser.parse_args() + + check_dummies(args.fix_and_overwrite)