Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure script modules get added to sys.modules #1614

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wcole3
Copy link
Contributor

@wcole3 wcole3 commented Aug 30, 2024

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 wcole3 requested a review from lllyasviel as a code owner August 30, 2024 23:10
@lllyasviel lllyasviel marked this pull request as draft August 30, 2024 23:46
@lllyasviel
Copy link
Owner

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

@altoiddealer
Copy link
Contributor

I rolled back my extension to an older commit which was afflicted by #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

@wcole3
Copy link
Contributor Author

wcole3 commented Aug 31, 2024

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.

@altoiddealer
Copy link
Contributor

Just sharing another example for extension affected by the inheritence bug continue-revolution/sd-webui-segment-anything#211 (comment)

@HelloLaohe
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants