Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/go/stablediffusion-ggml/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package/
sources/
.cache/
build/
libgosd.so
stablediffusion-ggml
2 changes: 1 addition & 1 deletion backend/go/stablediffusion-ggml/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ JOBS?=$(shell nproc --ignore=1)

# stablediffusion.cpp (ggml)
STABLEDIFFUSION_GGML_REPO?=https://github.com/leejet/stable-diffusion.cpp
STABLEDIFFUSION_GGML_VERSION?=2eb3845df5675a71565d5a9e13b7bad0881fafcd
STABLEDIFFUSION_GGML_VERSION?=d7f430cd693f2e12ecbaa0ce881746cf305c3b1f

CMAKE_ARGS+=-DGGML_MAX_NAME=128

Expand Down
35 changes: 14 additions & 21 deletions backend/go/stablediffusion-ggml/gosd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const char* sample_method_str[] = {
};

// Names of the sigma schedule overrides, same order as sample_schedule in stable-diffusion.h
const char* schedule_str[] = {
const char* schedulers[] = {
"default",
"discrete",
"karras",
Expand All @@ -54,6 +54,8 @@ const char* schedule_str[] = {
};

sd_ctx_t* sd_c;
// Moved from the context (load time) to generation time params
scheduler_t scheduler = scheduler_t::DEFAULT;

sample_method_t sample_method;

Expand Down Expand Up @@ -105,7 +107,7 @@ int load_model(const char *model, char *model_path, char* options[], int threads
const char *clip_g_path = "";
const char *t5xxl_path = "";
const char *vae_path = "";
const char *scheduler = "";
const char *scheduler_str = "";
const char *sampler = "";
char *lora_dir = model_path;
bool lora_dir_allocated = false;
Expand Down Expand Up @@ -133,7 +135,7 @@ int load_model(const char *model, char *model_path, char* options[], int threads
vae_path = optval;
}
if (!strcmp(optname, "scheduler")) {
scheduler = optval;
scheduler_str = optval;
}
if (!strcmp(optname, "sampler")) {
sampler = optval;
Expand Down Expand Up @@ -170,22 +172,13 @@ int load_model(const char *model, char *model_path, char* options[], int threads
}
sample_method = (sample_method_t)sample_method_found;

int schedule_found = -1;
for (int d = 0; d < SCHEDULE_COUNT; d++) {
if (!strcmp(scheduler, schedule_str[d])) {
schedule_found = d;
fprintf (stderr, "Found scheduler: %s\n", scheduler);

if (!strcmp(scheduler_str, schedulers[d])) {
scheduler = (scheduler_t)d;
fprintf (stderr, "Found scheduler: %s\n", scheduler_str);
}
}

if (schedule_found == -1) {
fprintf (stderr, "Invalid scheduler! using DEFAULT\n");
schedule_found = DEFAULT;
}

schedule_t schedule = (schedule_t)schedule_found;

fprintf (stderr, "Creating context\n");
sd_ctx_params_t ctx_params;
sd_ctx_params_init(&ctx_params);
Expand All @@ -205,7 +198,6 @@ int load_model(const char *model, char *model_path, char* options[], int threads
ctx_params.free_params_immediately = false;
ctx_params.n_threads = threads;
ctx_params.rng_type = STD_DEFAULT_RNG;
ctx_params.schedule = schedule;
sd_ctx_t* sd_ctx = new_sd_ctx(&ctx_params);

if (sd_ctx == NULL) {
Expand Down Expand Up @@ -241,15 +233,16 @@ int gen_image(char *text, char *negativeText, int width, int height, int steps,

p.prompt = text;
p.negative_prompt = negativeText;
p.guidance.txt_cfg = cfg_scale;
p.guidance.slg.layers = skip_layers.data();
p.guidance.slg.layer_count = skip_layers.size();
p.sample_params.guidance.txt_cfg = cfg_scale;
p.sample_params.guidance.slg.layers = skip_layers.data();
p.sample_params.guidance.slg.layer_count = skip_layers.size();
p.width = width;
p.height = height;
p.sample_method = sample_method;
p.sample_steps = steps;
p.sample_params.sample_method = sample_method;
p.sample_params.sample_steps = steps;
p.seed = seed;
p.input_id_images_path = "";
p.sample_params.scheduler = scheduler;

// Handle input image for img2img
bool has_input_image = (src_image != NULL && strlen(src_image) > 0);
Expand Down
Loading