Skip to content

Commit 04d7648

Browse files
authored
fix: correctly set alphas_cumprod (#3106)
1 parent 350fdd9 commit 04d7648

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

ldm_patched/modules/model_sampling.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import torch
22
from ldm_patched.ldm.modules.diffusionmodules.util import make_beta_schedule
33
import math
4+
import numpy as np
45

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

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

7477
def set_sigmas(self, sigmas):
7578
self.register_buffer('sigmas', sigmas.float())
7679
self.register_buffer('log_sigmas', sigmas.log().float())
7780

81+
def set_alphas_cumprod(self, alphas_cumprod):
82+
self.register_buffer("alphas_cumprod", alphas_cumprod.float())
83+
7884
@property
7985
def sigma_min(self):
8086
return self.sigmas[0]

modules/patch_precision.py

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def patched_register_schedule(self, given_betas=None, beta_schedule="linear", ti
5151
self.linear_end = linear_end
5252
sigmas = torch.tensor(((1 - alphas_cumprod) / alphas_cumprod) ** 0.5, dtype=torch.float32)
5353
self.set_sigmas(sigmas)
54+
alphas_cumprod = torch.tensor(alphas_cumprod, dtype=torch.float32)
55+
self.set_alphas_cumprod(alphas_cumprod)
5456
return
5557

5658

0 commit comments

Comments
 (0)