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

[Bug]: Error when using symlinks instead of model files

Open blobbfobb opened this issue 2 years ago • 9 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits

What happened?

I have created symlinks to the model files in the models directory, instead of copying the model files there. When I load such a model, there is an error, although image creation seems to work fine.

Steps to reproduce the problem

  1. On MacOS, go to Terminal and create a symlink to the model file by using this command (adapt paths): ln -s /Users/myusername/Desktop/artErosAerosATribute_aerosNovae.safetensors /Users/myusername/stable-diffusion-webui/models/Stable-diffusion/artErosAerosATribute_aerosNovae.safetensors
  2. (Re)Start the WebUI.
  3. Load the model.
  4. Look at the Terminal.

What should have happened?

There should not have been an error message in the Terminal.

Commit where the problem happens

https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/3715ece0adce7bf7c5e9c5ab3710b2fdc3848f39

What platforms do you use to access the UI ?

MacOS

What browsers do you use to access the UI ?

Mozilla Firefox

Command Line Arguments

Launching Web UI with arguments: --upcast-sampling --no-half-vae --use-cpu interrogate

List of extensions

stable-diffusion-webui-images-browser

Console logs

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 407, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/applications.py", line 271, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/applications.py", line 124, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 24, in __call__
    await responder(scope, receive, send)
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 44, in __call__
    await self.app(scope, receive, self.send_with_gzip)
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/routing.py", line 706, in __call__
    await route.handle(scope, receive, send)
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/routing.py", line 237, in app
    raw_response = await run_endpoint_function(
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/routing.py", line 163, in run_endpoint_function
    return await dependant.call(**values)
  File "/Users/myusername/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/routes.py", line 402, in predict
    if app.get_blocks().dependencies[fn_index_inferred]["cancels"]:
IndexError: list index out of range
Loading weights [8e44077b7b] from /Users/myusername/stable-diffusion-webui/models/Stable-diffusion/artErosAerosATribute_aerosNovae.safetensors
Loading VAE weights found near the checkpoint: /Users/myusername/stable-diffusion-webui/models/Stable-diffusion/artErosAerosATribute_aerosNovae.vae.pt
Applying cross attention optimization (InvokeAI).
Weights loaded in 6.2s (apply weights to model: 4.6s, load VAE: 0.3s, move model to device: 1.2s).

Additional information

No response

blobbfobb avatar Feb 17 '23 10:02 blobbfobb

this is feature request at best, not a bug as it was never advertised that symlinking individual models is supported.

you can symlink actual models folder and that works.

vladmandic avatar Feb 17 '23 12:02 vladmandic

I've actually got a few models symlinked under Linux, but it looks like I put my entire AI ecosystem on an NTFS drive. In a situation like this, specifically, a hardlink would also work.

That said, the terminal output is also indicating that it was able to locate and load the model successfully. It's not clear to me exactly what it's doing with the stack where it broke.

DejitaruJin avatar Feb 17 '23 23:02 DejitaruJin

you can symlink actual models folder and that works.

Do I need to replace the models folder with a symlink, or do I need to put a symlink inside the models folder?

blobbfobb avatar Feb 18 '23 09:02 blobbfobb

Do I need to replace the models folder with a symlink, or do I need to put a symlink inside the models folder?

I can confirm for a fact that replacing the model folder with a symlink works for me.

Alyndiar avatar Feb 18 '23 13:02 Alyndiar

@Alyndiar Thank you, that's good to know. Maybe I can make use of that somehow. Unfortunately my models each reside in their own folder, with other files relevant to the respective model (different versions of the model, sample images, sample prompts, links to websites, etc.), so I would prefer if I didn't have to put all models in the same folder, as that would destroy the order I'm trying to keep.

blobbfobb avatar Feb 19 '23 21:02 blobbfobb

I see your problem. The only thing I could possibly propose, unless they solve the problem, is to put all the models you are using in the models folder and put symlink to those into your sorted tree structure. Not the best, but you get about the same result (ordered models in folders and all models accessible for webui), you just have to take the problem in reverse.

Le dim. 19 févr. 2023, à 16 h 09, blobbfobb @.***> a écrit :

@Alyndiar https://github.com/Alyndiar Thank you, that's good to know. Maybe I can make use of that somehow. Unfortunately my models each reside in their own folder, with other files relevant to the respective model (different versions of the model, sample images, sample prompts, links to websites, etc.), so I would prefer if I didn't have to put all models in the same folder, as that would destroy the order I'm trying to keep.

— Reply to this email directly, view it on GitHub https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/7873#issuecomment-1436094561, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKKZH7UBE3HEDJRFSH3JC3DWYKDY5ANCNFSM6AAAAAAU7ILYAQ . You are receiving this because you were mentioned.Message ID: @.***>

Alyndiar avatar Feb 22 '23 14:02 Alyndiar

I have found that Junctions on windows works for junction folders inside the model folder. Regular symlinks do not.

I found this useful to include less frequently used models from a slower drive without the hassle of moving/copying them to my main folder (SD on nvme). (Watch out for spaces in the SD directories though, I believe those will mess things up. Also, network locations do not work this way, but, might with a fuse drive. 10gig enet highly recommended for that silliness.)

Example from commandline:

C:\AI\SD\stable-diffusion-webui\models\Stable-diffusion>mklink /J models2 "E:\AI\SD Models" Junction created for models2 <<===>> E:\AI\SD Models

https://interworks.com/blog/jpoehls/2012/06/07/soft-links-hard-links-junctions-oh-my-symlinks-windows-how/

whitewlf avatar Jul 30 '23 03:07 whitewlf

I also tried SymLinks, and they worked only with stable-diffusion models, not for LoRa or ControlNet (extension). After I had changed it to Junctions as @whitewlf told above, it began to work. So my advice is to use Junctions.

VerdonTrigance avatar Dec 13 '23 19:12 VerdonTrigance

doesn't work