DeepSeek-V4: Towards Highly Efficient Million-Token Context Intelligence ## Report GitHub Issue × Title: Content selection saved. Describe the issue below: Description: Submit without GitHub Submit in GitHub arXiv is now an independent nonprofit! Learn more × Back to arXiv Why HTML? Report Issue Back to Abstract Download PDF Abstract 1 Introduction 2 Architecture 2.1 Designs Inherited from DeepSeek-V3 Mixture-of-Experts. Multi-Token Prediction. 2.2 Manifold-Constrained Hyper-Connections Standard Hyper-Connections. Manifold-Constrained Residual Mapping. Dynamic Parameterization. Applying Parameter Constraints. 2.3 Hybrid Attention with CSA and HCA 2.3.1 Compressed Sparse Attention Compressed Key-Value Entries. Lightning Indexer for Sparse Selection. Shared Key-Value MQA. Grouped Output Projection. 2.3.2 Heavily Compressed Attention Compressed Key-Value Entries. Shared Key-Value MQA and Grouped Output Projection. 2.3.3 Other Details Query and Key-Value Entry Normalization. Partial Rotary Positional Embedding. Additional Branch of Sliding Window Attention. Attention Sink. 2.3.4 Efficiency Discussion 2.4 Muon Optimizer Basic Configurations. Hybrid Newton-Schulz Iterations. Avoiding Exploding Attention Logits. 3 General Infrastructures 3.1 Fine-Grained Communication-Computation Overlap in Expert Parallelism Communication Latency Can Be Hidden. Fine-Grained EP Scheme. Performance and Open-Sourced Mega-Kernel. Observations and Proposals. 3.2 Flexible and Efficient Kernel Development with TileLang Reducing Invocation Overhead with Host Codegen. SMT-Solver-Assisted Formal Integer Analysis. Numerical Precision and Bitwise Reproducibility. 3.3 High-Performance Batch-Invariant and Deterministic Kernel Libraries Batch Invariance. Determinism. 3.4 Training Framework 3.4.1 Efficient Implementation of Muon 3.4.2 Cost-Effective and Memory-Efficient Implementation of m HC 3.4.3 Contextual Parallelism for Long-Context Attention 3.4.4 Extended Automatic Differentiation for Flexible Activation Checkpointing 3.5 Inference Framework 3.5.1 KV Cache Structure and Management Heterogeneous KV Entries in DeepSeek-V4. Challenges in Managing Hybrid Attention KV Cache. State Cache for SWA and Uncompressed Tail Tokens. Sparse Attention Kernel Co-Design. 3.5.2 On-Disk KV Cache Storage 4 Pre-Training 4.1 Data Construction 4.2 Pre-Training Setups 4.2.1 Model Setups DeepSeek-V4-Flash. DeepSeek-V4-Pro. 4.2.2 Training Setups DeepSeek-V4-Flash. DeepSeek-V4-Pro. 4.2.3 Mitigating Training Instability Anticipatory Routing. SwiGLU Clamping. 4.3 Evaluations 4.3.1 Evaluation Benchmarks 4.3.2 Evaluation Results 5 Post-Training 5.1 Post-Training Pipeline 5.1.1 Specialist Training Reasoning Efforts. Generative Reward Model. Tool-Call Schema and Special Token. Interleaved Thinking. Quick Instruction. 5.1.2 On-Policy Distillation 5.2 Post-Training Infrastructures 5.2.1 FP4 Quantization-Aware Training 5.2.2 Efficient Teacher Scheduling for Full-Vocabulary OPD 5.2.3 Preemptible and Fault-Tolerant Rollout Service 5.2.4 Scaling RL Framework for Million-Token Context 5.2.5 Sandbox Infrastructure for Agentic AI Four Execution Substrates Behind One Unified Interface. Fast Image Loading via Layered Storage. Density Optimizations Under Massive Concurrency. Trajectory Logging and Preemption-Safe Resumption. 5.3 Standard Benchmark Evaluation 5.3.1 Evaluation Setup Knowledge and Reasoning. 1M-Token Context. Agent. 5.3.2 Evaluation Results Knowledge. Reasoning. Agent. 1M-Token Context. Reasoning Effort. 5.4 Performance on Real-World Tasks 5.4.1 Chinese Writing 5.4.2 Search Retrieval Augmented Search. Agentic Search. 5.4.3 White-Collar Task 5.4.4 Code Agent 6 Conclusion, Limitations, and Future Directions References A Author List and Acknowledgment A.1 Author List A.2 Acknowledgment B Evaluation Details License: arXiv.org perpetual non-exclusive license arXiv:2606.19348v1 [cs.CL] 26 Apr 2026 \reportnumber 001 ## DeepSeek-V4: Towards Highly Efficient Million-Token Context Intelligence DeepSeek-AI research@deepseek.com ## Abstract We present a preview version of DeepSeek-V4 series, including two strong Mixture-of-Experts (MoE) language models — DeepSeek-V4-Pro with 1.6T parameters (49B activated) and DeepSeek-V4-Flash with 284B parameters (13B activated) — both supporting a context length of one million tokens. DeepSeek-V4 series incorporate several key upgrades in architecture and optimization: (1) a hybrid attention architecture that combines Compressed Sparse Attention (CSA) and Heavily Compressed Attention (HCA) to improve long-context efficiency; (2) Manifold-Constrained Hyper-Connections ( m HC) that enhance conventional residual connections; (3) and the Muon optimizer for faster convergence and greater training stability. We pre-train both models on more than 32T diverse and high-quality tokens, followed by a comprehensive post-training pipeline that unlocks and further enhances their capabilities. DeepSeek-V4-Pro-Max, the maximum reasoning effort mode of DeepSeek-V4-Pro, redefines the state-of-the-art for open models, outperforming its predecessors in core tasks. Meanwhile, DeepSeek-V4 series are highly efficient in long-context scenarios. In the one-million-token context setting, DeepSeek-V4-Pro requires only 27% of single-token inference FLOPs and 10% of KV cache compared with DeepSeek-V3.2. This enables us to routinely support one-million-token contexts, thereby making long-horizon tasks and further test-time scaling more feasible. The model checkpoints are available at https://huggingface.co/collections/deepseek-ai/deepseek-v4 . Figure 1: Left : benchmark performance of DeepSeek-V4-Pro-Max and its counterparts. Right : inference FLOPs and KV cache size of DeepSeek-V4 series and DeepSeek-V3.2. ## Contents 1 Introduction 2 Architecture 2.1 Designs Inherited from DeepSeek-V3 2.2 Manifold-Constrained Hyper-Connections 2.3 Hybrid Attention with CSA and HCA 2.3.1 Compressed Sparse Attention 2.3.2 Heavily Compressed Attention 2.3.3 Other Details 2.3.4 Efficiency Discussion 2.4 Muon Optimizer 3 General Infrastructures 3.1 Fine-Grained Communication-Computation Overlap in Expert Parallelism 3.2 Flexible and Efficient Kernel Development with TileLang 3.3 High-Performance Batch-Invariant and Deterministic Kernel Libraries 3.4 Training Framework 3.4.1 Efficient Implementation of Muon 3.4.2 Cost-Effective and Memory-Efficient Implementation of m HC 3.4.3 Contextual Parallelism for Long-Context Attention 3.4.4 Extended Automatic Differentiation for Flexible Activation Checkpointing 3.5 Inference Framework 3.5.1 KV Cache Structure and Management 3.5.2 On-Disk KV Cache Storage 4 Pre-Training 4.1 Data Construction 4.2 Pre-Training Setups 4.2.1 Model Setups 4.2.2 Training Setups 4.2.3 Mitigating Training Instability 4.3 Evaluations 4.3.1 Evaluation Benchmarks 4.3.2 Evaluation Results 5 Post-Training 5.1 Post-Training Pipeline 5.1.1 Specialist Training 5.1.2 On-Policy Distillation 5.2 Post-Training Infrastructures 5.2.1 FP4 Quantization-Aware Training 5.2.2 Efficient Teacher Scheduling for Full-Vocabulary OPD 5.2.3 Preemptible and Fault-Tolerant Rollout Service 5.2.4 Scaling RL Framework for Million-Token Context 5.2.5 Sandbox Infrastructure for Agentic AI 5.3 Standard Benchmark Evaluation 5.3.1 Evaluation Setup 5.3.2 Evaluation Results 5.4 Performance on Real-World Tasks 5.4.1 Chinese Writing 5.4.2 Search 5.4.3 White-Collar Task 5.4.4 Code Agent 6 Conclusion, Limitations, and Future Directions References A Author List and Acknowledgment A.1 Author List A.2 Acknowledgment B Evaluation Details ## 1 Introduction The emergence of reasoning models ( OpenAI, 2024c ; DeepSeek-AI, 2025a ) has established a new paradigm of test-time scaling, driving substantial performance gains for Large Language Models (LLMs). However, this scaling paradigm is fundamentally constrained by the quadratic computational complexity of the vanilla attention mechanism ( Vaswani et al., 2017 ) , which creates a prohibitive bottleneck for ultra-long contexts and reasoning processes. Concurrently, the emergence of long-horizon scenarios and tasks — from complex agentic workflows to massive cross-document analysis — has also made efficient support for ultra-long contexts critical for future progress. While recent open-source efforts ( DeepSeek-AI, 2024c ; Qwen, 2025 ; MiniMax, 2025 ; Bai et al., 2025a ) have advanced general capabilities, this core architectural inefficiency in handling ultra-long sequences remains a key impediment, limiting further gains from test-time scaling and hindering further exploration into long-horizon scenarios and tasks. In order to break the efficiency barrier in ultra-long contexts, we develop the DeepSeek-V4 series, including the preview versions of DeepSeek-V4-Pro with 1.6T parameters (49B activated) and DeepSeek-V4-Flash with 284B parameters (13B activated). Through architectural innovations, DeepSeek-V4 series achieve a dramatic leap in computational efficiency for processing ultra-long sequences. This breakthrough enables efficient support for a context length of one million tokens, ushering in a new era of million-length contexts for next-generation LLMs. We believe our capability to efficiently handle ultra-long sequences unlocks the next frontier of test-time scaling, paves the way for deeper research into long-horizon tasks, and establishes a necessary foundation for exploring future paradigms like online learning. Compared with the DeepSeek-V3 architecture ( DeepSeek-AI, 2024c ) , DeepSeek-V4 series retain the DeepSeekMoE framework ( Dai et al., 2024 ) and Multi-Token Prediction (MTP) strategy, while introducing several key innovations in architecture and optimization. To enhance long-context efficiency, we design a hybrid attention mechanism combining Compressed Sparse Attention (CSA) and Heavily Compressed Attention (HCA). CSA compresses the KV caches along the sequence dimension and then performs DeepSeek Sparse Attention (DSA) ( DeepSeek-AI, 2025b ) , whereas HCA applies more aggressive compression to the KV caches but keeps dense attention. To strengthen modeling capability, we incorporate Manifold-Constrained Hyper-Connections ( m HC) ( Xie et al., 2026 ) that upgrade conventional residual connections. Additionally, we introduce the Muon ( Jordan et al., 2024 ; Liu et al., 2025 ) optimizer to the training of DeepSeek-V4 series, leading to faster convergence and improved training stability. To enable efficient training and inference for DeepSeek-V4 series as well as productive development, we introduce several infrastructure optimizations. First, we design and implement a single fused kernel for MoE modules that fully overlaps computation, communication, and memory access. Second, we employ TileLang ( Wang et al., 2026 ) , a Domain-Specific Language (DSL) to balance development productivity and runtime efficiency. Third, we provide efficient batch-invariant and deterministic kernel libraries to ensure bitwise reproducibility across training and inference. Fourth, for the training framework, we extend the autograd framework with tensor-level checkpointing for fine-grained recomputation control; and we enhance training efficiency with a hybrid ZeRO strategy for the Muon optimizer, cost-effective m HC implementations via recomputation and fused kernels, and two-stage contextual parallelism to manage compressed attention. Fifth, for the inference framework, we design a heterogeneous KV cache structure with on-disk storage strategies to enable efficient shared-prefix reuse. In addition, during the post-training stage, we incorporate FP4 quantization-aware training for MoE expert weights and the indexer QK path to reduce memory and computation. By employing hybrid CSA and HCA, along with precision optimizations on computation and storage, DeepSeek-V4 series achieve significantly lower inference FLOPs and a substantially reduced KV cache size compared with DeepSeek-V3.2, especially in long-context settings. The right part of Figure 1 demonstrates the estimated single-token inference FLOPs and accumulated KV cache size of DeepSeek-V3.2 and DeepSeek-V4 series. In the scenario of 1M-token context, even DeepSeek-V4-Pro, which has a larger number of activated parameters, attains only 27% of the single-token FLOPs (measured in equivalent FP8 FLOPs) and 10% of the KV cache size relative to DeepSeek-V3.2. Furthermore, DeepSeek-V4-Flash, with its smaller number of activated parameters, pushes efficiency even further: in the 1M-token context setting, it achieves only 10% of the single-token FLOPs and 7% of the KV cache size compared with DeepSeek-V3.2. Additionally, for DeepSeek-V4 series, the routed expert parameters utilize FP4 precision. While the peak FLOPs for FP4 × \times FP8 operations are currently the same as FP8 × \times FP8 on existing hardware, they can theoretically be implemented to be 1 / 3 1/3 more efficient on future hardware, which will further enhance the efficiency of DeepSeek-V4 series. During pre-training, we train DeepSeek-V4-Flash on 32T tokens and DeepSeek-V4-Pro on 33T tokens, respectively. After pre-training, these two models can natively and efficiently support 1M-length contexts. In our internal evaluations, DeepSeek-V4-Flash-Base already surpasses DeepSeek-V3.2-Base across a majority of benchmarks with its more parameter-efficient design. DeepSeek-V4-Pro-Base further extends this advantage to set a new performance standard among DeepSeek foundation models, achieving comprehensive superiority across reasoning, coding, long-context, and world knowledge tasks. The post-training pipeline of DeepSeek-V4 series features a two-stage paradigm: the independent cultivation of domain-specific experts, followed by unified model consolidation via on-policy distillation ( Lu and Lab, 2025 ; Gu et al., 2024 ) . Initially, for each target domain — such as mathematics, coding, agent, and instruction following — a separate expert model is trained independently. The base model first undergoes Supervised Fine-Tuning (SFT) on high-quality, domain-specific data to establish foundational capabilities. Subsequently, Reinforcement Learning (RL) is applied using Group Relative Policy Optimization (GRPO) ( DeepSeek-AI, 2025a ) , which further optimizes the model for domain-aligned behaviors guided by reward models tailored to specific success criteria. This phase yields a diverse set of specialized experts, each excelling in its respective field. Finally, to integrate these distinct proficiencies, a single unified model is trained through on-policy distillation, wherein the unified model acts as the student learning to optimize the reverse KL loss with teacher models. Summary of Core Evaluation Results • Knowledge : In assessments of broad world knowledge, DeepSeek-V4-Pro-Max, the maximum reasoning effort mode of DeepSeek-V4-Pro, significantly outperforms leading open-source models on the SimpleQA ( OpenAI, 2024a ) and Chinese-SimpleQA ( He et al., 2024 ) benchmarks. Regarding educational knowledge — evaluated via MMLU-Pro ( Wang et al., 2024b ) , HLE ( Phan et al., 2025 ) , and GPQA ( Rein et al., 2023 ) — DeepSeek-V4-Pro-Max shows a marginal lead over its open-source counterparts. DeepSeek-V4-Pro-Max has significantly closed the gap with the leading proprietary model, Gemini-3.1-Pro, despite still trailing it in these knowledge-based evaluations. • Reasoning : Through the expansion of reasoning tokens, DeepSeek-V4-Pro-Max demonstrates superior performance relative to GPT-5.2 and Gemini-3.0-Pro on standard reasoning benchmarks. Nevertheless, its performance falls marginally short of GPT-5.4 and Gemini-3.1-Pro, suggesting a developmental trajectory that trails state-of-the-art frontier models by approximately 3 to 6 months. Furthermore, DeepSeek-V4-Flash-Max achieves comparable performance to GPT-5.2 and Gemini-3.0-Pro, establishing itself as a highly cost-effective architecture for complex reasoning tasks. • Agent : On public benchmarks, DeepSeek-V4-Pro-Max is on par with leading open-source models, such as Kimi-K2.6 and GLM-5.1, but slightly worse than frontier closed models. In our internal evaluation, DeepSeek-V4-Pro-Max outperforms Claude Sonnet 4.5 and approaches the level of Opus 4.5. • Long-Context : DeepSeek-V4-Pro-Max delivers strong results on synthetic and real use cases with a 1-million-token context window, surpassing even Gemini-3.1-Pro on academic benchmarks. • DeepSeek-V4-Pro v.s. DeepSeek-V4-Flash : DeepSeek-V4-Flash-Max exhibits lower performance in knowledge evaluations due to its smaller parameter scale. However, it achieves comparable results on reasoning tasks when allocated a larger thinking budget. In agent evaluations, while DeepSeek-V4-Flash-Max matches the performance of DeepSeek-V4-Pro-Max on several benchmarks, it still trails its larger counterpart on more complex, high-difficulty tasks. Figure 2: Overall architecture of DeepSeek-V4 series. We use hybrid CSA (Compressed Sparse Attention) and HCA (Heavily Compressed Attention) for attention layers, DeepSeekMoE for feed-forward layers, and strengthen conventional residual connections with m HC. ## 2 Architecture Overall, DeepSeek-V4 series retain the Transformer ( Vaswani et al., 2017 ) architecture and Multi-Token Prediction (MTP) modules ( Gloeckle et al., 2024 ; DeepSeek-AI, 2024c ) , while introducing several key upgrades over DeepSeek-V3: (1) firstly, we introduce the Manifold-Constrained Hyper-Connections ( m HC) ( Xie et al., 2026 ) to strengthen conventional residual connections; (2) secondly, we design a hybrid attention architecture, which greatly improves long-context efficiency through Compressed Sparse Attention and Heavily Compressed Attention. (3) thirdly, we employ Muon ( Jordan et al., 2024 ; Liu et al., 2025 ) as the optimizer. For the Mixture-of-Experts (MoE) components, we still adopt the DeepSeekMoE ( Dai et al., 2024 ) architecture, with only minor adjustments from DeepSeek-V3. The Multi-Token Prediction (MTP) ( Qi et al., 2020 ; Gloeckle et al., 2024 ; Li et al., 2024 ; DeepSeek-AI, 2024c ) configuration remains identical to that of DeepSeek-V3. All other unspecified details follow the settings established in DeepSeek-V3 ( DeepSeek-AI, 2024c ) . Figure 2 illustrates the overall architecture of DeepSeek-V4, and the details are described below. ## 2.1 Designs Inherited from DeepSeek-V3 ## Mixture-of-Experts. As previous DeepSeek-series models ( DeepSeek-AI, 2024b ; DeepSeek-AI, 2024c ) , DeepSeek-V4 series also adopt the DeepSeekMoE paradigm ( Dai et al., 2024 ) for Feed-Forward Networks (FFNs), which sets fine-grained routed experts and shared experts. Different from DeepSeek-V3, we change the activation function that computes the affinity scores from Sigmoid ⁡ ( ⋅ ) \operatorname{Sigmoid}(\cdot) into Sqrt ⁡ ( Softplus ⁡ ( ⋅ ) ) \operatorname{Sqrt}(\operatorname{Softplus}(\cdot)) . For load balancing, we also employ the auxiliary-loss-free strategy ( Wang et al., 2024a ; DeepSeek-AI, 2024c ) , augmented by a slight sequence-wise balance loss that prevents extreme imbalance within individual sequences. For DeepSeek-V4, we remove the constraint on the number of routing target nodes, and carefully redesign the parallelism strategy to maintain training efficiency. Furthermore, compared with DeepSeek-V3, we replace the dense FFN layers in the initial several Transformer blocks with MoE layers that employ Hash routing ( Roller et al., 2021 ) . The Hash routing strategy determines the target experts of each token according to a predefined hash function with regard to the input token ID. ## Multi-Token Prediction. As DeepSeek-V3, DeepSeek-V4 series also set MTP modules and objectives. Given that the MTP strategy has been validated in DeepSeek-V3, we adopt the same strategy for DeepSeek-V4 series without modification. ## 2.2 Manifold-Constrained Hyper-Connections As shown in Figure 2 , DeepSeek-V4 series incorporate Manifold-Constrained Hyper-Connections ( m HC) ( Xie et al., 2026 ) to strengthen the conventional residual connections between adjacent Transformer blocks. Compared with naive Hyper-Connections (HC) ( Zhu et al., 2025 ) , the core idea of m HC is to constrain the residual mapping onto a specific manifold, and thus enhance the stability of signal propagation across layers while preserving model expressivity. This subsection briefly introduces the standard HC and describes how we design m HC for stable training. ## Standard Hyper-Connections. The standard HC expands the width of the residual stream by a factor of n hc n_{\text{hc}} . Specifically, the shape of the residual stream is expanded from ℝ d \mathbb{R}^{d} to ℝ n hc × d \mathbb{R}^{n_{\text{hc}}\times d} , where d d is the hidden size of the actual layer input. Let X l = [ 𝐱 l , 1 ; … ; 𝐱 l , n hc ] T ∈ ℝ n hc × d X_{l}=[\mathbf{x}_{l,1};\ldots;\mathbf{x}_{l,n_{\text{hc}}}]^{T}\in\mathbb{R}^{n_{\text{hc}}\times d} be the residual state before the l l -th layer. HC introduces three linear mappings: an input mapping A l ∈ ℝ 1 × n hc A_{l}\in\mathbb{R}^{1\times n_{\text{hc}}} , a residual transformation B l ∈ ℝ n hc × n hc B_{l}\in\mathbb{R}^{n_{\text{hc}}\times n_{\text{hc}}} , and an output mapping C l ∈ ℝ n hc × 1 C_{l}\in\mathbb{R}^{n_{\text{hc}}\times 1} . The update of the residual state is then formulated as: X l + 1 = B l ​ X l + C l ​ ℱ l ​ ( A l ​ X l ) , X_{l+1}=B_{l}X_{l}+C_{l}\mathcal{F}_{l}(A_{l}X_{l}), (1) where ℱ l \mathcal{F}_{l} denotes the l l -th layer (e.g., an MoE layer), whose input and output shapes are both ℝ d \mathbb{R}^{d} . Note that the actual layer input A l ​ X l ∈ ℝ d A_{l}X_{l}\in\mathbb{R}^{d} is also d d -dimensional, so the expanded residual width does not influence the design of the inner layers. HC decouples the residual width from the actual hidden size, offering a complementary scaling axis with minimal computational overhead, as n hc n_{\text{hc}} is typically much smaller than the hidden size d d . However, even though HC has demonstrated potential in improving model performance, we find that the training will frequently exhibit numerical instability when stacking multiple layers, which hinders the scaling of HC. ## Manifold-Constrained Residual Mapping. The core innovation of m HC is to constrain the residual mapping matrix B l B_{l} to the manifold of doubly stochastic matrices (the Birkhoff polytope) ℳ \mathcal{M} , and thus enhance the stability of signal propagation across layers: B l ∈ ℳ :- { M ∈ ℝ n × n ∣ M 𝟏 n = 𝟏 n , 1 n T M = 𝟏 n T , M ⩾ 0 } . B_{l}\in\mathcal{M}\coloneq\{M\in\mathbb{R}^{n\times n}\mid M\mathbf{1}_{n}=\mathbf{1}_{n},\;\mathbf{1}_{n}^{T}M=\mathbf{1}_{n}^{T},\;M\geqslant 0\}. (2) This constraint ensures that the spectral norm of the mapping matrix ‖ B l ‖ 2 \|B_{l}\|_{2} is bounded by 1, so the residual transformation is non-expansive, which increases the numerical stability during both the forward pass and backpropagation. Besides, the set ℳ \mathcal{M} is closed under multiplication, which guarantees stability in the scenarios of deep stacks of m HC. In addition, the input transformation A l A_{l} and output transformation C l C_{l} are also constrained to be non-negative and bounded via a Sigmoid function to avoid the risk of signal cancellation. ## Dynamic Parameterization. The parameters of three linear mappings are dynamically generated, which are decomposed into a dynamic (input-dependent) component and a static (input-independent) component. Given the input X l ∈ ℝ n hc × d X_{l}\in\mathbb{R}^{n_{\text{hc}}\times d} , it is first flattened and normalized: X ^ l = RMSNorm ⁡ ( vec ⁡ ( X l ) ) ∈ ℝ 1 × n hc ​ d \hat{X}_{l}=\operatorname{RMSNorm}(\operatorname{vec}(X_{l}))\in\mathbb{R}^{1\times n_{\text{hc}}d} . Then, we follow the conventional HC to generate the unconstrained raw parameters A ~ l ∈ ℝ 1 × n hc \tilde{A}_{l}\in\mathbb{R}^{1\times n_{\text{hc}}} , B ~ l ∈ ℝ n hc × n hc \tilde{B}_{l}\in\mathbb{R}^{n_{\text{hc}}\times n_{\text{hc}}} , and C ~ l ∈ ℝ n hc × 1 \tilde{C}_{l}\in\mathbb{R}^{n_{\text{hc}}\times 1} : A ~ l \displaystyle\tilde{A}_{l} = α l pre ⋅ ( X ^ l ​ W l pre ) + S l pre , \displaystyle=\alpha_{l}^{\mathrm{pre}}\cdot(\hat{X}_{l}W^{\mathrm{pre}}_{l})+S_{l}^{\mathrm{pre}}, (3) B ~ l \displaystyle\tilde{B}_{l} = α l res ⋅ Mat ⁡ ( X ^ l ​ W l res ) + S l res , \displaystyle=\alpha_{l}^{\mathrm{res}}\cdot\operatorname{Mat}(\hat{X}_{l}W^{\mathrm{res}}_{l})+S_{l}^{\mathrm{res}}, (4) C ~ l \displaystyle\tilde{C}_{l} = α l post ⋅ ( X ^ l ​ W l post ) T + S l post , \displaystyle=\alpha_{l}^{\mathrm{post}}\cdot(\hat{X}_{l}W^{\mathrm{post}}_{l})^{T}+S_{l}^{\mathrm{post}}, (5) where W l pre , W l post ∈ ℝ n hc ​ d × n hc W^{\mathrm{pre}}_{l},W^{\mathrm{post}}_{l}\in\mathbb{R}^{n_{\text{hc}}d\times n_{\text{hc}}} and W l res ∈ ℝ n hc ​ d × n hc 2 W^{\mathrm{res}}_{l}\in\mathbb{R}^{n_{\text{hc}}d\times n_{\text{hc}}^{2}} are learnable parameters for generating the dynamic components; Mat ⁡ ( ⋅ ) \operatorname{Mat}(\cdot) reshapes a vector of size 1 × n hc 2 1\times n_{\text{hc}}^{2} into a matrix of size n hc × n hc n_{\text{hc}}\times n_{\text{hc}} ; S l pre ∈ ℝ 1 × n hc S_{l}^{\mathrm{pre}}\in\mathbb{R}^{1\times n_{\text{hc}}} , S l post ∈ ℝ n hc × 1 S_{l}^{\mathrm{post}}\in\mathbb{R}^{n_{\text{hc}}\times 1} , and S l res ∈ ℝ n hc × n hc S_{l}^{\mathrm{res}}\in\mathbb{R}^{n_{\text{hc}}\times n_{\text{hc}}} are learnable static biases; and α l pre \alpha_{l}^{\mathrm{pre}} , α l res \alpha_{l}^{\mathrm{res}} , α l post ∈ ℝ \alpha_{l}^{\mathrm{post}}\in\mathbb{R} are learnable gating factors initialized to small values. ## Applying Parameter Constraints. After obtaining the unconstrained raw parameters A ~ l , B ~ l , C ~ l \tilde{A}_{l},\tilde{B}_{l},\tilde{C}_{l} , we then apply constraints described earlier to them to enhance the numerical stability. To be specific, for the input and output mappings, we employ a Sigmoid function σ ⁡ ( ⋅ ) \sigma(\cdot) to ensure their non-negativity and boundedness: A l \displaystyle A_{l} = σ ⁡ ( A ~ l ) , \displaystyle=\sigma(\tilde{A}_{l}), (6) C l \displaystyle C_{l} = 2 ​ σ ​ ( C ~ l ) . \displaystyle=2\sigma(\tilde{C}_{l}). (7) As for the residual mapping B ~ l \tilde{B}_{l} , we project it onto the manifold of doubly stochastic matrices ℳ \mathcal{M} . This is achieved by the Sinkhorn-Knopp algorithm, which first applies an exponential function to B ~ l \tilde{B}_{l} to ensure positivity, getting M ( 0 ) = exp ⁡ ( B ~ l ) M^{(0)}=\exp(\tilde{B}_{l}) , and then iteratively performs column and row normalization: M ( t ) = 𝒯 r ​ ( 𝒯 c ​ ( M ( t − 1 ) ) ) , M^{(t)}=\mathcal{T}_{r}(\mathcal{T}_{c}(M^{(t-1)})), (8) where 𝒯 r \mathcal{T}_{r} and 𝒯 c \mathcal{T}_{c} denote row and column normalization, respectively. This iteration converges to a constrained doubly stochastic matrix B l = M ( t max ) B_{l}=M^{(t_{\text{max}})} . We choose t max = 20 t_{\text{max}}=20 as a practical value. ## 2.3 Hybrid Attention with CSA and HCA As the context length reaches extreme scales, the attention mechanism emerges as the dominant computational bottleneck in a model. For DeepSeek-V4, we design two efficient attention architectures — Compressed Sparse Attention (CSA) and Heavily Compressed Attention (HCA) — and employ their interleaved hybrid configuration, which substantially reduces the computational cost of attention in long-text scenarios. CSA integrates both compression and sparse attention strategies: it first compresses the Key-Value (KV) cache of every m m tokens into one entry, and then applies DeepSeek Sparse Attention (DSA) ( DeepSeek-AI, 2025b ) where each query token attends to only k k compressed KV entries. HCA aims for extreme compression by consolidating the KV cache of every m ′ m^{\prime} ( ≫ m \gg m ) tokens into a single entry. The hybrid architecture of CSA and HCA remarkably improves the long-context efficiency of DeepSeek-V4 series, making one-million-token context feasible in practice. This subsection describes the core techniques of our hybrid attention architecture, and we also provide an open-source implementation 1 1 1 https://huggingface.co/deepseek-ai/DeepSeek-V4-Pro/tree/main/inference to specify more details unambiguously. Figure 3: Core architectures of CSA. It compresses the number of KV entries to 1 m \frac{1}{m} times, and then applies DeepSeek Sparse Attention for further acceleration. Additionally, a small set of sliding window KV entries is combined with the selected compressed KV entries to enhance local fine-grained dependencies. ## 2.3.1 Compressed Sparse Attention The core architecture of CSA is illustrated in Figure 3 , which first compresses the KV cache of each m m tokens into one entry, and then applies DeepSeek Sparse Attention for further acceleration. ## Compressed Key-Value Entries. Let H ∈ ℝ n × d H\in\mathbb{R}^{n\times d} be a sequence of input hidden states, where n n is the sequence length and d d is the hidden size. CSA first computes two series of KV entries C a , C b ∈ ℝ n × c C^{a},C^{b}\in\mathbb{R}^{n\times c} and their corresponding compression weights Z a , Z b ∈ ℝ n × c Z^{a},Z^{b}\in\mathbb{R}^{n\times c} , where c c is the head dimension: C a \displaystyle C^{a} = H ⋅ W a ​ K ​ V , C b = H ⋅ W b ​ K ​ V , \displaystyle=H\cdot W^{aKV},\quad C^{b}=H\cdot W^{bKV}, (9) Z a \displaystyle Z^{a} = H ⋅ W a ​ Z , Z b = H ⋅ W b ​ Z , \displaystyle=H\cdot W^{aZ},\quad\penalty\ \penalty\ Z^{b}=H\cdot W^{bZ}, (10) where W a ​ K ​ V , W b ​ K ​ V , W a ​ Z , W b ​ Z ∈ ℝ d × c W^{aKV},W^{bKV},W^{aZ},W^{bZ}\in\mathbb{R}^{d\times c} are trainable parameters. Next, each m m KV entries in C a C^{a} and C b C^{b} will be compressed into one entry according to their compression weights and learnable positional biases B a , B b ∈ ℝ m × c B^{a},B^{b}\in\mathbb{R}^{m\times c} , producing C Comp ∈ ℝ n m × c C^{\text{Comp}}\in\mathbb{R}^{\frac{n}{m}\times c} . Each compressed entry C i Comp ∈ ℝ c C^{\text{Comp}}_{i}\in\mathbb{R}^{c} is computed by [ S m ​ i : m ⁡ ( i + 1 ) − 1 a ; S m ⁡ ( i − 1 ) : m ​ i − 1 b ] \displaystyle[S^{a}_{mi:m(i+1)-1};S^{b}_{m(i-1):mi-1}] = Softmax row ( [ Z m ​ i : m ⁡ ( i + 1 ) − 1 a + B a ; Z m ⁡ ( i − 1 ) : m ​ i − 1 b + B b ] ) , \displaystyle=\operatorname{Softmax}_{\text{row}}([Z^{a}_{mi:m(i+1)-1}+B^{a};Z^{b}_{m(i-1):mi-1}+B^{b}]), (11) C i Comp \displaystyle C^{\text{Comp}}_{i} = ∑ j = m ​ i m ⁡ ( i + 1 ) − 1 S j a ⊙ C j a + ∑ j = m ⁡ ( i − 1 ) m ​ i − 1 S j b ⊙ C j b , \displaystyle=\sum_{j=mi}^{m(i+1)-1}S^{a}_{j}\odot C^{a}_{j}+\sum_{j=m(i-1)}^{mi-1}S^{b}_{j}\odot C^{b}_{j}, (12) where ⊙ \odot denotes the Hadamard product; Softmax row ⁡ ( ⋅ ) \operatorname{Softmax}_{\text{row}}(\cdot) denotes the softmax operation along the row dimension, which performs normalization across the total of 2 ​ m 2m elements from both Z a Z^{a} and Z b Z^{b} . When i = 0 i=0 , Z b m ⁡ ( i − 1 ) : m ​ i − 1 Z^{b}_{m(i-1):mi-1} is padded with negative infinity and C b m ⁡ ( i − 1 ) : m ​ i − 1 C^{b}_{m(i-1):mi-1} is padded with zeros. Note that each C i Comp C^{\text{Comp}}_{i} is derived from 2 ​ m 2m KV entries, but the indexes of C b C^{b} used for C i Comp C^{\text{Comp}}_{i} and the indexes of C a C^{a} used for C i − 1 Comp C^{\text{Comp}}_{i-1} are overlapped. Therefore, CSA in fact compresses the sequence length to 1 m \frac{1}{m} times. ## Lightning Indexer for Sparse Selection. After obtaining the compressed KV entries C Comp C^{\text{Comp}} , CSA applies the DSA strategy to select top-k compressed KV entries for core attention. First, CSA performs the same compression operation used for C Comp C^{\text{Comp}} to get compressed indexer keys K IComp ∈ ℝ n m × c I K^{\text{IComp}}\in\mathbb{R}^{\frac{n}{m}\times c^{I}} , where c I c^{I} is the indexer head dimension. Then, for a query token t t , we produce the indexer queries { 𝐪 t , 1 I ; 𝐪 t , 2 I ; … ; 𝐪 t , n h I I } \{\mathbf{q}_{t,1}^{I};\mathbf{q}_{t,2}^{I};...;\mathbf{q}_{t,n_{h}^{I}}^{I}\} in a low-rank manner: 𝐜 t Q \displaystyle\mathbf{c}_{t}^{Q} = 𝐡 t ⋅ W D ​ Q , \displaystyle=\mathbf{h}_{t}\cdot W^{DQ}, (13) [ 𝐪 t , 1 I ; 𝐪 t , 2 I ; … ; 𝐪 t , n h I I ] = 𝐪 t I \displaystyle[\mathbf{q}_{t,1}^{I};\mathbf{q}_{t,2}^{I};...;\mathbf{q}_{t,n_{h}^{I}}^{I}]=\mathbf{q}_{t}^{I} = 𝐜 t Q ⋅ W I ​ U ​ Q , \displaystyle=\mathbf{c}_{t}^{Q}\cdot W^{IUQ}, (14) where 𝐡 t ∈ ℝ d \mathbf{h}_{t}\in\mathbb{R}^{d} is the input hidden state of the query token t t ; 𝐜 t Q ∈ ℝ d c \mathbf{c}_{t}^{Q}\in\mathbb{R}^{d_{c}} is the compressed latent vector for queries; d c d_{c} denotes the query compression dimension; n h I n_{h}^{I} denotes the number of indexer query heads; W D ​ Q ∈ ℝ d × d c W^{DQ}\in\mathbb{R}^{d\times d_{c}} and W I ​ U ​ Q ∈ ℝ d c × c I ​ n h I W^{IUQ}\in\mathbb{R}^{d_{c}\times c^{I}n_{h}^{I}} are the down-projection and up-projection matrices for indexer queries, respectively. Next, the index score I t , s ∈ ℝ I_{t,s}\in\mathbb{R} between the query token t t and a preceding compressed block s s ( s s < Floor ⁡ ( t m ) \operatorname{Floor}(\frac{t}{m}) ) is computed by [ w t , 1 I ; w t , 2 I ; … ; w t , n h I I ] = 𝐰 t I \displaystyle[w_{t,1}^{I};w_{t,2}^{I};...;w_{t,n_{h}^{I}}^{I}]=\mathbf{w}_{t}^{I} = 𝐡 t ⋅ W w , \displaystyle=\mathbf{h}_{t}\cdot W^{w}, (15) I t , s \displaystyle I_{t,s} = ∑ h = 1 n h I w t , h I ⋅ ReLU ​ ( 𝐪 t , h I ⋅ K s IComp ) , \displaystyle=\sum_{h=1}^{n_{h}^{I}}w_{t,h}^{I}\cdot\text{ReLU}\left(\mathbf{q}^{I}_{t,h}\cdot K^{\text{IComp}}_{s}\right), (16) where W w ∈ ℝ d × n h I W^{w}\in\mathbb{R}^{d\times n_{h}^{I}} is a learnable matrix; w t , h I ∈ ℝ w_{t,h}^{I}\in\mathbb{R} is the weight of the h h -th indexer head. For a query token t t , given its index scores I t , : I_{t,:} , we employ a top-k selector to selectively retain a subset of compressed KV entries 𝒞 t SprsComp \mathcal{C}^{\text{SprsComp}}_{t} for subsequent core attention: 𝒞 t SprsComp = { C s Comp | I t , s ∈ Top − k ( I t , : ) } . \mathcal{C}^{\text{SprsComp}}_{t}=\left\{C^{\text{Comp}}_{s}\penalty\ \Big|\penalty\ I_{t,s}\in\operatorname{Top-k}(I_{t,:})\right\}. (17) ## Shared Key-Value MQA. After selecting the sparse KV entries, CSA then performs core attention in a Multi-Query Attention (MQA) ( Shazeer, 2019 ) manner, where each compressed KV entry in 𝒞 t SprsComp \mathcal{C}^{\text{SprsComp}}_{t} serves as both attention key and value. To be specific, for a query token t t , we first produce attention queries { 𝐪 t , 1 ; 𝐪 t , 2 ; … ; 𝐪 t , n h } \{\mathbf{q}_{t,1};\mathbf{q}_{t,2};...;\mathbf{q}_{t,n_{h}}\} from the compressed latent vector 𝐜 t Q \mathbf{c}_{t}^{Q} : [ 𝐪 t , 1 ; 𝐪 t , 2 ; … ; 𝐪 t , n h ] = 𝐪 t = 𝐜 t Q ⋅ W U ​ Q , [\mathbf{q}_{t,1};\mathbf{q}_{t,2};...;\mathbf{q}_{t,n_{h}}]=\mathbf{q}_{t}=\mathbf{c}_{t}^{Q}\cdot W^{UQ}, (18) where n h n_{h} denotes the number of query heads; W U ​ Q ∈ ℝ d c × c ​ n h W^{UQ}\in\mathbb{R}^{d_{c}\times cn_{h}} is the up-projection matrices for queries. Note that the latent query vector 𝐜 t Q \mathbf{c}_{t}^{Q} is shared with that used for the indexer queries. Next, we perform MQA on { 𝐪 t , i } \{\mathbf{q}_{t,i}\} and 𝒞 t SprsComp \mathcal{C}^{\text{SprsComp}}_{t} : 𝐨 t , i = CoreAttn ⁡ ( query= ​ 𝐪 t , i , key= ​ 𝒞 t SprsComp , value= ​ 𝒞 t SprsComp ) , \mathbf{o}_{t,i}=\operatorname{CoreAttn}\left(\texttt{query=}\mathbf{q}_{t,i},\texttt{key=}\mathcal{C}^{\text{SprsComp}}_{t},\texttt{value=}\mathcal{C}^{\text{SprsComp}}_{t}\right), (19) where 𝐨 t , i ∈ ℝ c \mathbf{o}_{t,i}\in\mathbb{R}^{c} is the core attention output of the i i -th head at the t t -th token; CoreAttn ⁡ ( ⋅ ) \operatorname{CoreAttn}(\cdot) denotes the core attention operation. ## Grouped Output Projection. In the configuration of DeepSeek-V4, c ​ n h cn_{h} is quite large. Therefore, directly projecting the outputs of the core attention operation [ 𝐨 t , 1 ; 𝐨 t , 2 ; … ; 𝐨 t , n h ] = 𝐨 t ∈ ℝ c ​ n h [\mathbf{o}_{t,1};\mathbf{o}_{t,2};...;\mathbf{o}_{t,n_{h}}]=\mathbf{o}_{t}\in\mathbb{R}^{cn_{h}} to a d d -dimensional hidden state will impose a substantial computational burden. To mitigate this cost, we design a grouped output projection strategy. To be specific, we first split n h n_{h} outputs into g g groups, and then for each group of output 𝐨 t , i G ∈ ℝ c ​ n h g \mathbf{o}^{G}_{t,i}\in\mathbb{R}^{c\frac{n_{h}}{g}} , we project it to a d g d_{g} -dimensional intermediate output 𝐨 t , i G ′ ∈ ℝ d g \mathbf{o}^{G^{\prime}}_{t,i}\in\mathbb{R}^{d_{g}} , where d g < c ​ n h g d_{g}