[BugFix] Probe __dict__ instead of hasattr when patching WanRMS_norm (#3400)
Signed-off-by: gcanlin <canlinguosdu@gmail.com>
This commit is contained in:
1 parent
5d4b16e6e3
commit
4a24a517ab
1 file changed
+8
-7
@@ -9,10 +9,11 @@ from vllm_omni.diffusion.layers.norm import RMSNormVAE
|
||||
def patch_wan_rms_norm():
|
||||
"""Patch diffusers Wan RMSNorm implementation with RMSNormVAE."""
|
||||
|
||||
# NOTE: iterate over a snapshot of sys.modules. `hasattr` can trigger lazy
|
||||
# submodule imports (e.g. transformers' `_LazyModule.__getattr__`), which
|
||||
# mutate sys.modules during iteration and raise
|
||||
# `RuntimeError: dictionary changed size during iteration`.
|
||||
for module_name, module in list(sys.modules.items()):
|
||||
if hasattr(module, "WanRMS_norm"):
|
||||
setattr(module, "WanRMS_norm", RMSNormVAE)
|
||||
# Probe `__dict__` directly instead of `hasattr`: the latter triggers
|
||||
# custom `__getattr__` hooks (e.g. transformers' image_processing alias
|
||||
# modules), which both emit spurious deprecation warnings and can lazily
|
||||
# import submodules, mutating sys.modules mid-iteration.
|
||||
for module in list(sys.modules.values()):
|
||||
module_dict = getattr(module, "__dict__", None)
|
||||
if module_dict is not None and "WanRMS_norm" in module_dict:
|
||||
module_dict["WanRMS_norm"] = RMSNormVAE
|
||||
Reference in new issue
Block a user