Cross-Attention Reads Encoder Records
Cross-attention projects decoder records into queries and encoder records into keys and values. Derive the target-by-source score shape, calculate a small matrix, and audit source assignment and masking.
Cross-attention assigns projected decoder records to queries and projected encoder records to keys and values. The source distinction is the operation's defining contract.
Let decoder state and encoder state . For one head,
Therefore
and the weighted source reading has shape before the head outputs are combined and projected.
Trace Two Target Queries and Three Source Records
For , , and one-dimensional queries and keys, choose
With , the score matrix is
Each target row softmaxes across three source columns. The second distribution is sharper because its score differences are larger.
If source values are , each target output is a weighted sum of these three values. There is no target-value column in this cross-attention operation.
Source Padding and Causality Are Different
Cross-attention normally masks padded or unavailable source columns. It does not usually need the target-side triangular mask because every current target query may read the complete available source. Causality is already enforced in target self-attention and target shifting.
A Source-Swap Audit
Hold decoder state fixed and alter one encoder record. Cross-attention outputs may change. Hold encoder state fixed and alter one later target record: an earlier target query must remain unchanged through causal decoder computation. Together these interventions test source assignment and target leakage.
Q1. Derive a cross-attention shape
For , , and , what is the per-head cross-attention score shape?
Answer it first, then check.