From 1a43524018ea3e64b93be2abc2a49b6159515442 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sun, 14 May 2023 13:27:50 +0300 Subject: [PATCH] fix model loading twice in some situations --- modules/sd_hijack.py | 3 +++ modules/sd_models.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/modules/sd_hijack.py b/modules/sd_hijack.py index 7e50f1abc..14e7f7993 100644 --- a/modules/sd_hijack.py +++ b/modules/sd_hijack.py @@ -216,6 +216,9 @@ class StableDiffusionModelHijack: self.comments = [] def get_prompt_lengths(self, text): + if self.clip is None: + return "-", "-" + _, token_count = self.clip.process_texts([text]) return token_count, self.clip.get_target_prompt_token_count(token_count) diff --git a/modules/sd_models.py b/modules/sd_models.py index 4c9a0a1fb..dddbc6e1c 100644 --- a/modules/sd_models.py +++ b/modules/sd_models.py @@ -414,6 +414,9 @@ class SdModelData: def get_sd_model(self): if self.sd_model is None: with self.lock: + if self.sd_model is not None: + return self.sd_model + try: load_model() except Exception as e: