Skip to content

Commit

Permalink
Merge pull request #143 from brkirch/use-unet-precision
Browse files Browse the repository at this point in the history
Use UNet precision, add `--upcast-sampling` support
  • Loading branch information
Mikubill authored Feb 17, 2023
2 parents 3484a30 + f1724fd commit ca279df
Showing 1 changed file with 7 additions and 5 deletions.
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

0 comments on commit ca279df

Please sign in to comment.