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

stable diffusion not work in WASM

Open Joinhack opened this issue 2 years ago • 5 comments

Hello, I compile this project to wasm, but when I run it crash. image

Joinhack avatar Sep 05 '23 11:09 Joinhack

@ggerganov any chance you could give us some pointers? :) Much obliged.

dmikey avatar Sep 05 '23 18:09 dmikey

Hard to tell - could be some problem with the WASM code. It's not very well tested.

Try this patch and see what happens:

diff --git a/src/ggml.c b/src/ggml.c
index d2a9dab..8a11f7c 100644
--- a/src/ggml.c
+++ b/src/ggml.c
@@ -12260,9 +12260,7 @@ static void ggml_compute_forward_soft_max_f32(
             }
         }
 
-        assert(sum > 0.0);
-
-        sum = 1.0/sum;
+        sum = sum > 0.0 ? 1.0/sum : 1.0;
         ggml_vec_scale_f32(nc, dp, sum);
 
 #ifndef NDEBUG

ggerganov avatar Sep 05 '23 18:09 ggerganov

yes, it work, but other error occur.

image

Joinhack avatar Sep 05 '23 22:09 Joinhack

@Joinhack , if you're using Emscripten then try adding these flags and values during compilation: -s INITIAL_MEMORY=1000MB -s MAXIMUM_MEMORY=4GB -s STACK_SIZE=11524288 -s ALLOW_MEMORY_GROWTH

This should get around the memory limitations. Example Script: https://github.com/rahuldshetty/ggml.js/blob/master/build-ggml.sh

rahuldshetty avatar Nov 21 '23 11:11 rahuldshetty

thanks.

Joinhack avatar Nov 28 '23 08:11 Joinhack