Skip to content

Commit 10eca0e

Browse files
committed
fix: avoid and warn about cfg-scale less than 1
1 parent 43a70e8 commit 10eca0e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

stable-diffusion.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,8 +1484,26 @@ class StableDiffusionGGML {
14841484
std::vector<int> skip_layers(guidance.slg.layers, guidance.slg.layers + guidance.slg.layer_count);
14851485

14861486
float cfg_scale = guidance.txt_cfg;
1487-
float img_cfg_scale = std::isfinite(guidance.img_cfg) ? guidance.img_cfg : guidance.txt_cfg;
1488-
float slg_scale = guidance.slg.scale;
1487+
float img_cfg_scale = guidance.img_cfg;
1488+
if (cfg_scale < 1.f) {
1489+
if (cfg_scale == 0.f) {
1490+
// many distilled model docs mention using 0 as guidance, so relax the message a bit
1491+
LOG_DEBUG("cfg-scale = 0, disabling classifier‑free guidance");
1492+
} else if (cfg_scale < 0) {
1493+
LOG_WARN("negative cfg-scale isn't supported; setting it to 1");
1494+
} else {
1495+
LOG_WARN("cfg-scale < 1 isn't supported; setting it to 1");
1496+
}
1497+
if (img_cfg_scale == cfg_scale) {
1498+
img_cfg_scale = 1.f;
1499+
}
1500+
cfg_scale = 1.f;
1501+
}
1502+
1503+
if (!std::isfinite(img_cfg_scale)) {
1504+
img_cfg_scale = cfg_scale;
1505+
}
1506+
float slg_scale = guidance.slg.scale;
14891507

14901508
if (img_cfg_scale != cfg_scale && !sd_version_is_inpaint_or_unet_edit(version)) {
14911509
LOG_WARN("2-conditioning CFG is not supported with this model, disabling it for better performance...");

0 commit comments

Comments
 (0)