Token embedding
×Look up a learned feature vector for each token ID.
- in
- [B batch, T positions]
- out
- [B batch, T positions, 7168 d]
Parameters926,679,040
926,679,040 parameters per instance.
| Component | Calculation | Parameters |
|---|---|---|
| Token embedding | 129,280 × 7,168 | 926,679,040 |
Sources
In codeself.embed(input_ids) · 803
Direct evidence
The token embedding is a learned table of vocabulary × width rows.
model.py 83–105 ↗ · deepseek-ai/DeepSeek-V4-Pro @ b5968e9190ef
Excerpt
class ParallelEmbedding(nn.Module):
"""Embedding sharded along the vocab dimension. Each rank holds vocab_size // world_size rows.
Out-of-range indices are zero-masked before all_reduce to combine partial embeddings."""
def __init__(self, vocab_size: int, dim: int):
super().__init__()
self.vocab_size = vocab_size
self.dim = dim
assert vocab_size % world_size == 0, f"Vocabulary size must be divisible by world size (world_size={world_size})"
self.part_vocab_size = (vocab_size // world_size)
self.vocab_start_idx = rank * self.part_vocab_size
self.vocab_end_idx = self.vocab_start_idx + self.part_vocab_size
self.weight = nn.Parameter(torch.empty(self.part_vocab_size, self.dim))
def forward(self, x: torch.Tensor) -> torch.Tensor:
if world_size > 1:
mask = (x < self.vocab_start_idx) | (x >= self.vocab_end_idx)
x = x - self.vocab_start_idx
x[mask] = 0
y = F.embedding(x, self.weight)
if world_size > 1:
y[mask] = 0
dist.all_reduce(y)
return yThe forward: embed, repeat into four streams, apply the 61 layers with the token IDs, read out through the head; the MTP block is not run.
model.py 801–809 ↗ · deepseek-ai/DeepSeek-V4-Pro @ b5968e9190ef
Excerpt
@torch.inference_mode()
def forward(self, input_ids: torch.Tensor, start_pos: int = 0):
h = self.embed(input_ids)
# Expand to hc_mult copies for Hyper-Connections
h = h.unsqueeze(2).repeat(1, 1, self.hc_mult, 1)
for layer in self.layers:
h = layer(h, start_pos, input_ids)
logits = self.head(h, self.hc_head_fn, self.hc_head_scale, self.hc_head_base, self.norm)
return logitsThe reference configuration: 61 layers of width 7,168, 128 heads of 512 features with a 64-feature rotary part, a 1,536-feature query latent, a grouped output of 16 groups at rank 1,024, a window of 128, the per-layer compression ratios (128, 128, then 4 and 128 alternating, and 0 for the MTP block), an indexer of 64 heads of 128 keeping 1,024, hyper-connections of 4 streams with 20 Sinkhorn iterations, 384 routed experts of 3,072 of which 6 are used with 1 shared, square-root-softplus scores scaled by 2.5, three hash-routed layers, and YaRN over 65,536 positions.
config.json 1–34 ↗ · deepseek-ai/DeepSeek-V4-Pro @ b5968e9190ef
Excerpt
{
"vocab_size": 129280,
"dim": 7168,
"moe_inter_dim": 3072,
"n_layers": 61,
"n_hash_layers": 3,
"n_heads": 128,
"n_routed_experts": 384,
"n_shared_experts": 1,
"n_activated_experts": 6,
"score_func": "sqrtsoftplus",
"route_scale": 2.5,
"swiglu_limit": 10.0,
"q_lora_rank": 1536,
"head_dim": 512,
"rope_head_dim": 64,
"o_groups": 16,
"o_lora_rank": 1024,
"window_size": 128,
"original_seq_len": 65536,
"rope_theta": 10000,
"rope_factor": 16,
"beta_fast": 32,
"beta_slow": 1,
"index_n_heads": 64,
"index_head_dim": 128,
"index_topk": 1024,
"hc_mult": 4,
"hc_sinkhorn_iters": 20,
"dtype": "fp8",
"scale_fmt": "ue8m0",
"expert_dtype": "fp4",
"compress_rope_theta": 160000,
"compress_ratios": [128, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 0]