Skip to content

Commit f53bd06

Browse files
committed
cleanup cpp/hpp split
1 parent 8a63b34 commit f53bd06

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

stable-diffusion.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66
#include "stb_image.h"
77

88

9+
void calculate_alphas_cumprod(float* alphas_cumprod,
10+
float linear_start,
11+
float linear_end,
12+
int timesteps) {
13+
float ls_sqrt = sqrtf(linear_start);
14+
float le_sqrt = sqrtf(linear_end);
15+
float amount = le_sqrt - ls_sqrt;
16+
float product = 1.0f;
17+
for (int i = 0; i < timesteps; i++) {
18+
float beta = ls_sqrt + amount * ((float)i / (timesteps - 1));
19+
product *= 1.0f - powf(beta, 2.0f);
20+
alphas_cumprod[i] = product;
21+
}
22+
}
23+
924
// ldm.models.diffusion.ddpm.LatentDiffusion.get_first_stage_encoding
1025
ggml_tensor* vae_sample(ggml_context* work_ctx, ggml_tensor* moments, float scale_factor, std::shared_ptr<RNG> rng)
1126
{

stable-diffusion.hpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,7 @@ ggml_tensor* vae_run(
4040
void calculate_alphas_cumprod(float* alphas_cumprod,
4141
float linear_start = 0.00085f,
4242
float linear_end = 0.0120,
43-
int timesteps = TIMESTEPS) {
44-
float ls_sqrt = sqrtf(linear_start);
45-
float le_sqrt = sqrtf(linear_end);
46-
float amount = le_sqrt - ls_sqrt;
47-
float product = 1.0f;
48-
for (int i = 0; i < timesteps; i++) {
49-
float beta = ls_sqrt + amount * ((float)i / (timesteps - 1));
50-
product *= 1.0f - powf(beta, 2.0f);
51-
alphas_cumprod[i] = product;
52-
}
53-
}
43+
int timesteps = TIMESTEPS);
5444

5545
struct StableDiffusionLoadConfiguration
5646
{

0 commit comments

Comments
 (0)