From f4a66ee74374838b0e143e73d9aa3b8de7e82229 Mon Sep 17 00:00:00 2001 From: ImpactFrames Date: Mon, 18 Mar 2024 11:55:02 +0000 Subject: [PATCH] Update interface.py Added this epsilon to avoid divide by zero errors --- crm/imagedream/ldm/interface.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crm/imagedream/ldm/interface.py b/crm/imagedream/ldm/interface.py index f7d417c..716c0a2 100644 --- a/crm/imagedream/ldm/interface.py +++ b/crm/imagedream/ldm/interface.py @@ -112,11 +112,12 @@ class LatentDiffusionInterface(nn.Module): self.register_buffer( "log_one_minus_alphas_cumprod", to_torch(np.log(1.0 - alphas_cumprod)) ) + eps = 1e-8 # Added this epsilon to avoid divide by zero errors self.register_buffer( - "sqrt_recip_alphas_cumprod", to_torch(np.sqrt(1.0 / alphas_cumprod)) + "sqrt_recip_alphas_cumprod", to_torch(np.sqrt(1.0 / (alphas_cumprod + eps))) ) self.register_buffer( - "sqrt_recipm1_alphas_cumprod", to_torch(np.sqrt(1.0 / alphas_cumprod - 1)) + "sqrt_recipm1_alphas_cumprod", to_torch(np.sqrt(1.0 / (alphas_cumprod + eps) - 1)) ) # calculations for posterior q(x_{t-1} | x_t, x_0)