Views
No views yet
head_dim=512 (vs V3's separate kv_lora_rank=512 + qk_nope_head_dim=128 + v_head_dim=128)q_lora_rank=1536 with RMSNorm bottlenecko_groups=16, o_lora_rank=1024 — output is split into groups, each compressed independentlysqrtsoftplus activation (√softplus) for remaining layersnoaux_tc)swiglu_limit=10.0 for numerical stabilityhc_mult=4 copies of hidden staten_mtp_layers=1: One additional prediction head| Config | Total Params | Active Params | Layers | Experts | Hidden | Heads |
|---|---|---|---|---|---|---|
| V4-Pro | 1.6T | 49B | 61 | 384 | 7168 | 128 |
| V4-Flash | 284B | 13B | 61 | 128* | 4096* | 64* |
| V4-Nano (ours) | ~523M | ~200M | 7 | 8 | 1024 | 16 |
| Feature | DeepSeek-V3 | DeepSeek-V4 |
|---|---|---|
| Attention | MLA with full KV | MLA + Compressed Sparse Attention |
| KV format | kv_lora_rank=512 separate nope/rope/v | Unified head_dim=512 |
| Output projection | Single wo | Grouped low-rank wo_a + wo_b |
| Residual connections | Standard | Manifold-Constrained Hyper-Connections |
| Expert scoring | sigmoid | sqrtsoftplus (√softplus) |
| Expert routing | Score-based all layers | Hash routing (first 3) + score-based |
| Expert precision | FP8 | FP4 (with E8M0 scales) |
| Context length | 128K | 1M tokens |
| Sliding window | None | 128 tokens |
| KV compression | None | Learned gated pooling (4:1 and 128:1) |
| Sparse attention | None | Indexer-based top-k selection |
| Optimizer | AdamW | Muon |
| Training tokens | 14.8T | 32T+ |
open-deepseek-v4/
├── configuration_deepseek_v4.py # HF-compatible config class
├── modeling_deepseek_v4.py # Full model implementation (pure PyTorch, no custom kernels)
├── architecture_analysis.py # Detailed V3→V4 architectural comparison
├── test_model.py # Comprehensive test suite (12 tests)
├── train.py # Training script with HF Trainer
├── configs/
│ ├── config_pro.json # 1.6T Pro config (matches official)
│ └── config_nano.json # ~523M Nano config for testing
└── README.md # This file1import json
2from configuration_deepseek_v4 import DeepSeekV4Config
3from modeling_deepseek_v4 import DeepSeekV4ForCausalLM
4
5# Load nano config for testing
6with open("configs/config_nano.json") as f:
7 config = DeepSeekV4Config(**json.load(f))
8
9model = DeepSeekV4ForCausalLM(config)
10
11# Forward pass
12import torch
13input_ids = torch.randint(0, config.vocab_size, (1, 128))
14outputs = model(input_ids)
15logits = outputs.logits # [1, 128, vocab_size]
16
17# With labels (training)
18labels = torch.randint(0, config.vocab_size, (1, 128))
19outputs = model(input_ids, labels=labels)
20loss = outputs.loss
21loss.backward()tilelang kernels for FP4/FP8 GEMM and sparse attention1@misc{deepseekai2026deepseekv4,
2 title={DeepSeek-V4: Towards Highly Efficient Million-Token Context Intelligence},
3 author={DeepSeek-AI},
4 year={2026},
5}