Sparse latent attention

Query compression

×

Compress each position’s 7,168 features into a 1,536-feature query latent.

Why

Queries pass through a low-rank latent as well; the authors say this can reduce activation memory during training. DeepSeek-V3 §2.1.1

cQ=xWDQc^{{\htmlClass{vl-stream-q}{Q}}}=xW_{DQ}
c^Q=RMSNorm⁡(cQ)\hat c^{{\htmlClass{vl-stream-q}{Q}}}=\operatorname{RMSNorm}(c^{{\htmlClass{vl-stream-q}{Q}}})
in
xx [B batch, 1 position, 7168 d]
out
c^Q\hat c^{Q} [B batch, 1 position, 1536 q latent]
Parameters11,011,584 × 3 layers

11,011,584 parameters per instance, across its learned components

ComponentCalculationParameters
Query down-projection7,168 × 1,53611,010,048
Query latent RMSNorm1,536
Per-instance total11,011,584

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

Explanation

Two matrices, 7,168 × 1,536 and 1,536 × 24,576, hold 48,758,784 weights; one 7,168 × 24,576 matrix would hold 176,160,768.

Sources

In codeself.q_norm(self.wq_a(x))

Open pinned code ↗

Direct evidence

MLA owns a query down-projection, query RMSNorm and up-projection, a joint key–value down-projection that also emits the shared rotary key, a latent RMSNorm, a key–value up-projection and an output projection.

model.py 523–539 ↗ · deepseek-ai/DeepSeek-V3.2-Exp @ 87e509a2e5a1

Excerpt
        self.qk_head_dim = args.qk_nope_head_dim + args.qk_rope_head_dim
        self.v_head_dim = args.v_head_dim

        self.wq_a = Linear(self.dim, self.q_lora_rank)
        self.q_norm = RMSNorm(self.q_lora_rank)
        self.wq_b = ColumnParallelLinear(self.q_lora_rank, self.n_heads * self.qk_head_dim)
        self.wkv_a = Linear(self.dim, self.kv_lora_rank + self.qk_rope_head_dim)
        self.kv_norm = RMSNorm(self.kv_lora_rank)
        self.wkv_b = ColumnParallelLinear(self.kv_lora_rank, self.n_heads * (self.qk_nope_head_dim + self.v_head_dim))
        self.wo = RowParallelLinear(self.n_heads * self.v_head_dim, self.dim)
        self.softmax_scale = self.qk_head_dim ** -0.5
        self.scale_fmt = args.scale_fmt
        if args.max_seq_len > args.original_seq_len:
            mscale = 0.1 * args.mscale * math.log(args.rope_factor) + 1.0
            self.softmax_scale = self.softmax_scale * mscale * mscale

        self.indexer = Indexer(args)

Queries are produced through a low-rank latent, split into a non-rotated and a rotated part, and rotated.

model.py 560–564 ↗ · deepseek-ai/DeepSeek-V3.2-Exp @ 87e509a2e5a1

Excerpt
        qr = self.q_norm(self.wq_a(x))
        q = self.wq_b(qr)
        q = q.view(bsz, seqlen, self.n_local_heads, self.qk_head_dim)
        q_nope, q_pe = torch.split(q, [self.qk_nope_head_dim, self.qk_rope_head_dim], dim=-1)
        q_pe = apply_rotary_emb(q_pe, freqs_cis)