Skip to content

Commit

Permalink
improve: bump basicsr version
Browse files Browse the repository at this point in the history
  • Loading branch information
samedii committed Sep 11, 2022
1 parent e0bdd38 commit 52b86f1
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 211 deletions.
3 changes: 0 additions & 3 deletions perceptor/models/stable_diffusion/predictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ def from_sigmas(self):

@property
def denoised_latents(self):
# return (
# latents - self.sqrt_one_minus_alphas_cumprod(index) * eps
# ) / self.alphas_cumprod(index).sqrt()
return (
self.from_diffused_latents - self.from_sigmas * self.predicted_noise
) / self.from_alphas.clamp(min=1e-7)
Expand Down
3 changes: 2 additions & 1 deletion perceptor/models/stable_diffusion/stable_diffusion.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Optional
from contextlib import contextmanager
import copy
import torch
import lantern
from transformers import CLIPTokenizer, CLIPTextModel, logging
Expand Down Expand Up @@ -133,7 +134,7 @@ def finetuneable_vae(self):
with diffusion_model.finetuneable_vae():
images = diffusion_model.decode(latents)
"""
state_dict = self.vae.state_dict()
state_dict = copy.deepcopy(self.vae.state_dict())
try:
for parameter, requires_grad in zip(
self.vae.parameters(), self.vae_original_requires_grads
Expand Down
8 changes: 4 additions & 4 deletions perceptor/models/velocity_diffusion/model_urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
model_urls = {
"yfcc_2": "https://the-eye.eu/public/AI/models/v-diffusion/yfcc_2.pth",
"yfcc_1": "https://the-eye.eu/public/AI/models/v-diffusion/yfcc_1.pth",
"cc12m_1": "https://the-eye.eu/public/AI/models/v-diffusion/cc12m_1.pth",
"cc12m_1_cfg": "https://the-eye.eu/public/AI/models/v-diffusion/cc12m_1_cfg.pth",
"yfcc_2": "https://s3.eu-central-1.wasabisys.com/nextml-model-data/velocity-diffusion/yfcc_2.pth",
"yfcc_1": "https://s3.eu-central-1.wasabisys.com/nextml-model-data/velocity-diffusion/yfcc_1.pth",
"cc12m_1": "https://s3.eu-central-1.wasabisys.com/nextml-model-data/velocity-diffusion/cc12m_1.pth",
"cc12m_1_cfg": "https://s3.eu-central-1.wasabisys.com/nextml-model-data/velocity-diffusion/cc12m_1_cfg.pth",
"wikiart": "https://the-eye.eu/public/AI/models/v-diffusion/wikiart_256.pth",
}
44 changes: 9 additions & 35 deletions perceptor/models/velocity_diffusion/predictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,6 @@ def step(self, to_ts, eta=0.0):
return diffusion_space.decode(to_diffused_xs)

def correction(self, previous: "Predictions"):
# k-diffusion has alphas=1 always so this should not work
# corrected_diffused_xs = (
# previous.from_diffused_xs
# + (self.from_sigmas - previous.from_sigmas) * (self.eps - previous.eps) / 2
# )
# return diffusion_space.decode(corrected_diffused_xs)

# blurry
# return Predictions(
# from_diffused_images=previous.from_diffused_images,
# from_ts=previous.from_ts,
# velocities=(self.velocities + previous.velocities) / 2,
# )

# looks ok but no apparent difference from double budget
return previous.forced_denoised(
(self.denoised_images + previous.denoised_images) / 2
)
Expand All @@ -127,29 +112,9 @@ def reverse_step(self, to_ts):
if (torch.as_tensor(self.from_ts) > torch.as_tensor(to_ts)).any():
raise ValueError("from_ts must be less than to_ts")

# replaced_noise_sigma = (
# self.sigmas(to_t) ** 2 - self.sigmas(from_t) ** 2
# ).sqrt()
# to_eps = (
# from_eps * self.sigmas(from_t)
# + torch.randn_like(from_eps) * replaced_noise_sigma
# ) / self.sigmas(to_t)
# to_eps = eps
# to_diffused = self.diffuse(from_denoised, to_t, noise=to_eps)
# return to_diffused

to_alphas, to_sigmas = self.alphas(to_ts), self.sigmas(to_ts)
return self.denoised_xs * to_alphas + self.predicted_noise * to_sigmas

def resample(self, resample_ts):
"""
Harmonizing resampling from https://github.com/andreas128/RePaint
"""
return diffusion_space.decode(
self.denoised_xs * self.from_alphas
+ self.resample_noise(resample_ts) * self.from_sigmas
)

def resample_noise(self, resample_ts):
if (torch.as_tensor(self.from_ts) < torch.as_tensor(resample_ts)).any():
raise ValueError("from_ts must be greater than resample_ts")
Expand All @@ -161,6 +126,15 @@ def resample_noise(self, resample_ts):
) # fmt: skip
return resampled_noise_sigma / self.from_sigmas

def resample(self, resample_ts):
"""
Harmonizing resampling from https://github.com/andreas128/RePaint
"""
return diffusion_space.decode(
self.denoised_xs * self.from_alphas
+ self.resample_noise(resample_ts) * self.from_sigmas
)

def noisy_reverse_step(self, to_ts):
to_alphas, to_sigmas = self.alphas(to_ts), self.sigmas(to_ts)

Expand Down
Loading

0 comments on commit 52b86f1

Please sign in to comment.