Self-attention में, Q, K, और V सभी एक ही sequence से आते हैं — प्रत्येक token उसी input में अन्य tokens पर attend करता है। Cross-attention में, Q एक source से (जैसे decoder) और K, V दूसरे से (जैसे encoder) आते हैं। Decoder token पूछता है "input में क्या relevant है जो मैं अभी generate कर रहा हूं?" और attention mechanism input का weighted summary प्रदान करता है।
Text-to-image models image generation को text पर condition करने के लिए cross-attention का उपयोग करते हैं। Text prompt को embeddings में encode किया जाता है (CLIP या T5 के माध्यम से), और प्रत्येक denoising step पर, image features cross-attention layers के माध्यम से text embeddings पर attend करते हैं। इसी तरह model जानता है कि "a cat on a surfboard" generate करना है — image में प्रत्येक spatial location relevant words पर attend करता है। इन cross-attention maps में हेरफेर करना ही prompt weighting और attention editing जैसी techniques काम करती हैं।
Self-attention और cross-attention के अलग computational profiles हैं। Self-attention sequence length में quadratic है (हर token हर दूसरे token पर attend करता है)। Cross-attention decoder length times encoder length में linear है (प्रत्येक decoder token सभी encoder tokens पर attend करता है)। व्यवहार में, encoder output अक्सर decoder sequence से बहुत छोटा होता है, जिससे cross-attention decoder self-attention से सस्ता होता है।