Key–value compression

xx [B, T, 7168]to c^KV\hat c^{KV} [B, T, 512]

prefill, empty cache

Parameters3,670,528 × 58 layers

3,670,528 parameters per instance, across its learned components

ComponentCalculationParameters
Key–value down-projection7,168 × 5123,670,016
Key–value latent RMSNorm512
Per-instance total3,670,528

One in each of the 58 MoE layers, each with its own weights.

Explanation

The reference caches this latent and the rotary key (model.py 572–573): 576 values per position. Full per-head keys (192 features) and values (128) would take 40,960. The lightning indexer caches one more key per position, of 128 features.

One matrix, wkv_a, produces this latent and the 64-feature rotary key together, 576 output features in all; the reference splits them after the product (model.py 565–566).

Every head’s key and value128 × (192 + 128) = 40,960Latent and rotary key, cached512 + 64 = 576Indexer key, cached128
Drawn to scale for one position in one layer: the latent and rotary key take 1/71 of every head’s keys and values; with the indexer key, 1/58.
Sources

In codeself.kv_norm(kv)

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 @ 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)

The joint down-projection yields the key–value latent and one rotary key shared by all heads; the latent is normalized and the key rotated.

model.py 565–568 ↗ · deepseek-ai/DeepSeek-V3.2 @ a7e62ac04ecb

Excerpt
        kv = self.wkv_a(x)
        kv, k_pe = torch.split(kv, [self.kv_lora_rank, self.qk_rope_head_dim], dim=-1)
        kv = self.kv_norm(kv)
        k_pe = apply_rotary_emb(k_pe.unsqueeze(2), freqs_cis)