From 6f9269bee22f801dc71b1c0a0ba016b7627e0dfa Mon Sep 17 00:00:00 2001 From: Pablo Montalvo Date: Fri, 20 Sep 2024 15:07:52 +0200 Subject: [PATCH] handle dependency errors in check_imports --- src/transformers/dynamic_module_utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/transformers/dynamic_module_utils.py b/src/transformers/dynamic_module_utils.py index 07cb5940dc4b61..0ecb24772f2e5e 100644 --- a/src/transformers/dynamic_module_utils.py +++ b/src/transformers/dynamic_module_utils.py @@ -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(