IA3 › Worked Example: Computing IA3-Adapted Attention
Language AI HandbookAll chapters IA3 › Worked Example: Computing IA3-Adapted AttentionOne section · Sections in this chapter5 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Let's work through a concrete numerical example to solidify the mechanics. We will trace exactly how IA3 modifies a small attention computation, showing every step of the calculation.
Consider a tiny transformer with hidden dimension , processing a sequence of 3 tokens. The input matrix and frozen weight matrices and are:
For simplicity, we set (the identity matrix), so value vectors equal the input embeddings. The IA3 rescaling vector for keys is:
Step 1: Compute the standard key matrix. Multiply by :
Each row is the key vector for one of the 3 tokens.
Step 2: Apply IA3 rescaling. Multiply each element of by the corresponding entry of . Since :
Notice the effect: dimensions 1 and 3 (indices 0 and 2), which had large initial values, are amplified further. Dimensions 2 and 4 (indices 1 and 3) are compressed. The first token's key has been pulled strongly toward dimensions 1 and 3, while its contributions from dimensions 2 and 4 are nearly suppressed.
Step 3: Observe the effect on attention scores. Suppose we compute a simple self-attention score for the first token querying itself (ignoring the multi-head structure for clarity). If the query for token 1 is (the same as its unscaled key vector for this example), then:
Without IA3:
With IA3:
The amplified dimensions 1 and 3 contribute much more to the attention score after IA3. This larger score makes token 1 appear more needed to itself. Meanwhile, the other tokens with less activation in dimensions 1 and 3 will see their keys relatively less scaled, changing the relative attention distribution.
Step 4: Count the parameters. For this toy example with and (assuming the expansion), IA3 introduces:
- parameters
- parameters
- parameters
- Total: 24 parameters
The frozen weight matrices and together contain parameters, plus and the output projection would add another 32. In this toy scale, IA3 adds 24 parameters to a block with 64 frozen parameters: 37% overhead. At real scales (LLaMA-7B with ), this ratio shrinks sharply. The frozen weights per layer include four matrices totaling 67 million parameters, while IA3 adds only about 19,000 parameters, which is 0.028% overhead.

