Browse Source

add code for skipping CFG on early steps

drhead 1 year ago
parent
commit
a1aa0af8a4
1 changed files with 5 additions and 0 deletions
  1. 5 0
      modules/sd_samplers_cfg_denoiser.py

+ 5 - 0
modules/sd_samplers_cfg_denoiser.py

@@ -212,6 +212,11 @@ class CFGDenoiser(torch.nn.Module):
         uncond = denoiser_params.text_uncond
         uncond = denoiser_params.text_uncond
         skip_uncond = False
         skip_uncond = False
 
 
+        if self.step < shared.opts.skip_cond_steps:
+            skip_uncond = True
+            x_in = x_in[:-batch_size]
+            sigma_in = sigma_in[:-batch_size]
+
         # alternating uncond allows for higher thresholds without the quality loss normally expected from raising it
         # alternating uncond allows for higher thresholds without the quality loss normally expected from raising it
         if self.step % 2 and s_min_uncond > 0 and sigma[0] < s_min_uncond and not is_edit_model:
         if self.step % 2 and s_min_uncond > 0 and sigma[0] < s_min_uncond and not is_edit_model:
             skip_uncond = True
             skip_uncond = True