Downloads · 30 days
0
yuan0763/open-deepseek-v4
open-deepseek-v4 is a text generation model from yuan0763. Use it when you need the model to write or continue text. The card lists the license as mit.
An open-source, HuggingFace-compatible reproduction of DeepSeek-V4 — a 1.6T parameter Mixture-of-Experts language model with 49B activated parameters and 1M token context length.
Downloads · 30 days
0
Access
Public
Updated Sep 19, 2026
Repo size
—
Likes
0
Public
Click a slice to open those files.
.py82.6 KB · 88%
From the Hugging Face model README
An open-source, HuggingFace-compatible reproduction of DeepSeek-V4 — a 1.6T parameter Mixture-of-Experts language model with 49B activated parameters and 1M token context length.
Based on the DeepSeek-V4 Technical Report and official inference code.
DeepSeek-V4 introduces several key innovations over DeepSeek-V3:
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 |
*V4-Flash specs are estimated from the paper.
| 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 file
import json
from configuration_deepseek_v4 import DeepSeekV4Config
from modeling_deepseek_v4 import DeepSeekV4ForCausalLM
# Load nano config for testing
with open("configs/config_nano.json") as f:
config = DeepSeekV4Config(**json.load(f))
model = DeepSeekV4ForCausalLM(config)
# Forward pass
import torch
input_ids = torch.randint(0, config.vocab_size, (1, 128))
outputs = model(input_ids)
logits = outputs.logits # [1, 128, vocab_size]
# With labels (training)
labels = torch.randint(0, config.vocab_size, (1, 128))
outputs = model(input_ids, labels=labels)
loss = outputs.loss
loss.backward()
All 12 architecture tests pass:
tilelang kernels for FP4/FP8 GEMM and sparse attentionMIT (matching DeepSeek-V4's license)
@misc{deepseekai2026deepseekv4,
title={DeepSeek-V4: Towards Highly Efficient Million-Token Context Intelligence},
author={DeepSeek-AI},
year={2026},
}