stable-diffusion-webui-forge icon indicating copy to clipboard operation
stable-diffusion-webui-forge copied to clipboard

Make sure script modules get added to sys.modules

Open wcole3 opened this issue 1 year ago • 5 comments

Long existing bug that Gradio 4 uncovered mainly in extensions. The importlib docs (and relevant cpython issue) detail the need to add the module created from spec to the sys.modules list.

More details: new in Gradio 4, the new Component base class ComponentBase explicitly uses the file containing a component for an id value. For certain extensions that subclassed a Gradio Component this could lead to the extension failing to load due to the above Gradio code. See examples here and here.

Should address issues #1605, part of #1599, and #1466

wcole3 avatar Aug 30 '24 23:08 wcole3

unfortunately this is going to break lots of things when they share same module name

lllyasviel avatar Aug 30 '24 23:08 lllyasviel

I rolled back my extension to an older commit which was afflicted by https://github.com/lllyasviel/stable-diffusion-webui-forge/issues/1605

It loads right up without error. Despite the cosmetic issues, the extension works in this state, the buttons all do what they are supposed to, etc.

Screenshot 2024-08-30 194132

altoiddealer avatar Aug 30 '24 23:08 altoiddealer

unfortunately this is going to break lots of things when they share same module name

Probably too optimistic, but are the likely duplicates all preload.py's from other scripts or are you worried about something conflicting elsewhere?

# naive investigation
    if module_spec.name not in sys.modules:
        sys.modules[module_spec.name] = module
    else:
        errors.report(f"Module {module_spec.name} already in sys.modules."
                      f" File {path} will not be loaded in sys modules.")

Resulting console log snippet with load_scripts() call moved to end of initialize_rest() for kicks.

Launching Web UI with arguments: 
Total VRAM 24563 MB, total RAM 130978 MB
pytorch version: 2.3.1+cu121
Set vram state to: NORMAL_VRAM
Device: cuda:0 NVIDIA GeForce RTX 4090 : native
Hint: your device supports --cuda-malloc for potential speed improvements.
VAE dtype preferences: [torch.bfloat16, torch.float32] -> torch.bfloat16
CUDA Using Stream: False
Using pytorch cross attention
Using pytorch attention for VAE
*** Module preload.py already in sys.modules. File I:\StableDiffusion\webui-forge\webui\extensions\stable-diffusion-webui-wildcards\preload.py will not be loaded in sys modules.
*** Module preload.py already in sys.modules. File I:\StableDiffusion\webui-forge\webui\extensions-builtin\ScuNET\preload.py will not be loaded in sys modules.
*** Module preload.py already in sys.modules. File I:\StableDiffusion\webui-forge\webui\extensions-builtin\SwinIR\preload.py will not be loaded in sys modules.
*** Module preload.py already in sys.modules. File I:\StableDiffusion\webui-forge\webui\extensions-builtin\sd_forge_controlnet\preload.py will not be loaded in sys modules.
*** Module preload.py already in sys.modules. File I:\StableDiffusion\webui-forge\webui\extensions-builtin\sd_forge_lora\preload.py will not be loaded in sys modules.
ControlNet preprocessor location: I:\StableDiffusion\webui-forge\webui\models\ControlNetPreprocessor
Tag Autocomplete: Could not locate model-keyword extension, Lora trigger word completion will be limited to those added through the extra networks menu.
[-] ADetailer initialized. version: 24.8.0, num models: 12
21:01:10 - ReActor - STATUS - Running v0.7.1-a2 on Device: CPU
2024-08-30 21:01:12,058 - ControlNet - INFO - ControlNet UI callback registered.
Model selected: {'checkpoint_info': {'filename': 'I:\\StableDiffusion\\webui-forge\\webui\\models\\Stable-diffusion\\ponyRealism_v21MainVAE.safetensors', 'hash': '94d89832'}, 'additional_modules': [], 'unet_storage_dtype': None}
Using online LoRAs in FP16: False

cnet seemed to work, and its preload still fired; but I know that's a flimsy test.

wcole3 avatar Aug 31 '24 01:08 wcole3

Just sharing another example for extension affected by the inheritence bug https://github.com/continue-revolution/sd-webui-segment-anything/issues/211#issuecomment-2254828218

altoiddealer avatar Aug 31 '24 01:08 altoiddealer

QQ20240927-221003 我做了一个类似Fooocus的,但不知道怎么提交。

HelloLaohe avatar Sep 27 '24 14:09 HelloLaohe