integrate the new samplers PR

This commit is contained in:
AUTOMATIC
2022-10-06 14:12:52 +03:00
parent a971e4a767
commit 5993df24a1
5 changed files with 36 additions and 87 deletions

View File

@@ -1,53 +0,0 @@
import inspect
from modules.processing import Processed, process_images
import gradio as gr
import modules.scripts as scripts
import k_diffusion.sampling
import torch
class Script(scripts.Script):
def title(self):
return "Alternate Sampler Noise Schedules"
def ui(self, is_img2img):
noise_scheduler = gr.Dropdown(label="Noise Scheduler", choices=['Default','Karras','Exponential', 'Variance Preserving'], value='Default', type="index")
sched_smin = gr.Slider(value=0.1, label="Sigma min", minimum=0.0, maximum=100.0, step=0.5,)
sched_smax = gr.Slider(value=10.0, label="Sigma max", minimum=0.0, maximum=100.0, step=0.5)
sched_rho = gr.Slider(value=7.0, label="Sigma rho (Karras only)", minimum=7.0, maximum=100.0, step=0.5)
sched_beta_d = gr.Slider(value=19.9, label="Beta distribution (VP only)",minimum=0.0, maximum=40.0, step=0.5)
sched_beta_min = gr.Slider(value=0.1, label="Beta min (VP only)", minimum=0.0, maximum=40.0, step=0.1)
sched_eps_s = gr.Slider(value=0.001, label="Epsilon (VP only)", minimum=0.001, maximum=1.0, step=0.001)
return [noise_scheduler, sched_smin, sched_smax, sched_rho, sched_beta_d, sched_beta_min, sched_eps_s]
def run(self, p, noise_scheduler, sched_smin, sched_smax, sched_rho, sched_beta_d, sched_beta_min, sched_eps_s):
noise_scheduler_func_name = ['-','get_sigmas_karras','get_sigmas_exponential','get_sigmas_vp'][noise_scheduler]
base_params = {
"sigma_min":sched_smin,
"sigma_max":sched_smax,
"rho":sched_rho,
"beta_d":sched_beta_d,
"beta_min":sched_beta_min,
"eps_s":sched_eps_s,
"device":"cuda" if torch.cuda.is_available() else "cpu"
}
if hasattr(k_diffusion.sampling,noise_scheduler_func_name):
sigma_func = getattr(k_diffusion.sampling,noise_scheduler_func_name)
sigma_func_kwargs = {}
for k,v in base_params.items():
if k in inspect.signature(sigma_func).parameters:
sigma_func_kwargs[k] = v
def substitute_noise_scheduler(n):
return sigma_func(n,**sigma_func_kwargs)
p.sampler_noise_scheduler_override = substitute_noise_scheduler
return process_images(p)

View File

@@ -8,7 +8,6 @@ import gradio as gr
from modules import processing, shared, sd_samplers, prompt_parser
from modules.processing import Processed
from modules.sd_samplers import samplers
from modules.shared import opts, cmd_opts, state
import torch
@@ -159,7 +158,7 @@ class Script(scripts.Script):
combined_noise = ((1 - randomness) * rec_noise + randomness * rand_noise) / ((randomness**2 + (1-randomness)**2) ** 0.5)
sampler = samplers[p.sampler_index].constructor(p.sd_model)
sampler = sd_samplers.create_sampler_with_index(sd_samplers.samplers, p.sampler_index, p.sd_model)
sigmas = sampler.model_wrap.get_sigmas(p.steps)