A model built around a different question: how little memory and prompt computation can a long-context agent need? Explore its causal encoder–decoder, shared sparse attention, conditional memory, and speculative drafter.
Twenty causal encoder layers. Twenty decoder layers. One shared decoder global KV source.
552Bbackbone parameters
+196BEngram parameters
8B / 16Bactive · prefill / decode
1,048,576maximum context tokens
890 Bglobal cache / token
Scope: the released DeepSeek-V4.1-Flash checkpoint, not an inferred “V4.1-Pro.” Parameter figures follow the report’s separate backbone and Engram accounting. Global-cache bytes exclude weights, local-window caches, and other runtime allocations. Report pp. 7–14, 22
01 / The exact topology
Forty layers. Four cache producers.
Select any layer to see its attention mode, memory source, and index source. All layer IDs are zero-based, matching the released configuration. The independent three-block DSpark drafter is outside this 40-layer backbone.
CONFIG-DRIVEN VISUAL
Backbone map · select a layer
FullReindexReuseSWA only
E = Engram before block
Image → ViT → projector↘Text embeddings · d = 5,120
Causal encoder L00–L19 · 20 layers
Decoder L20–L39 · 20 layers
Encoder’s final state→L20 global KV projection→Shared by L20–L39
Each block: Single-Pass mHC → attention → Single-Pass mHC → MoE. Each attention layer computes its own main Q and local SWA KV. Cache sharing applies to global memory; it does not remove the layer’s own computation.
The static schedule contains 2 SWA-only, 4 Full, 4 Reindex, and 30 Reuse layers. Select a layer; dashed outlines identify the preceding sources it depends on.
Read the complete schedule as text
Layer IDs
Mode
Global KV source
Index source
00–01
SWA only
None
None
02 / 03–07
Full / Reuse
02
02
08 / 09–13
Full / Reuse
08
08
14 / 15–19
Full / Reuse
14
14
20 / 21–23
Full / Reuse
20, from encoder output
20
24 / 25–27
Reindex / Reuse
20
24
28 / 29–31
Reindex / Reuse
20
28
32 / 33–35
Reindex / Reuse
20
32
36 / 37–39
Reindex / Reuse
20
36
“Full” is a mode name, not dense full attention. It means the layer generates global KV, indexer keys, and a fresh sparse selection. Its main attention still uses selected global records plus a 128-token sliding window. Figure 4 · pp. 10–11
02 / Causal encoder–decoder
Process the prompt once. Reuse it above.
The decoder’s global KV is derived from the final encoder hidden states. Most prompt positions can therefore skip full decoder computation. Local SWA state still depends on the decoder’s own hidden states, so the serving system replays a short prompt tail.
REPORT §§2.2, 3.2.2
A prompt’s optimized path
All prompt tokens20 encoder layers
→
Global KV projectionfrom encoder output
↓ only the final min(N, 128) prompt positions ↓
Decoder bounded replay20 decoder layers · seed local SWA state
The first generation step needs decoder local caches. Replaying the final 128 prompt tokens bounds their reconstruction cost; it does not mean the decoder is never evaluated during prefill.
Each generated token then traverses both encoder and decoder. The “8B / 16B active” distinction describes the optimized phase-dependent path, rather than a fixed per-token active count under every execution strategy.
Explore the computation proxy
1281,048,576
40-layer baseline
20-layer encoder
20-layer replay
50.20%of baseline block-token work
128maximum tail positions replayed
Proxy: baseline = 40N; CED = 20N + 20min(N,128). This counts block–token evaluations, not FLOPs or latency. It excludes projection cost, cache-hit behavior, vision, and kernel differences.
Bounded replay is approximate. Exact SWA dependencies accumulate across depth. The report contrasts the 128-token replay with a theoretical 20 × 128 = 2,560-token decoder replay horizon. Truncating local attention to the replay segment changes reconstructed states. The authors report negligible quality impact and simulate decoder replay during post-training; this is not a mathematical equivalence guarantee. p. 20
Encoder replay after a cache miss
If global prefix KV exists but encoder SWA state is missing, replay the last 128 cached prefix tokens along with the uncached suffix. Replayed positions regenerate local SWA only, without recomputing or overwriting their global KV. New suffix positions generate both kinds of state.
Short-lived versus persistent state
The deployment keeps encoder SWA in a short-TTL distributed memory pool, while global KV stays in the long-lived persistent cache. Decoder SWA is reconstructed at prefill and used for decoding. Removing SWA from persistent storage plus shrinking global KV explains the reported ~8× persistent-cache reduction under the stated workload.
03 / Compressed Sparse Attention 2
Choose what to compute. Choose what to share.
CSA2 decouples global cache creation from sparse-index generation. Every mode still computes its own main query, its own local-window KV, and a new attention output. Switch modes to trace which quantities are fresh or reused.
FIGURE 4 · REPORT p. 10
Attention component ownership
Current layer input ↓
Main Qfresh · every layer
Local SWA KVfresh · 128-token window
Main global KVcreated here
Indexer Kprojected from main KV
Indexer Qfresh · score candidate keys
Top-512 indicesfresh sparse selection
↓ gather global records + concatenate local records ↓
64 query heads × 512 dimensions Attention over ≤512 global + ≤128 local entries Inverse RoPE on output → grouped projection
Computed hereShared cacheReused indices
Full mode
Creates the main global KV and projects indexer K from the unrotated main latent. Computes a fresh indexer query, scores eligible positions, and selects Top-512. In the decoder, the global latent comes from the final encoder representation.
Global latent → indexer K Indexer Q · K → scores → Top-512 Main Q attends to gathered KV + SWA
“Global” means the records may cover distant context. Ratio 1 means no sequence compression; it still uses latent dimensions, low-bit storage, and cross-layer reuse.
Query and output projections are low-rank/grouped. The reference applies inverse RoPE to the output’s rotary coordinates before the grouped projection. Each head also has a learned attention sink.
The global and index paths
Main KV latent, shared across heads512 dimensions
Indexer K from main latent512 → 128
Indexer Q from query bottleneck1280 → 32 × 128
Indexer head-weight projection5120 → 32
Selected global records per queryat most 512
Additional local-window entriesat most 128
Indexer scores combine rectified query–key products across 32 weighted heads. Its selection is causal. Main attention uses the selected global records together with the current layer’s local KV.
B = batch size; T = processed token positions. For cache accounting, a KV entry is one shared latent, not separately stored per-head K and V.
How compression differs from DeepSeek-V4 CSA
V4.1 removes overlapping compression windows and absolute positional embeddings inside the compressor. In encoder Full layers, two consecutive positions are pooled into one latent using learned channel-wise softmax gates, then RMS normalization. In decoder Full mode, ratio 1 is a plain normalized projection. Indexer K is projected from the pre-RoPE main latent; it no longer has a separate hidden-state compression path. An incomplete pair is held until it is causally complete. §2.3, p. 10Compressor.forward
04 / Hierarchical sparse indexing
One wide search. Four narrower searches.
Decoder layer 20 scans all causally visible global positions. It selects Top-512 for its own attention and separately builds a larger candidate pool. Layers 24, 28, 32, and 36 re-score within that shared pool.
DECODER ONLY
TOY POSITION MAP
Shared candidate poolSelected for attentionOther positions
L20 selects from the whole visible context and constructs the shared candidate pool.
Visualization scale: 128 toy positions, blocks of 4, 8 candidate blocks, and Top-8. Synthetic deterministic scores illustrate the mechanism; they are not the model’s activations. Actual budgets are shown alongside.
Actual released budgets
2,048 × 8candidate blocks × positions
16,384maximum candidate positions
512final global KV entries per query
4later decoder indexers
Each block’s score is the maximum score among its positions. Selecting the best blocks creates a pool larger than the final attention set. Later indexers share the pool and keys, but use their own queries and can select different records.
L20: N positions → block maxima → ≤16,384 candidates L24 / L28 / L32 / L36: pool → own Top-512
The hierarchy is training-aware and was introduced during post-training. It bounds later indexers’ search work for a fixed pool size. The first indexer still scans the full visible range. §2.3.2 · pp. 11–12
Reference code is not a speed benchmark. The released Python reference computes a full index-score tensor and then masks positions outside the candidate pool. This reproduces selection semantics; it does not itself realize the production kernel’s candidate-only scoring efficiency. Indexer.forward
05 / Quantization × compression × sharing
Where the 890 bytes come from.
Global memory consists of four shared cache banks, each holding a main KV latent and an indexer key. Three encoder banks compress two positions into one record; the decoder bank keeps one record per position. Scale metadata matters.
DERIVED FROM CONFIG + FORMATS
Packed global-cache estimateNO WEIGHTS OR LOCAL SWA
1,0241,048,576
Assumes the same full context length per sequence and no prefix sharing across sequences. Byte totals describe packed formats, excluding alignment, replication, and allocator overhead.
[3 × floor(N / 2) + N] × (288 + 68) For even N: N × 890 bytes per sequence
Total global cache
GiB
Main KV · 720 B/tokenIndex K · 170 B/token
933,232,640 bytes across 1 sequence.
GiB = 2³⁰ bytes. This is not the amount of VRAM required to load or serve the model.
(
288 B512 × 4 bits + 32 scales
+
68 B128 × 4 bits + 4 scales
×
2.5records / original token
=
890 Bglobal cache / token
Main KV: a particular FP4 format
The 512-dimensional main latent uses E2M1 data with one E4M3 scale per 16 channels. The report follows NVFP4’s local format but omits its second-level global scale. Quantization occurs after RoPE, on both rotary and non-rotary dimensions.
Stored values are dequantized for attention. Here FP4 targets cache storage, rather than requiring native FP4 attention matrix multiplication. QAT for main KV was introduced during post-training. §2.4.4 · p. 14
Indexer and local caches differ
Indexer Q/K use OCP MXFP4: 4-bit data with a shared 8-bit E8M0 scale per 32 elements. A 128-dimensional index key therefore occupies 64 + 4 = 68 packed bytes. Indexer queries are computed, not persistently cached as keys.
The local SWA cache stays FP8 because it is more sensitive to quantization. All 40 backbone layers retain local state. Reference tensors may store dequantized values; reading their allocated dtype alone will not reproduce packed serving-memory figures. Indexer / Attention
The two reduction claims measure different things. ~4× refers to global KV versus V4-Flash; ~8× refers to persistent-cache storage after also removing SWA from that long-lived cache, under the publisher’s stated workload. Neither says that all model memory or all request costs drop by those factors. §3.2.1 · p. 19
mHC carries four parallel residual streams of width 5,120. Its learned coefficients mix a single sublayer input, redistribute the sublayer output, and mix the residual streams. Single-Pass mHC changes when the input-mixing coefficients are consumed.
REPORT EQUATION 6
Residual mixing dependency
STREAM 0 · 5120
STREAM 1 · 5120
STREAM 2 · 5120
STREAM 3 · 5120
Use A from the previous sublayer → mix current input Predict current A, B, C → carry A forward
Xₗ₊₁ = BₗXₗ + CₗFₗ(Aₗ₋₁Xₗ) (Aₗ, Bₗ, Cₗ) = H(Xₗ)
Here l indexes attention/FFN sublayers in the mixing equation, not necessarily one complete two-sublayer Transformer block. X is 4 × 5,120 per token.
Why one index shift matters
Input mixing uses coefficients already produced by the previous sublayer. It no longer waits for the current coefficient predictor’s reduction over the hidden dimension, allowing residual update, input mixing, and coefficient prediction to be fused.
The deployment kernel Mega-mHC also incorporates input pre-normalization and FP8 conversion. The report gives activation traffic of (2n + 2)d for Single-Pass versus (4n + 4)d in the original implementation: at n = 4, that is 10d versus 20d values moved.
This is a reduction in the described residual-mixing activation traffic, not a 2× speedup for the entire model. Training retained a multi-kernel implementation. The released configuration uses 20 Sinkhorn-Knopp iterations for the manifold constraint.
Each of the 40 backbone FFNs contains 384 routed experts and one shared expert. A token executes six routed FFNs plus the shared FFN. Image and text tokens use separate expert-selection correction biases.
384 ROUTED + 1 SHARED
SYNTHETIC ROUTER SCORES
Selected · 6Not selected · 378
Shared expert · executes for every token
EXAMPLE 01
All 384 boxes are shown. These are synthetic logits and biases. Switching modality holds logits fixed to isolate the effect of correction bias; real image and text hidden states also differ. Expert numbers are not human-assigned specialisms.
Correction bias changes which experts are chosen; the original unbiased scores determine their combination weights. The training procedure updates image and text biases separately to balance loads.
Each expert is a 5,120 → 2,304 → 5,120 SwiGLU FFN. The gate/up projections are distinct: the gate is clamped above at 10, and the up branch is clamped to [−10, 10], before SiLU(gate) × up. Gate / Expert / MoE
Capacity and storage do not disappear when routing is sparse. The model still stores all experts, or accesses them through a distributed/offloaded deployment. The six selected experts are only part of a token’s total compute: attention, shared experts, residual mixing, and communication also remain.
08 / Conditional lookup memory
Memorization gets its own path.
Two Engram modules add 196B sparsely accessed parameters, placed before backbone blocks L01 and L14. Deterministic n-gram addressing makes the memory lookups prefetchable before those hidden states are computed.
TWO MODULES · ~98B EACH
ILLUSTRATIVE TEXT WINDOW
↓ tokenizer compression + 8 hash heads per order ↓
4 × 5,120 key channels + 5,120 value channels context-aware gates → add to the 4 residual streams
The phrases represent conceptual token windows, not actual tokenizer output. Real hashes use compressed token IDs, distinct prime-sized tables, and checkpoint-specific hash parameters.
What gets looked up—and what does not
Each module uses orders {2, 3, 4}. Each order has eight 256-dimensional hash heads, totaling 2,048 dimensions per order. Per-head tables have approximately 16M entries, with distinct prime sizes. The released packed tables have 384,006,168 and 384,016,682 rows of width 256.
Retrieved features are projected to a key for each residual stream and a shared value. A context-aware sigmoid gate controls how much of that value is added. The reference uses a signed square-root transform of the normalized query–key score before the sigmoid.
Image positions do not receive Engram contributions and do not participate in the n-gram history. The released tokenizer-compressed vocabulary size is 99,092. Both lookup tables and key/value projections use FP8 in the report.
Changes from the earlier Engram design and deployment details
V4.1 omits the short causal convolution because its measured gain did not justify inference complexity. It also changes embedding optimization to momentum updates followed by Sinkhorn balancing. The report describes host-memory prefetch via background RDMA during inference, and GPU-resident tables during RL rollouts. Placement and movement of the tables depend on the deployment; deterministic addressing does not make the storage free. This is learned model memory, distinct from retrieving documents with RAG. §2.4.2 p. 13; §3.1.3 p. 18
09 / Semi-autoregressive speculative decoding
Draft five positions. Verify what is worthwhile.
DSpark is a separate three-block drafter with a 128-token sliding window. One pass computes five positions’ base logits in parallel; a lightweight Markov head adds inter-token dependencies. A confidence head informs how much of the draft to verify.
3 DRAFT BLOCKS ≠ 3 BACKBONE LAYERS
The actual component path
Backbone attention inputs at L37, L38, L39reference collects stream means, then concatenates
↓ 3 × 5,120 → 5,120 projection + norm ↓
3 DSpark blocks128 routed experts · 3 active + 1 shared per block
↓ 5 base-logit vectors in one neural forward ↓
Markov headrank 256 · conditional sampling
Confidence headconditional acceptance estimates
Draft generation is semi-autoregressive: the heavy forward pass covers all five positions, while Markov-conditioned token sampling proceeds through them. Main-model verification remains responsible for deciding which draft tokens can be accepted.
Synthetic conditional acceptance probabilities: [0.94, 0.88, 0.81, 0.73, 0.61]. Bars show prefix survival: P(all first j accepted) = ∏ᵢ≤ⱼ pᵢ. Expected accepted prefix length through L is the sum of these survival probabilities.
The slider is an explanatory control, not the real scheduling policy. The production scheduler also uses profiled engine throughput and current system load to choose verification lengths; confidence alone does not determine the optimum. Bonus/correction tokens are excluded from this toy expectation.
Training schedule: the backbone is pre-trained without an MTP module. DSpark is trained afterward with the backbone frozen. During post-training, it is updated alongside the changing backbone, but its objective’s gradients do not propagate into the backbone. p. 14
10 / DeepSeek-ViT + projector
Images enter the same causal sequence.
The vision encoder processes an image bidirectionally with 2D-RoPE. Pixel-unshuffle groups 3 × 3 neighboring visual features into channels, then an MLP maps them to the language model’s width. Visual embeddings replace the corresponding image-token positions.
Dimension arithmetic for square images divisible by 42. The actual processor supports varying aspect ratios, resizes under its token/pixel policy, and the aligner pads feature grids when needed. Counts here exclude image delimiters and newline control tokens. This control does not run image inference. vision.py§2.1.1 p. 8; §4.2.1 p. 22
Native multimodal pre-training
After its separate preparatory training, DeepSeek-ViT is integrated with the language backbone. Visual and text embeddings are processed jointly from the start of language-model pre-training. The report describes 45T tokens overall and a 7:1 token ratio of text-only to multimodal data.
Context and training are separate settings
The released context limit is 1,048,576 positions. The report trains sparse attention at 64K from scratch, extending to 1M at 34T training tokens. The config specifies YaRN factor 16 and a 65,536-position original context. A supported context size is not a guarantee of perfect retrieval everywhere.
11 / Evidence, boundaries, and reproducibility
Designed to be checked.
This explorer is grounded in the 51-page report, the released configuration, and the Python reference implementation. Sources are pinned to repository revision dba1be0a40aa45a94ad051997016db3960a90277 and were retrieved on September 22, 2026.
PRIMARY SOURCES ONLY
Distinction
What this explorer shows
Architecture versus reference execution
The optimized CED prefill and bounded replay are described in the report. The simple released Transformer.forward iterates all 40 backbone layers. Its code should not be treated as an implementation of the optimized encoder-only bulk-prefill schedule.
Sparse semantics versus optimized kernels
The reference masks full score tensors to implement candidate restriction. Production claims refer to optimized candidate-scoring and sparse-attention kernels, not that dense reference evaluation.
Packed format versus allocated tensor dtype
The 890-byte derivation follows packed main-KV and index-key formats. Reference tensors can hold dequantized values and therefore allocate more memory.
Exact values versus demonstrations
Layer IDs, dimensions, routing counts, and cache formats come from sources. Colored toy positions, router scores, example phrases, and DSpark probabilities are synthetic explanatory values.
Report versus independent measurement
Parameter counts, training totals, quality effects, and efficiency comparisons are publisher-reported. This project does not load the model or reproduce benchmarks.
Public weights versus training reproducibility
The model card states an MIT license for its code and weights. Public weights and a report do not by themselves establish release of the complete training data or production serving stack.
The primary-source notebook
01 / Technical report
DeepSeek-V4.1-Flash: Pushing the Limits of KV Cache Compression
Architecture: pp. 7–14; cache management and approximate replay: pp. 19–20; exact model setup: pp. 21–22. Figure 3 is the overall graph; Figures 4–5 explain CSA2 and hierarchy.
Layer schedule, source indices, attention dimensions, expert counts, Engram placement, DSpark settings, visual dimensions, and context limit. The extra three compression entries belong to the drafter.
Table layout, tokenizer compression, hash construction, n-gram state, and handling of image-token positions. Complemented by the Engram module in model.py.
The model card provides the scope of release and license statement. The local manifest records retrieval date, revision, source URLs, and SHA-256 hashes for eight saved original files.
Reading suggestion: follow Figure 3 with the 40-layer map, then inspect one Full layer, one Reindex layer, and a Reuse layer that depends on it. Trace global KV and sparse indices separately. This explains why the decoder can keep one global cache while changing its selected context across depth.