Skip to content

Commit

Permalink
Set sys.modules
Browse files Browse the repository at this point in the history
  • Loading branch information
XuehaiPan committed Apr 24, 2024
1 parent 14c3e5d commit 1fccb99
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/transformers/dynamic_module_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,11 @@ def get_class_in_module(class_name: str, module_path: Union[str, os.PathLike]) -
name = os.path.normpath(module_path).rstrip(".py").replace(os.path.sep, ".")
module_path = str(Path(HF_MODULES_CACHE) / module_path)
module_spec = importlib.util.spec_from_file_location(name, location=module_path)
module = importlib.util.module_from_spec(module_spec)
module = sys.modules.pop(name, None)
if module is None:
module = importlib.util.module_from_spec(module_spec)
module_spec.loader.exec_module(module)
sys.modules[name] = module
return getattr(module, class_name)


Expand Down

0 comments on commit 1fccb99

Please sign in to comment.