File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -716,8 +716,24 @@ class StableDiffusionGGML {
716716
717717 auto comp_vis_denoiser = std::dynamic_pointer_cast<CompVisDenoiser>(denoiser);
718718 if (comp_vis_denoiser) {
719+ float * alphas_ptr = (float *)alphas_cumprod_tensor->data ;
720+ bool needs_regen = false ;
721+
722+ for (int i = 0 ; i < TIMESTEPS; ++i) {
723+ float alpha = alphas_ptr[i];
724+ if (!std::isfinite (alpha) || alpha <= 0 .0f || alpha >= 1 .0f ) {
725+ needs_regen = true ;
726+ break ;
727+ }
728+ }
729+
730+ if (needs_regen) {
731+ calculate_alphas_cumprod (alphas_ptr);
732+ }
733+
719734 for (int i = 0 ; i < TIMESTEPS; i++) {
720- comp_vis_denoiser->sigmas [i] = std::sqrt ((1 - ((float *)alphas_cumprod_tensor->data )[i]) / ((float *)alphas_cumprod_tensor->data )[i]);
735+ float alpha = std::min (std::max (alphas_ptr[i], 1e-12f ), 1 .0f - 1e-12f );
736+ comp_vis_denoiser->sigmas [i] = std::sqrt ((1 .0f - alpha) / alpha);
721737 comp_vis_denoiser->log_sigmas [i] = std::log (comp_vis_denoiser->sigmas [i]);
722738 }
723739 }
You can’t perform that action at this time.
0 commit comments