From db580ccefd55515e90e29ad44e19a62ccf40c8a6 Mon Sep 17 00:00:00 2001 From: David Wager Date: Thu, 1 Sep 2022 19:02:57 +0100 Subject: [PATCH 1/4] Create models.yaml models.yaml can serve as a base for expanding our support for other versions of Latent/Stable Diffusion. Contained are parameters for default width/height, as well as where to find the config and weights for this model. Adding a new model is as simple as adding to this file. --- configs/models.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 configs/models.yaml diff --git a/configs/models.yaml b/configs/models.yaml new file mode 100644 index 0000000000..cb4f6b2770 --- /dev/null +++ b/configs/models.yaml @@ -0,0 +1,10 @@ +laion400m: + config: configs/latent-diffusion/txt2img-1p4B-eval.yaml + weights: models/ldm/text2img-large/model.ckpt + width: 256 + height: 256 +stable-diffusion-1.4: + config: configs/stable-diffusion/v1-inference.yaml + weights: models/ldm/stable-diffusion-v1.4/model.ckpt + width: 512 + height: 512 \ No newline at end of file From d319b8a76238a79177c14621a1ff4ec9be5100be Mon Sep 17 00:00:00 2001 From: David Wager Date: Thu, 1 Sep 2022 19:04:31 +0100 Subject: [PATCH 2/4] Reference model from configs/models.yaml By supplying --model (defaulting to stable-diffusion-1.4) a user can specify which model to load. Width/Height/Config Location/Weights Location are referenced from configs/models.yaml --- scripts/dream.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/scripts/dream.py b/scripts/dream.py index 85b2ed5211..fec0475724 100755 --- a/scripts/dream.py +++ b/scripts/dream.py @@ -13,11 +13,13 @@ import ldm.dream.readline from ldm.dream.pngwriter import PngWriter, PromptFormatter from ldm.dream.server import DreamServer, ThreadingDreamServer from ldm.dream.image_util import make_grid +from omegaconf import OmegaConf def main(): """Initialize command-line parsers and the diffusion model""" arg_parser = create_argv_parser() opt = arg_parser.parse_args() + """ if opt.laion400m: # defaults suitable to the older latent diffusion weights width = 256 @@ -33,6 +35,15 @@ def main(): weights = opt.weights else: weights = f'models/ldm/stable-diffusion-v1/{opt.weights}.ckpt' + """ + try: + models = OmegaConf.load('configs/models.yaml') + width = models[opt.model].width + height = models[opt.model].height + config = models[opt.model].config + weights = models[opt.model].weights + except (FileNotFoundError, IOError, KeyError) as e: + print(f'{e}. Aborting.') print('* Initializing, be patient...\n') sys.path.append('.') @@ -426,6 +437,11 @@ def create_argv_parser(): default='model', help='Indicates the Stable Diffusion model to use.', ) + parser.add_argument( + '--model', + default='stable-diffusion-1.4', + help='Indicates which Diffusion model to load.', + ) return parser @@ -540,4 +556,4 @@ def create_cmd_parser(): if __name__ == '__main__': - main() + main() \ No newline at end of file From a4f69e62d720e062a81466458eefb49868b0ad86 Mon Sep 17 00:00:00 2001 From: David Wager Date: Thu, 1 Sep 2022 20:21:39 +0100 Subject: [PATCH 3/4] Set sensible default for 1.4 Use the file that already exists for the majority of users for the default value. --- configs/models.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configs/models.yaml b/configs/models.yaml index cb4f6b2770..9f3920c741 100644 --- a/configs/models.yaml +++ b/configs/models.yaml @@ -5,6 +5,6 @@ laion400m: height: 256 stable-diffusion-1.4: config: configs/stable-diffusion/v1-inference.yaml - weights: models/ldm/stable-diffusion-v1.4/model.ckpt + weights: models/ldm/stable-diffusion-v1/model.ckpt width: 512 - height: 512 \ No newline at end of file + height: 512 From 68eabab2af13658e2de0d748a5839a6acdc29b19 Mon Sep 17 00:00:00 2001 From: David Wager Date: Thu, 1 Sep 2022 20:46:53 +0100 Subject: [PATCH 4/4] Deprecate --laion400m and --weights arguments Removes functionality for the --laion400m and --weights arguments and notifies user to use the --model argument instead. --- scripts/dream.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/scripts/dream.py b/scripts/dream.py index 37ad78ec31..0c0e1e7e6e 100755 --- a/scripts/dream.py +++ b/scripts/dream.py @@ -19,23 +19,14 @@ def main(): """Initialize command-line parsers and the diffusion model""" arg_parser = create_argv_parser() opt = arg_parser.parse_args() - """ + if opt.laion400m: - # defaults suitable to the older latent diffusion weights - width = 256 - height = 256 - config = 'configs/latent-diffusion/txt2img-1p4B-eval.yaml' - weights = 'models/ldm/text2img-large/model.ckpt' - else: - # some defaults suitable for stable diffusion weights - width = 512 - height = 512 - config = 'configs/stable-diffusion/v1-inference.yaml' - if '.ckpt' in opt.weights: - weights = opt.weights - else: - weights = f'models/ldm/stable-diffusion-v1/{opt.weights}.ckpt' - """ + print('--laion400m flag has been deprecated. Please use --model laion400m instead.') + sys.exit(-1) + if opt.weights != 'model': + print('--weights argument has been deprecated. Please configure /configs/models.yaml, and call it using --model instead.') + sys.exit(-1) + try: models = OmegaConf.load('configs/models.yaml') width = models[opt.model].width @@ -44,6 +35,7 @@ def main(): weights = models[opt.model].weights except (FileNotFoundError, IOError, KeyError) as e: print(f'{e}. Aborting.') + sys.exit(-1) print('* Initializing, be patient...\n') sys.path.append('.') @@ -555,4 +547,4 @@ def create_cmd_parser(): if __name__ == '__main__': - main() \ No newline at end of file + main()