Skip to content

added a fix to models/xti_attention_processor.py #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions models/xti_attention_processor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from typing import Dict, Optional

import torch
from diffusers.models.cross_attention import CrossAttention

try:
from diffusers.models.cross_attention import CrossAttention as Attention
except ImportError:
print(f"current version of diffusers does not have diffusers.models.cross_attention, using diffusers.models.attention_processor.Attention instead.")
from diffusers.models.attention_processor import Attention

class XTIAttenProc:

def __call__(self, attn: CrossAttention,
def __call__(self, attn: Attention,
hidden_states: torch.Tensor,
encoder_hidden_states: Optional[Dict[str, torch.Tensor]] = None,
attention_mask: Optional[torch.Tensor] = None):
Expand All @@ -31,7 +35,7 @@ def __call__(self, attn: CrossAttention,

if _ehs is None:
_ehs = hidden_states
elif attn.cross_attention_norm:
elif ((hasattr(attn, cross_attention_norm) and attn.cross_attention_norm) or attn.norm_cross is not None):
_ehs = attn.norm_cross(_ehs)
_ehs_bypass = attn.norm_cross(_ehs_bypass)

Expand Down