Unverified Commit 9b0d2860 authored by Sylvain Gugger's avatar Sylvain Gugger Committed by GitHub
Browse files

Better error in the Auto API when a dep is missing (#17289)

parent 66b3e106
...@@ -84,6 +84,12 @@ def feature_extractor_class_from_name(class_name: str): ...@@ -84,6 +84,12 @@ def feature_extractor_class_from_name(class_name: str):
if getattr(extractor, "__name__", None) == class_name: if getattr(extractor, "__name__", None) == class_name:
return extractor return extractor
# We did not fine the class, but maybe it's because a dep is missing. In that case, the class will be in the main
# init and we return the proper dummy to get an appropriate error message.
main_module = importlib.import_module("transformers")
if hasattr(main_module, class_name):
return getattr(main_module, class_name)
return None return None
......
...@@ -74,6 +74,12 @@ def processor_class_from_name(class_name: str): ...@@ -74,6 +74,12 @@ def processor_class_from_name(class_name: str):
if getattr(processor, "__name__", None) == class_name: if getattr(processor, "__name__", None) == class_name:
return processor return processor
# We did not fine the class, but maybe it's because a dep is missing. In that case, the class will be in the main
# init and we return the proper dummy to get an appropriate error message.
main_module = importlib.import_module("transformers")
if hasattr(main_module, class_name):
return getattr(main_module, class_name)
return None return None
......
...@@ -287,6 +287,12 @@ def tokenizer_class_from_name(class_name: str): ...@@ -287,6 +287,12 @@ def tokenizer_class_from_name(class_name: str):
if getattr(tokenizer, "__name__", None) == class_name: if getattr(tokenizer, "__name__", None) == class_name:
return tokenizer return tokenizer
# We did not fine the class, but maybe it's because a dep is missing. In that case, the class will be in the main
# init and we return the proper dummy to get an appropriate error message.
main_module = importlib.import_module("transformers")
if hasattr(main_module, class_name):
return getattr(main_module, class_name)
return None return None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment