Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added k-style callback, mac compatibility, v-ram optimization (should merge with PR36) #69

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
mem
XmYx committed Jun 16, 2023
commit f47a75d8eaad51140a4818e507ead45befbd56e3
11 changes: 11 additions & 0 deletions kandinsky2/kandinsky2_1_model.py
Original file line number Diff line number Diff line change
@@ -248,6 +248,8 @@ def generate_img(

def model_fn(x_t, ts, **kwargs):
half = x_t[: len(x_t) // 2]
x_t = x_t.detach().cpu()
del x_t
combined = torch.cat([half, half], dim=0)
if not self.use_fp16:
combined = combined.to(dtype=torch.float32)
@@ -257,9 +259,18 @@ def model_fn(x_t, ts, **kwargs):
cond_eps, uncond_eps = torch.split(eps, len(eps) // 2, dim=0)
half_eps = uncond_eps + guidance_scale * (cond_eps - uncond_eps)
eps = torch.cat([half_eps, half_eps], dim=0)

half_eps = half_eps.detach().to("cpu")
cond_eps = cond_eps.detach().to("cpu")
del half_eps
del cond_eps


if sampler == "p_sampler":
return torch.cat([eps, rest], dim=1)
else:
rest = rest.detach().to("cpu")
del rest
return eps

if noise is not None: