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

Enable ONNX export when PyTorch and TensorFlow installed in the same env #15625

Merged
merged 1 commit into from Feb 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/transformers/onnx/features.py
Expand Up @@ -303,8 +303,16 @@ def get_model_from_feature(feature: str, model: str) -> Union[PreTrainedModel, T
The instance of the model.

"""
# If PyTorch and TensorFlow are installed in the same environment, we
# load an AutoModel class by default
model_class = FeaturesManager.get_model_class_for_feature(feature)
return model_class.from_pretrained(model)
try:
model = model_class.from_pretrained(model)
# Load TensorFlow weights in an AutoModel instance if PyTorch and
# TensorFlow are installed in the same environment
except OSError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure it's the only possible exception that can be raised?
It seems like EnvironmentError and ValueError can be raised too according to here and here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second Value error is complete legacy code for when people pass the name of filename, you won't reach it with an auto model call :-)

model = model_class.from_pretrained(model, from_tf=True)
return model

@staticmethod
def check_supported_model_or_raise(
Expand Down