Skip to content

Commit

Permalink
Merge pull request #12542 from AUTOMATIC1111/res-sampler
Browse files Browse the repository at this point in the history
Add RES sampler and reorder the sampler list
  • Loading branch information
AUTOMATIC1111 committed Aug 14, 2023
2 parents 3a4bee1 + aa26f8e commit f37cc5f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions modules/sd_samplers_kdiffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
('DPM++ 2M', 'sample_dpmpp_2m', ['k_dpmpp_2m'], {}),
('DPM++ SDE', 'sample_dpmpp_sde', ['k_dpmpp_sde'], {"second_order": True, "brownian_noise": True}),
('DPM++ 2M SDE', 'sample_dpmpp_2m_sde', ['k_dpmpp_2m_sde_ka'], {"brownian_noise": True}),
('DPM++ 2M SDE Heun', 'sample_dpmpp_2m_sde', ['k_dpmpp_2m_sde_heun'], {"brownian_noise": True, "solver_type": "heun"}),
('DPM++ 2M SDE Heun Karras', 'sample_dpmpp_2m_sde', ['k_dpmpp_2m_sde_heun_ka'], {'scheduler': 'karras', "brownian_noise": True, "solver_type": "heun"}),
('DPM++ 2M SDE Heun Exponential', 'sample_dpmpp_2m_sde', ['k_dpmpp_2m_sde_heun_exp'], {'scheduler': 'exponential', "brownian_noise": True, "solver_type": "heun"}),
('DPM++ 3M SDE', 'sample_dpmpp_3m_sde', ['k_dpmpp_3m_sde'], {'discard_next_to_last_sigma': True, "brownian_noise": True}),
('DPM++ 3M SDE Karras', 'sample_dpmpp_3m_sde', ['k_dpmpp_3m_sde_ka'], {'scheduler': 'karras', 'discard_next_to_last_sigma': True, "brownian_noise": True}),
('DPM++ 3M SDE Exponential', 'sample_dpmpp_3m_sde', ['k_dpmpp_3m_sde_exp'], {'scheduler': 'exponential', 'discard_next_to_last_sigma': True, "brownian_noise": True}),
Expand Down Expand Up @@ -161,6 +164,9 @@ def sample_img2img(self, p, x, noise, conditioning, unconditional_conditioning,
noise_sampler = self.create_noise_sampler(x, sigmas, p)
extra_params_kwargs['noise_sampler'] = noise_sampler

if self.config.options.get('solver_type', None) == 'heun':
extra_params_kwargs['solver_type'] = 'heun'

self.model_wrap_cfg.init_latent = x
self.last_latent = x
self.sampler_extra_args = {
Expand Down Expand Up @@ -202,6 +208,9 @@ def sample(self, p, x, conditioning, unconditional_conditioning, steps=None, ima
noise_sampler = self.create_noise_sampler(x, sigmas, p)
extra_params_kwargs['noise_sampler'] = noise_sampler

if self.config.options.get('solver_type', None) == 'heun':
extra_params_kwargs['solver_type'] = 'heun'

self.last_latent = x
self.sampler_extra_args = {
'cond': conditioning,
Expand All @@ -210,6 +219,7 @@ def sample(self, p, x, conditioning, unconditional_conditioning, steps=None, ima
'cond_scale': p.cfg_scale,
's_min_uncond': self.s_min_uncond
}

samples = self.launch_sampling(steps, lambda: self.func(self.model_wrap_cfg, x, extra_args=self.sampler_extra_args, disable=False, callback=self.callback_state, **extra_params_kwargs))

if self.model_wrap_cfg.padded_cond_uncond:
Expand Down

0 comments on commit f37cc5f

Please sign in to comment.