Multi-head latent attention

Causal attention

×

Attend over current and earlier positions with 128 heads and project the result to the model width.

O=AVO=AV
Δattn=oWO\Delta_{\mathrm{attn}}=oW_{O}
All 8 steps
S=QKTS=QK^{\mathsf T}
St′=St⋅τt192S'_{t}=S_{t}\cdot\frac{\tau_t}{\sqrt{192}}
S~=S′+M\tilde S=S'+{\htmlClass{vl-stream-context}{M}}
A[b,i,t,s]=exp⁡(S~[b,i,t,s])∑u=0T−1exp⁡(S~[b,i,t,u])A[b,i,t,s]=\frac{\exp(\tilde S[b,i,t,s])}{\sum_{u=0}^{T-1}\exp(\tilde S[b,i,t,u])}
Mix and project:\text{Mix and project:}
O=AVO=AV
o=reshape⁡(O)o=\operatorname{reshape}(O)
Δattn=oWO\Delta_{\mathrm{attn}}=oW_{O}
in
QQ [B batch, 128 heads, T positions, 192 content + rotary]KK [B batch, 128 heads, T positions, 192 content + rotary]VV [B batch, 128 heads, T positions, 128 value]MM [T queries, T keys]τ\tau [T positions]
out
Δattn\Delta_{\mathrm{attn}} [B batch, T positions, 7168 d]
Parameters117,440,512 × 3 layers

117,440,512 parameters per instance, across its learned components

ComponentParameters
Mix and project117,440,512

One in each of the 3 dense layers, each with its own weights.

Explanation

These cards follow the prefill path, forward_mha (mla_attention.py 3207–3227), with attention as vLLM’s CPU backend writes it out (cpu_sdpa.py 65–79). Decoding scores the cached latents directly (mla_attention.py 93–117).

Sources

In codeprefill_backend.run_prefill_new_tokens(q=q, k=k, v=v, …)

Open pinned code ↗

Direct evidence

On the prefill path kv_b_proj rebuilds each head’s content keys and values from the normalized latent, each head’s key joins its content part and the shared rotary key, and the prefill backend runs attention over the new tokens.

mla_attention.py 3207–3227 ↗ · vllm-project/vllm @ 5df63a7203cd

Excerpt
        kv_nope = self.kv_b_proj(kv_c_normed)[0].view(
            -1, self.num_heads, self.qk_nope_head_dim + self.v_head_dim
        )
        k_nope, v = kv_nope.split([self.qk_nope_head_dim, self.v_head_dim], dim=-1)
        k = self._concat_k_nope_k_pe(k_nope, k_pe)

        if use_fp8_prefill:
            k = k.to(prefill_metadata.q_data_type)
            v = v.to(prefill_metadata.q_data_type)

        output_prefill = prefill_metadata.prefill_backend.run_prefill_new_tokens(
            q=q,
            k=k,
            v=v,
            return_softmax_lse=has_context,
            out=(
                output.view(-1, self.num_heads, self.v_head_dim)
                if output_scale is not None
                else None
            ),
            output_scale=output_scale,

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]