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
e58cbed5
Unverified
Commit
e58cbed5
authored
Oct 11, 2023
by
Yih-Dar
Committed by
GitHub
Oct 11, 2023
Browse files
Revert #20715 (#26734)
* fix --------- Co-authored-by:
ydshieh
<
ydshieh@users.noreply.github.com
>
parent
b219ae6b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletion
+37
-1
src/transformers/utils/__init__.py
src/transformers/utils/__init__.py
+2
-0
src/transformers/utils/import_utils.py
src/transformers/utils/import_utils.py
+35
-1
No files found.
src/transformers/utils/__init__.py
View file @
e58cbed5
...
...
@@ -186,7 +186,9 @@ from .import_utils import (
is_training_run_on_sagemaker
,
is_vision_available
,
requires_backends
,
tf_required
,
torch_only_method
,
torch_required
,
)
from
.peft_utils
import
(
ADAPTER_CONFIG_NAME
,
...
...
src/transformers/utils/import_utils.py
View file @
e58cbed5
...
...
@@ -24,7 +24,7 @@ import subprocess
import
sys
import
warnings
from
collections
import
OrderedDict
from
functools
import
lru_cache
from
functools
import
lru_cache
,
wraps
from
itertools
import
chain
from
types
import
ModuleType
from
typing
import
Any
,
Tuple
,
Union
...
...
@@ -1222,6 +1222,40 @@ class DummyObject(type):
requires_backends
(
cls
,
cls
.
_backends
)
def
torch_required
(
func
):
warnings
.
warn
(
"The method `torch_required` is deprecated and will be removed in v4.36. Use `requires_backends` instead."
,
FutureWarning
,
)
# Chose a different decorator name than in tests so it's clear they are not the same.
@
wraps
(
func
)
def
wrapper
(
*
args
,
**
kwargs
):
if
is_torch_available
():
return
func
(
*
args
,
**
kwargs
)
else
:
raise
ImportError
(
f
"Method `
{
func
.
__name__
}
` requires PyTorch."
)
return
wrapper
def
tf_required
(
func
):
warnings
.
warn
(
"The method `tf_required` is deprecated and will be removed in v4.36. Use `requires_backends` instead."
,
FutureWarning
,
)
# Chose a different decorator name than in tests so it's clear they are not the same.
@
wraps
(
func
)
def
wrapper
(
*
args
,
**
kwargs
):
if
is_tf_available
():
return
func
(
*
args
,
**
kwargs
)
else
:
raise
ImportError
(
f
"Method `
{
func
.
__name__
}
` requires TF."
)
return
wrapper
def
is_torch_fx_proxy
(
x
):
if
is_torch_fx_available
():
import
torch.fx
...
...
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