From 579f1ef278080ff7545be3a42c5fe36fc2890887 Mon Sep 17 00:00:00 2001 From: missionfloyd Date: Sun, 28 Apr 2024 22:36:43 -0600 Subject: [PATCH 1/2] Allow old sampler names in API --- modules/api/api.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/api/api.py b/modules/api/api.py index f468c3852..b1201fe77 100644 --- a/modules/api/api.py +++ b/modules/api/api.py @@ -48,6 +48,15 @@ def validate_sampler_name(name): return name +def parse_old_sampler_name(name): + for scheduler in sd_schedulers.schedulers: + for scheduler_name in [scheduler.label, scheduler.name, *(scheduler.aliases or [])]: + if name.endswith(" " + scheduler_name): + return name[0:-(len(scheduler_name) + 1)], scheduler_name + + return name, "Automatic" + + def setUpscalers(req: dict): reqDict = vars(req) reqDict['extras_upscaler_1'] = reqDict.pop('upscaler_1', None) @@ -438,15 +447,19 @@ class Api: self.apply_infotext(txt2imgreq, "txt2img", script_runner=script_runner, mentioned_script_args=infotext_script_args) selectable_scripts, selectable_script_idx = self.get_selectable_script(txt2imgreq.script_name, script_runner) + sampler, scheduler = parse_old_sampler_name(txt2imgreq.sampler_name or txt2imgreq.sampler_index) populate = txt2imgreq.copy(update={ # Override __init__ params - "sampler_name": validate_sampler_name(txt2imgreq.sampler_name or txt2imgreq.sampler_index), + "sampler_name": validate_sampler_name(sampler), "do_not_save_samples": not txt2imgreq.save_images, "do_not_save_grid": not txt2imgreq.save_images, }) if populate.sampler_name: populate.sampler_index = None # prevent a warning later on + if not populate.scheduler: + populate.scheduler = scheduler + args = vars(populate) args.pop('script_name', None) args.pop('script_args', None) # will refeed them to the pipeline directly after initializing them @@ -502,9 +515,10 @@ class Api: self.apply_infotext(img2imgreq, "img2img", script_runner=script_runner, mentioned_script_args=infotext_script_args) selectable_scripts, selectable_script_idx = self.get_selectable_script(img2imgreq.script_name, script_runner) + sampler, scheduler = parse_old_sampler_name(img2imgreq.sampler_name or img2imgreq.sampler_index) populate = img2imgreq.copy(update={ # Override __init__ params - "sampler_name": validate_sampler_name(img2imgreq.sampler_name or img2imgreq.sampler_index), + "sampler_name": validate_sampler_name(sampler), "do_not_save_samples": not img2imgreq.save_images, "do_not_save_grid": not img2imgreq.save_images, "mask": mask, @@ -512,6 +526,9 @@ class Api: if populate.sampler_name: populate.sampler_index = None # prevent a warning later on + if not populate.scheduler: + populate.scheduler = scheduler + args = vars(populate) args.pop('include_init_images', None) # this is meant to be done by "exclude": True in model, but it's for a reason that I cannot determine. args.pop('script_name', None) From c8336c45b98c2226923503e17b1d7f9170af0f8a Mon Sep 17 00:00:00 2001 From: missionfloyd Date: Tue, 30 Apr 2024 01:53:41 -0600 Subject: [PATCH 2/2] Use existing function for old sampler names --- modules/api/api.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/modules/api/api.py b/modules/api/api.py index b1201fe77..d8e54529b 100644 --- a/modules/api/api.py +++ b/modules/api/api.py @@ -48,15 +48,6 @@ def validate_sampler_name(name): return name -def parse_old_sampler_name(name): - for scheduler in sd_schedulers.schedulers: - for scheduler_name in [scheduler.label, scheduler.name, *(scheduler.aliases or [])]: - if name.endswith(" " + scheduler_name): - return name[0:-(len(scheduler_name) + 1)], scheduler_name - - return name, "Automatic" - - def setUpscalers(req: dict): reqDict = vars(req) reqDict['extras_upscaler_1'] = reqDict.pop('upscaler_1', None) @@ -447,7 +438,7 @@ class Api: self.apply_infotext(txt2imgreq, "txt2img", script_runner=script_runner, mentioned_script_args=infotext_script_args) selectable_scripts, selectable_script_idx = self.get_selectable_script(txt2imgreq.script_name, script_runner) - sampler, scheduler = parse_old_sampler_name(txt2imgreq.sampler_name or txt2imgreq.sampler_index) + sampler, scheduler = sd_samplers.get_sampler_and_scheduler(txt2imgreq.sampler_name or txt2imgreq.sampler_index, txt2imgreq.scheduler) populate = txt2imgreq.copy(update={ # Override __init__ params "sampler_name": validate_sampler_name(sampler), @@ -457,7 +448,7 @@ class Api: if populate.sampler_name: populate.sampler_index = None # prevent a warning later on - if not populate.scheduler: + if not populate.scheduler and scheduler != "Automatic": populate.scheduler = scheduler args = vars(populate) @@ -515,7 +506,7 @@ class Api: self.apply_infotext(img2imgreq, "img2img", script_runner=script_runner, mentioned_script_args=infotext_script_args) selectable_scripts, selectable_script_idx = self.get_selectable_script(img2imgreq.script_name, script_runner) - sampler, scheduler = parse_old_sampler_name(img2imgreq.sampler_name or img2imgreq.sampler_index) + sampler, scheduler = sd_samplers.get_sampler_and_scheduler(img2imgreq.sampler_name or img2imgreq.sampler_index, img2imgreq.scheduler) populate = img2imgreq.copy(update={ # Override __init__ params "sampler_name": validate_sampler_name(sampler), @@ -526,7 +517,7 @@ class Api: if populate.sampler_name: populate.sampler_index = None # prevent a warning later on - if not populate.scheduler: + if not populate.scheduler and scheduler != "Automatic": populate.scheduler = scheduler args = vars(populate)