18
18
#include " rng_philox.h"
19
19
#include " stable-diffusion.h"
20
20
21
- #define EPS 1e-05
21
+ #define EPS 1e-05f
22
22
23
23
static SDLogLevel log_level = SDLogLevel::INFO;
24
24
@@ -122,9 +122,9 @@ ggml_tensor* load_tensor_from_file(ggml_context* ctx, const std::string& file_pa
122
122
}
123
123
124
124
void ggml_tensor_set_f32_randn (struct ggml_tensor * tensor, std::shared_ptr<RNG> rng) {
125
- uint32_t n = ggml_nelements (tensor);
125
+ uint32_t n = ( uint32_t ) ggml_nelements (tensor);
126
126
std::vector<float > random_numbers = rng->randn (n);
127
- for (int i = 0 ; i < n; i++) {
127
+ for (uint32_t i = 0 ; i < n; i++) {
128
128
ggml_set_f32_1d (tensor, i, random_numbers[i]);
129
129
}
130
130
}
@@ -438,12 +438,12 @@ std::vector<std::pair<std::string, float>> parse_prompt_attention(const std::str
438
438
std::string weight = m[1 ];
439
439
440
440
if (text == " (" ) {
441
- round_brackets.push_back (res.size ());
441
+ round_brackets.push_back (( int ) res.size ());
442
442
} else if (text == " [" ) {
443
- square_brackets.push_back (res.size ());
443
+ square_brackets.push_back (( int ) res.size ());
444
444
} else if (!weight.empty ()) {
445
445
if (!round_brackets.empty ()) {
446
- multiply_range (round_brackets.back (), std::stod (weight));
446
+ multiply_range (round_brackets.back (), std::stof (weight));
447
447
round_brackets.pop_back ();
448
448
}
449
449
} else if (text == " )" && !round_brackets.empty ()) {
@@ -2707,13 +2707,13 @@ struct DiscreteSchedule : SigmaSchedule {
2707
2707
if (n == 0 ) {
2708
2708
return result;
2709
2709
} else if (n == 1 ) {
2710
- result.push_back (t_to_sigma (t_max));
2710
+ result.push_back (t_to_sigma (( float ) t_max));
2711
2711
result.push_back (0 );
2712
2712
return result;
2713
2713
}
2714
2714
2715
2715
float step = static_cast <float >(t_max) / static_cast <float >(n - 1 );
2716
- for (int i = 0 ; i < n; ++i) {
2716
+ for (uint32_t i = 0 ; i < n; ++i) {
2717
2717
float t = t_max - step * i;
2718
2718
result.push_back (t_to_sigma (t));
2719
2719
}
@@ -2726,17 +2726,17 @@ struct KarrasSchedule : SigmaSchedule {
2726
2726
std::vector<float > get_sigmas (uint32_t n) {
2727
2727
// These *COULD* be function arguments here,
2728
2728
// but does anybody ever bother to touch them?
2729
- float sigma_min = 0.1 ;
2730
- float sigma_max = 10 .;
2731
- float rho = 7 .;
2729
+ float sigma_min = 0 .1f ;
2730
+ float sigma_max = 10 .f ;
2731
+ float rho = 7 .f ;
2732
2732
2733
2733
std::vector<float > result (n + 1 );
2734
2734
2735
- float min_inv_rho = pow (sigma_min, (1 . / rho));
2736
- float max_inv_rho = pow (sigma_max, (1 . / rho));
2737
- for (int i = 0 ; i < n; i++) {
2735
+ float min_inv_rho = pow (sigma_min, (1 .f / rho));
2736
+ float max_inv_rho = pow (sigma_max, (1 .f / rho));
2737
+ for (uint32_t i = 0 ; i < n; i++) {
2738
2738
// Eq. (5) from Karras et al 2022
2739
- result[i] = pow (max_inv_rho + (float )i / ((float )n - 1 .) * (min_inv_rho - max_inv_rho), rho);
2739
+ result[i] = pow (max_inv_rho + (float )i / ((float )n - 1 .f ) * (min_inv_rho - max_inv_rho), rho);
2740
2740
}
2741
2741
result[n] = 0 .;
2742
2742
return result;
@@ -3748,7 +3748,7 @@ class StableDiffusionGGML {
3748
3748
}
3749
3749
} else {
3750
3750
// DPM-Solver-2
3751
- float sigma_mid = exp (0.5 * (log (sigmas[i]) + log (sigmas[i + 1 ])));
3751
+ float sigma_mid = exp (0 .5f * (log (sigmas[i]) + log (sigmas[i + 1 ])));
3752
3752
float dt_1 = sigma_mid - sigmas[i];
3753
3753
float dt_2 = sigmas[i + 1 ] - sigmas[i];
3754
3754
@@ -3811,7 +3811,7 @@ class StableDiffusionGGML {
3811
3811
float t = t_fn (sigmas[i]);
3812
3812
float t_next = t_fn (sigma_down);
3813
3813
float h = t_next - t;
3814
- float s = t + 0.5 * h;
3814
+ float s = t + 0 .5f * h;
3815
3815
3816
3816
float * vec_d = (float *)d->data ;
3817
3817
float * vec_x = (float *)x->data ;
@@ -3820,7 +3820,7 @@ class StableDiffusionGGML {
3820
3820
3821
3821
// First half-step
3822
3822
for (int j = 0 ; j < ggml_nelements (x); j++) {
3823
- vec_x2[j] = (sigma_fn (s) / sigma_fn (t)) * vec_x[j] - (exp (-h * 0.5 ) - 1 ) * vec_denoised[j];
3823
+ vec_x2[j] = (sigma_fn (s) / sigma_fn (t)) * vec_x[j] - (exp (-h * 0 .5f ) - 1 ) * vec_denoised[j];
3824
3824
}
3825
3825
3826
3826
denoise (x2, sigmas[i + 1 ], i + 1 );
@@ -3862,7 +3862,7 @@ class StableDiffusionGGML {
3862
3862
float t_next = t_fn (sigmas[i + 1 ]);
3863
3863
float h = t_next - t;
3864
3864
float a = sigmas[i + 1 ] / sigmas[i];
3865
- float b = exp (-h) - 1 .;
3865
+ float b = exp (-h) - 1 .f ;
3866
3866
float * vec_x = (float *)x->data ;
3867
3867
float * vec_denoised = (float *)denoised->data ;
3868
3868
float * vec_old_denoised = (float *)old_denoised->data ;
@@ -3876,7 +3876,7 @@ class StableDiffusionGGML {
3876
3876
float h_last = t - t_fn (sigmas[i - 1 ]);
3877
3877
float r = h_last / h;
3878
3878
for (int j = 0 ; j < ggml_nelements (x); j++) {
3879
- float denoised_d = (1 . + 1 . / (2 . * r)) * vec_denoised[j] - (1 . / (2 . * r)) * vec_old_denoised[j];
3879
+ float denoised_d = (1 .f + 1 .f / (2 .f * r)) * vec_denoised[j] - (1 .f / (2 .f * r)) * vec_old_denoised[j];
3880
3880
vec_x[j] = a * vec_x[j] - b * denoised_d;
3881
3881
}
3882
3882
}
@@ -3910,7 +3910,7 @@ class StableDiffusionGGML {
3910
3910
3911
3911
if (i == 0 || sigmas[i + 1 ] == 0 ) {
3912
3912
// Simpler step for the edge cases
3913
- float b = exp (-h) - 1 .;
3913
+ float b = exp (-h) - 1 .f ;
3914
3914
for (int j = 0 ; j < ggml_nelements (x); j++) {
3915
3915
vec_x[j] = a * vec_x[j] - b * vec_denoised[j];
3916
3916
}
@@ -3919,10 +3919,10 @@ class StableDiffusionGGML {
3919
3919
float h_min = std::min (h_last, h);
3920
3920
float h_max = std::max (h_last, h);
3921
3921
float r = h_max / h_min;
3922
- float h_d = (h_max + h_min) / 2 .;
3923
- float b = exp (-h_d) - 1 .;
3922
+ float h_d = (h_max + h_min) / 2 .f ;
3923
+ float b = exp (-h_d) - 1 .f ;
3924
3924
for (int j = 0 ; j < ggml_nelements (x); j++) {
3925
- float denoised_d = (1 . + 1 . / (2 . * r)) * vec_denoised[j] - (1 . / (2 . * r)) * vec_old_denoised[j];
3925
+ float denoised_d = (1 .f + 1 .f / (2 .f * r)) * vec_denoised[j] - (1 .f / (2 .f * r)) * vec_old_denoised[j];
3926
3926
vec_x[j] = a * vec_x[j] - b * denoised_d;
3927
3927
}
3928
3928
}
0 commit comments