Merge pull request #10 from Dango233/230327 · huo-ju/diffusers@18aa8cd · GitHub
Skip to content

Commit 18aa8cd

Browse files
authored
Merge pull request huggingface#10 from Dango233/230327
wip
2 parents 2e3541d + f487ed4 commit 18aa8cd

4 files changed

Lines changed: 31 additions & 7 deletions

File tree

‎src/diffusers/models/transformer_2d.py‎

Lines changed: 1 addition & 0 deletions

‎src/diffusers/models/unet_2d_blocks.py‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def get_down_block(
4242
only_cross_attention=False,
4343
upcast_attention=False,
4444
resnet_time_scale_shift="default",
45+
transformer_num_layers=1,
4546
):
4647
down_block_type = down_block_type[7:] if down_block_type.startswith("UNetRes") else down_block_type
4748
if down_block_type == "DownBlock2D":
@@ -103,6 +104,7 @@ def get_down_block(
103104
only_cross_attention=only_cross_attention,
104105
upcast_attention=upcast_attention,
105106
resnet_time_scale_shift=resnet_time_scale_shift,
107+
transformer_num_layers=transformer_num_layers,
106108
)
107109
elif down_block_type == "SimpleCrossAttnDownBlock2D":
108110
if cross_attention_dim is None:
@@ -214,6 +216,7 @@ def get_up_block(
214216
only_cross_attention=False,
215217
upcast_attention=False,
216218
resnet_time_scale_shift="default",
219+
transformer_num_layers=1,
217220
):
218221
up_block_type = up_block_type[7:] if up_block_type.startswith("UNetRes") else up_block_type
219222
if up_block_type == "UpBlock2D":
@@ -262,6 +265,7 @@ def get_up_block(
262265
only_cross_attention=only_cross_attention,
263266
upcast_attention=upcast_attention,
264267
resnet_time_scale_shift=resnet_time_scale_shift,
268+
transformer_num_layers=transformer_num_layers,
265269
)
266270
elif up_block_type == "SimpleCrossAttnUpBlock2D":
267271
if cross_attention_dim is None:
@@ -465,6 +469,7 @@ def __init__(
465469
dual_cross_attention=False,
466470
use_linear_projection=False,
467471
upcast_attention=False,
472+
transformer_num_layers=1,
468473
):
469474
super().__init__()
470475

@@ -496,7 +501,7 @@ def __init__(
496501
attn_num_head_channels,
497502
in_channels // attn_num_head_channels,
498503
in_channels=in_channels,
499-
num_layers=1,
504+
num_layers=transformer_num_layers,
500505
cross_attention_dim=cross_attention_dim,
501506
norm_num_groups=resnet_groups,
502507
use_linear_projection=use_linear_projection,
@@ -509,7 +514,7 @@ def __init__(
509514
attn_num_head_channels,
510515
in_channels // attn_num_head_channels,
511516
in_channels=in_channels,
512-
num_layers=1,
517+
num_layers=transformer_num_layers,
513518
cross_attention_dim=cross_attention_dim,
514519
norm_num_groups=resnet_groups,
515520
)
@@ -742,6 +747,7 @@ def __init__(
742747
use_linear_projection=False,
743748
only_cross_attention=False,
744749
upcast_attention=False,
750+
transformer_num_layers=1,
745751
):
746752
super().__init__()
747753
resnets = []
@@ -772,7 +778,7 @@ def __init__(
772778
attn_num_head_channels,
773779
out_channels // attn_num_head_channels,
774780
in_channels=out_channels,
775-
num_layers=1,
781+
num_layers=transformer_num_layers,
776782
cross_attention_dim=cross_attention_dim,
777783
norm_num_groups=resnet_groups,
778784
use_linear_projection=use_linear_projection,
@@ -786,7 +792,7 @@ def __init__(
786792
attn_num_head_channels,
787793
out_channels // attn_num_head_channels,
788794
in_channels=out_channels,
789-
num_layers=1,
795+
num_layers=transformer_num_layers,
790796
cross_attention_dim=cross_attention_dim,
791797
norm_num_groups=resnet_groups,
792798
)
@@ -1712,6 +1718,7 @@ def __init__(
17121718
use_linear_projection=False,
17131719
only_cross_attention=False,
17141720
upcast_attention=False,
1721+
transformer_num_layers=1,
17151722
):
17161723
super().__init__()
17171724
resnets = []
@@ -1744,7 +1751,7 @@ def __init__(
17441751
attn_num_head_channels,
17451752
out_channels // attn_num_head_channels,
17461753
in_channels=out_channels,
1747-
num_layers=1,
1754+
num_layers=transformer_num_layers,
17481755
cross_attention_dim=cross_attention_dim,
17491756
norm_num_groups=resnet_groups,
17501757
use_linear_projection=use_linear_projection,
@@ -1758,7 +1765,7 @@ def __init__(
17581765
attn_num_head_channels,
17591766
out_channels // attn_num_head_channels,
17601767
in_channels=out_channels,
1761-
num_layers=1,
1768+
num_layers=transformer_num_layers,
17621769
cross_attention_dim=cross_attention_dim,
17631770
norm_num_groups=resnet_groups,
17641771
)

‎src/diffusers/models/unet_2d_condition.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def __init__(
147147
time_cond_proj_dim: Optional[int] = None,
148148
conv_in_kernel: int = 3,
149149
conv_out_kernel: int = 3,
150+
transformer_num_layers: int = 1,
150151
projection_class_embeddings_input_dim: Optional[int] = None,
151152
):
152153
super().__init__()
@@ -264,6 +265,7 @@ def __init__(
264265
only_cross_attention=only_cross_attention[i],
265266
upcast_attention=upcast_attention,
266267
resnet_time_scale_shift=resnet_time_scale_shift,
268+
transformer_num_layers=transformer_num_layers,
267269
)
268270
self.down_blocks.append(down_block)
269271

@@ -282,6 +284,7 @@ def __init__(
282284
dual_cross_attention=dual_cross_attention,
283285
use_linear_projection=use_linear_projection,
284286
upcast_attention=upcast_attention,
287+
transformer_num_layers=transformer_num_layers,
285288
)
286289
elif mid_block_type == "UNetMidBlock2DSimpleCrossAttn":
287290
self.mid_block = UNetMidBlock2DSimpleCrossAttn(
@@ -341,6 +344,7 @@ def __init__(
341344
only_cross_attention=only_cross_attention[i],
342345
upcast_attention=upcast_attention,
343346
resnet_time_scale_shift=resnet_time_scale_shift,
347+
transformer_num_layers=transformer_num_layers,
344348
)
345349
self.up_blocks.append(up_block)
346350
prev_output_channel = output_channel

‎src/diffusers/pipelines/stable_diffusion/convert_from_ckpt.py‎

Lines changed: 13 additions & 1 deletion

0 commit comments

Comments
 (0)