Mix and project

Merge heads

×

Concatenate the heads at each position.

[B, 128, T, 128][B,\,128,\,T,\,128]
→  [B, T, 128, 128]\to\;[B,\,T,\,128,\,128]
→  [B, T, 16384]\to\;[B,\,T,\,16384]
in
OO [B batch, 128 heads, 1 position, 128 value]
out
oo [B batch, 1 position, 16384 heads × value]
Explanation

Heads are concatenated in order: head ii fills features 128i,…,128i+127{128i},\dots,{128i+127}.

Sources

In codeattn_output.reshape(bsz, q_len, self.num_heads * self.v_head_dim)

Open pinned code ↗

Direct evidence

Head outputs are flattened and projected back to the model width.

modeling_deepseek.py 894–898 ↗ · deepseek-ai/DeepSeek-V2 @ 4461458f186c

Excerpt
        attn_output = attn_output.transpose(1, 2).contiguous()

        attn_output = attn_output.reshape(bsz, q_len, self.num_heads * self.v_head_dim)

        attn_output = self.o_proj(attn_output)