From f80c3696f63a181f720105559d42ee53453ed0eb Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Fri, 30 Sep 2022 08:21:05 +0300 Subject: [PATCH] fix the sys not found error when importing sd_samplers that appeared after PR --- modules/paths.py | 19 +++++++++++-------- modules/sd_samplers.py | 2 -- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/paths.py b/modules/paths.py index df7b9d9a6..484f04ca7 100644 --- a/modules/paths.py +++ b/modules/paths.py @@ -15,21 +15,24 @@ for possible_sd_path in possible_sd_paths: assert sd_path is not None, "Couldn't find Stable Diffusion in any of: " + str(possible_sd_paths) path_dirs = [ - (sd_path, 'ldm', 'Stable Diffusion'), - (os.path.join(sd_path, '../taming-transformers'), 'taming', 'Taming Transformers'), - (os.path.join(sd_path, '../CodeFormer'), 'inference_codeformer.py', 'CodeFormer'), - (os.path.join(sd_path, '../BLIP'), 'models/blip.py', 'BLIP'), - (os.path.join(sd_path, '../latent-diffusion'), 'LDSR.py', 'LDSR'), - (os.path.join(sd_path, '../k-diffusion'), 'k_diffusion/sampling.py', 'k_diffusion'), + (sd_path, 'ldm', 'Stable Diffusion', []), + (os.path.join(sd_path, '../taming-transformers'), 'taming', 'Taming Transformers', []), + (os.path.join(sd_path, '../CodeFormer'), 'inference_codeformer.py', 'CodeFormer', []), + (os.path.join(sd_path, '../BLIP'), 'models/blip.py', 'BLIP', []), + (os.path.join(sd_path, '../latent-diffusion'), 'LDSR.py', 'LDSR', []), + (os.path.join(sd_path, '../k-diffusion'), 'k_diffusion/sampling.py', 'k_diffusion', ["atstart"]), ] paths = {} -for d, must_exist, what in path_dirs: +for d, must_exist, what, options in path_dirs: must_exist_path = os.path.abspath(os.path.join(script_path, d, must_exist)) if not os.path.exists(must_exist_path): print(f"Warning: {what} not found at path {must_exist_path}", file=sys.stderr) else: d = os.path.abspath(d) - sys.path.append(d) + if "atstart" in options: + sys.path.insert(0, d) + else: + sys.path.append(d) paths[what] = d diff --git a/modules/sd_samplers.py b/modules/sd_samplers.py index 5e60e494b..dff89c092 100644 --- a/modules/sd_samplers.py +++ b/modules/sd_samplers.py @@ -4,8 +4,6 @@ import torch import tqdm from PIL import Image import inspect -from modules.paths import paths -sys.path.insert(0, paths["k_diffusion"]) import k_diffusion.sampling import ldm.models.diffusion.ddim import ldm.models.diffusion.plms