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

Use UNet precision, add --upcast-sampling support #143

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Changes from all commits
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
12 changes: 7 additions & 5 deletions scripts/cldm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import torch as th
import torch.nn as nn
from modules import devices, lowvram, shared
from modules.devices import cond_cast_unet

from ldm.modules.diffusionmodules.util import (
conv_nd,
Expand Down Expand Up @@ -128,8 +129,8 @@ def forward(self, x, timesteps=None, context=None, **kwargs):
assert timesteps is not None, ValueError(f"insufficient timestep: {timesteps}")
hs = []
with torch.no_grad():
t_emb = timestep_embedding(
timesteps, self.model_channels, repeat_only=False)
t_emb = cond_cast_unet(timestep_embedding(
timesteps, self.model_channels, repeat_only=False))
emb = self.time_embed(t_emb)
h = x.type(self.dtype)
for module in self.input_blocks:
Expand Down Expand Up @@ -212,6 +213,7 @@ def __init__(
disable_middle_self_attn=False,
use_linear_in_transformer=False,
):
use_fp16 = devices.dtype_unet == torch.float16
super().__init__()
if use_spatial_transformer:
assert context_dim is not None, 'Fool!! You forgot to include the dimension of your cross-attention conditioning...'
Expand Down Expand Up @@ -427,11 +429,11 @@ def align(self, hint, h, w):
return hint

def forward(self, x, hint, timesteps, context, **kwargs):
t_emb = timestep_embedding(
timesteps, self.model_channels, repeat_only=False)
t_emb = cond_cast_unet(timestep_embedding(
timesteps, self.model_channels, repeat_only=False))
emb = self.time_embed(t_emb)

guided_hint = self.input_hint_block(hint, emb, context)
guided_hint = self.input_hint_block(cond_cast_unet(hint), emb, context)
outs = []

h1, w1 = x.shape[-2:]
Expand Down