Skip to content

Commit

Permalink
handle dependency errors in check_imports
Browse files Browse the repository at this point in the history
  • Loading branch information
molbap committed Sep 20, 2024
1 parent bdf4649 commit 6f9269b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/transformers/dynamic_module_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.error(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(
Expand Down

0 comments on commit 6f9269b

Please sign in to comment.