diff --git a/src/transformers/commands/serving.py b/src/transformers/commands/serving.py index 04dea67bf69..4d543fee5e3 100644 --- a/src/transformers/commands/serving.py +++ b/src/transformers/commands/serving.py @@ -107,7 +107,7 @@ class ServeCommand(BaseTransformersCLICommand): self._host = host self._port = port if not _serve_dependancies_installed: - raise ImportError( + raise RuntimeError( "Using serve command requires FastAPI and unicorn. " "Please install transformers with [serving]: pip install transformers[serving]." "Or install FastAPI and unicorn separatly." diff --git a/src/transformers/commands/train.py b/src/transformers/commands/train.py index bf16a4f5e04..afa035c9401 100644 --- a/src/transformers/commands/train.py +++ b/src/transformers/commands/train.py @@ -8,7 +8,7 @@ from transformers.commands import BaseTransformersCLICommand if not is_tf_available() and not is_torch_available(): - raise ImportError("At least one of PyTorch or TensorFlow 2.0+ should be installed to use CLI training") + raise RuntimeError("At least one of PyTorch or TensorFlow 2.0+ should be installed to use CLI training") # TF training parameters USE_XLA = False diff --git a/src/transformers/data/processors/squad.py b/src/transformers/data/processors/squad.py index 8df4547c5fb..e2dc3f85b34 100644 --- a/src/transformers/data/processors/squad.py +++ b/src/transformers/data/processors/squad.py @@ -324,7 +324,7 @@ def squad_convert_examples_to_features( del new_features if return_dataset == "pt": if not is_torch_available(): - raise ImportError("Pytorch must be installed to return a pytorch dataset.") + raise RuntimeError("PyTorch must be installed to return a PyTorch dataset.") # Convert to Tensors and build dataset all_input_ids = torch.tensor([f.input_ids for f in features], dtype=torch.long) @@ -354,7 +354,7 @@ def squad_convert_examples_to_features( return features, dataset elif return_dataset == "tf": if not is_tf_available(): - raise ImportError("TensorFlow must be installed to return a TensorFlow dataset.") + raise RuntimeError("TensorFlow must be installed to return a TensorFlow dataset.") def gen(): for ex in features: diff --git a/src/transformers/data/processors/utils.py b/src/transformers/data/processors/utils.py index e2e96f6b220..a7244ab39cf 100644 --- a/src/transformers/data/processors/utils.py +++ b/src/transformers/data/processors/utils.py @@ -294,7 +294,7 @@ class SingleSentenceClassificationProcessor(DataProcessor): return features elif return_tensors == "tf": if not is_tf_available(): - raise ImportError("return_tensors set to 'tf' but TensorFlow 2.0 can't be imported") + raise RuntimeError("return_tensors set to 'tf' but TensorFlow 2.0 can't be imported") import tensorflow as tf def gen(): @@ -309,7 +309,7 @@ class SingleSentenceClassificationProcessor(DataProcessor): return dataset elif return_tensors == "pt": if not is_torch_available(): - raise ImportError("return_tensors set to 'pt' but PyTorch can't be imported") + raise RuntimeError("return_tensors set to 'pt' but PyTorch can't be imported") import torch from torch.utils.data import TensorDataset diff --git a/src/transformers/pipelines.py b/src/transformers/pipelines.py index 996521ac5cf..3ce8ea72e4a 100755 --- a/src/transformers/pipelines.py +++ b/src/transformers/pipelines.py @@ -68,7 +68,7 @@ def get_framework(model=None): # Try to guess which framework to use from the model classname framework = "tf" if model.__class__.__name__.startswith("TF") else "pt" elif not is_tf_available() and not is_torch_available(): - raise ImportError( + raise RuntimeError( "At least one of TensorFlow 2.0 or PyTorch should be installed. " "To install TensorFlow 2.0, read the instructions at https://www.tensorflow.org/install/ " "To install PyTorch, read the instructions at https://pytorch.org/."