From a2344daa26a94bd5db40c84b1572803a3bf1a287 Mon Sep 17 00:00:00 2001 From: Wagner Bruna Date: Wed, 17 Dec 2025 11:10:01 -0300 Subject: [PATCH 1/3] feat: warn about cfg values smaller than 1 --- stable-diffusion.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/stable-diffusion.cpp b/stable-diffusion.cpp index 2cb588213..36d6968b7 100644 --- a/stable-diffusion.cpp +++ b/stable-diffusion.cpp @@ -1484,6 +1484,17 @@ class StableDiffusionGGML { std::vector skip_layers(guidance.slg.layers, guidance.slg.layers + guidance.slg.layer_count); float cfg_scale = guidance.txt_cfg; + if (cfg_scale < 1) { + if (cfg_scale == 0.f) { + // Diffusers follow the convention from the original paper + // (https://arxiv.org/abs/2207.12598v1), so many distilled model docs + // recommend 0 as guidance; warn the user that it'll disable prompt folowing + LOG_WARN("unconditioned mode, images won't follow the prompt (use cfg-scale=1 for distilled models)"); + } else { + LOG_WARN("unsupported cfg-scale value"); + } + } + float img_cfg_scale = std::isfinite(guidance.img_cfg) ? guidance.img_cfg : guidance.txt_cfg; float slg_scale = guidance.slg.scale; From 349f55b14adac818c4b567b4064db2168da927fe Mon Sep 17 00:00:00 2001 From: leejet Date: Fri, 19 Dec 2025 23:37:36 +0800 Subject: [PATCH 2/3] Update warn message --- stable-diffusion.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stable-diffusion.cpp b/stable-diffusion.cpp index 36d6968b7..6a41f8448 100644 --- a/stable-diffusion.cpp +++ b/stable-diffusion.cpp @@ -1491,7 +1491,7 @@ class StableDiffusionGGML { // recommend 0 as guidance; warn the user that it'll disable prompt folowing LOG_WARN("unconditioned mode, images won't follow the prompt (use cfg-scale=1 for distilled models)"); } else { - LOG_WARN("unsupported cfg-scale value"); + LOG_WARN("cfg value out of expected range may produce unexpected results"); } } @@ -3886,4 +3886,4 @@ SD_API sd_image_t* generate_video(sd_ctx_t* sd_ctx, const sd_vid_gen_params_t* s LOG_INFO("generate_video completed in %.2fs", (t5 - t0) * 1.0f / 1000); return result_images; -} \ No newline at end of file +} From 9fdaedd18180cbe48dc90ac6de1b89bc14411f27 Mon Sep 17 00:00:00 2001 From: leejet Date: Fri, 19 Dec 2025 23:39:56 +0800 Subject: [PATCH 3/3] use float literal for cfg_vale comparison --- stable-diffusion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stable-diffusion.cpp b/stable-diffusion.cpp index 6a41f8448..a0217942c 100644 --- a/stable-diffusion.cpp +++ b/stable-diffusion.cpp @@ -1484,7 +1484,7 @@ class StableDiffusionGGML { std::vector skip_layers(guidance.slg.layers, guidance.slg.layers + guidance.slg.layer_count); float cfg_scale = guidance.txt_cfg; - if (cfg_scale < 1) { + if (cfg_scale < 1.f) { if (cfg_scale == 0.f) { // Diffusers follow the convention from the original paper // (https://arxiv.org/abs/2207.12598v1), so many distilled model docs