-
-
Notifications
You must be signed in to change notification settings - Fork 92
Description
Describe the bug
When using the RMBG node with RMBG-2.0 (BiRefNet), loading fails with:
module 'custom_birefnet_model_...' has no attribute '__file__'- Fallback then fails with:
Tensor.item() cannot be called on meta tensors
Cause
The BiRefNet code is loaded via types.ModuleType() and exec(). That creates a module without __file__, which the Hugging Face BiRefNet code expects.
Fix
In py/AILab_RMBG.py, in the RMBGModel.load_model() block where the birefnet module is created, set __file__ and __path__ before exec():
module_name = f"custom_birefnet_model_{hash(birefnet_path)}"
module = types.ModuleType(module_name)
module.file = birefnet_path
module.path = [os.path.dirname(birefnet_path)]
sys.modules[module_name] = module
exec(birefnet_content, module.dict)
(Add the two lines module.file = birefnet_path and module.path = [os.path.dirname(birefnet_path)] right after module = types.ModuleType(module_name).)
Environment
ComfyUI-RMBG (main), Python 3.x, PyTorch, transformers, RMBG-2.0 model files including model.safetensors.