@@ -848,7 +848,6 @@ class StableDiffusionGGML {
848
848
int start_merge_step,
849
849
SDCondition id_cond,
850
850
std::vector<ggml_tensor*> ref_latents = {},
851
- sd_apg_params_t apg_params = {1 , 0 , 0 , 0 },
852
851
ggml_tensor* denoise_mask = nullptr ) {
853
852
std::vector<int > skip_layers (guidance.slg .layers , guidance.slg .layers + guidance.slg .layer_count );
854
853
@@ -913,7 +912,7 @@ class StableDiffusionGGML {
913
912
struct ggml_tensor * denoised = ggml_dup_tensor (work_ctx, x);
914
913
915
914
std::vector<float > apg_momentum_buffer;
916
- if (apg_params .momentum != 0 )
915
+ if (guidance. apg .momentum != 0 )
917
916
apg_momentum_buffer.resize ((size_t )ggml_nelements (denoised));
918
917
919
918
auto denoise = [&](ggml_tensor* input, float sigma, int step) -> ggml_tensor* {
@@ -1096,14 +1095,14 @@ class StableDiffusionGGML {
1096
1095
// classic CFG (img_cfg_scale == cfg_scale != 1)
1097
1096
delta = positive_data[i] - negative_data[i];
1098
1097
}
1099
- if (apg_params .momentum != 0 ) {
1100
- delta += apg_params .momentum * apg_momentum_buffer[i];
1098
+ if (guidance. apg .momentum != 0 ) {
1099
+ delta += guidance. apg .momentum * apg_momentum_buffer[i];
1101
1100
apg_momentum_buffer[i] = delta;
1102
1101
}
1103
- if (apg_params .norm_treshold > 0 || log_cfg_norm) {
1102
+ if (guidance. apg .norm_treshold > 0 || log_cfg_norm) {
1104
1103
diff_norm += delta * delta;
1105
1104
}
1106
- if (apg_params .eta != 1 .0f ) {
1105
+ if (guidance. apg .eta != 1 .0f ) {
1107
1106
cond_norm_sq += positive_data[i] * positive_data[i];
1108
1107
dot += positive_data[i] * delta;
1109
1108
}
@@ -1112,30 +1111,30 @@ class StableDiffusionGGML {
1112
1111
if (log_cfg_norm) {
1113
1112
LOG_INFO (" CFG Delta norm: %.2f" , sqrtf (diff_norm));
1114
1113
}
1115
- if (apg_params .norm_treshold > 0 ) {
1114
+ if (guidance. apg .norm_treshold > 0 ) {
1116
1115
diff_norm = sqrtf (diff_norm);
1117
- if (apg_params .norm_treshold_smoothing <= 0 ) {
1118
- apg_scale_factor = std::min (1 .0f , apg_params .norm_treshold / diff_norm);
1116
+ if (guidance. apg .norm_treshold_smoothing <= 0 ) {
1117
+ apg_scale_factor = std::min (1 .0f , guidance. apg .norm_treshold / diff_norm);
1119
1118
} else {
1120
1119
// Experimental: smooth saturate
1121
- float x = apg_params .norm_treshold / diff_norm;
1122
- apg_scale_factor = x / std::pow (1 + std::pow (x, 1.0 / apg_params. norm_treshold_smoothing ), apg_params .norm_treshold_smoothing );
1120
+ float x = guidance. apg .norm_treshold / diff_norm;
1121
+ apg_scale_factor = x / std::pow (1 + std::pow (x, 1.0 / guidance. apg . norm_treshold_smoothing ), guidance. apg .norm_treshold_smoothing );
1123
1122
}
1124
1123
}
1125
- if (apg_params .eta != 1 .0f ) {
1124
+ if (guidance. apg .eta != 1 .0f ) {
1126
1125
dot *= apg_scale_factor;
1127
1126
// pre-normalize (avoids one square root and ne_elements extra divs)
1128
1127
dot /= cond_norm_sq;
1129
1128
}
1130
1129
1131
1130
for (int i = 0 ; i < ne_elements; i++) {
1132
1131
deltas[i] *= apg_scale_factor;
1133
- if (apg_params .eta != 1 .0f ) {
1132
+ if (guidance. apg .eta != 1 .0f ) {
1134
1133
float apg_parallel = dot * positive_data[i];
1135
1134
float apg_orthogonal = deltas[i] - apg_parallel;
1136
1135
1137
1136
// tweak deltas
1138
- deltas[i] = apg_orthogonal + apg_params .eta * apg_parallel;
1137
+ deltas[i] = apg_orthogonal + guidance. apg .eta * apg_parallel;
1139
1138
}
1140
1139
}
1141
1140
}
@@ -1636,7 +1635,6 @@ sd_image_t* generate_image_internal(sd_ctx_t* sd_ctx,
1636
1635
std::string input_id_images_path,
1637
1636
std::vector<ggml_tensor*> ref_latents,
1638
1637
ggml_tensor* concat_latent = NULL ,
1639
- sd_apg_params_t apg_params = {},
1640
1638
ggml_tensor* denoise_mask = NULL ) {
1641
1639
if (seed < 0 ) {
1642
1640
// Generally, when using the provided command line, the seed is always >0.
@@ -1906,7 +1904,6 @@ sd_image_t* generate_image_internal(sd_ctx_t* sd_ctx,
1906
1904
start_merge_step,
1907
1905
id_cond,
1908
1906
ref_latents,
1909
- apg_params,
1910
1907
denoise_mask);
1911
1908
1912
1909
// struct ggml_tensor* x_0 = load_tensor_from_file(ctx, "samples_ddim.bin");
@@ -1981,7 +1978,7 @@ ggml_tensor* generate_init_latent(sd_ctx_t* sd_ctx,
1981
1978
return init_latent;
1982
1979
}
1983
1980
1984
- sd_image_t * generate_image (sd_ctx_t * sd_ctx, const sd_img_gen_params_t * sd_img_gen_params, sd_apg_params_t apg_params ) {
1981
+ sd_image_t * generate_image (sd_ctx_t * sd_ctx, const sd_img_gen_params_t * sd_img_gen_params) {
1985
1982
int width = sd_img_gen_params->width ;
1986
1983
int height = sd_img_gen_params->height ;
1987
1984
LOG_DEBUG (" generate_image %dx%d" , width, height);
@@ -2181,7 +2178,6 @@ sd_image_t* generate_image(sd_ctx_t* sd_ctx, const sd_img_gen_params_t* sd_img_g
2181
2178
sd_img_gen_params->input_id_images_path ,
2182
2179
ref_latents,
2183
2180
concat_latent,
2184
- apg_params,
2185
2181
denoise_mask);
2186
2182
2187
2183
size_t t2 = ggml_time_ms ();
0 commit comments