2023-01-30 07:11:30 +00:00
|
|
|
from modules import sd_samplers_compvis, sd_samplers_kdiffusion, shared
|
2022-09-03 09:08:45 +00:00
|
|
|
|
2023-01-30 06:51:06 +00:00
|
|
|
# imports for functions that previously were here and are used by other modules
|
2023-05-10 06:02:23 +00:00
|
|
|
from modules.sd_samplers_common import samples_to_image_grid, sample_to_image # noqa: F401
|
2022-09-03 14:21:15 +00:00
|
|
|
|
2022-10-06 09:08:48 +00:00
|
|
|
all_samplers = [
|
2023-01-30 07:11:30 +00:00
|
|
|
*sd_samplers_kdiffusion.samplers_data_k_diffusion,
|
|
|
|
*sd_samplers_compvis.samplers_data_compvis,
|
2022-09-03 09:08:45 +00:00
|
|
|
]
|
2022-11-19 09:01:51 +00:00
|
|
|
all_samplers_map = {x.name: x for x in all_samplers}
|
2022-10-06 09:08:48 +00:00
|
|
|
|
|
|
|
samplers = []
|
|
|
|
samplers_for_img2img = []
|
2022-11-27 10:43:10 +00:00
|
|
|
samplers_map = {}
|
2022-10-06 09:08:48 +00:00
|
|
|
|
|
|
|
|
2023-05-16 08:54:02 +00:00
|
|
|
def find_sampler_config(name):
|
2022-11-19 09:01:51 +00:00
|
|
|
if name is not None:
|
|
|
|
config = all_samplers_map.get(name, None)
|
|
|
|
else:
|
|
|
|
config = all_samplers[0]
|
|
|
|
|
2023-05-16 08:54:02 +00:00
|
|
|
return config
|
|
|
|
|
|
|
|
|
|
|
|
def create_sampler(name, model):
|
|
|
|
config = find_sampler_config(name)
|
|
|
|
|
2022-11-19 09:01:51 +00:00
|
|
|
assert config is not None, f'bad sampler name: {name}'
|
|
|
|
|
2022-10-06 11:12:52 +00:00
|
|
|
sampler = config.constructor(model)
|
|
|
|
sampler.config = config
|
2022-11-19 09:01:51 +00:00
|
|
|
|
2022-10-06 11:12:52 +00:00
|
|
|
return sampler
|
|
|
|
|
|
|
|
|
2022-10-06 09:08:48 +00:00
|
|
|
def set_samplers():
|
|
|
|
global samplers, samplers_for_img2img
|
|
|
|
|
2023-01-30 07:11:30 +00:00
|
|
|
hidden = set(shared.opts.hide_samplers)
|
2023-02-10 13:00:09 +00:00
|
|
|
hidden_img2img = set(shared.opts.hide_samplers + ['PLMS', 'UniPC'])
|
2022-10-06 09:08:48 +00:00
|
|
|
|
|
|
|
samplers = [x for x in all_samplers if x.name not in hidden]
|
|
|
|
samplers_for_img2img = [x for x in all_samplers if x.name not in hidden_img2img]
|
|
|
|
|
2022-11-27 10:43:10 +00:00
|
|
|
samplers_map.clear()
|
|
|
|
for sampler in all_samplers:
|
|
|
|
samplers_map[sampler.name.lower()] = sampler.name
|
|
|
|
for alias in sampler.aliases:
|
|
|
|
samplers_map[alias.lower()] = sampler.name
|
|
|
|
|
2022-10-06 09:08:48 +00:00
|
|
|
|
|
|
|
set_samplers()
|