Skip to content

Commit 4fb0982

Browse files
fxmartyyoung-developer
authored andcommitted
CI: Avoid iterating over a mutated iterable (huggingface#1683)
fix
1 parent 4b5312d commit 4fb0982

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

optimum/exporters/onnx/model_patcher.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ def patch_everywhere(attribute_name: str, patch: Any, module_name_prefix: Option
6262
module_name_prefix (`Optional[str]`, defaults to `None`):
6363
If set, only module names starting with this prefix will be considered for patching.
6464
"""
65-
for name, module in sys.modules.items():
65+
# sys.modules may be updated while being iterated over, hence the list copy.
66+
for name in list(sys.modules):
67+
module = sys.modules[name]
6668
if module_name_prefix is not None and not name.startswith(module_name_prefix):
6769
continue
6870
if hasattr(module, attribute_name):

0 commit comments

Comments
 (0)