Skip to content

Commit f899992

Browse files
fix: Add back apply_rotary_emb for Qwen Image (Comfy-Org#14364)
1 parent cb9f639 commit f899992

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

comfy/ldm/qwen_image/model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ def forward(self, hidden_states: torch.Tensor, *args, **kwargs) -> torch.Tensor:
5151
return hidden_states
5252

5353

54+
# Addin this back because Nunchaku custom nodes rely on it, see comment here:
55+
# https://github.com/Comfy-Org/ComfyUI/pull/14178#issuecomment-4640475161
56+
# TODO: Eventually remove this once we natively support SVDQuants
57+
def apply_rotary_emb(x, freqs_cis):
58+
if x.shape[1] == 0:
59+
return x
60+
61+
t_ = x.reshape(*x.shape[:-1], -1, 1, 2)
62+
t_out = freqs_cis[..., 0] * t_[..., 0] + freqs_cis[..., 1] * t_[..., 1]
63+
return t_out.reshape(*x.shape)
64+
65+
5466
class QwenTimestepProjEmbeddings(nn.Module):
5567
def __init__(self, embedding_dim, pooled_projection_dim, use_additional_t_cond=False, dtype=None, device=None, operations=None):
5668
super().__init__()

0 commit comments

Comments
 (0)