-
Notifications
You must be signed in to change notification settings - Fork 594
refactor: centralize CompVisDenoiser table calculations #1383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,19 +76,9 @@ const char* sampling_methods_str[] = { | |
|
|
||
| /*================================================== Helper Functions ================================================*/ | ||
|
|
||
| void calculate_alphas_cumprod(float* alphas_cumprod, | ||
| float linear_start = 0.00085f, | ||
| float linear_end = 0.0120f, | ||
| int timesteps = TIMESTEPS) { | ||
| float ls_sqrt = sqrtf(linear_start); | ||
| float le_sqrt = sqrtf(linear_end); | ||
| float amount = le_sqrt - ls_sqrt; | ||
| float product = 1.0f; | ||
| for (int i = 0; i < timesteps; i++) { | ||
| float beta = ls_sqrt + amount * ((float)i / (timesteps - 1)); | ||
| product *= 1.0f - powf(beta, 2.0f); | ||
| alphas_cumprod[i] = product; | ||
| } | ||
| void calculate_alphas_cumprod(float* alphas_cumprod) { | ||
| const float * src = CompVisDenoiser::get_alphas_cumprods(); | ||
| std::copy(src, src + TIMESTEPS, alphas_cumprod); | ||
| } | ||
|
|
||
| static float get_cache_reuse_threshold(const sd_cache_params_t& params) { | ||
|
|
@@ -999,13 +989,6 @@ class StableDiffusionGGML { | |
| } | ||
| } | ||
|
|
||
| auto comp_vis_denoiser = std::dynamic_pointer_cast<CompVisDenoiser>(denoiser); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change removes the initialization path from Previously, This means we can no longer use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, it doesn't: the diff doesn't show this, but the tensor is always filled by `calculate_alphas_cumprod unconditionally at line ~802: calculate_alphas_cumprod((float*)alphas_cumprod_tensor->data);and then propagated to the |
||
| if (comp_vis_denoiser) { | ||
| for (int i = 0; i < TIMESTEPS; i++) { | ||
| comp_vis_denoiser->sigmas[i] = std::sqrt((1 - ((float*)alphas_cumprod_tensor->data)[i]) / ((float*)alphas_cumprod_tensor->data)[i]); | ||
| comp_vis_denoiser->log_sigmas[i] = std::log(comp_vis_denoiser->sigmas[i]); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| ggml_free(ctx); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've preserved this, but I'm not sure the
alphas_cumprodtensor is really being used.