[Feature] Prebuilt binaries support of AMD CPUs without FMA3
Feature Summary
Prebuilt binaries should support AMD CPUs without FMA3
Detailed Description
I want to use stable diffusion prebuilt binaries on an AMD FX(tm)-6100, but it fails with Illegal instruction. After some debugging I found that vfmadd213ss (FMA3 instruction) is used in libstable-diffusion.so, which is not supported by my CPU. It would be great if you could provide a variant for type of CPU.
Alternatives you considered
No response
Additional context
No response
I downloaded build master-665 of commit 02f0637 from #1591. Illegal instructions still occurs in ggml_cpu_init due to unsupported FMA3 instruction, so it does not solve this issue
I downloaded build master-665 of commit 02f0637 from #1591 . Illegal instructions still occurs in ggml_cpu_init due to unsupported FMA3 instruction, so it does not solve this issue
As I've explained in that PR, it opened up the possibility of a released binary to support several CPU arches at the same time; a proper fix still needs changes to the Github release configuration.
I've pushed a tentative change to my fork; could you give it a try?
https://github.com/wbruna/stable-diffusion.cpp/releases/tag/master-674-fd19aaa
It shall pick the appropriate backend for your CPU at the beginning:
$ /tmp/user/1000/test-sdcpp/sd-cli -m dreamshaper_8.safetensors -p sunset -v
[DEBUG] main.cpp:597 - version: stable-diffusion.cpp version unknown, commit fd19aaa
ggml_vulkan: Found 2 Vulkan devices:
(...)
load_backend: loaded Vulkan backend from /tmp/user/1000/test-sdcpp/libggml-vulkan.so
load_backend: loaded CPU backend from /tmp/user/1000/test-sdcpp/libggml-cpu-haswell.so
[DEBUG] main.cpp:598 - System Info:
SSE3 = 1 | SSSE3 = 1 | AVX = 1 | AVX2 = 1 | F16C = 1 | FMA = 1 | BMI2 = 1 | OPENMP = 1 | REPACK = 1 |
[DEBUG] main.cpp:599 - SDCliParams {
(...)
This version runs and does not terminate with illegal instruction any more. The generated image is not OK however.
Log Output:
./sd-cli --model /root/.cache/huggingface/hub/models--stabilityai--sdxl-turbo/snapshots/71153311d3dbb46851df1931d3ca6e939de83304/sd_xl_turbo_1.0_fp16.safetensors -p sunset -v [DEBUG] main.cpp:597 - version: stable-diffusion.cpp version unknown, commit fd19aaa ggml_vulkan: Found 1 Vulkan devices: ggml_vulkan: 0 = AMD Radeon RX 6600 XT (RADV NAVI23) (radv) | uma: 0 | fp16: 1 | bf16: 0 | warp size: 32 | shared memory: 65536 | int dot: 0 | matrix cores: none load_backend: loaded Vulkan backend from /root/.cache/lemonade/bin/sd-cpp/rocm-stable/libggml-vulkan.so load_backend: loaded CPU backend from /root/.cache/lemonade/bin/sd-cpp/rocm-stable/libggml-cpu-sandybridge.so [DEBUG] main.cpp:598 - System Info: SSE3 = 1 | SSSE3 = 1 | AVX = 1 | OPENMP = 1 | REPACK = 1 | ...
This version runs and does not terminate with illegal instruction any more. The generated image is not OK however.
I was able to reproduce something like that on my iGPU (3400G):
versus the dGPU (7600 XT):
With SD1.5, both the dGPU and the iGPU work:
except with the iGPU + --vae-conv-direct:
So I suspect this is a separate issue: likely a bug on the Vulkan backend (ggml, or the driver), because it seems to be triggered only by certain device+model+flag combinations.
Could you check if other models work for you?
I did some checks with both SD15 and SDXL both with rocm 7.13 backend and vulkan backend.
SD15 on rocm: OK SD15 on vulkan: OK SDXL on rocm: OK SDXL on vulkan: garbled SDXL on vulkan --offload-to-cpu: OK SDXL on vulkan --vae-conv-direct: OK
Seems indeed to be a problem of model+options
This should be resolved now.
@klkr1 , could you verify if the garbled image issue still happens on the latest release (master-737-3b6c9ca)? I cannot reproduce it anymore on my iGPU.
@wbruna: with this version for me it is still garbled for SDXL without options: SD15 on rocm: OK SD15 on vulkan: OK SDXL on rocm: now outOfMemory, unless I use --offload-to-cpu, then it is OK SDXL on vulkan: garbled SDXL on vulkan --offload-to-cpu: OK SDXL on vulkan --vae-conv-direct: OK Edit: I mixed up SD15 on vulkan and SDXL on rocm SD15 is OK in both cases, SDXL on rocm was outOfMemory Is there anything I can do for debugging?
At least with SDXL, this is a bit more consistent: the issue seems directly related to the total VRAM available. Could you check if --params-backend disk also avoids the issue? (by the way, SDXL Turbo is a distilled model, so the default parameters are a bit too much; try --cfg-scale 1 --steps 4 or so)
It shouldn't really happen with sd-cli, though, because sd-cli drops the diffusion weights from VRAM before running the VAE. But, on my card, I am seeing a VRAM spike on the VAE phase, instead of the expected drop. @leejet , is this expected default behavior for current sd-cli?
The SD1.5 result is very weird: it shouldn't take more memory than SDXL in any case. Could you post a full --debug log?
And @leejet , since the original issue is fixed, please let us know if this should be moved to a separate one.
Currently, unless --params-backend is set to disk, the weights of unused components will not be automatically released.
@wbruna: --params-backend disk also solves the issue with vulkan and SDXL.
Here is the output of SDXL on vulkan without additional options: vulkan.log
Thanks! Your Radeon RX 6600 XT has 8GiB VRAM, right? And from the logs the generation hits:
VRAM 6624.11MB
So this really looks like that bug: when VRAM is too tight, Vulkan can produce bad images.
Edit: I mixed up SD15 on vulkan and SDXL on rocm SD15 is OK in both cases, SDXL on rocm was outOfMemory
You are getting close to the VRAM limit, so depending on the options and how much other programs are using, it is expected that i fails in some attempts.
I was able to reproduce it, and posted a test on the llama.cpp issue: ggml-org/llama.cpp#24943