|
9 | 9 |
|
10 | 10 |
|
11 | 11 | def guess_by_size(fn, current_guess): |
| 12 | + new_guess = None |
12 | 13 | if os.path.isfile(fn) and fn.endswith('.safetensors'): |
13 | 14 | size = round(os.path.getsize(fn) / 1024 / 1024) |
14 | 15 | if (size > 0 and size < 128): |
15 | 16 | shared.log.warning(f'Model size smaller than expected: file="{fn}" size={size} MB') |
16 | 17 | elif (size >= 316 and size <= 324) or (size >= 156 and size <= 164): # 320 or 160 |
17 | 18 | shared.log.warning(f'Model detected as VAE model, but attempting to load as model: file="{fn}" size={size} MB') |
18 | | - return 'VAE' |
| 19 | + new_guess = 'VAE' |
19 | 20 | elif (size >= 2002 and size <= 2038): # 2032 |
20 | | - return 'Stable Diffusion 1.5' |
| 21 | + new_guess = 'Stable Diffusion 1.5' |
21 | 22 | elif (size >= 3138 and size <= 3142): #3140 |
22 | | - return 'Stable Diffusion XL' |
| 23 | + new_guess = 'Stable Diffusion XL' |
23 | 24 | elif (size >= 3361 and size <= 3369): # 3368 |
24 | | - return 'Stable Diffusion Upscale' |
| 25 | + new_guess = 'Stable Diffusion Upscale' |
25 | 26 | elif (size >= 4891 and size <= 4899): # 4897 |
26 | | - return 'Stable Diffusion XL Inpaint' |
| 27 | + new_guess = 'Stable Diffusion XL Inpaint' |
27 | 28 | elif (size >= 4970 and size <= 4976): # 4973 |
28 | | - return 'Stable Diffusion 2' # SD v2 but could be eps or v-prediction |
| 29 | + new_guess = 'Stable Diffusion 2' # SD v2 but could be eps or v-prediction |
29 | 30 | elif (size >= 5791 and size <= 5799): # 5795 |
30 | | - return 'Stable Diffusion XL Refiner' |
| 31 | + new_guess = 'Stable Diffusion XL Refiner' |
31 | 32 | elif (size > 5692 and size < 5698) or (size > 4134 and size < 4138) or (size > 10362 and size < 10366) or (size > 15028 and size < 15228): |
32 | | - return 'Stable Diffusion 3' |
| 33 | + new_guess = 'Stable Diffusion 3' |
33 | 34 | elif (size >= 6420 and size <= 7220): # 6420, IustriousRedux is 6541, monkrenRealisticINT_v10 is 7217 |
34 | | - return 'Stable Diffusion XL' |
| 35 | + new_guess = 'Stable Diffusion XL' |
35 | 36 | elif (size >= 9791 and size <= 9799): # 9794 |
36 | | - return 'Stable Diffusion XL Instruct' |
| 37 | + new_guess = 'Stable Diffusion XL Instruct' |
37 | 38 | elif (size >= 18414 and size <= 18420): # sd35-large aio |
38 | | - return 'Stable Diffusion 3' |
| 39 | + new_guess = 'Stable Diffusion 3' |
39 | 40 | elif (size >= 20000 and size <= 40000): |
40 | | - return 'FLUX' |
41 | | - return current_guess |
| 41 | + new_guess = 'FLUX' |
| 42 | + if debug_load: |
| 43 | + shared.log.trace(f'Autodetect: method=size file="{fn}" size={size} previous="{current_guess}" current="{new_guess}"') |
| 44 | + return new_guess or current_guess |
42 | 45 |
|
43 | 46 |
|
44 | 47 | def guess_by_name(fn, current_guess): |
| 48 | + new_guess = None |
45 | 49 | if 'instaflow' in fn.lower(): |
46 | | - return 'InstaFlow' |
| 50 | + new_guess = 'InstaFlow' |
47 | 51 | elif 'segmoe' in fn.lower(): |
48 | | - return 'SegMoE' |
| 52 | + new_guess = 'SegMoE' |
49 | 53 | elif 'hunyuandit' in fn.lower(): |
50 | | - return 'HunyuanDiT' |
| 54 | + new_guess = 'HunyuanDiT' |
51 | 55 | elif 'hdm-xut' in fn.lower(): |
52 | | - return 'hdm' |
| 56 | + new_guess = 'hdm' |
53 | 57 | elif 'pixart-xl' in fn.lower(): |
54 | | - return 'PixArt Alpha' |
| 58 | + new_guess = 'PixArt Alpha' |
55 | 59 | elif 'stable-diffusion-3' in fn.lower(): |
56 | | - return 'Stable Diffusion 3' |
| 60 | + new_guess = 'Stable Diffusion 3' |
57 | 61 | elif 'stable-cascade' in fn.lower() or 'stablecascade' in fn.lower() or 'wuerstchen3' in fn.lower() or ('sotediffusion' in fn.lower() and "v2" in fn.lower()): |
58 | 62 | if devices.dtype == torch.float16: |
59 | 63 | shared.log.warning('Stable Cascade does not support Float16') |
60 | | - return 'Stable Cascade' |
| 64 | + new_guess = 'Stable Cascade' |
61 | 65 | elif 'pixart-sigma' in fn.lower(): |
62 | | - return 'PixArt Sigma' |
| 66 | + new_guess = 'PixArt Sigma' |
63 | 67 | elif 'sana' in fn.lower(): |
64 | | - return 'Sana' |
| 68 | + new_guess = 'Sana' |
65 | 69 | elif 'lumina-next' in fn.lower(): |
66 | | - return 'Lumina-Next' |
| 70 | + new_guess = 'Lumina-Next' |
67 | 71 | elif 'lumina-image-2' in fn.lower(): |
68 | | - return 'Lumina 2' |
| 72 | + new_guess = 'Lumina 2' |
69 | 73 | elif 'kolors' in fn.lower(): |
70 | | - return 'Kolors' |
| 74 | + new_guess = 'Kolors' |
71 | 75 | elif 'auraflow' in fn.lower() or 'pony-v7' in fn.lower(): |
72 | | - return 'AuraFlow' |
| 76 | + new_guess = 'AuraFlow' |
73 | 77 | elif 'cogview3' in fn.lower(): |
74 | | - return 'CogView 3' |
| 78 | + new_guess = 'CogView 3' |
75 | 79 | elif 'cogview4' in fn.lower(): |
76 | | - return 'CogView 4' |
| 80 | + new_guess = 'CogView 4' |
77 | 81 | elif 'meissonic' in fn.lower(): |
78 | | - return 'Meissonic' |
| 82 | + new_guess = 'Meissonic' |
79 | 83 | elif 'monetico' in fn.lower(): |
80 | | - return 'Monetico' |
| 84 | + new_guess = 'Monetico' |
81 | 85 | elif 'omnigen2' in fn.lower(): |
82 | | - return 'OmniGen2' |
| 86 | + new_guess = 'OmniGen2' |
83 | 87 | elif 'omnigen' in fn.lower(): |
84 | | - return 'OmniGen' |
| 88 | + new_guess = 'OmniGen' |
85 | 89 | elif 'sd3' in fn.lower(): |
86 | | - return 'Stable Diffusion 3' |
| 90 | + new_guess = 'Stable Diffusion 3' |
87 | 91 | elif 'hidream' in fn.lower(): |
88 | | - return 'HiDream' |
| 92 | + new_guess = 'HiDream' |
89 | 93 | elif 'chroma' in fn.lower() and 'xl' not in fn.lower(): |
90 | | - return 'Chroma' |
| 94 | + new_guess = 'Chroma' |
91 | 95 | elif 'flux' in fn.lower() or 'flex.1' in fn.lower(): |
92 | 96 | size = round(os.path.getsize(fn) / 1024 / 1024) if os.path.isfile(fn) else 0 |
93 | 97 | if size > 11000 and size < 16000: |
94 | 98 | shared.log.warning(f'Model detected as FLUX UNET model, but attempting to load a base model: file="{fn}" size={size} MB') |
95 | | - return 'FLUX' |
| 99 | + new_guess = 'FLUX' |
96 | 100 | elif 'flex.2' in fn.lower(): |
97 | | - return 'FLEX' |
| 101 | + new_guess = 'FLEX' |
98 | 102 | elif 'cosmos-predict2' in fn.lower(): |
99 | | - return 'Cosmos' |
| 103 | + new_guess = 'Cosmos' |
100 | 104 | elif 'f-lite' in fn.lower(): |
101 | | - return 'FLite' |
| 105 | + new_guess = 'FLite' |
102 | 106 | elif 'wan' in fn.lower(): |
103 | | - return 'WanAI' |
| 107 | + new_guess = 'WanAI' |
104 | 108 | if 'chronoedit' in fn.lower(): |
105 | | - return 'ChronoEdit' |
| 109 | + new_guess = 'ChronoEdit' |
106 | 110 | elif 'bria' in fn.lower(): |
107 | | - return 'Bria' |
| 111 | + new_guess = 'Bria' |
108 | 112 | elif 'qwen' in fn.lower(): |
109 | | - return 'Qwen' |
| 113 | + new_guess = 'Qwen' |
110 | 114 | elif 'nextstep' in fn.lower(): |
111 | | - return 'NextStep' |
| 115 | + new_guess = 'NextStep' |
112 | 116 | elif 'kandinsky-2-1' in fn.lower(): |
113 | | - return 'Kandinsky 2.1' |
| 117 | + new_guess = 'Kandinsky 2.1' |
114 | 118 | elif 'kandinsky-2-2' in fn.lower(): |
115 | | - return 'Kandinsky 2.2' |
| 119 | + new_guess = 'Kandinsky 2.2' |
116 | 120 | elif 'kandinsky-3' in fn.lower(): |
117 | | - return 'Kandinsky 3.0' |
| 121 | + new_guess = 'Kandinsky 3.0' |
118 | 122 | elif 'hunyuanimage3' in fn.lower() or 'hunyuanimage-3' in fn.lower(): |
119 | | - return 'HunyuanImage3' |
| 123 | + new_guess = 'HunyuanImage3' |
120 | 124 | elif 'hunyuanimage' in fn.lower(): |
121 | | - return 'HunyuanImage' |
| 125 | + new_guess = 'HunyuanImage' |
122 | 126 | elif 'x-omni' in fn.lower(): |
123 | | - return 'X-Omni' |
| 127 | + new_guess = 'X-Omni' |
124 | 128 | elif 'sdxl-turbo' in fn.lower() or 'stable-diffusion-xl' in fn.lower(): |
125 | | - return 'Stable Diffusion XL' |
126 | | - return current_guess |
| 129 | + new_guess = 'Stable Diffusion XL' |
| 130 | + if debug_load: |
| 131 | + shared.log.trace(f'Autodetect: method=name file="{fn}" previous="{current_guess}" current="{new_guess}"') |
| 132 | + return new_guess or current_guess |
127 | 133 |
|
128 | 134 |
|
129 | 135 | def guess_by_diffusers(fn, current_guess): |
@@ -160,22 +166,27 @@ def guess_by_diffusers(fn, current_guess): |
160 | 166 | if v is not None and v.__name__ == pipeline.__name__: |
161 | 167 | if is_quant: |
162 | 168 | k = f'{k} SDNQ' |
| 169 | + if debug_load: |
| 170 | + shared.log.trace(f'Autodetect: method=diffusers file="{fn}" previous="{current_guess}" current="{k}"') |
163 | 171 | return k, v |
164 | 172 | return current_guess, None |
165 | 173 |
|
166 | 174 |
|
167 | 175 | def guess_variant(fn, current_guess): |
| 176 | + new_guess = None |
168 | 177 | if 'inpaint' in fn.lower(): |
169 | 178 | if current_guess == 'Stable Diffusion': |
170 | | - return 'Stable Diffusion Inpaint' |
| 179 | + new_guess = 'Stable Diffusion Inpaint' |
171 | 180 | elif current_guess == 'Stable Diffusion XL': |
172 | | - return 'Stable Diffusion XL Inpaint' |
| 181 | + new_guess = 'Stable Diffusion XL Inpaint' |
173 | 182 | elif 'instruct' in fn.lower(): |
174 | 183 | if current_guess == 'Stable Diffusion': |
175 | | - return 'Stable Diffusion Instruct' |
| 184 | + new_guess = 'Stable Diffusion Instruct' |
176 | 185 | elif current_guess == 'Stable Diffusion XL': |
177 | | - return 'Stable Diffusion XL Instruct' |
178 | | - return current_guess |
| 186 | + new_guess = 'Stable Diffusion XL Instruct' |
| 187 | + if debug_load: |
| 188 | + shared.log.trace(f'Autodetect: method=variant file="{fn}" previous="{current_guess}" current="{new_guess}"') |
| 189 | + return new_guess or current_guess |
179 | 190 |
|
180 | 191 |
|
181 | 192 | def detect_pipeline(f: str, op: str = 'model'): |
|
0 commit comments