1818import torch .nn .functional as F
1919from torch import nn
2020
21- from .attention import AdaGroupNorm , AttentionBlock , SpatialNorm
21+ from .attention import AdaGroupNorm
2222from .attention_processor import Attention , AttnAddedKVProcessor , AttnAddedKVProcessor2_0
2323from .dual_transformer_2d import DualTransformer2DModel
2424from .resnet import Downsample2D , FirDownsample2D , FirUpsample2D , KDownsample2D , KUpsample2D , ResnetBlock2D , Upsample2D
@@ -348,7 +348,6 @@ def get_up_block(
348348 resnet_act_fn = resnet_act_fn ,
349349 resnet_groups = resnet_groups ,
350350 resnet_time_scale_shift = resnet_time_scale_shift ,
351- temb_channels = temb_channels
352351 )
353352 elif up_block_type == "AttnUpDecoderBlock2D" :
354353 return AttnUpDecoderBlock2D (
@@ -361,7 +360,6 @@ def get_up_block(
361360 resnet_groups = resnet_groups ,
362361 attn_num_head_channels = attn_num_head_channels ,
363362 resnet_time_scale_shift = resnet_time_scale_shift ,
364- temb_channels = temb_channels
365363 )
366364 elif up_block_type == "KUpBlock2D" :
367365 return KUpBlock2D (
@@ -408,6 +406,7 @@ def __init__(
408406 super ().__init__ ()
409407 resnet_groups = resnet_groups if resnet_groups is not None else min (in_channels // 4 , 32 )
410408 self .add_attention = add_attention
409+
411410 # there is always at least one resnet
412411 resnets = [
413412 ResnetBlock2D (
@@ -440,6 +439,7 @@ def __init__(
440439 upcast_softmax = True ,
441440 _from_deprecated_attn_block = True ,
442441 )
442+ )
443443 else :
444444 attentions .append (None )
445445
@@ -465,8 +465,7 @@ def forward(self, hidden_states, temb=None):
465465 hidden_states = self .resnets [0 ](hidden_states , temb )
466466 for attn , resnet in zip (self .attentions , self .resnets [1 :]):
467467 if attn is not None :
468- hidden_states = attn (hidden_states , temb )
469-
468+ hidden_states = attn (hidden_states )
470469 hidden_states = resnet (hidden_states , temb )
471470
472471 return hidden_states
@@ -1972,30 +1971,6 @@ def custom_forward(*inputs):
19721971 return hidden_states
19731972
19741973
1975- class MOVQAttention (nn .Module ):
1976- def __init__ (self , query_dim , temb_channels , attn_num_head_channels ):
1977- super ().__init__ ()
1978-
1979- self .norm = SpatialNorm (query_dim , temb_channels )
1980- num_heads = query_dim // attn_num_head_channels if attn_num_head_channels is not None else 1
1981- dim_head = attn_num_head_channels if attn_num_head_channels is not None else query_dim
1982- self .attention = Attention (
1983- query_dim = query_dim ,
1984- heads = num_heads ,
1985- dim_head = dim_head ,
1986- bias = True
1987- )
1988-
1989- def forward (self , hidden_states , temb ):
1990- residual = hidden_states
1991- hidden_states = self .norm (hidden_states , temb ).view (hidden_states .shape [0 ], hidden_states .shape [1 ], - 1 )
1992- hidden_states = self .attention (hidden_states .transpose (1 , 2 ), None , None ).transpose (1 , 2 )
1993- hidden_states = hidden_states .view (residual .shape )
1994- hidden_states = hidden_states + residual
1995- return hidden_states
1996-
1997-
1998-
19991974class UpDecoderBlock2D (nn .Module ):
20001975 def __init__ (
20011976 self ,
@@ -2010,7 +1985,6 @@ def __init__(
20101985 resnet_pre_norm : bool = True ,
20111986 output_scale_factor = 1.0 ,
20121987 add_upsample = True ,
2013- temb_channels = None
20141988 ):
20151989 super ().__init__ ()
20161990 resnets = []
@@ -2022,7 +1996,7 @@ def __init__(
20221996 ResnetBlock2D (
20231997 in_channels = input_channels ,
20241998 out_channels = out_channels ,
2025- temb_channels = temb_channels ,
1999+ temb_channels = None ,
20262000 eps = resnet_eps ,
20272001 groups = resnet_groups ,
20282002 dropout = dropout ,
@@ -2040,9 +2014,9 @@ def __init__(
20402014 else :
20412015 self .upsamplers = None
20422016
2043- def forward (self , hidden_states , temb = None ):
2017+ def forward (self , hidden_states ):
20442018 for resnet in self .resnets :
2045- hidden_states = resnet (hidden_states , temb = temb )
2019+ hidden_states = resnet (hidden_states , temb = None )
20462020
20472021 if self .upsamplers is not None :
20482022 for upsampler in self .upsamplers :
@@ -2066,7 +2040,6 @@ def __init__(
20662040 attn_num_head_channels = 1 ,
20672041 output_scale_factor = 1.0 ,
20682042 add_upsample = True ,
2069- temb_channels = None
20702043 ):
20712044 super ().__init__ ()
20722045 resnets = []
@@ -2079,7 +2052,7 @@ def __init__(
20792052 ResnetBlock2D (
20802053 in_channels = input_channels ,
20812054 out_channels = out_channels ,
2082- temb_channels = temb_channels ,
2055+ temb_channels = None ,
20832056 eps = resnet_eps ,
20842057 groups = resnet_groups ,
20852058 dropout = dropout ,
@@ -2102,6 +2075,7 @@ def __init__(
21022075 upcast_softmax = True ,
21032076 _from_deprecated_attn_block = True ,
21042077 )
2078+ )
21052079
21062080 self .attentions = nn .ModuleList (attentions )
21072081 self .resnets = nn .ModuleList (resnets )
@@ -2111,10 +2085,10 @@ def __init__(
21112085 else :
21122086 self .upsamplers = None
21132087
2114- def forward (self , hidden_states , temb = None ):
2088+ def forward (self , hidden_states ):
21152089 for resnet , attn in zip (self .resnets , self .attentions ):
2116- hidden_states = resnet (hidden_states , temb = temb )
2117- hidden_states = attn (hidden_states , temb )
2090+ hidden_states = resnet (hidden_states , temb = None )
2091+ hidden_states = attn (hidden_states )
21182092
21192093 if self .upsamplers is not None :
21202094 for upsampler in self .upsamplers :
@@ -2873,4 +2847,3 @@ def forward(
28732847 hidden_states = attn_output + hidden_states
28742848
28752849 return hidden_states
2876-
0 commit comments