Inkling 2 Mini Architecture: AttnRes and the Looped Transformer
1. Vanilla Transformer
In a vanilla Transformer, each layer has a self-attention sublayer and a feed-forward network (FFN). Inkling uses a mixture of experts (MoE) for the FFN. Self-attention exchanges information along the token sequence. Residual connections carry information along model depth by adding each sublayer output and passing the updated representation to the next layer.
Here, h is the residual stream. As the model processes more layers, it carries the embedding and the accumulated outputs of earlier layers. The attention in this example is self-attention, which exchanges information between token positions. The depth-wise attention in AttnRes operates across layers.
From the perspective of AttnRes, standard residual addition in a vanilla Transformer accumulates every sublayer’s contribution with a weight of 1.
Information from different depths can be useful to different degrees. Could each sublayer learn which earlier contributions to read and how much weight to give them? Attention Residuals, introduced by the Kimi Team, use learned, input-dependent softmax weights to select earlier representations. Block AttnRes groups layers to reduce the cost of reading every layer individually.
2. Attention Residuals
2.1 Block Running Sum
Inkling 2 Mini divides its 24 layers into four blocks of six layers each. During inference, each block maintains a running sum with shape [sequence_length, hidden_size]. In the examples below, the B3 running sum is the sum for the third block.
At token position t, each attention or MoE output is a vector of length hidden_size. The current block’s running sum contains a vector of the same length at that position. Whenever the model produces an o_attn or o_MoE vector for a token, it adds that vector element by element to the running sum at the corresponding token position.
These o_attn and o_MoE outputs play a similar role to o_attn and o_FFN in the vanilla Transformer. Section 2.2 explains how depth-wise attention changes the way their inputs are formed.
Take B3 = L13–L18 as an example. Throughout this example, we look at a single token position t and use hidden_size = 3 to show the addition. After L13–L15 finish, six outputs have been written into B3.
Next, the model executes L16 and L17. Each depth-wise read uses B3’s value at that moment. The running sum changes when a sublayer finishes its computation and writes its output.
| Point in execution | Newly written output vector | B3 running sum (token t) |
|---|---|---|
| Before L16 attention | No new output yet | (2, −1, 4) |
| After L16 attention | o_attn^(16) = (1, 2, −1) |
(3, 1, 3) |
| After L16 MoE | o_MoE^(16) = (−2, 0, 2) |
(1, 1, 5) |
| After L17 attention | o_attn^(17) = (0, 3, −1) |
(1, 4, 4) |
| After L17 MoE | o_MoE^(17) = (1, −2, 0) |
(2, 2, 4) |
At the start of L16, B3 holds the sum of the L13–L15 outputs. At the start of L17, it also includes both outputs from L16.
More generally, just before layer ℓ starts in the current block B_i, the running sum includes only the layers in that block that have finished. Throughout the sum, t refers to the same token position.
For a real token sequence, each position has its own vector of length hidden_size, giving the running sum an overall shape of [sequence_length, hidden_size].
Comparison with a vanilla Transformer
| Aspect | Vanilla Transformer | Inkling’s Block AttnRes |
|---|---|---|
| Storage of earlier outputs | One continuously updated residual stream | A separate running sum for each block |
| How a sublayer gets its input | Reads the current residual stream h |
Uses a learned query and softmax weights to read available blocks |
| Where attention and MoE outputs go | Into the shared residual stream | Into the current block’s running sum |
| How tokens exchange information | Self-attention | Self-attention |
| How earlier contributions are selected | The residual stream adds all earlier outputs with equal weight | A depth-wise read selects contributions based on token content and learned reader parameters |
Block AttnRes lets deeper sublayers read normalized representations from earlier blocks directly and vary how much weight they give each depth.
2.2 Depth-wise Attention
At the same token position, a depth-wise read combines three sources to form the current sublayer input. It reads the embedding (block 0), the sums from all earlier completed blocks, and the current block’s partial running sum. Each self-attention sublayer and each MoE sublayer has its own depth-wise read. The read computes softmax across blocks. The subsequent self-attention operates across the token sequence.
Inkling 2 Mini divides its 24 layers into four AttnRes blocks of six layers each.
| Block | Layers | What it stores |
|---|---|---|
| B0 | Embedding | The initial token representation, available as an independent source |
| B1 | L1–L6 | Sum of the attention and MoE outputs from these six layers |
| B2 | L7–L12 | Sum of the attention and MoE outputs from these six layers |
| B3 | L13–L18 | Sum of the attention and MoE outputs from these six layers |
| B4 | L19–L24 | Sum of the attention and MoE outputs from these six layers |
B0 is the normalized embedding, v₀ = RMSNorm(Embedding). Each of B1–B4 maintains a block running sum that starts at zero. Once a block finishes, its running sum becomes the final block sum.
Goodfire Figure 1. The depth-wise read at layer 16
The blue arrows just before L16 converge at the depth-wise read from the B0 embedding, completed blocks B1 and B2, and the current B3 partial sum. At this point, B3 contains only the outputs of L13–L15 because L16 has yet to run.
Computing depth-wise attention
First, divide each available block vector vⱼ by its root mean square.
Each layer contains two sublayers, attention and MoE (the FFN). They have separate learned query parameters, q_attn and q_MoE, which stay fixed during inference. Each sublayer uses its own q to compute a weighted sum of the available block vectors.
Start with pass 1. The attention sublayer’s depth-wise read produces x_A (written as x in the formula above). After RMSNorm, W_Q, W_K, and W_V project that same input into Q, K, and V for self-attention. Once attention writes its output, the MoE sublayer does its own depth-wise read to obtain x_M. Passes 2 and 3 still perform these reads and also incorporate messages from the preceding pass before projection or MoE computation, as shown in section 3.
For example, suppose the L16 attention reader assigns weights of 0.10/0.20/0.50/0.20 to B0, B1, B2, and B3. Its input is the weighted sum of those four normalized block vectors.
Depth-wise attention only reads B3’s running sum. The sum changes when self-attention or MoE computes its own output and adds it to the block.
Layer 16 (B3) during inference
The equations below use DRead for the block scoring and weighted sum. It reads the available block vectors using the definitions of αⱼ and v̂ⱼ above.
The attention sublayer of layer 16 reads and combines B0, B1, B2, and the current B3 sum from L13–L15. It then runs ordinary self-attention and adds the resulting o_attn^(16) to B3.
Next, the MoE sublayer of the same layer does another depth-wise read from B0, B1, B2, and the updated B3. B3 now includes this layer’s attention output, so the two reads see different inputs. They also use separate reader parameters. When MoE finishes, it writes o_moe^(16) to B3.
| Step | Operation | What happens to B3? |
|---|---|---|
| 1 | Depth-wise read for attention | B3 still holds the sum from L13–L15 |
| 2 | Ordinary self-attention | Computes o_attn^(16) |
| 3 | First write | Adds the L16 attention output to B3 |
| 4 | Depth-wise read for MoE | Reads the updated B3 |
| 5 | MoE / FFN | Computes o_moe^(16) |
| 6 | Second write | Adds the L16 MoE output to B3 and passes the sum to L17 |
3. Looped Transformer
3.1 Blocks 2 and 3 Run Three Times
Inkling 2 Mini’s 24 layers are still divided into the same four blocks. B1 (L1–L6) runs once at the start. B2 (L7–L12) and B3 (L13–L18) then run together for three passes, each in the order L7 → L18. Finally, B4 (L19–L24) runs once.
Every pass reuses the same weights for L7–L18, though the inputs and resulting block sums can differ. The model executes 6 + 12 × 3 + 6 = 48 layers’ worth of computation and stores weights for 24 layers. This gives the model more computation per token with a fixed parameter count.
| Stage | Result at the end of the stage | What uses it next |
|---|---|---|
| B1, once | v₁ |
Available as earlier context in all three passes |
| Pass 1, B2 → B3 | v₂^[1] and v₃^[1] |
Read across the loop in pass 2 |
| Pass 2, B2 → B3 | v₂^[2] and v₃^[2] |
Read across the loop in pass 3 |
| Pass 3, B2 → B3 | v₂^[3] and v₃^[3] |
Passed to B4 |
| B4, once | Final representation | The final read and output layer produce the prediction |
The superscripts [1], [2], and [3] indicate the pass number.
The rest of this example still follows one token position, t.
3.2 Messages Between Passes
What the first pass leaves for the second
In the first pass, B2 starts at zero and adds the attention and MoE outputs of L7–L12. B3 starts at zero as well and accumulates the outputs of L13–L18. The pass leaves two completed block sums.
At the start of pass 2, the B2 and B3 running sums reset to zero. The completed sums from pass 1, v₂^[1] and v₃^[1], stay available as sources for cross-loop messages.
When pass 2 reaches the attention sublayer of L7, the first layer in B2, the current pass has yet to write anything into B2. The sublayer reads along two paths.
| Read path | What it reads | What it produces |
|---|---|---|
| Depth-wise read | The B0 embedding and completed B1. The current B2 is still empty. | Current-pass input x |
| Cross-loop read | Completed B2 and B3 from the previous pass | Previous-pass message m |
In pass 1, the attention sublayer gets its current-pass input x from a depth-wise read. Then W_Q, W_K, and W_V project it into Q, K, and V for self-attention.
Pass 2 also starts by computing the current-pass x. Cross-loop attention then reads a message m from the previous pass.
At a fixed token position t, each of the completed B2 and B3 sums from the previous pass contains a vector of length hidden_size = 2304. The cross-loop read selects between the two vectors at that same token position. Each layer has four learned reader vectors, u_Q, u_K, u_V, and u_MoE. They serve the three attention input paths and the MoE input path, respectively.
In vanilla attention and in the depth-wise attention example above, W_Q, W_K, and W_V project the same input matrix. When cross-loop reads supply a separate message to each path, the three projections receive three different input matrices.
For example, u_Q is a 2,304-dimensional parameter vector used to select between blocks from the previous pass. The equations below show how it produces the message m_Q.
At position t, β₂,Q and β₃,Q might be 0.20/0.80. The message m_Q(t) is the weighted sum of the previous pass’s B2 and B3 vectors at that position, so it still has 2,304 dimensions. The same procedure produces m_K, m_V, and m_MoE using u_K, u_V, and u_MoE. Attention starts with one shared current-pass input x and three previous-pass messages, one each for Q, K, and V. Each path combines its message with x as follows.
The symbol ⊙ means element-wise multiplication. First, β controls how much each of the previous pass’s B2 and B3 contributes to the message. Then κ and γ control how much of the current-pass x to retain and how much of the message to add. Suppose 80% of m_Q comes from B3. Setting γ_Q=0 for a particular coordinate still lets the model omit cross-loop information from that coordinate of x′_Q.
The three x′ vectors are inputs to the projections that produce Q, K, and V for self-attention. The paths are x′_Q → RMSNorm → W_Q → Q, x′_K → RMSNorm → W_K → K, and x′_V → RMSNorm → W_V → V. Self-attention then exchanges information across the token sequence. Once attention writes its output to the current B2, the MoE sublayer performs another depth-wise read to obtain an updated x_M, merges it with m_MoE, and uses the result as its input.
By L8 in pass 2, the depth-wise read can see the B2 partial sum that L7 wrote in that pass. The cross-loop read still uses the completed B2 and B3 sums from pass 1.
3.4 Layer 16 as an Example
Section 2.2 followed L16 within one pass through the depth-wise read, self-attention, write to B3, another read, MoE, and another write. Pass 2 follows the same order and adds a cross-loop read before each sublayer runs.
When L16 attention starts in pass 2, the current B3 already contains the outputs of L13–L15. The current-pass path works as in the previous section. The cross-loop path reads the completed B2 and B3 sums from pass 1.
Here, x_A^[2] is the current-pass input to L16 attention. The equations show the Q path in detail. The reader u_Q retrieves the previous-pass message m_Q^[2], and the gates combine it with x_A^[2] to produce x′_Q before projection. The K and V paths use u_K/u_V to obtain m_K^[2]/m_V^[2] and produce x′_K/x′_V. After the three paths project their inputs into Q, K, and V, self-attention computes o_attn^(16,[2]) for pass 2 and writes it to the current B3. MoE then reads the updated B3, uses u_MoE to retrieve its own message from the previous B2 and B3 sums, and merges that message into its input. It writes o_MoE^(16,[2]) into the current B3 as well.
Pass 3 repeats the same process, reading v₂^[2] and v₃^[2] from pass 2. Information from pass 1 can still influence pass 3 through the results computed in pass 2. After the three passes, B4 reads the available sums from the final pass and continues the computation.
The three reads operate on different axes. Depth-wise reads select among blocks in the current pass at the same token position. Cross-loop reads select between B2 and B3 from the previous pass at that same position. Ordinary self-attention then exchanges information between token positions.