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
582c5371
Unverified
Commit
582c5371
authored
Aug 18, 2022
by
Matt
Committed by
GitHub
Aug 18, 2022
Browse files
Allow users to force TF availability (#18650)
* Allow users to force TF availability * Correctly name the envvar!
parent
49e44b21
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
33 deletions
+40
-33
src/transformers/utils/import_utils.py
src/transformers/utils/import_utils.py
+40
-33
No files found.
src/transformers/utils/import_utils.py
View file @
582c5371
...
@@ -42,6 +42,8 @@ USE_TF = os.environ.get("USE_TF", "AUTO").upper()
...
@@ -42,6 +42,8 @@ USE_TF = os.environ.get("USE_TF", "AUTO").upper()
USE_TORCH
=
os
.
environ
.
get
(
"USE_TORCH"
,
"AUTO"
).
upper
()
USE_TORCH
=
os
.
environ
.
get
(
"USE_TORCH"
,
"AUTO"
).
upper
()
USE_JAX
=
os
.
environ
.
get
(
"USE_FLAX"
,
"AUTO"
).
upper
()
USE_JAX
=
os
.
environ
.
get
(
"USE_FLAX"
,
"AUTO"
).
upper
()
FORCE_TF_AVAILABLE
=
os
.
environ
.
get
(
"FORCE_TF_AVAILABLE"
,
"AUTO"
).
upper
()
_torch_version
=
"N/A"
_torch_version
=
"N/A"
if
USE_TORCH
in
ENV_VARS_TRUE_AND_AUTO_VALUES
and
USE_TF
not
in
ENV_VARS_TRUE_VALUES
:
if
USE_TORCH
in
ENV_VARS_TRUE_AND_AUTO_VALUES
and
USE_TF
not
in
ENV_VARS_TRUE_VALUES
:
_torch_available
=
importlib
.
util
.
find_spec
(
"torch"
)
is
not
None
_torch_available
=
importlib
.
util
.
find_spec
(
"torch"
)
is
not
None
...
@@ -57,40 +59,45 @@ else:
...
@@ -57,40 +59,45 @@ else:
_tf_version
=
"N/A"
_tf_version
=
"N/A"
if
USE_TF
in
ENV_VARS_TRUE_AND_AUTO_VALUES
and
USE_TORCH
not
in
ENV_VARS_TRUE_VALUES
:
if
FORCE_TF_AVAILABLE
in
ENV_VARS_TRUE_VALUES
:
_tf_available
=
importlib
.
util
.
find_spec
(
"tensorflow"
)
is
not
None
_tf_available
=
True
if
_tf_available
:
candidates
=
(
"tensorflow"
,
"tensorflow-cpu"
,
"tensorflow-gpu"
,
"tf-nightly"
,
"tf-nightly-cpu"
,
"tf-nightly-gpu"
,
"intel-tensorflow"
,
"intel-tensorflow-avx512"
,
"tensorflow-rocm"
,
"tensorflow-macos"
,
"tensorflow-aarch64"
,
)
_tf_version
=
None
# For the metadata, we have to look for both tensorflow and tensorflow-cpu
for
pkg
in
candidates
:
try
:
_tf_version
=
importlib_metadata
.
version
(
pkg
)
break
except
importlib_metadata
.
PackageNotFoundError
:
pass
_tf_available
=
_tf_version
is
not
None
if
_tf_available
:
if
version
.
parse
(
_tf_version
)
<
version
.
parse
(
"2"
):
logger
.
info
(
f
"TensorFlow found but with version
{
_tf_version
}
. Transformers requires version 2 minimum."
)
_tf_available
=
False
else
:
logger
.
info
(
f
"TensorFlow version
{
_tf_version
}
available."
)
else
:
else
:
logger
.
info
(
"Disabling Tensorflow because USE_TORCH is set"
)
if
USE_TF
in
ENV_VARS_TRUE_AND_AUTO_VALUES
and
USE_TORCH
not
in
ENV_VARS_TRUE_VALUES
:
_tf_available
=
False
_tf_available
=
importlib
.
util
.
find_spec
(
"tensorflow"
)
is
not
None
if
_tf_available
:
candidates
=
(
"tensorflow"
,
"tensorflow-cpu"
,
"tensorflow-gpu"
,
"tf-nightly"
,
"tf-nightly-cpu"
,
"tf-nightly-gpu"
,
"intel-tensorflow"
,
"intel-tensorflow-avx512"
,
"tensorflow-rocm"
,
"tensorflow-macos"
,
"tensorflow-aarch64"
,
)
_tf_version
=
None
# For the metadata, we have to look for both tensorflow and tensorflow-cpu
for
pkg
in
candidates
:
try
:
_tf_version
=
importlib_metadata
.
version
(
pkg
)
break
except
importlib_metadata
.
PackageNotFoundError
:
pass
_tf_available
=
_tf_version
is
not
None
if
_tf_available
:
if
version
.
parse
(
_tf_version
)
<
version
.
parse
(
"2"
):
logger
.
info
(
f
"TensorFlow found but with version
{
_tf_version
}
. Transformers requires version 2 minimum."
)
_tf_available
=
False
else
:
logger
.
info
(
f
"TensorFlow version
{
_tf_version
}
available."
)
else
:
logger
.
info
(
"Disabling Tensorflow because USE_TORCH is set"
)
_tf_available
=
False
if
USE_JAX
in
ENV_VARS_TRUE_AND_AUTO_VALUES
:
if
USE_JAX
in
ENV_VARS_TRUE_AND_AUTO_VALUES
:
...
...
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