Skip to content

Commit 3273afc

Browse files
committed
sync(stablediffusion-cpp): Switch back to upstream and update
Signed-off-by: Richard Palethorpe <io@richiejp.com>
1 parent e29b2c3 commit 3273afc

File tree

2 files changed

+44
-59
lines changed

2 files changed

+44
-59
lines changed

backend/go/stablediffusion-ggml/Makefile

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ GO_TAGS?=
1818
LD_FLAGS?=
1919

2020
# stablediffusion.cpp (ggml)
21-
STABLEDIFFUSION_GGML_REPO?=https://github.com/richiejp/stable-diffusion.cpp
22-
STABLEDIFFUSION_GGML_VERSION?=53e3b17eb3d0b5760ced06a1f98320b68b34aaae
21+
STABLEDIFFUSION_GGML_REPO?=https://github.com/leejet/stable-diffusion.cpp
22+
STABLEDIFFUSION_GGML_VERSION?=1896b28ef2fd5b3643120e66979bea487385439f
2323

2424
# Disable Shared libs as we are linking on static gRPC and we can't mix shared and static
2525
CMAKE_ARGS+=-DBUILD_SHARED_LIBS=OFF
@@ -91,23 +91,18 @@ endif
9191
# (ggml can have different backends cpu, cuda, etc., each backend generates a .a archive)
9292
GGML_ARCHIVE_DIR := build/ggml/src/
9393
ALL_ARCHIVES := $(shell find $(GGML_ARCHIVE_DIR) -type f -name '*.a')
94+
ALL_OBJS := $(shell find $(GGML_ARCHIVE_DIR) -type f -name '*.o')
9495

9596
# Name of the single merged library
9697
COMBINED_LIB := libggmlall.a
9798

98-
# Rule to merge all the .a files into one
99+
# Instead of using the archives generated by GGML, use the object files directly to avoid overwriting objects with the same base name
99100
$(COMBINED_LIB): $(ALL_ARCHIVES)
100-
@echo "Merging all .a into $(COMBINED_LIB)"
101+
@echo "Merging all .o into $(COMBINED_LIB): $(ALL_OBJS)"
101102
rm -f $@
102-
mkdir -p merge-tmp
103-
for a in $(ALL_ARCHIVES); do \
104-
( cd merge-tmp && ar x ../$$a ); \
105-
done
106-
( cd merge-tmp && ar rcs ../$@ *.o )
103+
ar -qc $@ $(ALL_OBJS)
107104
# Ensure we have a proper index
108105
ranlib $@
109-
# Clean up
110-
rm -rf merge-tmp
111106

112107
build/libstable-diffusion.a:
113108
@echo "Building SD with $(BUILD_TYPE) build type and $(CMAKE_ARGS)"

backend/go/stablediffusion-ggml/gosd.cpp

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int load_model(char *model, char* options[], int threads, int diff) {
9999
}
100100

101101
int sample_method_found = -1;
102-
for (int m = 0; m < N_SAMPLE_METHODS; m++) {
102+
for (int m = 0; m < SAMPLE_METHOD_COUNT; m++) {
103103
if (!strcmp(sampler, sample_method_str[m])) {
104104
sample_method_found = m;
105105
}
@@ -111,7 +111,7 @@ int load_model(char *model, char* options[], int threads, int diff) {
111111
sample_method = (sample_method_t)sample_method_found;
112112

113113
int schedule_found = -1;
114-
for (int d = 0; d < N_SCHEDULES; d++) {
114+
for (int d = 0; d < SCHEDULE_COUNT; d++) {
115115
if (!strcmp(scheduler, schedule_str[d])) {
116116
schedule_found = d;
117117
fprintf (stderr, "Found scheduler: %s\n", scheduler);
@@ -125,30 +125,28 @@ int load_model(char *model, char* options[], int threads, int diff) {
125125
}
126126

127127
schedule_t schedule = (schedule_t)schedule_found;
128-
128+
129129
fprintf (stderr, "Creating context\n");
130-
sd_ctx_t* sd_ctx = new_sd_ctx(model,
131-
clip_l_path,
132-
clip_g_path,
133-
t5xxl_path,
134-
stableDiffusionModel,
135-
vae_path,
136-
"",
137-
"",
138-
"",
139-
"",
140-
"",
141-
false,
142-
false,
143-
false,
144-
threads,
145-
SD_TYPE_COUNT,
146-
STD_DEFAULT_RNG,
147-
schedule,
148-
false,
149-
false,
150-
false,
151-
false);
130+
sd_ctx_params_t ctx_params;
131+
sd_ctx_params_init(&ctx_params);
132+
ctx_params.model_path = model;
133+
ctx_params.clip_l_path = clip_l_path;
134+
ctx_params.clip_g_path = clip_g_path;
135+
ctx_params.t5xxl_path = t5xxl_path;
136+
ctx_params.diffusion_model_path = stableDiffusionModel;
137+
ctx_params.vae_path = vae_path;
138+
ctx_params.taesd_path = "";
139+
ctx_params.control_net_path = "";
140+
ctx_params.lora_model_dir = "";
141+
ctx_params.embedding_dir = "";
142+
ctx_params.stacked_id_embed_dir = "";
143+
ctx_params.vae_decode_only = false;
144+
ctx_params.vae_tiling = false;
145+
ctx_params.free_params_immediately = false;
146+
ctx_params.n_threads = threads;
147+
ctx_params.rng_type = STD_DEFAULT_RNG;
148+
ctx_params.schedule = schedule;
149+
sd_ctx_t* sd_ctx = new_sd_ctx(&ctx_params);
152150

153151
if (sd_ctx == NULL) {
154152
fprintf (stderr, "failed loading model (generic error)\n");
@@ -169,29 +167,21 @@ int gen_image(char *text, char *negativeText, int width, int height, int steps,
169167

170168
fprintf (stderr, "Generating image\n");
171169

172-
results = txt2img(sd_c,
173-
text,
174-
negativeText,
175-
-1, //clip_skip
176-
cfg_scale, // sfg_scale
177-
3.5f,
178-
0, // eta
179-
width,
180-
height,
181-
sample_method,
182-
steps,
183-
seed,
184-
1,
185-
NULL,
186-
0.9f,
187-
20.f,
188-
false,
189-
"",
190-
skip_layers.data(),
191-
skip_layers.size(),
192-
0,
193-
0.01,
194-
0.2);
170+
sd_img_gen_params_t p;
171+
sd_img_gen_params_init(&p);
172+
173+
p.prompt = text;
174+
p.negative_prompt = negativeText;
175+
p.guidance.txt_cfg = cfg_scale;
176+
p.guidance.slg.layers = skip_layers.data();
177+
p.guidance.slg.layer_count = skip_layers.size();
178+
p.width = width;
179+
p.height = height;
180+
p.sample_method = sample_method;
181+
p.sample_steps = steps;
182+
p.seed = seed;
183+
184+
results = generate_image(sd_c, &p);
195185

196186
if (results == NULL) {
197187
fprintf (stderr, "NO results\n");

0 commit comments

Comments
 (0)