Trying to get Stable Diffusion / Automatic1111 to work

Hey there! I am struggling to get Stable Diffusion to work here on NixOS. It is no problem on Garuda Linux on the same PC, so it should work in theory (at least i think so). I have this issue for month now and I can not find an answer for it. So I am just stuck at this point. The project i want to use is Stable Diffusion Webui by Automatic1111: GitHub - AUTOMATIC1111/stable-diffusion-webui: Stable Diffusion web UI

Also i use this flake: GitHub - virchau13/automatic1111-webui-nix: AUTOMATIC1111/stable-diffusion-webui for CUDA and ROCm on NixOS

My GPU is an AMD ATI Radeon RX 6700 XT.

I can run the UI with the help of that flake and generate smaller images. But generating bigger images does not work. Here is my output:

################################################################  
Install script for stable-diffusion + Web UI  
Tested on Debian 11 (Bullseye)  
################################################################  
  
################################################################  
Running on simon user  
################################################################  
  
################################################################  
Repo already cloned, using it as install directory  
################################################################  
  
################################################################  
Create and activate python venv  
################################################################  
  
################################################################  
Launching launch.py...  
################################################################  
ldconfig: Can't open cache file /nix/store/aw2fw9ag10wr9pf0qk4nk5sxi0q0bn56-glibc-2.37-8/etc/ld.so.cache  
: No such file or directory  
Cannot locate TCMalloc (improves CPU memory usage)  
Python 3.10.12 (main, Jun  6 2023, 22:43:10) [GCC 12.3.0]  
Version: v1.6.0  
Commit hash: 5ef669de080814067961f28357256e8fe27544f4  
Launching Web UI with arguments: --no-download-sd-model --api --no-half-vae --opt-split-attention  
/home/simon/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/cuda/__init__.py:546: UserWarning: Can't initialize NVML  
 warnings.warn("Can't initialize NVML")  
/opt/amdgpu/share/libdrm/amdgpu.ids: No such file or directory  
/opt/amdgpu/share/libdrm/amdgpu.ids: No such file or directory  
no module 'xformers'. Processing without...  
no module 'xformers'. Processing without...  
No module 'xformers'. Proceeding without it.  
Loading weights [ef76aa2332] from /home/simon/stable-diffusion-webui/models/Stable-diffusion/realisticVisionV51_v51VAE.safetensors  
Running on local URL:  http://127.0.0.1:7860  
  
To create a public link, set `share=True` in `launch()`.  
Creating model from config: /home/simon/stable-diffusion-webui/configs/v1-inference.yaml  
Startup time: 12.4s (prepare environment: 3.8s, import torch: 3.0s, import gradio: 0.8s, setup paths: 0.8s, other imports: 0.6s, setu  
p codeformer: 0.1s, load scripts: 0.4s, create ui: 0.8s, gradio launch: 2.1s).  
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/simon/stable-diffusion-webui/venv/lib/python3.10/site-packages/c  
v2/qt/plugins" even though it was found.  
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this proble  
m.  
  
Available platform plugins are: xcb, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, eglfs, linuxfb, minimal, m  
inimalegl, offscreen, vnc.  
  
/run/current-system/sw/bin/xdg-open: line 613: 166130 Aborted                 (core dumped) kde-open${KDE_SESSION_VERSION} "$1"  
Applying attention optimization: Doggettx... done.  
Model loaded in 10.0s (load weights from disk: 2.9s, create model: 0.4s, apply weights to model: 6.0s, calculate empty prompt: 0.5s).  
MIOpen(HIP): Error [Compile] 'hiprtcCompileProgram(prog.get(), c_options.size(), c_options.data())' naive_conv.cpp: HIPRTC_ERROR_COMP  
ILATION (6)  
MIOpen(HIP): Error [BuildHip] HIPRTC status = HIPRTC_ERROR_COMPILATION (6), source file: naive_conv.cpp  
MIOpen(HIP): Warning [BuildHip] /tmp/nix-shell.InWroS/comgr-0cd5eb/input/naive_conv.cpp:39:10: fatal error: 'limits' file not found  
#include <limits> // std::numeric_limits  
        ^~~~~~~~  
