2024-01-08 05:43:39 -07:00
|
|
|
from modules import sd_samplers_kdiffusion, sd_samplers_timesteps, sd_samplers_lcm, shared
|
2022-09-03 03:08:45 -06:00
|
|
|
|
2023-01-29 23:51:06 -07:00
|
|
|
# imports for functions that previously were here and are used by other modules
|
2023-05-10 00:02:23 -06:00
|
|
|
from modules.sd_samplers_common import samples_to_image_grid, sample_to_image # noqa: F401
|
2022-09-03 08:21:15 -06:00
|
|
|
|
2022-10-06 03:08:48 -06:00
|
|
|
all_samplers = [
|
2023-01-30 00:11:30 -07:00
|
|
|
*sd_samplers_kdiffusion.samplers_data_k_diffusion,
|
2023-08-08 10:20:11 -06:00
|
|
|
*sd_samplers_timesteps.samplers_data_timesteps,
|
2024-01-08 05:43:39 -07:00
|
|
|
*sd_samplers_lcm.samplers_data_lcm,
|
2022-09-03 03:08:45 -06:00
|
|
|
]
|
2022-11-19 02:01:51 -07:00
|
|
|
all_samplers_map = {x.name: x for x in all_samplers}
|
2022-10-06 03:08:48 -06:00
|
|
|
|
|
|
|
samplers = []
|
|
|
|
samplers_for_img2img = []
|
2022-11-27 03:43:10 -07:00
|
|
|
samplers_map = {}
|
2023-08-08 12:28:34 -06:00
|
|
|
samplers_hidden = {}
|
2022-10-06 03:08:48 -06:00
|
|
|
|
|
|
|
|
2023-05-16 02:54:02 -06:00
|
|
|
def find_sampler_config(name):
|
2022-11-19 02:01:51 -07:00
|
|
|
if name is not None:
|
|
|
|
config = all_samplers_map.get(name, None)
|
|
|
|
else:
|
|
|
|
config = all_samplers[0]
|
|
|
|
|
2023-05-16 02:54:02 -06:00
|
|
|
return config
|
|
|
|
|
|
|
|
|
|
|
|
def create_sampler(name, model):
|
|
|
|
config = find_sampler_config(name)
|
|
|
|
|
2022-11-19 02:01:51 -07:00
|
|
|
assert config is not None, f'bad sampler name: {name}'
|
|
|
|
|
2023-07-14 12:41:21 -06:00
|
|
|
if model.is_sdxl and config.options.get("no_sdxl", False):
|
|
|
|
raise Exception(f"Sampler {config.name} is not supported for SDXL")
|
|
|
|
|
2022-10-06 05:12:52 -06:00
|
|
|
sampler = config.constructor(model)
|
|
|
|
sampler.config = config
|
2022-11-19 02:01:51 -07:00
|
|
|
|
2022-10-06 05:12:52 -06:00
|
|
|
return sampler
|
|
|
|
|
|
|
|
|
2022-10-06 03:08:48 -06:00
|
|
|
def set_samplers():
|
2023-08-08 12:28:34 -06:00
|
|
|
global samplers, samplers_for_img2img, samplers_hidden
|
2022-10-06 03:08:48 -06:00
|
|
|
|
2023-08-08 12:28:34 -06:00
|
|
|
samplers_hidden = set(shared.opts.hide_samplers)
|
|
|
|
samplers = all_samplers
|
|
|
|
samplers_for_img2img = all_samplers
|
2022-10-06 03:08:48 -06:00
|
|
|
|
2022-11-27 03:43:10 -07: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 03:08:48 -06:00
|
|
|
|
2023-08-08 12:28:34 -06:00
|
|
|
def visible_sampler_names():
|
|
|
|
return [x.name for x in samplers if x.name not in samplers_hidden]
|
|
|
|
|
|
|
|
|
2022-10-06 03:08:48 -06:00
|
|
|
set_samplers()
|