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

Remove imports and use forward references in ONNX feature #17926

Merged
merged 1 commit into from
Jun 29, 2022
Merged
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
12 changes: 8 additions & 4 deletions src/transformers/onnx/features.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from functools import partial, reduce
from typing import Callable, Dict, Optional, Tuple, Type, Union
from typing import TYPE_CHECKING, Callable, Dict, Optional, Tuple, Type, Union

import transformers

from .. import PretrainedConfig, PreTrainedModel, TFPreTrainedModel, is_tf_available, is_torch_available
from .. import PretrainedConfig, is_tf_available, is_torch_available
from ..utils import logging
from .config import OnnxConfig


if TYPE_CHECKING:
from transformers import PreTrainedModel, TFPreTrainedModel


logger = logging.get_logger(__name__) # pylint: disable=invalid-name

if is_torch_available():
Expand Down Expand Up @@ -505,7 +509,7 @@ def get_model_class_for_feature(feature: str, framework: str = "pt") -> Type:
@staticmethod
def get_model_from_feature(
feature: str, model: str, framework: str = "pt", cache_dir: str = None
) -> Union[PreTrainedModel, TFPreTrainedModel]:
) -> Union["PreTrainedModel", "TFPreTrainedModel"]:
"""
Attempts to retrieve a model from a model's name and the feature to be enabled.

Expand Down Expand Up @@ -533,7 +537,7 @@ def get_model_from_feature(

@staticmethod
def check_supported_model_or_raise(
model: Union[PreTrainedModel, TFPreTrainedModel], feature: str = "default"
model: Union["PreTrainedModel", "TFPreTrainedModel"], feature: str = "default"
) -> Tuple[str, Callable]:
"""
Check whether or not the model has the requested features.
Expand Down