Skip to content

Commit 8c6b47c

Browse files
AttentionProcessor.group_norm num_channels should be query_dim (#3046)
* `AttentionProcessor.group_norm` num_channels should be `query_dim` The group_norm on the attention processor should really norm the number of channels in the query _not_ the inner dim. This wasn't caught before because the group_norm is only used by the added kv attention processors and the added kv attention processors are only used by the karlo models which are configured such that the inner dim is the same as the query dim. * add_{k,v}_proj should be projecting to inner_dim
1 parent 67ec9cf commit 8c6b47c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/diffusers/models/attention_processor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(
8181
self.added_kv_proj_dim = added_kv_proj_dim
8282

8383
if norm_num_groups is not None:
84-
self.group_norm = nn.GroupNorm(num_channels=inner_dim, num_groups=norm_num_groups, eps=1e-5, affine=True)
84+
self.group_norm = nn.GroupNorm(num_channels=query_dim, num_groups=norm_num_groups, eps=1e-5, affine=True)
8585
else:
8686
self.group_norm = None
8787

@@ -93,8 +93,8 @@ def __init__(
9393
self.to_v = nn.Linear(cross_attention_dim, inner_dim, bias=bias)
9494

9595
if self.added_kv_proj_dim is not None:
96-
self.add_k_proj = nn.Linear(added_kv_proj_dim, cross_attention_dim)
97-
self.add_v_proj = nn.Linear(added_kv_proj_dim, cross_attention_dim)
96+
self.add_k_proj = nn.Linear(added_kv_proj_dim, inner_dim)
97+
self.add_v_proj = nn.Linear(added_kv_proj_dim, inner_dim)
9898

9999
self.to_out = nn.ModuleList([])
100100
self.to_out.append(nn.Linear(inner_dim, query_dim, bias=out_bias))

0 commit comments

Comments
 (0)