handle dependency errors in check_imports (#33622)

* handle dependency errors in check_imports

* change log level to warning
This commit is contained in:
Pablo Montalvo 2024-09-23 12:38:52 +02:00 committed by GitHub
parent b7c381f011
commit 6d02968d51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -183,8 +183,15 @@ def check_imports(filename: Union[str, os.PathLike]) -> List[str]:
for imp in imports:
try:
importlib.import_module(imp)
except ImportError:
missing_packages.append(imp)
except ImportError as exception:
logger.warning(f"Encountered exception while importing {imp}: {exception}")
# Some packages can fail with an ImportError because of a dependency issue.
# This check avoids hiding such errors.
# See https://github.com/huggingface/transformers/issues/33604
if "No module named" in str(exception):
missing_packages.append(imp)
else:
raise
if len(missing_packages) > 0:
raise ImportError(