Skip to content

Commit

Permalink
fixup for imports
Browse files Browse the repository at this point in the history
  • Loading branch information
sambhavnoobcoder committed Jan 23, 2025
1 parent 5f9f222 commit 729939b
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/transformers/utils/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2275,14 +2275,11 @@ def define_import_structure(module_path: str) -> IMPORT_STRUCTURE_T:
def clear_import_cache():
"""
Clear cached Transformers modules to allow reloading modified code.
This is useful when actively developing/modifying Transformers code.
"""
# Get all transformers modules
transformers_modules = [
mod_name for mod_name in sys.modules
if mod_name.startswith('transformers.')
]
transformers_modules = [mod_name for mod_name in sys.modules if mod_name.startswith("transformers.")]

# Remove them from sys.modules
for mod_name in transformers_modules:
Expand All @@ -2293,8 +2290,8 @@ def clear_import_cache():
del sys.modules[mod_name]

# Force reload main transformers module
if 'transformers' in sys.modules:
main_module = sys.modules['transformers']
if "transformers" in sys.modules:
main_module = sys.modules["transformers"]
if isinstance(main_module, _LazyModule):
main_module._objects = {} # Clear cached objects
importlib.reload(main_module)

0 comments on commit 729939b

Please sign in to comment.