From 0bef4a273825d2cfc52ddfe62ba486ee61cc116f Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 29 May 2024 13:33:26 +0100 Subject: [PATCH] Fix faulty rstrip in module loading (#31108) --- src/transformers/dynamic_module_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/transformers/dynamic_module_utils.py b/src/transformers/dynamic_module_utils.py index 9de22a3592..b23e9f1717 100644 --- a/src/transformers/dynamic_module_utils.py +++ b/src/transformers/dynamic_module_utils.py @@ -198,7 +198,10 @@ def get_class_in_module(class_name: str, module_path: Union[str, os.PathLike]) - Returns: `typing.Type`: The class looked for. """ - name = os.path.normpath(module_path).rstrip(".py").replace(os.path.sep, ".") + name = os.path.normpath(module_path) + if name.endswith(".py"): + name = name[:-3] + name = name.replace(os.path.sep, ".") module_spec = importlib.util.spec_from_file_location(name, location=Path(HF_MODULES_CACHE) / module_path) module = sys.modules.get(name) if module is None: