@@ -810,7 +810,7 @@ class StableDiffusionGGML {
810
810
int step,
811
811
struct ggml_tensor * latents,
812
812
enum SDVersion version,
813
- sd_preview_policy_t preview_mode,
813
+ sd_preview_t preview_mode,
814
814
ggml_tensor* result,
815
815
std::function<void (int , sd_image_t )> step_callback) {
816
816
const uint32_t channel = 3 ;
@@ -922,14 +922,11 @@ class StableDiffusionGGML {
922
922
const std::vector<float >& sigmas,
923
923
int start_merge_step,
924
924
SDCondition id_cond,
925
- std::vector<int > skip_layers = {},
926
- float slg_scale = 0 ,
927
- float skip_layer_start = 0.01 ,
928
- float skip_layer_end = 0.2 ,
929
- ggml_tensor* noise_mask = nullptr ,
930
- sd_preview_policy_t preview_mode = SD_PREVIEW_NONE,
931
- int preview_interval = 1 ,
932
- std::function<void (int , sd_image_t )> step_callback = nullptr ) {
925
+ std::vector<int > skip_layers = {},
926
+ float slg_scale = 0 ,
927
+ float skip_layer_start = 0.01 ,
928
+ float skip_layer_end = 0.2 ,
929
+ ggml_tensor* noise_mask = nullptr ) {
933
930
size_t steps = sigmas.size () - 1 ;
934
931
// noise = load_tensor_from_file(work_ctx, "./rand0.bin");
935
932
// print_ggml_tensor(noise);
@@ -961,7 +958,8 @@ class StableDiffusionGGML {
961
958
struct ggml_tensor * denoised = ggml_dup_tensor (work_ctx, x);
962
959
963
960
struct ggml_tensor * preview_tensor = NULL ;
964
- if (preview_mode != SD_PREVIEW_NONE && preview_mode != SD_PREVIEW_PROJ) {
961
+ auto sd_preview_mode = sd_get_preview_mode ();
962
+ if (sd_preview_mode != SD_PREVIEW_NONE && sd_preview_mode != SD_PREVIEW_PROJ) {
965
963
preview_tensor = ggml_new_tensor_4d (work_ctx, GGML_TYPE_F32,
966
964
(denoised->ne [0 ] * 8 ),
967
965
(denoised->ne [1 ] * 8 ),
@@ -1109,10 +1107,11 @@ class StableDiffusionGGML {
1109
1107
pretty_progress (step, (int )steps, (t1 - t0) / 1000000 .f );
1110
1108
// LOG_INFO("step %d sampling completed taking %.2fs", step, (t1 - t0) * 1.0f / 1000000);
1111
1109
}
1112
-
1113
- if (step_callback != nullptr ) {
1114
- if (step % preview_interval == 0 ) {
1115
- preview_image (work_ctx, step, denoised, version, preview_mode, preview_tensor, step_callback);
1110
+ auto sd_preview_cb = sd_get_preview_callback ();
1111
+ auto sd_preview_mode = sd_get_preview_mode ();
1112
+ if (sd_preview_cb != NULL ) {
1113
+ if (step % sd_get_preview_interval () == 0 ) {
1114
+ preview_image (work_ctx, step, denoised, version, sd_preview_mode, preview_tensor, sd_preview_cb);
1116
1115
}
1117
1116
}
1118
1117
return denoised;
@@ -1338,14 +1337,11 @@ sd_image_t* generate_image(sd_ctx_t* sd_ctx,
1338
1337
float style_ratio,
1339
1338
bool normalize_input,
1340
1339
std::string input_id_images_path,
1341
- std::vector<int > skip_layers = {},
1342
- float slg_scale = 0 ,
1343
- float skip_layer_start = 0.01 ,
1344
- float skip_layer_end = 0.2 ,
1345
- ggml_tensor* masked_image = NULL ,
1346
- sd_preview_policy_t preview_mode = SD_PREVIEW_NONE,
1347
- int preview_interval = 1 ,
1348
- std::function<void (int , sd_image_t )> step_callback = nullptr) {
1340
+ std::vector<int > skip_layers = {},
1341
+ float slg_scale = 0 ,
1342
+ float skip_layer_start = 0.01 ,
1343
+ float skip_layer_end = 0.2 ,
1344
+ ggml_tensor* masked_image = NULL ) {
1349
1345
if (seed < 0 ) {
1350
1346
// Generally, when using the provided command line, the seed is always >0.
1351
1347
// However, to prevent potential issues if 'stable-diffusion.cpp' is invoked as a library
@@ -1602,10 +1598,7 @@ sd_image_t* generate_image(sd_ctx_t* sd_ctx,
1602
1598
slg_scale,
1603
1599
skip_layer_start,
1604
1600
skip_layer_end,
1605
- noise_mask,
1606
- preview_mode,
1607
- preview_interval,
1608
- step_callback);
1601
+ noise_mask);
1609
1602
1610
1603
// struct ggml_tensor* x_0 = load_tensor_from_file(ctx, "samples_ddim.bin");
1611
1604
// print_ggml_tensor(x_0);
@@ -1674,14 +1667,11 @@ sd_image_t* txt2img(sd_ctx_t* sd_ctx,
1674
1667
float style_ratio,
1675
1668
bool normalize_input,
1676
1669
const char * input_id_images_path_c_str,
1677
- int * skip_layers = NULL ,
1678
- size_t skip_layers_count = 0 ,
1679
- float slg_scale = 0 ,
1680
- float skip_layer_start = 0.01 ,
1681
- float skip_layer_end = 0.2 ,
1682
- sd_preview_policy_t preview_mode = SD_PREVIEW_NONE,
1683
- int preview_interval = 1 ,
1684
- step_callback_t step_callback = NULL ) {
1670
+ int * skip_layers = NULL ,
1671
+ size_t skip_layers_count = 0 ,
1672
+ float slg_scale = 0 ,
1673
+ float skip_layer_start = 0.01 ,
1674
+ float skip_layer_end = 0.2 ) {
1685
1675
std::vector<int > skip_layers_vec (skip_layers, skip_layers + skip_layers_count);
1686
1676
LOG_DEBUG (" txt2img %dx%d" , width, height);
1687
1677
if (sd_ctx == NULL ) {
@@ -1699,7 +1689,8 @@ sd_image_t* txt2img(sd_ctx_t* sd_ctx,
1699
1689
if (sd_ctx->sd ->stacked_id ) {
1700
1690
params.mem_size += static_cast <size_t >(10 * 1024 * 1024 ); // 10 MB
1701
1691
}
1702
- if (preview_mode != SD_PREVIEW_NONE && preview_mode != SD_PREVIEW_PROJ) {
1692
+ auto sd_preview_mode = sd_get_preview_mode ();
1693
+ if (sd_preview_mode != SD_PREVIEW_NONE && sd_preview_mode != SD_PREVIEW_PROJ) {
1703
1694
params.mem_size *= 2 ;
1704
1695
}
1705
1696
params.mem_size += width * height * 3 * sizeof (float );
@@ -1763,10 +1754,7 @@ sd_image_t* txt2img(sd_ctx_t* sd_ctx,
1763
1754
slg_scale,
1764
1755
skip_layer_start,
1765
1756
skip_layer_end,
1766
- NULL ,
1767
- preview_mode,
1768
- preview_interval,
1769
- step_callback);
1757
+ NULL );
1770
1758
1771
1759
size_t t1 = ggml_time_ms ();
1772
1760
@@ -1796,14 +1784,11 @@ sd_image_t* img2img(sd_ctx_t* sd_ctx,
1796
1784
float style_ratio,
1797
1785
bool normalize_input,
1798
1786
const char * input_id_images_path_c_str,
1799
- int * skip_layers = NULL ,
1800
- size_t skip_layers_count = 0 ,
1801
- float slg_scale = 0 ,
1802
- float skip_layer_start = 0.01 ,
1803
- float skip_layer_end = 0.2 ,
1804
- sd_preview_policy_t preview_mode = SD_PREVIEW_NONE,
1805
- int preview_interval = 1 ,
1806
- step_callback_t step_callback = NULL ) {
1787
+ int * skip_layers = NULL ,
1788
+ size_t skip_layers_count = 0 ,
1789
+ float slg_scale = 0 ,
1790
+ float skip_layer_start = 0.01 ,
1791
+ float skip_layer_end = 0.2 ) {
1807
1792
std::vector<int > skip_layers_vec (skip_layers, skip_layers + skip_layers_count);
1808
1793
LOG_DEBUG (" img2img %dx%d" , width, height);
1809
1794
if (sd_ctx == NULL ) {
@@ -1950,10 +1935,7 @@ sd_image_t* img2img(sd_ctx_t* sd_ctx,
1950
1935
slg_scale,
1951
1936
skip_layer_start,
1952
1937
skip_layer_end,
1953
- masked_image,
1954
- preview_mode,
1955
- preview_interval,
1956
- step_callback);
1938
+ masked_image);
1957
1939
1958
1940
size_t t2 = ggml_time_ms ();
1959
1941
@@ -2057,9 +2039,7 @@ SD_API sd_image_t* img2vid(sd_ctx_t* sd_ctx,
2057
2039
-1 ,
2058
2040
SDCondition (NULL , NULL , NULL ),
2059
2041
{},
2060
- 0 , 0 , 0 , NULL ,
2061
- (sd_preview_policy_t )0 , 1 ,
2062
- NULL );
2042
+ 0 , 0 , 0 , NULL );
2063
2043
2064
2044
int64_t t2 = ggml_time_ms ();
2065
2045
LOG_INFO (" sampling completed, taking %.2fs" , (t2 - t1) * 1 .0f / 1000 );
0 commit comments