Query heads
×Expand the query latent into 128 query heads of 192 features: 128 content features and 64 rotated features.
All 7 steps
- in
- [B batch, 1 position, 1536 q latent] [1 position, 32 pairs]
- out
- [B batch, 128 heads, 1 position, 576 latent + rotary]
Parameters37,748,736 × 3 layers
37,748,736 parameters per instance, across its learned components
| Component | Calculation | Parameters |
|---|---|---|
| Query content up-projection | 1,536 × 16,384 | 25,165,824 |
| Query rotary up-projection | 1,536 × 8,192 | 12,582,912 |
| Per-instance total | 37,748,736 | |
One in each of the 3 dense layers, each with its own weights.
Explanation
One matrix, wq_b, produces both parts; the reference splits each head’s 192 features after the product (model.py 561–563).
Sources
In codeq · 575
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 @ a7e62ac04ecb
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 @ a7e62ac04ecb
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)