From 7e008497ecaa9d42ebdd97a4ba59959d84af827d Mon Sep 17 00:00:00 2001 From: LostSunset Date: Mon, 16 Mar 2026 17:56:24 +0800 Subject: [PATCH] Fix model loading crash with transformers 5.0.0 Set __file__ attribute on dynamically created module to prevent AttributeError in transformers' _can_set_experts_implementation(). Without this, transformers 5.0.0 fails at sys.modules[cls.__module__].__file__ because the module created via types.ModuleType() lacks __file__. The fallback path also fails due to meta tensor .item() calls during from_pretrained() initialization. Co-Authored-By: Claude Opus 4.6 (1M context) --- py/AILab_RMBG.py | 1 + 1 file changed, 1 insertion(+) diff --git a/py/AILab_RMBG.py b/py/AILab_RMBG.py index 06c5a63..3db7f26 100644 --- a/py/AILab_RMBG.py +++ b/py/AILab_RMBG.py @@ -187,6 +187,7 @@ def load_model(self, model_name): module_name = f"custom_birefnet_model_{hash(birefnet_path)}" module = types.ModuleType(module_name) + module.__file__ = birefnet_path sys.modules[module_name] = module exec(birefnet_content, module.__dict__)