@@ -886,7 +886,7 @@ class StableDiffusionGGML {
886886
887887 bool has_unconditioned = img_cfg_scale != 1.0 && uncond.c_crossattn != NULL ;
888888 bool has_img_cond = cfg_scale != img_cfg_scale && img_cond.c_crossattn != NULL ;
889- bool has_skiplayer = slg_scale != 0.0 && skip_layers.size () > 0 ;
889+ bool has_skiplayer = ( slg_scale != 0.0 || guidance. slg . uncond ) && skip_layers.size () > 0 ;
890890
891891 // denoise wrapper
892892 struct ggml_tensor * out_cond = ggml_dup_tensor (work_ctx, x);
@@ -899,7 +899,9 @@ class StableDiffusionGGML {
899899 }
900900 if (has_skiplayer) {
901901 if (sd_version_is_dit (version)) {
902- out_skip = ggml_dup_tensor (work_ctx, x);
902+ if (slg_scale != 0.0 ) {
903+ out_skip = ggml_dup_tensor (work_ctx, x);
904+ }
903905 } else {
904906 has_skiplayer = false ;
905907 LOG_WARN (" SLG is incompatible with %s models" , model_version_to_str[version]);
@@ -973,6 +975,8 @@ class StableDiffusionGGML {
973975 control_strength,
974976 &out_cond);
975977 }
978+ int step_count = sigmas.size ();
979+ bool is_skiplayer_step = has_skiplayer && step > (int )(guidance.slg .layer_start * step_count) && step < (int )(guidance.slg .layer_end * step_count);
976980
977981 float * negative_data = NULL ;
978982 if (has_unconditioned) {
@@ -981,18 +985,36 @@ class StableDiffusionGGML {
981985 control_net->compute (n_threads, noised_input, control_hint, timesteps, uncond.c_crossattn , uncond.c_vector );
982986 controls = control_net->controls ;
983987 }
984- diffusion_model->compute (n_threads,
985- noised_input,
986- timesteps,
987- uncond.c_crossattn ,
988- uncond.c_concat ,
989- uncond.c_vector ,
990- guidance_tensor,
991- ref_latents,
992- -1 ,
993- controls,
994- control_strength,
995- &out_uncond);
988+ if (is_skiplayer_step && guidance.slg .uncond ) {
989+ LOG_DEBUG (" Skipping layers at uncond step %d\n " , step);
990+ diffusion_model->compute (n_threads,
991+ noised_input,
992+ timesteps,
993+ uncond.c_crossattn ,
994+ uncond.c_concat ,
995+ uncond.c_vector ,
996+ guidance_tensor,
997+ ref_latents,
998+ -1 ,
999+ controls,
1000+ control_strength,
1001+ &out_uncond,
1002+ NULL ,
1003+ skip_layers);
1004+ } else {
1005+ diffusion_model->compute (n_threads,
1006+ noised_input,
1007+ timesteps,
1008+ uncond.c_crossattn ,
1009+ uncond.c_concat ,
1010+ uncond.c_vector ,
1011+ guidance_tensor,
1012+ ref_latents,
1013+ -1 ,
1014+ controls,
1015+ control_strength,
1016+ &out_uncond);
1017+ }
9961018 negative_data = (float *)out_uncond->data ;
9971019 }
9981020
@@ -1013,10 +1035,8 @@ class StableDiffusionGGML {
10131035 img_cond_data = (float *)out_img_cond->data ;
10141036 }
10151037
1016- int step_count = sigmas.size ();
1017- bool is_skiplayer_step = has_skiplayer && step > (int )(guidance.slg .layer_start * step_count) && step < (int )(guidance.slg .layer_end * step_count);
10181038 float * skip_layer_data = NULL ;
1019- if (is_skiplayer_step) {
1039+ if (is_skiplayer_step && slg_scale != 0.0 ) {
10201040 LOG_DEBUG (" Skipping layers at step %d\n " , step);
10211041 // skip layer (same as conditionned)
10221042 diffusion_model->compute (n_threads,
@@ -1106,7 +1126,7 @@ class StableDiffusionGGML {
11061126 } else {
11071127 float delta = deltas[i];
11081128
1109- if (cfg_scale != 1 ) {
1129+ if (cfg_scale != 1 ) {
11101130 latent_result = positive_data[i] + (cfg_scale - 1 ) * delta;
11111131 } else if (has_img_cond) {
11121132 latent_result = positive_data[i] + (img_cfg_scale - 1 ) * delta;
@@ -1116,7 +1136,7 @@ class StableDiffusionGGML {
11161136 // img_cfg_scale == 1
11171137 latent_result = img_cond_data[i] + cfg_scale * (positive_data[i] - img_cond_data[i]);
11181138 }
1119- if (is_skiplayer_step) {
1139+ if (is_skiplayer_step && slg_scale != 0.0 ) {
11201140 latent_result = latent_result + (positive_data[i] - skip_layer_data[i]) * slg_scale;
11211141 }
11221142 // v = latent_result, eps = latent_result
0 commit comments