stable-diffusion.cpp icon indicating copy to clipboard operation
stable-diffusion.cpp copied to clipboard

Macos binary is using an absolute library path

Open remixer-dec opened this issue 1 year ago • 3 comments

Hi! There is a problem with the mac os build. When running ./sd binary, it outputs an error

dyld[37566]: Library not loaded: @rpath/libstable-diffusion.dylib
  Referenced from: <97C4B798-BDE1-3DB5-88EE-024F5899A711> sd-master--bin-Darwin-macOS-14.4.1-arm64/sd
  Reason: tried: '/Users/runner/work/stable-diffusion.cpp/stable-diffusion.cpp/build/bin/libstable-diffusion.dylib' (no such file), 
'/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/stable-diffusion.cpp/stable-diffusion.cpp/build/bin/libstable-diffusion.dylib' (no such file), 
'/Users/runner/work/stable-diffusion.cpp/stable-diffusion.cpp/build/bin/libstable-diffusion.dylib' (no such file), 
'/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/stable-diffusion.cpp/stable-diffusion.cpp/build/bin/libstable-diffusion.dylib' (no such file)

I tried

  • giving dlyb extra permissions and opening it as executable
  • movng dlib to "@rpath"
  • moving dlib to a mentioned directory (had to recreate the whole path), this worked.

remixer-dec avatar May 10 '24 23:05 remixer-dec

Linux prebuilt binary seems to be also dynamically built.

./sd: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./sd)
./sd: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by libstable-diffusion.so)
./sd: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by libstable-diffusion.so)
./sd: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by libstable-diffusion.so)
./sd: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by libstable-diffusion.so)

Even in a container with all these dependencies, it still refused to run:

/usr/share/py/sd # ldd sd 
        /lib64/ld-linux-x86-64.so.2 (0x7f7898226000)
Error loading shared library libstable-diffusion.so: No such file or directory (needed by sd)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7f7898050000)
        libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f7898226000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7f7898036000)
        libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f7898226000)
Error relocating sd: __printf_chk: symbol not found
Error relocating sd: free_sd_ctx: symbol not found
Error relocating sd: txt2img: symbol not found
Error relocating sd: new_upscaler_ctx: symbol not found
Error relocating sd: sd_type_name: symbol not found
Error relocating sd: __vsnprintf_chk: symbol not found
Error relocating sd: upscale: symbol not found
Error relocating sd: img2img: symbol not found
Error relocating sd: sd_get_system_info: symbol not found
Error relocating sd: sd_set_log_callback: symbol not found
Error relocating sd: convert: symbol not found
Error relocating sd: img2vid: symbol not found
Error relocating sd: get_num_physical_cores: symbol not found
Error relocating sd: new_sd_ctx: symbol not found
Error relocating sd: __fprintf_chk: symbol not found
Error relocating sd: preprocess_canny: symbol not found
ldd libstable-diffusion.so 
        /lib/ld-musl-x86_64.so.1 (0x7ffaa5193000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7ffaa4cb7000)
        libm.so.6 => /lib/ld-musl-x86_64.so.1 (0x7ffaa5193000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7ffaa4c9d000)
        libc.so.6 => /lib/ld-musl-x86_64.so.1 (0x7ffaa5193000)
Error relocating libstable-diffusion.so: __printf_chk: symbol not found
Error relocating libstable-diffusion.so: __strncat_chk: symbol not found
Error relocating libstable-diffusion.so: __snprintf_chk: symbol not found
Error relocating libstable-diffusion.so: getcpu: symbol not found
Error relocating libstable-diffusion.so: _ZSt28__throw_bad_array_new_lengthv: symbol not found
Error relocating libstable-diffusion.so: __vsnprintf_chk: symbol not found
Error relocating libstable-diffusion.so: __sched_cpualloc: symbol not found
Error relocating libstable-diffusion.so: __memset_chk: symbol not found
Error relocating libstable-diffusion.so: __sched_cpufree: symbol not found
Error relocating libstable-diffusion.so: __fprintf_chk: symbol not found
Error relocating libstable-diffusion.so: __memcpy_chk: symbol not found
Error relocating libstable-diffusion.so: __libc_single_threaded: symbol not found

After moving libstable-diffusion.so to /usr/lib/ it still refused to run: sh: ./sd: not found. Later I managed to make a static build from source, adding add_link_options(-static) and add_link_options(-static-libgcc -static-libstdc++)

Only managed to generate 64x64 images on a 2GB ram server with Q4_1. Build with flash attention. Generating higher resolution crashes with:

[DEBUG] ggml_extend.hpp:834  - unet compute buffer size: 7.99 MB(RAM)
GGML_ASSERT: /root/stable-diffusion.cpp/ggml/src/ggml.c:13829: P >= 0
GGML_ASSERT: /root/stable-diffusion.cpp/ggml/src/ggml.c:13829: P >= 0

UPDATE: I commented out the line that asserts P in ggml.c and it worked! But the resulting image was not following the prompt at all, with default cfg scale, which is 7. Tried SDTurbo, it just outputs green image at 4 steps, when on mac it works just fine, something is definitely broken.

remixer-dec avatar May 10 '24 23:05 remixer-dec

set DYLD_LIBRARY_PATH Environment Variables for the process works for me

bosxixi avatar Jun 26 '24 04:06 bosxixi

install_name_tool -add_rpath @loader_path ./sd is another fix that adds sd's directory to the load path

unexge avatar Dec 30 '24 20:12 unexge