comdoleger commited on
Commit
99b524c
·
verified ·
1 Parent(s): 9eee3af

Upload scripts/make_lcm_sdxl_model.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/make_lcm_sdxl_model.py +67 -0
scripts/make_lcm_sdxl_model.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ from collections import OrderedDict
3
+
4
+ import torch
5
+
6
+ from toolkit.config_modules import ModelConfig
7
+ from toolkit.stable_diffusion_model import StableDiffusion
8
+
9
+
10
+ parser = argparse.ArgumentParser()
11
+ parser.add_argument(
12
+ 'input_path',
13
+ type=str,
14
+ help='Path to original sdxl model'
15
+ )
16
+ parser.add_argument(
17
+ 'output_path',
18
+ type=str,
19
+ help='output path'
20
+ )
21
+ parser.add_argument('--sdxl', action='store_true', help='is sdxl model')
22
+ parser.add_argument('--refiner', action='store_true', help='is refiner model')
23
+ parser.add_argument('--ssd', action='store_true', help='is ssd model')
24
+ parser.add_argument('--sd2', action='store_true', help='is sd 2 model')
25
+
26
+ args = parser.parse_args()
27
+ device = torch.device('cpu')
28
+ dtype = torch.float32
29
+
30
+ print(f"Loading model from {args.input_path}")
31
+
32
+ if args.sdxl:
33
+ adapter_id = "latent-consistency/lcm-lora-sdxl"
34
+ if args.refiner:
35
+ adapter_id = "latent-consistency/lcm-lora-sdxl"
36
+ elif args.ssd:
37
+ adapter_id = "latent-consistency/lcm-lora-ssd-1b"
38
+ else:
39
+ adapter_id = "latent-consistency/lcm-lora-sdv1-5"
40
+
41
+
42
+ diffusers_model_config = ModelConfig(
43
+ name_or_path=args.input_path,
44
+ is_xl=args.sdxl,
45
+ is_v2=args.sd2,
46
+ is_ssd=args.ssd,
47
+ dtype=dtype,
48
+ )
49
+ diffusers_sd = StableDiffusion(
50
+ model_config=diffusers_model_config,
51
+ device=device,
52
+ dtype=dtype,
53
+ )
54
+ diffusers_sd.load_model()
55
+
56
+
57
+ print(f"Loaded model from {args.input_path}")
58
+
59
+ diffusers_sd.pipeline.load_lora_weights(adapter_id)
60
+ diffusers_sd.pipeline.fuse_lora()
61
+
62
+ meta = OrderedDict()
63
+
64
+ diffusers_sd.save(args.output_path, meta=meta)
65
+
66
+
67
+ print(f"Saved to {args.output_path}")