1 error generated when compiling for gfx1030.  
MIOpen Error: /long_pathname_so_that_rpms_can_package_the_debug_info/data/driver/MLOpen/src/hipoc/hipoc_program.cpp:304: Code object  
build failed. Source: naive_conv.cpp  
Exception in thread Thread-2 (load_model):  
Traceback (most recent call last):  
 File "/nix/store/lx8vhp4fxclp494svlfis3sb2g8z4l9h-python3-3.10.12/lib/python3.10/threading.py", line 1016, in _bootstrap_inner  
   self.run()  
 File "/nix/store/lx8vhp4fxclp494svlfis3sb2g8z4l9h-python3-3.10.12/lib/python3.10/threading.py", line 953, in run  
   self._target(*self._args, **self._kwargs)  
 File "/home/simon/stable-diffusion-webui/modules/initialize.py", line 153, in load_model  
   devices.first_time_calculation()  
 File "/home/simon/stable-diffusion-webui/modules/devices.py", line 152, in first_time_calculation  
   conv2d(x)  
 File "/home/simon/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl  
   return forward_call(*args, **kwargs)  
 File "/home/simon/stable-diffusion-webui/extensions-builtin/Lora/networks.py", line 444, in network_Conv2d_forward  
   return originals.Conv2d_forward(self, input)  
 File "/home/simon/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/conv.py", line 463, in forward  
   return self._conv_forward(input, self.weight, self.bias)  
 File "/home/simon/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/conv.py", line 459, in _conv_forward  
   return F.conv2d(input, weight, bias, self.stride,  
RuntimeError: miopenStatusUnknownError  
 0%|                                                                                                         | 0/20 [00:00<?, ?it/s]  
MIOpen(HIP): Error [Compile] 'hiprtcCompileProgram(prog.get(), c_options.size(), c_options.data())' naive_conv.cpp: HIPRTC_ERROR_COMP  
ILATION (6)  
MIOpen(HIP): Error [BuildHip] HIPRTC status = HIPRTC_ERROR_COMPILATION (6), source file: naive_conv.cpp  
MIOpen(HIP): Warning [BuildHip] /tmp/nix-shell.InWroS/comgr-ebbdc4/input/naive_conv.cpp:39:10: fatal error: 'limits' file not found  
#include <limits> // std::numeric_limits  
        ^~~~~~~~  
1 error generated when compiling for gfx1030.  
terminate called after throwing an instance of 'miopen::Exception'  
 what():  /long_pathname_so_that_rpms_can_package_the_debug_info/data/driver/MLOpen/src/hipoc/hipoc_program.cpp:304: Code object bui  
ld failed. Source: naive_conv.cpp

I can not run the UI without the flake:

################################################################  
Install script for stable-diffusion + Web UI  
Tested on Debian 11 (Bullseye)  
################################################################  
  
################################################################  
Running on simon user  
################################################################  
  
################################################################  
Repo already cloned, using it as install directory  
################################################################  
  
################################################################  
Create and activate python venv  
################################################################  
  
################################################################  
Launching launch.py...  
################################################################  
ldconfig: Can't open cache file /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/etc/ld.so.cache  
: No such file or directory  
Cannot locate TCMalloc (improves CPU memory usage)  
Python 3.10.12 (main, Jun  6 2023, 22:43:10) [GCC 12.3.0]  
Version: v1.6.0  
Commit hash: 5ef669de080814067961f28357256e8fe27544f4  
Traceback (most recent call last):  
 File "/home/simon/stable-diffusion-webui/launch.py", line 48, in <module>  
   main()  
 File "/home/simon/stable-diffusion-webui/launch.py", line 39, in main  
   prepare_environment()  
 File "/home/simon/stable-diffusion-webui/modules/launch_utils.py", line 356, in prepare_environment  
   raise RuntimeError(  
RuntimeError: Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check?

with --skip-torch-cuda-test:

./webui.sh --skip-torch-cuda-test                                                                                     
Bereits aktuell.  
  
################################################################  
Install script for stable-diffusion + Web UI  
Tested on Debian 11 (Bullseye)  
################################################################  
  
################################################################  
Running on simon user  
################################################################  
  
################################################################  
Repo already cloned, using it as install directory  
################################################################  
  
################################################################  
Create and activate python venv  
################################################################  
  
################################################################  
Launching launch.py...  
################################################################  
ldconfig: Can't open cache file /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/etc/ld.so.cache  
: No such file or directory  
Cannot locate TCMalloc (improves CPU memory usage)  
Python 3.10.12 (main, Jun  6 2023, 22:43:10) [GCC 12.3.0]  
Version: v1.6.0  
Commit hash: 5ef669de080814067961f28357256e8fe27544f4  
Launching Web UI with arguments: --skip-torch-cuda-test --no-download-sd-model --api --no-half-vae --opt-split-attention  
Traceback (most recent call last):  
 File "/home/simon/stable-diffusion-webui/launch.py", line 48, in <module>  
   main()  
 File "/home/simon/stable-diffusion-webui/launch.py", line 44, in main  
   start()  
 File "/home/simon/stable-diffusion-webui/modules/launch_utils.py", line 432, in start  
   import webui  
 File "/home/simon/stable-diffusion-webui/webui.py", line 13, in <module>  
   initialize.imports()  
 File "/home/simon/stable-diffusion-webui/modules/initialize.py", line 14, in imports  
   import torch  # noqa: F401  
 File "/home/simon/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/__init__.py", line 229, in <module>  
   from torch._C import *  # noqa: F403  
ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory  

but libstdc++.so.6 should be on my system (right?):

nix-locate --top-level libstdc++.so.6                                             
wasabibackend.out                             2,206,888 r /nix/store/4cmwvpga2y2j94njlycld78j0fcy77f3-wasabibackend-2.0.2.1/lib/wasab  
ibackend/Microservices/Binaries/lin64/Tor/libstdc++/libstdc++.so.6  
wasabiwallet.out                              2,206,888 r /nix/store/nh551a8kqfnhgjpl9qq07f0lbsrr9wvs-wasabiwallet-2.0.3/opt/wasabiwa  
llet/Microservices/Binaries/lin64/Tor/libstdc++/libstdc++.so.6  
tor-browser-bundle-bin.out                    1,878,384 x /nix/store/4ckng76gnii7glc7nb3g405w2795xfd4-tor-browser-bundle-bin-12.5.4/s  
hare/tor-browser/TorBrowser/Tor/libstdc++/libstdc++.so.6  
tor-browser-bundle-bin.out                   16,758,432 x /nix/store/4ckng76gnii7glc7nb3g405w2795xfd4-tor-browser-bundle-bin-12.5.4/s  
hare/tor-browser/libstdc++/libstdc++.so.6  
tor-browser-bundle-bin.out                   16,758,432 x /nix/store/4ckng76gnii7glc7nb3g405w2795xfd4-tor-browser-bundle-bin-12.5.4/s  
hare/tor-browser/libstdc++/libstdc++.so.6.0.28  
tor-browser-bundle-bin.out                        2,412 r /nix/store/4ckng76gnii7glc7nb3g405w2795xfd4-tor-browser-bundle-bin-12.5.4/s  
hare/tor-browser/libstdc++/libstdc++.so.6.0.28-gdb.py  
robo3t.out                                            0 s /nix/store/85m9g67x9fc7wwcqwj3639swx72s7hmy-robo3t-1.4.3/lib/robo3t/lib/lib  
stdc++.so.6  
robo3t.out                                    1,964,904 r /nix/store/85m9g67x9fc7wwcqwj3639swx72s7hmy-robo3t-1.4.3/lib/robo3t/lib/lib  
stdc++.so.6.0.28  
remarkable-toolchain.out                              0 s /nix/store/cw01xn9j03vsflsvkr5a87hiwk84r2mz-remarkable-toolchain-3.1.2/sysr  
oots/cortexa9hf-neon-remarkable-linux-gnueabi/usr/lib/libstdc++.so.6  
remarkable-toolchain.out                      1,561,028 x /nix/store/cw01xn9j03vsflsvkr5a87hiwk84r2mz-remarkable-toolchain-3.1.2/sysr  
oots/cortexa9hf-neon-remarkable-linux-gnueabi/usr/lib/libstdc++.so.6.0.28  
remarkable-toolchain.out                              0 s /nix/store/cw01xn9j03vsflsvkr5a87hiwk84r2mz-remarkable-toolchain-3.1.2/sysr  
oots/x86_64-codexsdk-linux/usr/lib/libstdc++.so.6  
remarkable-toolchain.out                      1,915,296 x /nix/store/cw01xn9j03vsflsvkr5a87hiwk84r2mz-remarkable-toolchain-3.1.2/sysr  
oots/x86_64-codexsdk-linux/usr/lib/libstdc++.so.6.0.28  
remarkable2-toolchain.out                             0 s /nix/store/85bfb9p05mcyanvjpj1ry3zmn6pvjwr7-remarkable2-toolchain-3.1.2/sys  
roots/cortexa7hf-neon-remarkable-linux-gnueabi/usr/lib/libstdc++.so.6  
remarkable2-toolchain.out                     1,556,920 x /nix/store/85bfb9p05mcyanvjpj1ry3zmn6pvjwr7-remarkable2-toolchain-3.1.2/sys  
roots/cortexa7hf-neon-remarkable-linux-gnueabi/usr/lib/libstdc++.so.6.0.28  
remarkable2-toolchain.out                             0 s /nix/store/85bfb9p05mcyanvjpj1ry3zmn6pvjwr7-remarkable2-toolchain-3.1.2/sys  
roots/x86_64-codexsdk-linux/usr/lib/libstdc++.so.6  
remarkable2-toolchain.out                     1,915,296 x /nix/store/85bfb9p05mcyanvjpj1ry3zmn6pvjwr7-remarkable2-toolchain-3.1.2/sys  
roots/x86_64-codexsdk-linux/usr/lib/libstdc++.so.6.0.28  
onlyoffice-bin.out                            1,865,752 r /nix/store/a4zxmyrlh8xxp7mk79v546mc3kr5x6hs-onlyoffice-desktopeditors-7.2.0  
/share/desktopeditors/converter/.system/libstdc++.so.6  
onlyoffice-documentserver.out                 1,566,440 r /nix/store/9as61l6jafqdg0bcdwcf5rnm971q7l9f-onlyoffice-documentserver-7.3.3  
/var/www/onlyoffice/documentserver/server/FileConverter/bin/.system/libstdc++.so.6  
mullvad-browser.out                          16,758,432 x /nix/store/30rynvp242s4r2jhzxg17rd7n76brgq1-mullvad-browser-12.5.4/share/mu  
llvad-browser/libstdc++/libstdc++.so.6  
mullvad-browser.out                          16,758,432 x /nix/store/30rynvp242s4r2jhzxg17rd7n76brgq1-mullvad-browser-12.5.4/share/mu  
llvad-browser/libstdc++/libstdc++.so.6.0.28  
mullvad-browser.out                               2,412 r /nix/store/30rynvp242s4r2jhzxg17rd7n76brgq1-mullvad-browser-12.5.4/share/mu  
llvad-browser/libstdc++/libstdc++.so.6.0.28-gdb.py  
julia-bin.out                                         0 s /nix/store/jgxargzw8s24azfrg8af289l0rrznmsb-julia-bin-1.9.3/lib/julia/libst  
dc++.so.6  
julia-bin.out                                19,066,032 x /nix/store/jgxargzw8s24azfrg8af289l0rrznmsb-julia-bin-1.9.3/lib/julia/libst  
dc++.so.6.0.30  
julia-lts.out                                         0 s /nix/store/2b3fyawvxjpik4bah1n14ri2qplsgccz-julia-bin-1.6.6/lib/julia/libst  
dc++.so.6  
julia-lts.out                                18,344,864 x /nix/store/2b3fyawvxjpik4bah1n14ri2qplsgccz-julia-bin-1.6.6/lib/julia/libst  
dc++.so.6.0.29  
julia_18-bin.out                                      0 s /nix/store/16qsymiwarw212mrxj57c2h3pjz8d6mf-julia-bin-1.8.5/lib/julia/libst  
dc++.so.6  
julia_18-bin.out                             19,066,032 x /nix/store/16qsymiwarw212mrxj57c2h3pjz8d6mf-julia-bin-1.8.5/lib/julia/libst  
dc++.so.6.0.30  
julia_18.out                                  2,830,920 x /nix/store/8kxas46d24zhiywhi9mxdmfzv39995z8-julia-1.8.5/lib/julia/libstdc++  
.so.6  
julia.out                                     2,830,920 x /nix/store/9qdgvw932xgzczkbd37344ryrlzhckpz-julia-1.9.3/lib/julia/libstdc++  
.so.6  
gcc-unwrapped.lib                                     0 s /nix/store/843dqq10jdkalr2yazaz6drx334visrb-gcc-12.2.0-lib/lib/libstdc++.so  
.6  
gcc-unwrapped.lib                             2,830,920 x /nix/store/843dqq10jdkalr2yazaz6drx334visrb-gcc-12.2.0-lib/lib/libstdc++.so  
.6.0.30  
gcc-unwrapped.lib                                 2,494 r /nix/store/843dqq10jdkalr2yazaz6drx334visrb-gcc-12.2.0-lib/lib/libstdc++.so  
.6.0.30-gdb.py

So, any ideas what to do? I bet it is something easy and obvious…

It seem there is some compilation at runtime it the library headers are not available at runtime.

If you are not particularly tied to the UI, you can try https://nixified.ai/

1 Like

Thank you, i will keep an eye out for that

Did you make any progress on running this with nix + ROCm? I am trying but getting nowhere. Maybe we could team up to fix this? @Unclepsymon

Oh, I thought I had replied to this. There probably are better implementations of SD out there, but, regardless, the particular error:

ldconfig: Can't open cache file /nix/store/aw2fw9ag10wr9pf0qk4nk5sxi0q0bn56-glibc-2.37-8/etc/ld.so.cache  
: No such file or directory  

…looks like someone upstream trying to infer locations of globally available dynamic shared libraries by running ldconfig and asking it to list stuff in the global ld so cache. This is a relatively wrong and commonly abused way to find libraries. There are many ways to approach this error, but I would recommend that you find who’s using ldconfig and why, and then patch that out of them.

Also none of these global paths exist on NixOS by default because they’re just not needed, which is why I think you’re observing the error. You can even see that ldconfig doesn’t search for ld.so.cache in the locations upstream probably expected.

1 Like

This is upstream using pytorch downloaded by pip which just expects libstdc++ and a bunch of other things to be installed in /usr/lib, which they aren’t. If you’re using NixOS you can just use programs.nix-ld.enable = true in your configuration.nix and that’ll get you rid of this particular error. There may be more.

Also note that torch from pip won’t know where to find the cuda userspace driver, so you’ll need to teach with LD_LIBRARY_PATH=/run/opengl-driver/lib (or, future-proof, LD_LIBRARY_PATH=$(nix eval --raw nixpkgs#addOpenGLRunpath.driverLink)/lib)

If you’re trying to package this repo as a nix derivation, you just need to remove all of those references to pip and make it use python3Packages.torch from nixpkgs

Thank you for your reply! But i think that this is a little bit above my head. At least it does not seem to be my fault ^^.

I was not able to get it to work yet, but I will keep you updated should i find a solution.

1 Like

That’s normal, just take it easy! You can just start with the nix-ld option and see how the libstdc++ error goes away.

If you can publish some intermediate results on e.g. github we could guide you more closely

RE: ldconfig

This is the line: https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/5ef669de080814067961f28357256e8fe27544f4/webui.sh#L225

You can just replace it with TCMALLOC="" to disable the whole thing. If there’s a good reason they’re asking for that other allocator, it seems nixpkgs provides it in the gperftools attribute:

❯ nix-locate libtcmall
gperftools.out                                        0 s /nix/store/00000000000000000000000000000000-gperftools-2.10/lib/libtcmalloc.so

So you could use that (I’m not providing the snippets because I don’t know if you’re trying to use the repo as is or package it with Nix)

1 Like

My prefered solution would be the “Nix way”. NixOS is still a mystery to me, although i installed it half a year ago. I am still a very very advanced noob when it comes to Linux in general. But this is the perfect chance to learn something! Would you say, that packaging Stable Diffusion or Automatic1111 as a derivation would be a good solution here?

Maybe you first get it running outside the sandbox (as I said, start with nix-ld and manually editing webui.sh), and then see if it’s worth packaging. I’m pretty sure packaging it is going to be a lot of work (there’s python, and node, and cuda/rocm involved, and their scripts try to do pip installs and git clones, and access ldconfig, all of which will need to be patched away)

So, that did not work ;(

programs.nix-ld.enable = true was already enabled in my configuration.nix for some time.
I edited the webui.sh in line 225 like you said:

prepare_tcmalloc() {
    if [[ "${OSTYPE}" == "linux"* ]] && [[ -z "${NO_TCMALLOC}" ]] && [[ -z "${LD_PRELOAD}" ]]; then
        TCMALLOC=""
        if [[ ! -z "${TCMALLOC}" ]]; then
            echo "Using TCMalloc: ${TCMALLOC}"
            export LD_PRELOAD="${TCMALLOC}"
        else
            printf "\e[1m\e[31mCannot locate TCMalloc (improves CPU memory usage)\e[0m\n"
        fi
    fi

Here is what i did:

[simon@nixos:~/stable-diffusion-webui]$ ./webui.sh 
Bereits aktuell.

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye)
################################################################

################################################################
Running on simon user
################################################################

################################################################
Repo already cloned, using it as install directory
################################################################

################################################################
Create and activate python venv
################################################################

################################################################
Launching launch.py...
################################################################
Cannot locate TCMalloc (improves CPU memory usage)
Python 3.10.12 (main, Jun  6 2023, 22:43:10) [GCC 12.3.0]
Version: v1.6.0-2-g4afaaf8a
Commit hash: 4afaaf8a020c1df457bcf7250cb1c7f609699fa7
Traceback (most recent call last):
  File "/home/simon/stable-diffusion-webui/launch.py", line 48, in <module>
    main()
  File "/home/simon/stable-diffusion-webui/launch.py", line 39, in main
    prepare_environment()
  File "/home/simon/stable-diffusion-webui/modules/launch_utils.py", line 356, in prepare_environment
    raise RuntimeError(
RuntimeError: Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check

[simon@nixos:~/stable-diffusion-webui]$ ./webui.sh --skip-torch-cuda-test
Bereits aktuell.

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye)
################################################################

################################################################
Running on simon user
################################################################

################################################################
Repo already cloned, using it as install directory
################################################################

################################################################
Create and activate python venv
################################################################

################################################################
Launching launch.py...
################################################################
Cannot locate TCMalloc (improves CPU memory usage)
Python 3.10.12 (main, Jun  6 2023, 22:43:10) [GCC 12.3.0]
Version: v1.6.0-2-g4afaaf8a
Commit hash: 4afaaf8a020c1df457bcf7250cb1c7f609699fa7
Launching Web UI with arguments: --skip-torch-cuda-test --no-download-sd-model --api --no-half-vae --opt-split-attention
Traceback (most recent call last):
  File "/home/simon/stable-diffusion-webui/launch.py", line 48, in <module>
    main()
  File "/home/simon/stable-diffusion-webui/launch.py", line 44, in main
    start()
  File "/home/simon/stable-diffusion-webui/modules/launch_utils.py", line 432, in start
    import webui
  File "/home/simon/stable-diffusion-webui/webui.py", line 13, in <module>
    initialize.imports()
  File "/home/simon/stable-diffusion-webui/modules/initialize.py", line 14, in imports
    import torch  # noqa: F401
  File "/home/simon/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/__init__.py", line 229, in <module>
    from torch._C import *  # noqa: F403
ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory

[simon@nixos:~/stable-diffusion-webui]$ nix-shell -p nix-ld gperftools

[nix-shell:~/stable-diffusion-webui]$ ./webui.sh 
Bereits aktuell.

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye)
################################################################

################################################################
Running on simon user
################################################################

################################################################
Repo already cloned, using it as install directory
################################################################

################################################################
Create and activate python venv
################################################################

################################################################
Launching launch.py...
################################################################
Cannot locate TCMalloc (improves CPU memory usage)
Python 3.10.12 (main, Jun  6 2023, 22:43:10) [GCC 12.3.0]
Version: v1.6.0-2-g4afaaf8a
Commit hash: 4afaaf8a020c1df457bcf7250cb1c7f609699fa7
Traceback (most recent call last):
  File "/home/simon/stable-diffusion-webui/launch.py", line 48, in <module>
    main()
  File "/home/simon/stable-diffusion-webui/launch.py", line 39, in main
    prepare_environment()
  File "/home/simon/stable-diffusion-webui/modules/launch_utils.py", line 356, in prepare_environment
    raise RuntimeError(
RuntimeError: Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check

[nix-shell:~/stable-diffusion-webui]$ ./webui.sh --skip-torch-cuda-test
Bereits aktuell.

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye)
################################################################

################################################################
Running on simon user
################################################################

################################################################
Repo already cloned, using it as install directory
################################################################

################################################################
Create and activate python venv
################################################################

################################################################
Launching launch.py...
################################################################
Cannot locate TCMalloc (improves CPU memory usage)
Python 3.10.12 (main, Jun  6 2023, 22:43:10) [GCC 12.3.0]
Version: v1.6.0-2-g4afaaf8a
Commit hash: 4afaaf8a020c1df457bcf7250cb1c7f609699fa7
Launching Web UI with arguments: --skip-torch-cuda-test --no-download-sd-model --api --no-half-vae --opt-split-attention
Traceback (most recent call last):
  File "/home/simon/stable-diffusion-webui/launch.py", line 48, in <module>
    main()
  File "/home/simon/stable-diffusion-webui/launch.py", line 44, in main
    start()
  File "/home/simon/stable-diffusion-webui/modules/launch_utils.py", line 432, in start
    import webui
  File "/home/simon/stable-diffusion-webui/webui.py", line 13, in <module>
    initialize.imports()
  File "/home/simon/stable-diffusion-webui/modules/initialize.py", line 14, in imports
    import torch  # noqa: F401
  File "/home/simon/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/__init__.py", line 229, in <module>
    from torch._C import *  # noqa: F403
ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory

[nix-shell:~/stable-diffusion-webui]$ 

Oh, and what did you mean by that?

Just for completeness sake in this discussion. I was trying to get things up and running with a flake which is adapted from the same github repo mentioned in the beginning here: GitHub - virchau13/automatic1111-webui-nix: AUTOMATIC1111/stable-diffusion-webui for CUDA and ROCm on NixOS

However I also just discovered there is another one here: GitHub - gbtb/nix-stable-diffusion: Flake for running SD on NixOS

Maybe that is helpful?

btw. I believe packaging this whole thing might be overkill. Having a flake that is nice and portable and provides all the things to run it (with ROCm on AMD in my case) is what I’d like to have though.

1 Like

Yes, i think a flake would be great. I tried a bunch of flakes already, but they where either not working or not up to date. I was playing around with ComfyUI for the last two weeks, but that one does seem to have the same or similar issues like Automatic1111 on NixOS. I was able to run InvokeAI with their shell.nix file and used it for Automatic1111 in the past, but that trick stopped working some time ago.

Yes, it also seems to me that ROCm is rather fragile. And there is basically no documentation on ROCm + NixOS as far as I can see. It is a rare combination.

On AMD’s side: Their suggested method of deployment is docker it seems. They provide a number of container images. I am going to try and see if that works in the coming days.

Also, some guy on discord told me that he had more luck running ROCm + Automatic1111 on Fedora 38 in distrobox rather than on NixOS directly.

1 Like

So, i found two solutions to get ComfyUI working. They should work for other UI’s as well.

  1. Just use this Docker Image: Docker

This is the not so elegant way and only worked once for me:

  1. Clone ComfyUI
    2.1 Create a virtual Python environment (I did not try a nix-shell or flake so far)
    2.2 Source the environment
    2.3 get the nix-autobahn script and place it in the ComfyUI folder: GitHub - Lassulus/nix-autobahn (for some reason nix-ld did not work)
    2.4 create a bash script (I named mine start.sh) with the following content: python main.py
    2.5 run ./nix-autobahn start.sh

Also i had to use HSA_OVERRIDE_GFX_VERSION=10.3.0 because of my GPU, but there should be instructions in the documentation of the UI.

So, I am happy now! Many thanks to everybody :heart:

1 Like