Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
c8b0c1e5
Commit
c8b0c1e5
authored
Dec 23, 2019
by
Aymeric Augustin
Browse files
Improve exception type.
ImportError isn't really appropriate when there's no import involved.
parent
4c09a960
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
7 additions
and
7 deletions
+7
-7
src/transformers/commands/serving.py
src/transformers/commands/serving.py
+1
-1
src/transformers/commands/train.py
src/transformers/commands/train.py
+1
-1
src/transformers/data/processors/squad.py
src/transformers/data/processors/squad.py
+2
-2
src/transformers/data/processors/utils.py
src/transformers/data/processors/utils.py
+2
-2
src/transformers/pipelines.py
src/transformers/pipelines.py
+1
-1
No files found.
src/transformers/commands/serving.py
View file @
c8b0c1e5
...
...
@@ -107,7 +107,7 @@ class ServeCommand(BaseTransformersCLICommand):
self
.
_host
=
host
self
.
_port
=
port
if
not
_serve_dependancies_installed
:
raise
Import
Error
(
raise
Runtime
Error
(
"Using serve command requires FastAPI and unicorn. "
"Please install transformers with [serving]: pip install transformers[serving]."
"Or install FastAPI and unicorn separatly."
...
...
src/transformers/commands/train.py
View file @
c8b0c1e5
...
...
@@ -8,7 +8,7 @@ from transformers.commands import BaseTransformersCLICommand
if
not
is_tf_available
()
and
not
is_torch_available
():
raise
Import
Error
(
"At least one of PyTorch or TensorFlow 2.0+ should be installed to use CLI training"
)
raise
Runtime
Error
(
"At least one of PyTorch or TensorFlow 2.0+ should be installed to use CLI training"
)
# TF training parameters
USE_XLA
=
False
...
...
src/transformers/data/processors/squad.py
View file @
c8b0c1e5
...
...
@@ -324,7 +324,7 @@ def squad_convert_examples_to_features(
del
new_features
if
return_dataset
==
"pt"
:
if
not
is_torch_available
():
raise
Import
Error
(
"Py
t
orch must be installed to return a
pyt
orch dataset."
)
raise
Runtime
Error
(
"Py
T
orch must be installed to return a
PyT
orch 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
Import
Error
(
"TensorFlow must be installed to return a TensorFlow dataset."
)
raise
Runtime
Error
(
"TensorFlow must be installed to return a TensorFlow dataset."
)
def
gen
():
for
ex
in
features
:
...
...
src/transformers/data/processors/utils.py
View file @
c8b0c1e5
...
...
@@ -294,7 +294,7 @@ class SingleSentenceClassificationProcessor(DataProcessor):
return
features
elif
return_tensors
==
"tf"
:
if
not
is_tf_available
():
raise
Import
Error
(
"return_tensors set to 'tf' but TensorFlow 2.0 can't be imported"
)
raise
Runtime
Error
(
"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
Import
Error
(
"return_tensors set to 'pt' but PyTorch can't be imported"
)
raise
Runtime
Error
(
"return_tensors set to 'pt' but PyTorch can't be imported"
)
import
torch
from
torch.utils.data
import
TensorDataset
...
...
src/transformers/pipelines.py
View file @
c8b0c1e5
...
...
@@ -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
Import
Error
(
raise
Runtime
Error
(
"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/."
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment