MackinationsAi / sd-webui-udav2

A1111 Extension integration for Upgraded-Depth-Anything-V2 - UDAV2
https://github.com/MackinationsAi/Upgraded-Depth-Anything-V2
Apache License 2.0
37 stars 1 forks source link

Conflict with extensions in SD Forge #2

Closed altoiddealer closed 2 months ago

altoiddealer commented 2 months ago

Hello, thanks for expanding this to be compatible with A1111.

I've installed this as an extension in both A1111 and Forge.

I'm reporting that it works in both.

However, it seems to cause issues with most of the extensions I have installed when using it with Forge. Forge is also quite popular, so I'm hoping that you may take a look at resolving this for Forge...

With your extension disabled, the following errors do not appear on startup:

*** Error loading script: attention_couple.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-forge-couple\scripts\attention_couple.py", line 8, in <module>
        from scripts.attention_masks import get_mask, lcm_for_list
    ModuleNotFoundError: No module named 'scripts.attention_masks'

---
*** Error loading script: couple_mapping.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-forge-couple\scripts\couple_mapping.py", line 9, in <module>
        from scripts.ui_funcs import parse_mapping
    ModuleNotFoundError: No module named 'scripts.ui_funcs'

---
*** Error loading script: couple_ui.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-forge-couple\scripts\couple_ui.py", line 5, in <module>
        from scripts.ui_funcs import (
    ModuleNotFoundError: No module named 'scripts.ui_funcs'

---
*** Error loading script: forge_couple.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-forge-couple\scripts\forge_couple.py", line 5, in <module>
        from scripts.couple_mapping import (
    ModuleNotFoundError: No module named 'scripts.couple_mapping'

---
*** Error loading script: adv_xyz_components.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-webui-advanced-xyz\scripts\adv_xyz_components.py", line 1, in <module>
        from scripts.xyz_grid import fill_values_symbol
    ModuleNotFoundError: No module named 'scripts.xyz_grid'

---
*** Error loading script: adv_xyz_ui.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-webui-advanced-xyz\scripts\adv_xyz_ui.py", line 1, in <module>
        from scripts.xyz_grid import (
    ModuleNotFoundError: No module named 'scripts.xyz_grid'

---
*** Error loading script: console_log_patch.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-webui-reactor\scripts\console_log_patch.py", line 17, in <module>
        from scripts.reactor_logger import logger
    ModuleNotFoundError: No module named 'scripts.reactor_logger'

---
*** Error loading script: reactor_api.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-webui-reactor\scripts\reactor_api.py", line 28, in <module>
        from scripts.reactor_swapper import EnhancementOptions, swap_face, DetectionOptions
    ModuleNotFoundError: No module named 'scripts.reactor_swapper'

---
*** Error loading script: reactor_faceswap.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-webui-reactor\scripts\reactor_faceswap.py", line 18, in <module>
        from reactor_ui import (
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-webui-reactor\reactor_ui\__init__.py", line 2, in <module>
        import reactor_ui.reactor_tools_ui as ui_tools
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-webui-reactor\reactor_ui\reactor_tools_ui.py", line 2, in <module>
        from scripts.reactor_swapper import build_face_model, blend_faces
    ModuleNotFoundError: No module named 'scripts.reactor_swapper'

---
*** Error loading script: reactor_helpers.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-webui-reactor\scripts\reactor_helpers.py", line 14, in <module>
        from scripts.reactor_globals import DEVICE, BASE_PATH, FACE_MODELS_PATH, IS_SDNEXT
    ModuleNotFoundError: No module named 'scripts.reactor_globals'

---
*** Error loading script: reactor_logger.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-webui-reactor\scripts\reactor_logger.py", line 6, in <module>
        from scripts.reactor_globals import IS_RUN
    ModuleNotFoundError: No module named 'scripts.reactor_globals'

---
*** Error loading script: reactor_swapper.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-webui-reactor\scripts\reactor_swapper.py", line 14, in <module>
        from scripts.reactor_globals import FACE_MODELS_PATH
    ModuleNotFoundError: No module named 'scripts.reactor_globals'

---
*** Error loading script: reactor_version.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-webui-reactor\scripts\reactor_version.py", line 4, in <module>
        from scripts.reactor_logger import logger, get_Run, set_Run
    ModuleNotFoundError: No module named 'scripts.reactor_logger'

---
*** Error loading script: reactor_xyz.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-webui-reactor\scripts\reactor_xyz.py", line 8, in <module>
        from scripts.reactor_helpers import (
    ModuleNotFoundError: No module named 'scripts.reactor_helpers'

---
*** Error loading script: api.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-webui-segment-anything\scripts\api.py", line 10, in <module>
        from scripts.sam import sam_predict, dino_predict, update_mask, cnet_seg, categorical_mask
    ModuleNotFoundError: No module named 'scripts.sam'

---
*** Error loading script: sam.py
    Traceback (most recent call last):
      File "D:\0_AI\stable-diffusion-webui-forge\modules\scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\0_AI\stable-diffusion-webui-forge\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\0_AI\stable-diffusion-webui-forge\extensions\sd-webui-segment-anything\scripts\sam.py", line 20, in <module>
        from scripts.dino import dino_model_list, dino_predict_internal, show_boxes, clear_dino_cache, dino_install_issue_text
    ModuleNotFoundError: No module named 'scripts.dino'
MackinationsAi commented 2 months ago

My primary UI's are Comfy & CLI. However, that being said, I just installed forge & will be looking into the issue you have encountered & see if I can replicate the error. Hopefully I'll be able to isolate the issue & fix it.

MackinationsAi commented 2 months ago

Was able to isolate the issue & correct it (I installed the exact same extensions you had & they now work even with sd-forge-udav2 installed). Here you go - sd-forge-udav2.

altoiddealer commented 2 months ago

Beautiful! Nice jorb :)

altoiddealer commented 2 months ago

Actually... this isn't working for me.

I snagged the .zip file, and unzipped it in my forge extensions folder.

C:\0_SD\stable-diffusion-webui-forge\extensions\sd-forge-udav2\(files)

All the extensions load up without any problems.

However, when I try actually using your extension on an image with all default values, I get this error:

Traceback (most recent call last):
  File "C:\0_SD\stable-diffusion-webui-forge\modules_forge\patch_basic.py", line 17, in loader
    result = original_loader(*args, **kwargs)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\safetensors\torch.py", line 308, in load_file
    with safe_open(filename, framework="pt", device=device) as f:
safetensors_rust.SafetensorError: Error while deserializing header: MetadataIncompleteBuffer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\routes.py", line 488, in run_predict
    output = await app.get_blocks().process_api(
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\blocks.py", line 1431, in process_api
    result = await self.call_function(
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\blocks.py", line 1103, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "C:\0_SD\stable-diffusion-webui-forge\extensions\sd-forge-udav2\scripts\upgraded_depth_anything_v2.py", line 239, in on_submit_single
    colourized_filenames, grey_depth_filename = process_image(image, colour_map_method, encoder, selection)
  File "C:\0_SD\stable-diffusion-webui-forge\extensions\sd-forge-udav2\scripts\upgraded_depth_anything_v2.py", line 82, in process_image
    model = load_model(encoder)
  File "C:\0_SD\stable-diffusion-webui-forge\extensions\sd-forge-udav2\scripts\upgraded_depth_anything_v2.py", line 41, in load_model
    state_dict = load_file(checkpoint_path)
  File "C:\0_SD\stable-diffusion-webui-forge\modules_forge\patch_basic.py", line 33, in loader
    raise ValueError(exp)
ValueError: Error while deserializing header: MetadataIncompleteBuffer
File corrupted: C:\0_SD\stable-diffusion-webui-forge\extensions\sd-forge-udav2\scripts\..\checkpoints\depth_anything_v2_vitl.safetensors
Forge has tried to move the corrupted file to C:\0_SD\stable-diffusion-webui-forge\extensions\sd-forge-udav2\scripts\..\checkpoints\depth_anything_v2_vitl.safetensors.corrupted
You may try again now and Forge will download models again.

If I try again, it yields:

Model loaded in 16.0s (load weights from disk: 0.7s, forge solving config: 0.1s, forge load real models: 14.2s, load textual inversion embeddings: 0.1s, calculate empty prompt: 0.8s).
Traceback (most recent call last):
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\routes.py", line 488, in run_predict
    output = await app.get_blocks().process_api(
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\blocks.py", line 1431, in process_api
    result = await self.call_function(
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\blocks.py", line 1103, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "C:\0_SD\stable-diffusion-webui-forge\extensions\sd-forge-udav2\scripts\upgraded_depth_anything_v2.py", line 239, in on_submit_single
    colourized_filenames, grey_depth_filename = process_image(image, colour_map_method, encoder, selection)
  File "C:\0_SD\stable-diffusion-webui-forge\extensions\sd-forge-udav2\scripts\upgraded_depth_anything_v2.py", line 82, in process_image
    model = load_model(encoder)
  File "C:\0_SD\stable-diffusion-webui-forge\extensions\sd-forge-udav2\scripts\upgraded_depth_anything_v2.py", line 38, in load_model
    raise FileNotFoundError(f"Checkpoint file not found: {checkpoint_path}")
FileNotFoundError: Checkpoint file not found: C:\0_SD\stable-diffusion-webui-forge\extensions\sd-forge-udav2\scripts\..\checkpoints\depth_anything_v2_vitl.safetensors

When I go to the checkpoints directory, here is a list of the files:

depth_anything_v2_vitb.safetensors
depth_anything_v2_vitl.safetensors.corrupted
depth_anything_v2_vits.safetensors
altoiddealer commented 2 months ago

Sorry, but now I see what the problem was.

The first time I launched Forge after adding the package to my extensions directory, it got this far in the CMD window and then froze:

venv "C:\0_SD\stable-diffusion-webui-forge\venv\Scripts\Python.exe"
Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec  6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)]
Version: f0.0.17v1.8.0rc-latest-276-g29be1da7
Commit hash: 29be1da7cf2b5dccfc70fbdd33eb35c56a31ffb7

I waited about 30 seconds, and figured it got stuck or something, so I closed the window.

I tried again, and again it froze except this time I waited patiently to see if it would finally load, and alas it finally did.

Now, this is when I received the errors in my previous comment.

...and now, I just launched Forge again from scratch, and since I had the checkpoints/ directory open, I noticed that it began creating the new checkpoint. So I see that the issue was that it did not finish download the checkpoint the first time (it is working now)

I recommend adding some sort of print statement or something, to advise that the checkpoints are downloading and not to close the window.

MackinationsAi commented 2 months ago

I've tried to add a print function but it didn't work & I didn't have the time to figure out a workaround, now that I'm on vacation I'll try again now that I've got a lot more time! I'll add it into the README.md so people know, so you are not the first to run into this & think something is wrong. (It usually takes between 45-90 secs the first time you launch the webui after installing the extension)

MackinationsAi commented 2 months ago

Just added it to README.md -

altoiddealer commented 2 months ago

I want to make one more comment...

If I visit your repo and go straight to the Releases page, the description makes it sound like your extension is designed exclusively for SD WebUI Forge - it is not worded in a way that says "this is a Forge-specific package which is separate from the "normal" install method described in the main Readme"

altoiddealer commented 2 months ago

LASTLY! (Sorry for all this)

For both A1111 and Forge... I can't remember if I changed this personally, or if it is default...

All my output images save to root folder output (not outputs). So when your extension runs, it creates a new folder called outputs

MackinationsAi commented 2 months ago

I noticed that a1111 & forge main output_dir's were labeled differently (about an hour after I released the package, thought it was irritating, so I went & updated the code for sd-forge-udav2 [then swapped out the .7z & .zip in the release w/ the updated version]).

That being said, sd-webui-udav2 just got accepted into the main index.json today. w-e-w one of the maintainers of the a1111 extension index helped push some commits (that I approved & merged to main) which consolidated & improved the code before it got approved for the masses. The most important improvement being the checkpoints download function has been moved from the install.py to the main script, now the user doesn't experience a prolonged launch!

I will be updating the forge extension to the same specs, but optimized to prevent conflicts w/ other extensions in forge & w/ the output_dir set to output. Once I've made the necessary updates, I'll add it to the release page here, & in addition I'll be creating a new repo called sd-forge-webui which I'll push to be included in the extension index.json as well, so any user can install either extension directly in a1111 or forge depending on which they are using! Appreciate all the feedback & help you've provided for troubleshooting/debugging 👍🏼

MackinationsAi commented 2 months ago

I want to make one more comment...

If I visit your repo and go straight to the Releases page, the description makes it sound like your extension is designed exclusively for SD WebUI Forge - it is not worded in a way that says "this is a Forge-specific package which is separate from the "normal" install method described in the main Readme"

Also it is stated here in the release page "This extension is STRICTLY for stable-diffusion-webui-forge to prevent any conflicts w/ pre-existing extensions you've installed." though not in the main README.md as you said. However, once I make the changes I specified above it won't be an issue.

altoiddealer commented 2 months ago

Sounds good!

However, Forge is basically coasting along... the main dev (lllyasviel) is required to authorize anything and everything, and they are not bothered at all. He popped on a few weeks ago and merged one PR, first one in months. Doubt extensions index will ever be updated.

MackinationsAi commented 2 months ago

Very true, but I'm still going to submit the pull request. Btw I'll send you a message here when I've made the updates so you can install the polished version!