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, T positions, 128 value]
out
oo [B batch, T positions, 16384 heads × value]
Explanation

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

Sources

In codeoutput_prefill.flatten(start_dim=-2)

Open pinned code ↗

Direct evidence

The attention output, heads flattened, is projected back to the model width by o_proj.

mla.py 244–255 ↗ · vllm-project/vllm @ 5df63a7203cd

Excerpt
        attn_out = self.mla_attn(
            q,
            kv_c_normed,
            k_pe,
            output_shape=(hidden_states.shape[0], self.num_heads * self.v_head_dim),
            q_dcp_replicated=q_dcp_replicated,
        )

        if self.g_proj is not None:
            attn_out = attn_out * self.g_proj(hidden_states)[0].sigmoid()

        return self.o_proj(attn_out)[0]