Skip to content

Commit 5d90e16

Browse files
sync: update submodule
1 parent 9221405 commit 5d90e16

File tree

6 files changed

+80
-52
lines changed

6 files changed

+80
-52
lines changed

stable_diffusion_cpp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
# isort: on
66

7-
__version__ = "0.2.5"
7+
__version__ = "0.2.6"

stable_diffusion_cpp/stable_diffusion.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ def txt_to_img(
187187
clip_skip: int = -1,
188188
cfg_scale: float = 7.0,
189189
guidance: float = 3.5,
190+
eta: float = 0.0,
190191
width: int = 512,
191192
height: int = 512,
192193
sample_method: Optional[Union[str, SampleMethod, int, float]] = "euler_a",
@@ -214,6 +215,7 @@ def txt_to_img(
214215
clip_skip: Ignore last layers of CLIP network; 1 ignores none, 2 ignores one layer.
215216
cfg_scale: Unconditional guidance scale.
216217
guidance: Guidance scale.
218+
eta: Eta in DDIM, only for DDIM and TCD.
217219
width: Image height, in pixel space.
218220
height: Image width, in pixel space.
219221
sample_method: Sampling method.
@@ -286,6 +288,7 @@ def sd_progress_callback(
286288
clip_skip,
287289
cfg_scale,
288290
guidance,
291+
eta,
289292
width,
290293
height,
291294
sample_method,
@@ -320,6 +323,7 @@ def img_to_img(
320323
clip_skip: int = -1,
321324
cfg_scale: float = 7.0,
322325
guidance: float = 3.5,
326+
eta: float = 0.0,
323327
width: int = 512,
324328
height: int = 512,
325329
sample_method: Optional[Union[str, SampleMethod, int, float]] = "euler_a",
@@ -350,6 +354,7 @@ def img_to_img(
350354
clip_skip: Ignore last layers of CLIP network; 1 ignores none, 2 ignores one layer.
351355
cfg_scale: Unconditional guidance scale.
352356
guidance: Guidance scale.
357+
eta: Eta in DDIM, only for DDIM and TCD.
353358
width: Image height, in pixel space.
354359
height: Image width, in pixel space.
355360
sample_method: Sampling method.
@@ -451,6 +456,7 @@ def _create_blank_mask_image(width: int, height: int):
451456
clip_skip,
452457
cfg_scale,
453458
guidance,
459+
eta,
454460
width,
455461
height,
456462
sample_method,
@@ -941,6 +947,8 @@ def validate_and_set_input(user_input: Union[str, int, float], type_map: Dict, a
941947
"ipndm": SampleMethod.IPNDM,
942948
"ipndm_v": SampleMethod.IPNDM_V,
943949
"lcm": SampleMethod.LCM,
950+
"ddim_trailing": SampleMethod.DDIM_TRAILING,
951+
"tcd": SampleMethod.TCD,
944952
"n_sample_methods": SampleMethod.N_SAMPLE_METHODS,
945953
}
946954

@@ -985,11 +993,14 @@ def validate_and_set_input(user_input: Union[str, int, float], type_map: Dict, a
985993
"f64": GGMLType.SD_TYPE_F64,
986994
"iq1_m": GGMLType.SD_TYPE_IQ1_M,
987995
"bf16": GGMLType.SD_TYPE_BF16,
988-
"q4_0_4_4": GGMLType.SD_TYPE_Q4_0_4_4,
989-
"q4_0_4_8": GGMLType.SD_TYPE_Q4_0_4_8,
990-
"q4_0_8_8": GGMLType.SD_TYPE_Q4_0_8_8,
996+
# "q4_0_4_4": GGMLType.SD_TYPE_Q4_0_4_4,
997+
# "q4_0_4_8": GGMLType.SD_TYPE_Q4_0_4_8,
998+
# "q4_0_8_8": GGMLType.SD_TYPE_Q4_0_8_8,
991999
"tq1_0": GGMLType.SD_TYPE_TQ1_0,
9921000
"tq2_0": GGMLType.SD_TYPE_TQ2_0,
1001+
# "iq4_nl_4_4": GGMLType.SD_TYPE_IQ4_NL_4_4,
1002+
# "iq4_nl_4_8": GGMLType.SD_TYPE_IQ4_NL_4_8,
1003+
# "iq4_nl_8_8": GGMLType.SD_TYPE_IQ4_NL_8_8,
9931004
# Default
9941005
"default": GGMLType.SD_TYPE_COUNT,
9951006
}

stable_diffusion_cpp/stable_diffusion_cpp.py

Lines changed: 57 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ class RNGType(IntEnum):
173173
# IPNDM,
174174
# IPNDM_V,
175175
# LCM,
176+
# DDIM_TRAILING,
177+
# TCD,
176178
# N_SAMPLE_METHODS
177179
# };
178180
class SampleMethod(IntEnum):
@@ -186,7 +188,9 @@ class SampleMethod(IntEnum):
186188
IPNDM = 7
187189
IPNDM_V = 8
188190
LCM = 9
189-
N_SAMPLE_METHODS = 10
191+
DDIM_TRAILING = 10
192+
TCD = 11
193+
N_SAMPLE_METHODS = 12
190194

191195

192196
# enum schedule_t {
@@ -210,43 +214,46 @@ class Schedule(IntEnum):
210214

211215
# // same as enum ggml_type
212216
# enum sd_type_t {
213-
# SD_TYPE_F32 = 0,
214-
# SD_TYPE_F16 = 1,
215-
# SD_TYPE_Q4_0 = 2,
216-
# SD_TYPE_Q4_1 = 3,
217+
# SD_TYPE_F32 = 0,
218+
# SD_TYPE_F16 = 1,
219+
# SD_TYPE_Q4_0 = 2,
220+
# SD_TYPE_Q4_1 = 3,
217221
# // SD_TYPE_Q4_2 = 4, support has been removed
218222
# // SD_TYPE_Q4_3 = 5, support has been removed
219-
# SD_TYPE_Q5_0 = 6,
220-
# SD_TYPE_Q5_1 = 7,
221-
# SD_TYPE_Q8_0 = 8,
222-
# SD_TYPE_Q8_1 = 9,
223-
# SD_TYPE_Q2_K = 10,
224-
# SD_TYPE_Q3_K = 11,
225-
# SD_TYPE_Q4_K = 12,
226-
# SD_TYPE_Q5_K = 13,
227-
# SD_TYPE_Q6_K = 14,
228-
# SD_TYPE_Q8_K = 15,
229-
# SD_TYPE_IQ2_XXS = 16,
230-
# SD_TYPE_IQ2_XS = 17,
231-
# SD_TYPE_IQ3_XXS = 18,
232-
# SD_TYPE_IQ1_S = 19,
233-
# SD_TYPE_IQ4_NL = 20,
234-
# SD_TYPE_IQ3_S = 21,
235-
# SD_TYPE_IQ2_S = 22,
236-
# SD_TYPE_IQ4_XS = 23,
237-
# SD_TYPE_I8 = 24,
238-
# SD_TYPE_I16 = 25,
239-
# SD_TYPE_I32 = 26,
240-
# SD_TYPE_I64 = 27,
241-
# SD_TYPE_F64 = 28,
242-
# SD_TYPE_IQ1_M = 29,
243-
# SD_TYPE_BF16 = 30,
244-
# SD_TYPE_Q4_0_4_4 = 31,
245-
# SD_TYPE_Q4_0_4_8 = 32,
246-
# SD_TYPE_Q4_0_8_8 = 33,
247-
# SD_TYPE_TQ1_0 = 34,
248-
# SD_TYPE_TQ2_0 = 35,
249-
# SD_TYPE_COUNT,
223+
# SD_TYPE_Q5_0 = 6,
224+
# SD_TYPE_Q5_1 = 7,
225+
# SD_TYPE_Q8_0 = 8,
226+
# SD_TYPE_Q8_1 = 9,
227+
# SD_TYPE_Q2_K = 10,
228+
# SD_TYPE_Q3_K = 11,
229+
# SD_TYPE_Q4_K = 12,
230+
# SD_TYPE_Q5_K = 13,
231+
# SD_TYPE_Q6_K = 14,
232+
# SD_TYPE_Q8_K = 15,
233+
# SD_TYPE_IQ2_XXS = 16,
234+
# SD_TYPE_IQ2_XS = 17,
235+
# SD_TYPE_IQ3_XXS = 18,
236+
# SD_TYPE_IQ1_S = 19,
237+
# SD_TYPE_IQ4_NL = 20,
238+
# SD_TYPE_IQ3_S = 21,
239+
# SD_TYPE_IQ2_S = 22,
240+
# SD_TYPE_IQ4_XS = 23,
241+
# SD_TYPE_I8 = 24,
242+
# SD_TYPE_I16 = 25,
243+
# SD_TYPE_I32 = 26,
244+
# SD_TYPE_I64 = 27,
245+
# SD_TYPE_F64 = 28,
246+
# SD_TYPE_IQ1_M = 29,
247+
# SD_TYPE_BF16 = 30,
248+
# // SD_TYPE_Q4_0_4_4 = 31, support has been removed from gguf files
249+
# // SD_TYPE_Q4_0_4_8 = 32,
250+
# // SD_TYPE_Q4_0_8_8 = 33,
251+
# SD_TYPE_TQ1_0 = 34,
252+
# SD_TYPE_TQ2_0 = 35,
253+
# // SD_TYPE_IQ4_NL_4_4 = 36,
254+
# // SD_TYPE_IQ4_NL_4_8 = 37,
255+
# // SD_TYPE_IQ4_NL_8_8 = 38,
256+
# SD_TYPE_COUNT = 39,
250257
# };
251258
class GGMLType(IntEnum):
252259
SD_TYPE_F32 = 0
@@ -281,12 +288,15 @@ class GGMLType(IntEnum):
281288
SD_TYPE_F64 = 28
282289
SD_TYPE_IQ1_M = 29
283290
SD_TYPE_BF16 = 30
284-
SD_TYPE_Q4_0_4_4 = 31
285-
SD_TYPE_Q4_0_4_8 = 32
286-
SD_TYPE_Q4_0_8_8 = 33
291+
# SD_TYPE_Q4_0_4_4 = 31 # support has been removed from gguf files
292+
# SD_TYPE_Q4_0_4_8 = 32
293+
# SD_TYPE_Q4_0_8_8 = 33
287294
SD_TYPE_TQ1_0 = 34
288295
SD_TYPE_TQ2_0 = 35
289-
SD_TYPE_COUNT = 36
296+
# SD_TYPE_IQ4_NL_4_4 = 36,
297+
# SD_TYPE_IQ4_NL_4_8 = 37,
298+
# SD_TYPE_IQ4_NL_8_8 = 38,
299+
SD_TYPE_COUNT = 39
290300

291301

292302
# ==================================
@@ -387,7 +397,7 @@ class sd_image_t(ctypes.Structure):
387397
# ------------ txt2img ------------
388398

389399

390-
# SD_API sd_image_t* txt2img(sd_ctx_t* sd_ctx, const char* prompt, const char* negative_prompt, int clip_skip, float cfg_scale, float guidance, int width, int height, enum sample_method_t sample_method, int sample_steps, int64_t seed, int batch_count, const sd_image_t* control_cond, float control_strength, float style_strength, bool normalize_input, const char* input_id_images_path, int* skip_layers, size_t skip_layers_count, float slg_scale, float skip_layer_start, float skip_layer_end);
400+
# SD_API sd_image_t* txt2img(sd_ctx_t* sd_ctx, const char* prompt, const char* negative_prompt, int clip_skip, float cfg_scale, float guidance, float eta, int width, int height, enum sample_method_t sample_method, int sample_steps, int64_t seed, int batch_count, const sd_image_t* control_cond, float control_strength, float style_strength, bool normalize_input, const char* input_id_images_path, int* skip_layers, size_t skip_layers_count, float slg_scale, float skip_layer_start, float skip_layer_end);
391401
@ctypes_function(
392402
"txt2img",
393403
[
@@ -397,6 +407,7 @@ class sd_image_t(ctypes.Structure):
397407
ctypes.c_int, # clip_skip
398408
ctypes.c_float, # cfg_scale
399409
ctypes.c_float, # guidance
410+
ctypes.c_float, # eta
400411
ctypes.c_int, # width
401412
ctypes.c_int, # height
402413
ctypes.c_int, # sample_method
@@ -423,6 +434,7 @@ def txt2img(
423434
clip_skip: int,
424435
cfg_scale: float,
425436
guidance: float,
437+
eta: float,
426438
width: int,
427439
height: int,
428440
sample_method: int, # SampleMethod
@@ -446,18 +458,19 @@ def txt2img(
446458
# ------------ img2img ------------
447459

448460

449-
# SD_API sd_image_t* img2img(sd_ctx_t* sd_ctx, sd_image_t init_image, sd_image_t mask_image, const char* prompt, const char* negative_prompt, int clip_skip, float cfg_scale, float guidance, int width, int height, enum sample_method_t sample_method, int sample_steps, float strength, int64_t seed, int batch_count, const sd_image_t* control_cond, float control_strength, float style_strength, bool normalize_input, const char* input_id_images_path, int* skip_layers, size_t skip_layers_count, float slg_scale, float skip_layer_start, float skip_layer_end);
461+
# SD_API sd_image_t* img2img(sd_ctx_t* sd_ctx, sd_image_t init_image, sd_image_t mask_image, const char* prompt, const char* negative_prompt, int clip_skip, float cfg_scale, float guidance, float eta, int width, int height, enum sample_method_t sample_method, int sample_steps, float strength, int64_t seed, int batch_count, const sd_image_t* control_cond, float control_strength, float style_strength, bool normalize_input, const char* input_id_images_path, int* skip_layers, size_t skip_layers_count, float slg_scale, float skip_layer_start, float skip_layer_end);
450462
@ctypes_function(
451463
"img2img",
452464
[
453465
sd_ctx_t_p_ctypes, # sd_ctx
454466
sd_image_t, # init_image
455-
sd_image_t, # mask_image
467+
sd_image_t, # mask_image
456468
ctypes.c_char_p, # prompt
457469
ctypes.c_char_p, # negative_prompt
458470
ctypes.c_int, # clip_skip
459471
ctypes.c_float, # cfg_scale
460472
ctypes.c_float, # guidance
473+
ctypes.c_float, # eta
461474
ctypes.c_int, # width
462475
ctypes.c_int, # height
463476
ctypes.c_int, # sample_method
@@ -487,6 +500,7 @@ def img2img(
487500
clip_skip: int,
488501
cfg_scale: float,
489502
guidance: float,
503+
eta: float,
490504
width: int,
491505
height: int,
492506
sample_method: int, # SampleMethod

tests/test_txt2img.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from stable_diffusion_cpp import StableDiffusion
55

66
# MODEL_PATH = "C:\\stable-diffusion\\turbovisionxlSuperFastXLBasedOnNew_tvxlV431Bakedvae.q8_0.gguf" # GGUF model wont work for LORAs (GGML_ASSERT error)
7-
MODEL_PATH = "C:\\stable-diffusion\\turbovisionxlSuperFastXLBasedOnNew_tvxlV431Bakedvae.safetensors"
7+
# MODEL_PATH = "C:\\stable-diffusion\\turbovisionxlSuperFastXLBasedOnNew_tvxlV431Bakedvae.safetensors"
8+
MODEL_PATH = "C:\\stable-diffusion\\catCitronAnimeTreasure_v10.safetensors"
89

910
LORA_DIR = "C:\\stable-diffusion\\loras"
1011

@@ -20,8 +21,10 @@ def callback(step: int, steps: int, time: float):
2021

2122
try:
2223
prompts = [
23-
{"add": "_lora", "prompt": "a lovely cat <lora:pixel_art:1>"}, # With LORA
24-
{"add": "", "prompt": "a lovely cat"}, # Without LORA
24+
# {"add": "_lora", "prompt": "a lovely cat <lora:realism_lora:1>"}, # With LORA
25+
# {"add": "", "prompt": "a lovely cat"}, # Without LORA
26+
{"add": "_lora", "prompt": "a cute cat glass statue <lora:glass_statue_v1:1>"}, # With LORA
27+
{"add": "2", "prompt": "a cute cat glass statue"}, # Without LORA
2528
]
2629

2730
OUTPUT_DIR = "tests/outputs"

tests/tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
```bash
2-
python tests\test_controlnet.py; python tests\test_convert_model.py; python tests\test_flux.py; python tests\test_img2img.py; python tests\test_preprocess_canny.py; python tests\test_system_info.py; python tests\test_txt2img.py; python tests\test_upscale.py; python tests\test_photomaker.py; python tests\test_inpainting.py
2+
python tests\test_txt2img.py; python tests\test_controlnet.py; python tests\test_convert_model.py; python tests\test_flux.py; python tests\test_img2img.py; python tests\test_preprocess_canny.py; python tests\test_system_info.py; python tests\test_upscale.py; python tests\test_photomaker.py; python tests\test_inpainting.py
33
```
44

55
```bash

0 commit comments

Comments
 (0)