Skip to content

Commit

Permalink
Fix lazy init to stop hiding errors in import (#14124)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgugger committed Oct 25, 2021
1 parent c99a283 commit 8560b55
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/transformers/file_utils.py
Expand Up @@ -2146,7 +2146,12 @@ def __getattr__(self, name: str) -> Any:
return value

def _get_module(self, module_name: str):
return importlib.import_module("." + module_name, self.__name__)
try:
return importlib.import_module("." + module_name, self.__name__)
except Exception as e:
raise RuntimeError(
f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its traceback):\n{e}"
) from e

def __reduce__(self):
return (self.__class__, (self._name, self.__file__, self._import_structure))
Expand Down

0 comments on commit 8560b55

Please sign in to comment.