Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert #20715 #26734

Merged
merged 4 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/transformers/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@
is_training_run_on_sagemaker,
is_vision_available,
requires_backends,
tf_required,
torch_only_method,
torch_required,
)
from .peft_utils import (
ADAPTER_CONFIG_NAME,
Expand Down
36 changes: 35 additions & 1 deletion src/transformers/utils/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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
Expand Down Expand Up @@ -1222,6 +1222,40 @@ def __getattribute__(cls, key):
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
Expand Down
Loading