Skip to content

Commit

Permalink
fix: correctly set alphas_cumprod (#3106)
Browse files Browse the repository at this point in the history
  • Loading branch information
mashb1t authored Jun 6, 2024
1 parent 350fdd9 commit 04d7648
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ldm_patched/modules/model_sampling.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import torch
from ldm_patched.ldm.modules.diffusionmodules.util import make_beta_schedule
import math
import numpy as np

class EPS:
def calculate_input(self, sigma, noise):
Expand Down Expand Up @@ -69,12 +70,17 @@ def _register_schedule(self, given_betas=None, beta_schedule="linear", timesteps
# self.register_buffer('alphas_cumprod_prev', torch.tensor(alphas_cumprod_prev, dtype=torch.float32))

sigmas = ((1 - alphas_cumprod) / alphas_cumprod) ** 0.5
alphas_cumprod = torch.tensor(np.cumprod(alphas, axis=0), dtype=torch.float32)
self.set_sigmas(sigmas)
self.set_alphas_cumprod(alphas_cumprod.float())

def set_sigmas(self, sigmas):
self.register_buffer('sigmas', sigmas.float())
self.register_buffer('log_sigmas', sigmas.log().float())

def set_alphas_cumprod(self, alphas_cumprod):
self.register_buffer("alphas_cumprod", alphas_cumprod.float())

@property
def sigma_min(self):
return self.sigmas[0]
Expand Down
2 changes: 2 additions & 0 deletions modules/patch_precision.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def patched_register_schedule(self, given_betas=None, beta_schedule="linear", ti
self.linear_end = linear_end
sigmas = torch.tensor(((1 - alphas_cumprod) / alphas_cumprod) ** 0.5, dtype=torch.float32)
self.set_sigmas(sigmas)
alphas_cumprod = torch.tensor(alphas_cumprod, dtype=torch.float32)
self.set_alphas_cumprod(alphas_cumprod)
return


Expand Down

0 comments on commit 04d7648

Please sign in to comment.