From 234523784472fcb2e4245f502dba7aef08f5c41a Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Mon, 19 Jun 2023 09:13:17 -0400 Subject: [PATCH] fix race condition on model load via api --- TODO.md | 2 ++ cli/simple-txt2txt.py | 3 +++ modules/sd_models.py | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index df4f26949..23466b135 100644 --- a/TODO.md +++ b/TODO.md @@ -14,6 +14,8 @@ Stuff to be added... - Import core repos - Update `train.py` to use `interrogator` - Update `train.py` to use `rembg` +- Create new train UI +- Create new Models UI ## Investigate diff --git a/cli/simple-txt2txt.py b/cli/simple-txt2txt.py index 34fadb4c5..1332979d9 100755 --- a/cli/simple-txt2txt.py +++ b/cli/simple-txt2txt.py @@ -9,6 +9,7 @@ from PIL import Image logging.basicConfig(level = logging.INFO, format = '%(asctime)s %(levelname)s: %(message)s') log = logging.getLogger(__name__) sd_url = "http://127.0.0.1:7860" +model = "realistic-vision-v13" options = { "prompt": "city at night", "negative_prompt": "foggy, blurry", @@ -33,6 +34,8 @@ def post(endpoint: str, dct: dict = None): def generate(num: int = 0): log.info(f'sending generate request: {num+1} {options}') + if model is not None: + post('/sdapi/v1/options', { 'sd_model_checkpoint': model }) data = post('/sdapi/v1/txt2img', options) if 'images' in data: for i in range(len(data['images'])): diff --git a/modules/sd_models.py b/modules/sd_models.py index 1d7bd8af5..b9977ccb2 100644 --- a/modules/sd_models.py +++ b/modules/sd_models.py @@ -617,7 +617,7 @@ def reload_model_weights(sd_model=None, info=None, reuse_dict=False): current_checkpoint_info = None else: current_checkpoint_info = sd_model.sd_checkpoint_info - if checkpoint_info is not None and sd_model.sd_model_checkpoint == checkpoint_info.filename: + if checkpoint_info is not None and current_checkpoint_info.filename == checkpoint_info.filename: return if shared.cmd_opts.lowvram or shared.cmd_opts.medvram: lowvram.send_everything_to_cpu()