diff --git a/CHANGELOG.md b/CHANGELOG.md index 34709c38a..de4886be9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -111,6 +111,8 @@ SD.Next will warn on startup on unused cache entries that can be removed. Also, - **API** - add `/sdapi/v1/checkpoint` POST endpoint to simply load a model - add `/sdapi/v1/modules` GET endpoint to get info on model components/modules + - all generate endpoints now support `sd_model_checkpoint` parameter + this allows to specify which model to use for generation without needing to use additional endpoints - **Refactor** - change default huggingface cache folder from system default to `models/huggingface` sd.next will warn on startup on unused cache entries diff --git a/extensions-builtin/sdnext-modernui b/extensions-builtin/sdnext-modernui index c302e359a..574fcf4e8 160000 --- a/extensions-builtin/sdnext-modernui +++ b/extensions-builtin/sdnext-modernui @@ -1 +1 @@ -Subproject commit c302e359ac268d04537fc190cccbb834cfe1fe5f +Subproject commit 574fcf4e8790e6faf3a3a500e4aedf399d0b0e4a diff --git a/modules/processing.py b/modules/processing.py index 675ac9160..2a5087d37 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -119,6 +119,9 @@ def process_images(p: StableDiffusionProcessing) -> Processed: if not hasattr(p.sd_model, 'sd_checkpoint_info'): shared.log.error('Processing: incomplete model') return None + if p.abort: + shared.log.debug('Processing: aborted') + return None if p.scripts is not None and isinstance(p.scripts, scripts_manager.ScriptRunner): p.scripts.before_process(p) stored_opts = {} diff --git a/modules/processing_class.py b/modules/processing_class.py index daff8ccea..8b02e38aa 100644 --- a/modules/processing_class.py +++ b/modules/processing_class.py @@ -15,6 +15,7 @@ debug = shared.log.trace if os.environ.get('SD_PROCESS_DEBUG', None) is not None @dataclass(repr=False) class StableDiffusionProcessing: def __init__(self, + sd_model_checkpoint: str = None, # # used only to set sd_model sd_model=None, # pylint: disable=unused-argument # local instance of sd_model # base params prompt: str = "", @@ -355,6 +356,17 @@ class StableDiffusionProcessing: self.prompt_attention_masks = [] self.negative_prompt_attention_mask = [] self.xyz = xyz + self.abort = False + + # set model + if sd_model_checkpoint is not None and len(sd_model_checkpoint) > 0: + from modules import sd_checkpoint + if sd_checkpoint.select_checkpoint(op='model', sd_model_checkpoint=sd_model_checkpoint) is None: + shared.log.error(f'Processing: model="{sd_model_checkpoint}" not found') + self.abort = True + else: + shared.opts.sd_model_checkpoint = sd_model_checkpoint + sd_models.reload_model_weights() def __str__(self): return f'{self.__class__.__name__}: {self.__dict__}' diff --git a/modules/sd_checkpoint.py b/modules/sd_checkpoint.py index 5dd08cca6..6afc5b953 100644 --- a/modules/sd_checkpoint.py +++ b/modules/sd_checkpoint.py @@ -269,8 +269,8 @@ def model_hash(filename): return 'NOHASH' -def select_checkpoint(op='model'): - model_checkpoint = shared.opts.data.get('sd_model_refiner', None) if op == 'refiner' else shared.opts.data.get('sd_model_checkpoint', None) +def select_checkpoint(op='model', sd_model_checkpoint=None): + model_checkpoint = sd_model_checkpoint or (shared.opts.data.get('sd_model_refiner', None) if op == 'refiner' else shared.opts.data.get('sd_model_checkpoint', None)) if model_checkpoint is None or model_checkpoint == 'None' or len(model_checkpoint) < 3: return None checkpoint_info = get_closet_checkpoint_match(model_checkpoint)