शोधपत्र

DeepSeek-V4.1-Flash: Getting the Global KV Cache Down to 890 Bytes per Token

DeepSeek-V4.1-Flash global KV cache ko 890 bytes per token tak laata hai — lagbhag V4-Flash ka 1/4, DeepSeek-V1 ka 1/437: causal encoder-decoder, CSA2 mein cross-layer cache sharing aur FP4 main KV. Yeh lekh paper samjhata hai aur public configs se in numbers ko jaanchta hai.

प्रकाशित अपडेट किया गया पढ़ने का समय: 47 मिनट

इस पृष्ठ पर
  1. Yeh paper kyun padhne layak hai
  2. Background: input-heavy workload aur KV cache ke teen dimensions
  3. Kul sanrachna
  4. Causal Encoder-Decoder (CED)
  5. CSA2: cache share karo, chunaav reuse karo
  6. Hierarchical sparse indexer
  7. FP4 main KV cache
  8. SWA Bounded Replay aur persistent cache
  9. Baki architectural badlav
  10. Hath se jaanch: KV bytes, layer plan, indexer kharcha, parameter ledger aur do algorithm
  11. Pre-training: shuru se hi sparse attention
  12. Post-training: data aur environments, algorithm nahi
  13. Paper ke results
  14. Seemaein aur answar na hue prashn
  15. Is paper se sabse badi baat kya leni chahiye
  16. Aage padhne ke liye
  17. अक्सर पूछे जाने वाले सवाल

“DeepSeek-V4.1-Flash: Pushing the Limits of KV Cache Compression” paper (DeepSeek-AI, September 2026; aage V4.1 paper) ek multimodal mixture-of-experts model ka varnan karta hai: 552B backbone parameters, 10 lakh token tak ka context, prefill mein sirf 8B parameters active aur decode mein 16B. Paper ki mukhya line sirf ek baat hai: lambi avadhi ke agents ka workload “input-heavy” ho raha hai, isliye cost ka bottleneck computation se KV cache ko store aur idhar-udhar le jaane ki taraf khisak gaya hai — aur paper cache size ke teen gunakkal-atmak dimensions (entry size, sequence, layers) ko ek saath nichorta hai. Nateeja: har token ka global KV cache sirf 890 bytes, lagbhag pichhli DeepSeek-V4-Flash ka 1/4; sliding-window KV ko persistent cache se bahar karne ke baad persistent cache V4-Flash ka lagbhag 1/8 reh jata hai. Post-training hissa khud spasht likhta hai ki usmein “koi algorithmic innovation nahi” hai; paper lagbhag saara labh data aur environments ko deta hai.

Paper 17 September 2026 ko arXiv par aaya (v1, aur yeh lekh v1 par aadharit hai). Is model ko laptop par train nahi kiya ja sakta, isliye yeh lekh jaanch karta hai: Hugging Face ke public configs aur parameter tallies se paper ke sabse chamkeele numbers dobara ginata hai. Jo mel khaate hain: Figure 1(b) ke chaar byte counts (389,120, 48,068, 3,514, 890) poore punarnirmit hote hain, har design kya kitna guna bachata hai (counterfactual), har parat ke CSA2 modes, indexer ka scoring kaam, Single-Pass mHC ka read/write volume, aur 552B, 196B ke parameter counts; ek toy gradient se paper ka Sinkhorn-balanced update aur Appendix C ki derivation jaanchi gayi. Ek seema pehle bata doon, aur wo paper ki apni hai: usne kisi ek design ka ablation nahi diya — “nagnah asar” aur “sirf marginal giraavat” qualitative kahawatein hain; akela quantitative comparison poora model vs V4-Flash / V4-Pro hai, jo size, data aur post-training mein sab alag hain.

Yeh paper kyun padhne layak hai

  • Yeh “KV cache kitna bada hai” ko teen gunakkal-atmak factors mein todta hai. Entry size, sequence aur layers — har ek ka taiyar ilaaj hai (GQA aur MLA, compressed attention, cross-layer sharing); paper ka yogdan hai teeno ko ek saath lagana aur har ek ka hisaab saaf-saaf rakhna. Yeh decomposition kisi ek number se zyada kaam ki hai.
  • Numbers jaanche ja sakte hain. Figure 1(b) ke chaaron numbers public config.json aur ek byte layout se ek-ek karke punarnirmit hote hain — efficiency papers mein yeh durlabh hai.
  • Engineering detail sach mein detail hai. Persistent cache ki tiering (SSD aur host memory), prefix miss par punarganana, aur Reuse parat ka prefill mein 15 aur decode mein 11 kernels mein fuse hona — sab likha hai; yahi wo samasyaein hain jo lamba context serve karne walon ko sach mein aati hain.
  • Post-training hissa V3.2 ke saath tulna deta hai. V3.2 badhe RL ko stable karne ke chaar tricks ke baare mein tha; V4.1 paper kehta hai algorithm wahi raha, labh data aur environments mein hai. Dono ko saath padhne se ek saal mein zor kahan khiska hai, dikhta hai.
  • Is site ke paas. Sparse attention aur lightning indexer ka purkha V3.2 lekh mein, MLA aur DeepSeekMoE V2 lekh mein, mHC mHC lekh mein; concept pages hain KV Cache, efficient attention aur long context.

Background: input-heavy workload aur KV cache ke teen dimensions

Lambi avadhi ka agent har turn par badhti hui context dobara model mein daalta hai: har tool call ek aur prefill paida karta hai. Prefix cache hit hone par sirf naya hissa process hota hai; miss par poora prefix dobara ginna padta hai. Paper cache ko do prakaar mein baantta hai: GPU memory (HBM) mein rehne wala runtime cache, aur prefix reuse ke liye SSD aur host memory par rakha “persistent KV cache”. V4 ki har parat ki do shakhayein hain: global shakha poore context ko cover karti hai aur global KV rakhti hai (main KV + indexer K); local shakha sliding-window attention (SWA) hai, jiska SWA KV fixed size ka hota hai. Context kaafi lamba hone par length ke saath rakhaik badhne wala global KV haavi ho jata hai, isliye compression ka mukhya lakshya wahi hai.

Paper compression tarike ko un dimensions ke hisaab se teen classon mein baantta hai jo aapas mein multiply hote hain:

DimensionKya karta haiUdaharan
Entry sizeKam heads store karo, ya sab heads ek chhota latent share kareinGQA, MLA
SequenceHar mm tokens ko ek entry mein nichodoV4 ka CSA aur HCA
LayersKuch paratein doosron ki cache aur chunaav reuse karein, ya poori parat sasti mein badleinCross-layer KV sharing, IndexCache, YOIO, HySparse

Paper ki tippani: sirf index reuse karne se main KV ki storage nahi bachti, poore network mein routing share karna quality seemit karta hai, hybrid schemes phir bhi full-attention paratein rakhti hain; koi ek bhi tareeka teeno dimensions ko ek saath cover nahi karta. CSA2 teeno ko ek saath use karta hai aur “cache share karna” ko “chunaav reuse karna” se alag rakhata hai.

Neeche chaar DeepSeek generations ke per-token global KV bytes hain. Numbers maine public configs se, aage “hath se jaanch” section ke byte layout se, ginay hain; paper ke Figure 1(b) se ek-ek milte hain.

Chaar DeepSeek generations mein per-token global KV cache bytes Horizontal bar chart; x-axis per-token global KV cache bytes hai (log scale, 100 se 10 lakh). DeepSeek-V1 67B ko 389,120 bytes chahiye, V3.2 ko 48,068, V4-Flash ko 3,514.25 aur V4.1-Flash ko 890; lagatar generations 8.1, 13.7 aur 3.9 guna chhoti hain, aur V1 se V4.1 tak kul 437 guna. Per-token global KV cache (bytes, log scale) 100 1K 10K 100K 1M DeepSeek-V1 67B GQA, bf16 389,120 B 1M-token sequence: 380.00 GiB DeepSeek-V3.2 MLA + DSA, FP8 48,068 B 1M-token sequence: 46.94 GiB DeepSeek-V4-Flash CSA/HCA hybrid 3,514 B 1M-token sequence: 3.43 GiB DeepSeek-V4.1-Flash CSA2 + sharing + FP4 890 B 1M-token sequence: 0.87 GiB 8.1x chhota 13.7x chhota 3.9x chhota V1 se V4.1-Flash tak kul 437x chhota
Chitra 1: chaar DeepSeek generations ka per-token global KV cache bytes. Bytes public config.json aur text mein diye byte layout se nikaale gaye hain aur paper ke Figure 1(b) se ek-ek milte hain; dayein labels 1M (2^20) token ki ek sequence ke global KV ka kul batate hain. Har parat ka sliding-window KV ismein shaamil nahi hai.

Do jagah ruk kar dekhne layak hain. Pehla: V4.1 ka sequence compression asal mein V4 se bahut kamzor hai. Configs ke hisaab se V4-Flash ki 43 paraton mein 2 sirf sliding-window, 21 ratio 4 aur 20 ratio 128 wali hain (byte ledger mein ratio-4 wali indexer ke saath CSA aur ratio-128 wali HCA fit hoti hain), jabki V4.1 mein 2 sirf sliding-window, 18 ratio 2 aur 20 ratio 1 (yani bina compression) hain; usne badikee context ko rakha aur cache ko paraton ke sharing aur FP4 se nichoda. Doosra: tasveer ke 890 bytes mein sliding-window KV bhi nahi aur har parat ke queries bhi nahi; sliding-window KV ka kya hota hai, wo aage “SWA Bounded Replay” section ka vishay hai.

Kul sanrachna

Model 40-parat ka causal Transformer hai: pehli 20 paratein causal encoder, aakhri 20 decoder; sirf pehli do paraton ke chhodkar har parat mein global attention aur sliding-window attention dono hain. Tasveerein vision encoder aur MLP projector se ho kar visual embeddings banti hain jo text embeddings ke saath process hoti hain; multimodal data pre-training ke pehle din se hissa hai. V4-Flash se wo antar jo configs aur paper se seedha padhe ja sakte hain, neeche table mein hai (config wala hissa dono config.json se hai; jaanch script ka section 1 use jaise hai waise print karta hai):

ItemV4-FlashV4.1-Flash
Layers aur hidden size43 layers, 409640 layers, 5120
Routed experts (active, expert width)256 (6, 2048)384 (6, 2304)
Indexer64 heads x 128 dims, Top-51232 heads x 128 dims, Top-512
Sequence compression ratios4 (21 layers) aur 128 (20 layers)2 (18 layers) aur 1 (20 layers)
Parameters (paper)284B backbone, 13B active552B backbone, prefill mein 8B, decode mein 16B active, alag se 196B ka Engram

Baki saamaanya settings paper ke section 4.2.1 se hain: 64 query heads, head dim 512, query compression dim 1280, sliding window 128; har parat mein 1 shared expert + routed experts, SwiGLU clamp 10; mHC ka expansion factor 4; vision encoder DeepSeek-ViT mein 32 layers, hidden 1024, 16 heads, patch 14 hai, aur 3x3 pixel-unshuffle visual tokens ko navambh (one-ninth) kar deta hai — lagbhag 1344x1344 pixels tak. Paper MTP module hata deta hai aur speculative decoding ke liye DSpark lagata hai.

Causal Encoder-Decoder (CED)

Agent workflows mein tool calls naye prefill requests paida karte rehte hain, aur cache miss par prefill mukhya kharcha ban jata hai. CED YOCO se prerit hai (YOCO mein upar ki paratein neeche ki paraton ke banaye KV ko seedha share karti hain); paper kehta hai isse prefill computation lagbhag aadha ho jata hai, jabki performance baseline ke barabar rehti hai.

Tareeka: global attention ke liye sabse neeche ki L/2L/2 paraton ko causal encoder maano; decoder ki paratein (l>L/2l>L/2) apne hidden states HlH^l se KV nahi nikalti, balki encoder ki aakhri parat ke hidden state HL/2H^{L/2} se apni-apni projection se nikalti hain:

Cl=HL/2 WlKV,Zl=HL/2 WlZ,l>L/2C^l = H^{L/2}\,W^{KV}_l,\qquad Z^l = H^{L/2}\,W^{Z}_l,\qquad l>L/2

CC mein KV entries hain, ZZ mein unke compression weights. Isse prefill mein sirf aadhi paratein chala kar upri paraton ka global KV mil jata hai; prefill ki complexity O(NL)O(NL) se O(NL/2+nwinL/2)O(NL/2+n_{\mathrm{win}}L/2) par girti hai, aur jab sequence length NN window nwinn_{\mathrm{win}} se bahut badi ho to lagbhag O(NL/2)O(NL/2). Sliding-window attention phir bhi parat-dar-parat ginaya jata hai (local KV har parat ke apne hidden state se aata hai, computation gehri hai), aur yahi ek dikkat paida karta hai: decoder ki har parat ka sliding-window KV banane ke liye extra nwin×L/2n_{\mathrm{win}}\times L/2 tokens replay karne padte hain — Bounded Replay isi ke liye hai.

Decode mein har token saari 40 paraton se guzarta hai, isliye active parameters dugne: prefill 8B, decode 16B. Aage ki jaanch mein dikhega ki sirf expert parameters hi prefill mein lagbhag 4.95B aur decode mein lagbhag 9.91B hain; paper ke 8B aur 16B in dono se bade hain, antar attention, embeddings jaise non-expert hisson ka hoga, jo maine alag karke nahi ginay.

CSA2: cache share karo, chunaav reuse karo

CSA2 (Compressed Sparse Attention 2) V4 ke CSA ka uttaradhikari hai: ek halke indexer indexer Q aur indexer K se main KV entries ko score karta hai, har query apni Top-K entries chunta hai, aur attention in par plus us parat ke sliding-window KV par chalta hai; compression ratio 1 (bina compression) iska vishes case hai. Paper ne CSA ko do jagah saral kiya: compressor ab aas-paas ki entries ko original KV share karne nahi deta (CSA mein ratio mm ki har entry 2m2m original entries se banti thi, aapas mein overlap karti hui), aur compression ka absolute positional encoding hata diya; indexer K ab main KV se seedha project hota hai, alag compression path se nahi. Dono badlav implementation saral aur training tez ke liye hain.

Har CSA2 parat ko static roop se teen modes mein se ek milta hai. Teenon mein parat apni main query aur sliding-window KV khud ginti hai; antar sirf global hisse mein hai:

ModeMain KV aur indexer KIndexer QTop-K indices
FullKhud ginaye (indexer K apne main KV se projected)Khud ginayaKhud chuna, saare dikhne wale positions scan karke
ReindexSabse haal ki Full parat se reuseKhud ginayaKhud chuna, candidate pool ke andar punah-score
ReuseSabse haal ki Full parat se reuseNahi ginayaSabse haal ke Full ya Reindex parat ke chune hue reuse

Main KV aur indexer K share karne se cache storage bachti hai; Top-K reuse se index computation bachta hai; Reindex beech mein hai: cache shared rehti hai, par chunaav parat ke saath badal sakta hai. Paper ki layer plan: pehli 2 paratein sirf sliding-window; encoder ki baki 18 paratein ratio 2, teen groups mein 6-6 ki, har group mein 1 Full + 5 Reuse; decoder ki 20 paratein ratio 1, paanch groups mein 4-4 ki, pehla group 1 Full + 3 Reuse, baki chaar groups mein 1 Reindex + 3 Reuse. Config ke compress_ratios, kv_source_layer_ids, index_source_layer_ids se yahi plan nikalta hai (jaanch script ka section 3):

DeepSeek-V4.1-Flash ki 40-parat CSA2 layer plan 40 chaukor 40 paratein dikhate hain. Pehli do paratein sirf sliding-window (S). Encoder mein parat 2, 8, 14 Full hain, har ke baad paanch Reuse. Decoder mein parat 20 Full hai, uske baad har 4 parat par Reindex (24, 28, 32, 36), baki Reuse. Global KV chaar groups mein share hota hai (encoder ke andar 3, poore decoder ka 1) aur Top-512 index aath groups mein reuse hota hai. Causal encoder: 20 layers, main KV ratio 2 Decoder: 20 layers, main KV bina compression Chaukor ka akshar us parat ka mode hai; neeche brackets sharing batate hain S S F R R R R R F R R R R R F R R R R R F R R R X R R R X R R R X R R R X R R R 0 10 20 30 39 Global KV aur indexer K: har Full parat khud banati hai, aage ki reuse karti hain 1/2 entry/token 1/2 entry/token 1/2 entry/token 1 entry/token Top-512 index: har Full ya Reindex parat naya chunti hai; aage ki Reuse wahi lagati hain Top-512 Top-512 Top-512 Top-512 Top-512 Top-512 Top-512 Top-512 Candidate pool: parat 20 (Full) saare dikhne wale positions scan karke 2,048 blocks x 8 = 16,384 positions rakhti hai; parat 24, 28, 32, 36 (Reindex) sirf pool ke andar punah-score karti hain. S sirf SWA F Full X Reindex R Reuse
Chitra 2: DeepSeek-V4.1-Flash ki 40-parat CSA2 plan, jo config.json ke compress_ratios, kv_source_layer_ids, index_source_layer_ids aur candidate_source_layer_id se padhi gayi. S: sirf sliding-window; F: Full, apna main KV, indexer Q aur indexer K banati hai aur Top-512 chunti hai; X: Reindex, main KV aur indexer K reuse, apna indexer Q banati hai aur pool ke andar dobara chunti hai; R: Reuse, main KV aur Top-512 dono reuse. Har parat ka apna main Q aur sliding-window KV hai.

Is plan ke hisaab se 40 paraton mein global KV sirf 4 paraton (parat 2, 8, 14, 20) se aata hai; har token ausat 2.5 entries rakhta hai, jabki har parat apni copy rakhe to 29 hoti.

Hierarchical sparse indexer

Index ko cross-layer reuse karne se indexer calls kam hoti hain, par bachi hui indexers ko phir bhi poora causally-visible context score karna padta hai — bahut lambe context mein yahi bottleneck hai. Paper ka observation: decoder mein gehri (deeper) indexers ke candidates ko chhotti (shallower) indexers ki jankari spasht roop se seemit kar sakti hai, bina koi extra state ke.

Tareeka: decoder ki pehli Full parat (parat 20) saare dikhne wale positions score karti hai — apna Top-512 bhi chunti hai aur block-wise chunaav bhi karti hai: har block (8 positions) mein sabse ooncha index score lekar sabse achhe 2,048 blocks chun liye jaate hain aur unke covered positions se 2048×8=163842048\times 8=16384 positions ka candidate pool banta hai. Aage ki Reindex paratein (24, 28, 32, 36) sirf isi pool ke andar score karke apna Top-512 chunti hain. Pool ka size fixed hai to aage har indexer ka kaam context length par depend nahi karta; pehli Full parat ko phir bhi poora range scan karna padta hai, isliye rakhaik (linear) pad khatam nahi hota, sirf ek parat mein simat jata hai. Yeh tantra sirf decoder mein hai aur “training-aware” hai: pool ki seema training aur inference mein ek jaisi lagti hai, gehri indexers wahi search-domain mein optimize hoti hain jismein wo chalengi; aur yeh post-training mein hi joda jata hai.

“Hath se jaanch” ka section 4 iska parimaan banata hai: 10 lakh tokens par 4 Full layers bina-weight indexer FLOPs ka 97.6% leti hain, aur 4 Reindex layers kul milak 3% se kam.

FP4 main KV cache

V4 indexer ki queries aur keys par pehle hi FP4 quantization-aware training (QAT) kar chuka tha, scoring tez karne ke liye. V4.1 QAT ko main KV tak phailata hai: yahan FP4 sirf storage bachane ke liye hai, matrix multiply tez karne ke liye nahi — attention se pehle dequantize hota hai, isliye zyada sahi format chun sakte hain aur hardware ki native support bhi chahiye nahi. Chunaa format: E2M1 + har 16 channels par ek E4M3 scale, NVFP4 ki tarah, par uska second-level global scale hata kar (indexer OCP-standard MXFP4 use karta hai).

Global scale chhodne ka bahana magnitude ki seema hai: format 448×6=2688448\times 6=2688 tak represent kar sakta hai; RMSNorm ke baad 512-channel KV latent ki L2 norm adhiktam lagbhag 512\sqrt{512} hai (trained RMSNorm weights ka max lagbhag 1), RoPE norm nahi badalta, to kisi channel ka absolute value lagbhag 22.6 se zyada nahi ho sakta, aur training mein max lagbhag 10 hi dikha. QAT post-training mein aata hai; quantization RoPE ke baad hoti hai, kyunki pehle karne se sirf marginal accuracy labh milta aur decode ka kharcha badhta; sliding-window KV quantization ke liye sensitive hai, isliye FP8 hi rehta hai. Mere byte ledger se main KV ki ek entry V4 ke 584 bytes (FP8) se 288 bytes par girti hai; paper ise “lagbhag aadha” kehta hai.

SWA Bounded Replay aur persistent cache

Persistent KV cache prefix reuse ke liye SSD aur host memory par rakha jata hai. V4 mein global KV poora save hota tha, hit par poora prefix reuse; sliding-window KV sirf do positions par cache hota tha (prompt ka ant aur output ka ant), regeneration aur multi-turn session ke liye — aur yahi persistent cache ka lagbhag aadha hissa tha. Paper ka faisla: sliding-window KV ko persist karna mehnga bhi aur bemaayne bhi hai, kyunki wo sirf ek session ke andar, minute-scale window mein reuse hota hai; session khatam ya agla turn shuru hote hi marg — persistent cache ke “lambi umar, long-tail reuse” pattern se match nahi karta. V4 ka jawab Zero SWA Caching tha: miss par dobara ginna, par theek recovery ke liye L×nwinL\times n_{\mathrm{win}} tokens ka poora forward chahiye (V4.1 mein 40×128=512040\times128=5120); paper kehta hai production mein yeh bahut mehnga nikla.

V4.1 ne do cheezein badli: sliding-window KV persistent cache se nikal kar ek distributed memory pool mein gaya, jo har machine ke 10% host memory se banta hai, umar sirf kuch minute, expired entries turant recycle; global KV persistent cache mein hi hai, kam se kam 72 ghante ki guaranteed life ke saath. Miss par Bounded Replay chalta hai: LL paraton ka sliding-window KV theek se banane mein L×nwinL\times n_{\mathrm{win}} tokens replay hote; Bounded Replay sirf haal ke nwin=128n_{\mathrm{win}}=128 tokens replay karta hai aur window ko replayed hisse tak kaat deta hai (replay ss se shuru ho to position ii ka query sirf [max⁡(s, i−W+1), i][\max(s,\,i-W+1),\,i] ke keys ko dekhta hai), anumit state sweekar karte hue.

  • Encoder replay. Global KV hit ho aur sliding-window KV miss ho, to cached prefix ke aakhri 128 tokens ko uncached suffix ke saath process kiya jata hai; replayed tokens sirf sliding-window KV dobara banate hain, global KV seedha reuse hota hai — na dobara ginaya jata hai na overwrite. Isse prefix caching sirf global KV par depend karti hai.
  • Decoder replay. CED ke tahat decoder ka global KV encoder ki aakhri parat se aata hai, to prefill encoder par ruk sakta hai; rukawat sirf decoder ka sliding-window KV hai. Har prefill mein prompt ke aakhri 128 tokens ka encoder output decoder ki paraton se guzaara jata hai; jo decoder sliding-window KV banta hai wo sirf decode ke kaam aata hai, cache mein nahi jata. Paper kehta hai isse decoder ka forward 128 tokens tak simat jata hai aur prefill ka kul computation lagbhag aadha ho jata hai.
  • Hisaab kaise hota hai. Persistent cache do factors ke multiply se ghata hai: sliding-window KV ka hatna (lagbhag aadha) aur global KV ka V4 ke 1/4 par girna — kul milak lagbhag 1/8.

Keemat bhi paper mein likhi hai: replayed state anumit hai, isliye uncached suffix ke liye nikla global KV aur sliding-window KV cache-hit ki position par depend karta hai; positions ke beech bit-wise ek jaisa nahi. Paper kehta hai experimental evidence ke anusaar iska jawab ki gunvatta par asar lagbhag nahi hai, aur post-training mein wahi replay simulate karke “training-aware” adaptation kiya gaya; par mukhya text mein koi tulnatmak number nahi.

Baki architectural badlav

Single-Pass mHC. mHC (mHC lekh dekho) nn residual streams Xl∈Rn×dX_l\in\mathbb R^{n\times d} rakhta hai, aur har block inhe aise update karta hai:

Xl+1=BlXl+Cl Fl(AlXl),(Al,Bl,Cl)=H(Xl)X_{l+1}=B_l X_l+C_l\,\mathcal F_l(A_l X_l),\qquad (A_l,B_l,C_l)=\mathcal H(X_l)

AlA_l nn streams ko block-input mein milata hai, BlB_l, ClC_l residual update dekhte hain, teeno coefficients XlX_l se predicted hote hain. V4 ka implementation teen aapas mein depend karne wale kernels mein hota hai (residual update, coefficient prediction, input mixing), plus block ka pre-norm — activation read/write (4n+4)d(4n+4)d, ideal lower bound (2n+2)d(2n+2)d ka dugna. Do-pass fused version (residual update aur coefficient prediction ek hi traversal mein share karte hain) ko (3n+2)d(3n+2)d chahiye, kyunki input mixing ko coefficients ka intezaar hai aur XlX_l ek aur baar padhna padta hai. Single-Pass mHC mixing coefficient ko ek block peeche khiska deta hai:

Xl+1=BlXl+Cl Fl(Al−1Xl),(Al,Bl,Cl)=H(Xl)X_{l+1}=B_l X_l+C_l\,\mathcal F_l(A_{l-1} X_l),\qquad (A_l,B_l,C_l)=\mathcal H(X_l)

Input mixing ab current block ke abhi nikle coefficients par depend nahi karta, to har tile ek hi baar padh kar mixing aur coefficient prediction dono kar leta hai; deploy hone wala Mega-mHC kernel (2n+2)d(2n+2)d ki bound tak pahunch jata hai. Pre-training purane multi-kernel implementation par hi chalta hai, kyunki yeh khisakav sirf yeh badalta hai ki har block kaunsa coefficient lagaye. Paper kehta hai is khisakav ka performance nuksan nagnah hai.

Engram. Conditional memory module (n-gram par hashed lookup table; “memory” ko “computation” se alag karta hai): 196B parameters do modules mein barabar bante hain, parat 1 aur 14 par (0 se ginna); har module {2, 3, 4} order ke n-gram, 8 hash heads aur per-order kul embedding dim 2048 use karta hai; har head lagbhag 1.6 crore entries ki table index karta hai, table ke sizes alag-alag primes hain, aur tables + key/value projections sab FP8. Paper ne original design ka short causal convolution hata diya (labh inference stack ki complexity ke muqable mein kam tha); inference mein addressing deterministic hai, isliye embeddings background RDMA se host memory se prefetch hote hain.

DSpark. MTP ki jagah lene wala speculative decoding module: 3 Transformer blocks, 128 ka sliding window; ek forward mein 5 draft positions ke base logits saath-saath nikalte hain, aur ek halke Markov head draft tokens ke beech nirbharta model karta hai; confidence head har position ki conditional acceptance probability predict karta hai, scheduler engine ke throughput profile ke saath milak har request ke liye verification length chunta hai. Yeh pre-training ke baad alag stage mein train hota hai (backbone frozen), post-training mein backbone ke saath chalta rehta hai, par gradient backbone mein nahi jata.

Optimizer. Muon backbone ke linear layer weights par hai; query aur key weights ke liye head-wise Muon (paper ke anusaar saadha Muon se behtar, aur GLM-5 aur Kimi-K3 ne bhi verify kiya); norm layers aur baki non-matrix parameters par AdamW. Embedding, prediction head aur Engram tables — yeh vishaal matrices Adam nahi use karte (second moment optimizer state dugna kar deta), unki jagah “momentum + Sinkhorn balancing” update hai: Nesterov momentum ke baad update matrix ki rows aur columns par alternately L2 normalization KK baar (paper K=11K=11), phir n\sqrt n se multiply karke unit row norm ko unit row RMS mein badla jata hai, taaki update ki row RMS aur column RMS dono lagbhag 1 ho jayein. Muon ki tarah isse bhi sirf ek momentum buffer chahiye. Agle section ki jaanch ek toy gradient par isi ko test karti hai.

Hath se jaanch: KV bytes, layer plan, indexer kharcha, parameter ledger aur do algorithm

Neeche ka script sirf NumPy use karta hai; Hugging Face se chaar models ke config.json aur V4.1, V4-Flash ke parameter tallies lata hai (network chahiye) aur aath kaam karta hai: paper ke Figure 1(b) ke per-token global KV bytes punarnirmit karna; wahi byte layout se counterfactual (har design kya bachata hai); config se layer plan padhna; har decoded token par indexer ka scoring kaam aankana; teen mHC implementations ka read/write compare karna; parameter ledger check karna; Appendix C ki derivation toy numbers se test karna; aur ek toy gradient par Sinkhorn-balanced update test karna.

Pehle yeh spasht karoon ki kya paper ka hai aur kya mera. Ek cache entry kitne bytes ki hai — yeh paper item-by-item nahi batata; script ka byte layout mera assumption hai: yeh Figure 1(b) ke chaaron numbers exact punar-paida karta hai, par iska matlab sirf itna hai ki yeh assumptions aapas mein self-consistent hain, yeh nahi ki paper yahi layout use karta hai. Section 2 ke counterfactual, section 4 ka FLOPs anuman (precision se unweighted), section 7 ke toy parameters aur section 8 ka toy gradient bhi mere constructions hain, paper ke numbers nahi.

Poora code (lagbhag 200 lines)
"""Checking DeepSeek-V4.1-Flash: KV bytes, layer plan, indexer cost"""
import json
import urllib.request
from collections import Counter

import numpy as np

HUB = "https://huggingface.co"


def fetch(url):
    with urllib.request.urlopen(url, timeout=60) as r:
        return json.load(r)


def cfg_of(repo):
    return fetch(f"{HUB}/{repo}/resolve/main/config.json")


v1 = cfg_of("deepseek-ai/deepseek-llm-67b-base")
v32 = cfg_of("deepseek-ai/DeepSeek-V3.2")
v4 = cfg_of("deepseek-ai/DeepSeek-V4-Flash")
t = cfg_of("deepseek-ai/DeepSeek-V4.1-Flash")["text_config"]
L = t["num_hidden_layers"]
ratios = t["compress_ratios"][:L]
kv_src, idx_src = t["kv_source_layer_ids"], t["index_source_layer_ids"]

# Bytes per cache entry (assumptions that reproduce the paper)
BF16 = 2
V32_MAIN = v32["kv_lora_rank"] + 4 * 4 + v32["qk_rope_head_dim"] * BF16
V32_IDX = v32["index_head_dim"] + 4          # FP8 plus one fp32 scale
V4_MAIN = 448 + 64 * BF16 + 8                # FP8 non-RoPE + bf16 RoPE + scales
FP4_MAIN = t["head_dim"] // 2 + t["head_dim"] // 16   # E2M1 + E4M3 / 16
IDX_FP4 = t["index_head_dim"] // 2 + t["index_head_dim"] // 32  # MXFP4

print("== 1. Global KV cache bytes per token (paper Fig. 1b)")
dh = v1["hidden_size"] // v1["num_attention_heads"]
b_v1 = 2 * v1["num_hidden_layers"] * v1["num_key_value_heads"] * dh * BF16
b_v32 = v32["num_hidden_layers"] * (V32_MAIN + V32_IDX)
r4 = v4["compress_ratios"][:v4["num_hidden_layers"]]
b_v4 = sum((V4_MAIN + (IDX_FP4 if r == 4 else 0)) / r for r in r4 if r)
b_v41 = sum((FP4_MAIN + IDX_FP4) / ratios[i] for i in kv_src)
rows = [("DeepSeek-V1 67B", b_v1, 389120), ("DeepSeek-V3.2", b_v32, 48068),
        ("DeepSeek-V4-Flash", b_v4, 3514), ("DeepSeek-V4.1-Flash", b_v41, 890)]
print(f"  {'model':20s}{'computed':>12s}{'paper':>10s}")
for name, b, paper in rows:
    print(f"  {name:20s}{b:>12,.2f}{paper:>10,}")
print(f"  bytes: V3.2 {V32_MAIN}+{V32_IDX} per layer; V4 {V4_MAIN} (+{IDX_FP4}"
      f" on ratio-4 layers); V4.1 {FP4_MAIN}+{IDX_FP4}")
print(f"  V4-Flash {len(r4)} layers, ratios: "
      f"{dict(sorted(Counter(r4).items()))}")
for name, c in (("V4-Flash  ", v4), ("V4.1-Flash", t)):
    print(f"  {name} {c['num_hidden_layers']}L d={c['hidden_size']} experts "
          f"{c['n_routed_experts']} top-{c['num_experts_per_tok']} "
          f"({c['moe_intermediate_size']}) indexer {c['index_n_heads']}x"
          f"{c['index_head_dim']} top-k {c['index_topk']}")
for (na, a, _), (nb, b, _), want in zip(rows, rows[1:], (8.1, 13.7, 3.9)):
    print(f"  {na} / {nb}: {a / b:.3f}x  (paper {want}x)")
print(f"  V1 / V4.1: {b_v1 / b_v41:.1f}x  (paper 437x)")

print("\n== 2. What each V4.1 choice buys (counterfactual, not paper numbers)")
own = sum(1 / r for r in ratios if r)
shared = sum(1 / ratios[i] for i in kv_src)
ladder = [("no sharing, FP8 main KV", own * (V4_MAIN + IDX_FP4)),
          ("no sharing, FP4 main KV", own * (FP4_MAIN + IDX_FP4)),
          ("shared + FP4 (V4.1)", shared * (FP4_MAIN + IDX_FP4))]
print(f"  cache entries per token: {own:g} "
      f"(every layer its own) vs {shared:g} (4 source layers)")
for (name, b), prev in zip(ladder, [None] + [b for _, b in ladder]):
    step = "" if prev is None else f"  ({prev / b:.2f}x)"
    print(f"  {name:26s}{b:>10,.0f} B{step}")
print(f"  total {ladder[0][1] / ladder[-1][1]:.1f}x")
N = 1 << 20
print("  global KV of one 1M-token (2^20) sequence:")
for name, b, _ in rows:
    print(f"    {name:20s}{b * N / 2**30:>9.2f} GiB")

print("\n== 3. Layer plan: the three CSA2 modes read from the config")
plan = ""
for i, r in enumerate(ratios):
    plan += "S" if r == 0 else "F" if i in kv_src else (
        "X" if i in idx_src else "R")
print("  " + plan[:20] + " | " + plan[20:])
print("  S=SWA only, F=Full, X=Reindex, R=Reuse; ratio "
      f"{sorted(set(ratios))}")
print("  " + ", ".join(f"{m}={plan.count(m)}" for m in "SFXR"),
      f"| Full {kv_src}, Reindex {[i for i in idx_src if i not in kv_src]}")

print("\n== 4. Indexer scoring per decoded token (raw FLOPs)")
cand = t["candidate_topk_blocks"] * t["candidate_block_size"]
f32 = 2 * v32["index_n_heads"] * v32["index_head_dim"]
f41 = 2 * t["index_n_heads"] * t["index_head_dim"]


def scored(n):
    return sum(n / ratios[i] if i in kv_src else min(cand, n / ratios[i])
               for i in idx_src)


print(f"  candidate pool {cand:,} positions; FLOPs/pair: "
      f"V3.2 {f32:,}, V4.1 {f41:,}")
print(f"  {'N':>9s}{'V3.2 GFLOP':>13s}{'V4.1 GFLOP':>13s}{'ratio':>8s}"
      f"{'Full share':>12s}")
for n in (4096, 65536, 131072, N):
    g32 = v32["num_hidden_layers"] * n * f32 / 1e9
    g41 = scored(n) * f41 / 1e9
    full = sum(n / ratios[i] for i in kv_src) / scored(n)
    print(f"  {n:>9,}{g32:>13.3f}{g41:>13.3f}{g32 / g41:>7.1f}x{full:>12.1%}")

print("\n== 5. Single-Pass mHC activation traffic (units of d, n=hc_mult)")
n = t["hc_mult"]
for name, v in (("multi-pass (3 kernels+norm)", 4 * n + 4),
                ("two-pass fused", 3 * n + 2),
                ("single-pass / lower bound", 2 * n + 2)):
    print(f"  {name:27s}{v:>3d} d = {v * t['hidden_size']:>7,} values"
          f" per token per block")
print(f"  n={n}: single-pass vs multi-pass "
      f"{(4 * n + 4) / (2 * n + 2):.1f}x")

print("\n== 6. Parameter ledger (Hub dtype tallies + config)")
tally = fetch(f"{HUB}/api/models/deepseek-ai/DeepSeek-V4.1-Flash")
tally = tally["safetensors"]["parameters"]
d, mi = t["hidden_size"], t["moe_intermediate_size"]
e = 3 * d * mi
routed = L * t["n_routed_experts"] * e
dspark = 3 * t["dspark_n_routed_experts"] * e
print(f"  one expert (three SwiGLU matrices) "
      f"3 x {d} x {mi} = {e:,}")
print(f"  I8 tally {tally['I8']:,}; {L} x {t['n_routed_experts']} "
      f"+ 3 x {t['dspark_n_routed_experts']} experts = {routed + dspark:,}")
engram = sum(t["engram_num_embeddings"]) * t["engram_head_dim"]
print(f"  Engram: {sum(t['engram_num_embeddings']):,} rows x "
      f"{t['engram_head_dim']} = {engram:,} (paper: 196B)")
print(f"  F8 tally {tally['F8_E4M3']:,} - Engram = "
      f"{tally['F8_E4M3'] - engram:,}")
total = sum(tally.values())
back = total - engram - dspark
print(f"  total {total:,}")
print(f"  - Engram - DSpark experts = {back:,} ({back / 1e9:.1f}B,"
      f" paper 552B)")
act = (1 + t["num_experts_per_tok"]) * e
print(f"  activated expert parameters: "
      f"{L * act / 1e9:.2f}B decode, {L // 2 * act / 1e9:.2f}B "
      f"prefill (paper 16B / 8B)")

print("\n== 7. Why the effort penalty decays exponentially (App. C, toy)")
s_, aL, k0, b0, tau, Ln = 4000.0, 0.75, 0.5, 25.0, 25.0, 4000.0
ell = np.arange(0, 40001, dtype=float)
p = 0.2 + (aL / Ln) * s_ * (1 - np.exp(-ell / s_))     # p'(l) = a exp(-l/s)
print(f"  setup: s={s_:g}, a*L={aL}, k0={k0}, b_min={b0:g}, tau={tau:g}")
print(f"  L_norm={Ln:g}, p(0)=0.2, p(inf)={0.2 + aL * s_ / Ln:.2f}")
print(f"  {'b':>4s}{'k(b)':>8s}{'closed form':>13s}{'grid':>8s}"
      f"{'cap 0.3':>9s}{'cap 0.8':>9s}")
grid = []
for b in (25, 50, 75, 100):
    k = k0 * np.exp(-(b - b0) / tau)
    closed = s_ * (np.log(aL / k0) + (b - b0) / tau)
    out = [int(np.argmax(p - k * ell / Ln))]
    out += [int(np.argmax(p - np.minimum(c, k * ell / Ln))) for c in (0.3, 0.8)]
    grid.append(out[0])
    print(f"  {b:>4d}{k:>8.4f}{closed:>13,.0f}{out[0]:>8,}{out[1]:>9,}"
          f"{out[2]:>9,}")
slope = np.polyfit([25, 50, 75, 100], grid, 1)[0]
print(f"  slope of the grid optimum {slope:.1f} "
      f"tokens per unit b; s/tau = {s_ / tau:.1f}")

print("\n== 8. Sinkhorn-balanced update (Algorithm 1): toy gradient")
rng = np.random.default_rng(0)
m_rows, n_cols = 4000, 64
seen = rng.random(m_rows) < 0.2            # tokens seen in this batch
G = rng.normal(size=(m_rows, n_cols))
G *= (np.exp(rng.normal(0, 1.5, m_rows)) * seen)[:, None]   # rows: heavy tail
G *= np.exp(rng.normal(0, 0.7, n_cols))[None, :]            # columns: unequal
beta, tau_s, eps = 0.95, 1e-3, 1e-20
G_hat = beta * ((1 - beta) * G) + (1 - beta) * G   # Nesterov, momentum from 0


def balanced(g, K):
    rho = np.linalg.norm(g, axis=1)
    u = np.where((rho <= tau_s * rho.mean())[:, None], 0.0, g)
    for k in range(1, K + 1):
        u /= np.linalg.norm(u, axis=1 if k % 2 else 0, keepdims=True) + eps
    return np.sqrt(g.shape[1]) * u


def spread(d):
    live = np.abs(d).sum(1) > 0
    r = np.sqrt((d[live] ** 2).mean(1))
    c = np.sqrt((d[live] ** 2).mean(0))
    return live.sum(), r.min(), r.max(), c.min(), c.max()


print(f"  {'':16s}{'rows':>5s}{'row RMS (min .. max)':>26s}"
      f"{'column RMS (min .. max)':>29s}")
for name, d in (("momentum", G_hat), ("K = 1", balanced(G_hat, 1)),
                ("K = 3", balanced(G_hat, 3)),
                ("K = 11 (paper)", balanced(G_hat, 11))):
    nl, r0, r1, c0, c1 = spread(d)
    print(f"  {name:16s}{nl:>5d}{r0:>13.4g} ..{r1:>9.4g}"
          f"{c0:>15.4g} ..{c1:>9.4g}")
print(f"  Engram has {engram:,} parameters; one FP32 state (assumed) = "
      f"{engram * 4 / 1e9:,.0f} GB")

Output (yeh aautput is page ki original Chinese-sanskaran poorni run se hai; prastuti ke liye labels angrezi mein dikhaye gaye hain, numbers adhourt hain):

== 1. Global KV cache bytes per token (paper Fig. 1b)
  model                   computed     paper
  DeepSeek-V1 67B       389,120.00   389,120
  DeepSeek-V3.2          48,068.00    48,068
  DeepSeek-V4-Flash       3,514.25     3,514
  DeepSeek-V4.1-Flash       890.00       890
  bytes: V3.2 656+132 per layer; V4 584 (+68 on ratio-4 layers); V4.1 288+68
  V4-Flash 43 layers, ratios: {0: 2, 4: 21, 128: 20}
  V4-Flash   43L d=4096 experts 256 top-6 (2048) indexer 64x128 top-k 512
  V4.1-Flash 40L d=5120 experts 384 top-6 (2304) indexer 32x128 top-k 512
  DeepSeek-V1 67B / DeepSeek-V3.2: 8.095x  (paper 8.1x)
  DeepSeek-V3.2 / DeepSeek-V4-Flash: 13.678x  (paper 13.7x)
  DeepSeek-V4-Flash / DeepSeek-V4.1-Flash: 3.949x  (paper 3.9x)
  V1 / V4.1: 437.2x  (paper 437x)

== 2. What each V4.1 choice buys (counterfactual, not paper numbers)
  cache entries per token: 29 (every layer its own) vs 2.5 (4 source layers)
  no sharing, FP8 main KV       18,908 B
  no sharing, FP4 main KV       10,324 B  (1.83x)
  shared + FP4 (V4.1)              890 B  (11.60x)
  total 21.2x
  global KV of one 1M-token (2^20) sequence:
    DeepSeek-V1 67B        380.00 GiB
    DeepSeek-V3.2           46.94 GiB
    DeepSeek-V4-Flash        3.43 GiB
    DeepSeek-V4.1-Flash      0.87 GiB

== 3. Layer plan: the three CSA2 modes read from the config
  SSFRRRRRFRRRRRFRRRRR | FRRRXRRRXRRRXRRRXRRR
  S=SWA only, F=Full, X=Reindex, R=Reuse; ratio [0, 1, 2]
  S=2, F=4, X=4, R=30 | Full [2, 8, 14, 20], Reindex [24, 28, 32, 36]

== 4. Indexer scoring per decoded token (raw FLOPs)
  candidate pool 16,384 positions; FLOPs/pair: V3.2 16,384, V4.1 8,192
          N   V3.2 GFLOP   V4.1 GFLOP   ratio  Full share
      4,096        4.094        0.218   18.8x       38.5%
     65,536       65.498        1.879   34.9x       71.4%
    131,072      130.997        3.221   40.7x       83.3%
  1,048,576     1047.972       22.012   47.6x       97.6%

== 5. Single-Pass mHC activation traffic (units of d, n=hc_mult)
  multi-pass (3 kernels+norm) 20 d = 102,400 values per token per block
  two-pass fused              14 d =  71,680 values per token per block
  single-pass / lower bound   10 d =  51,200 values per token per block
  n=4: single-pass vs multi-pass 2.0x

== 6. Parameter ledger (Hub dtype tallies + config)
  one expert (three SwiGLU matrices) 3 x 5120 x 2304 = 35,389,440
  I8 tally 557,171,343,360; 40 x 384 + 3 x 128 experts = 557,171,343,360
  Engram: 768,022,850 rows x 256 = 196,613,849,600 (paper: 196B)
  F8 tally 204,015,223,296 - Engram = 7,401,373,696
  total 763,205,315,794
  - Engram - DSpark experts = 553,001,921,234 (553.0B, paper 552B)
  activated expert parameters: 9.91B decode, 4.95B prefill (paper 16B / 8B)

== 7. Why the effort penalty decays exponentially (App. C, toy)
  setup: s=4000, a*L=0.75, k0=0.5, b_min=25, tau=25
  L_norm=4000, p(0)=0.2, p(inf)=0.95
     b    k(b)  closed form    grid  cap 0.3  cap 0.8
    25  0.5000        1,622   1,622   40,000    1,622
    50  0.1839        5,622   5,622   40,000    5,622
    75  0.0677        9,622   9,622    9,622    9,622
   100  0.0249       13,622  13,622   13,622   13,622
  slope of the grid optimum 160.0 tokens per unit b; s/tau = 160.0

== 8. Sinkhorn-balanced update (Algorithm 1): toy gradient
                   rows      row RMS (min .. max)      column RMS (min .. max)
  momentum          833     0.002021 ..    38.08         0.2766 ..    5.102
  K = 1             833            1 ..        1         0.2194 ..    3.137
  K = 3             833            1 ..        1         0.9721 ..    1.145
  K = 11 (paper)    833            1 ..        1              1 ..        1
  Engram has 196,613,849,600 parameters; one FP32 state (assumed) = 786 GB

Ek-ek karke:

  • Figure 1(b) ke chaaron numbers punarnirmit hote hain (section 1). Layout aisa hai. V1 67B GQA hai (95 layers, 8 KV heads, head dim 128, bf16) — per token 389,120 bytes. V3.2 har layer mein main KV 656 bytes (512-dim FP8 latent, 16 bytes scales, 64 bf16 position dims) + indexer K 132 bytes (128 FP8 dims + 4-byte scale) rakhti hai; 61 layers par kul 48,068 bytes. V4-Flash ka ek main-KV entry 584 bytes (448 FP8 dims, 64 bf16 position dims, 8 bytes scales) aur ratio-4 paraton mein alag se 68 bytes ka FP4 indexer K; har parat ke compression ratio se bharn par 3,514.25 bytes bante hain (paper ke figure mein 3,514 likha hai). V4.1 ke har source layer mein main KV 288 bytes (512 FP4 dims + har 16 channels par FP8 scale) + 68 bytes indexer K; ratio se bharn ke baad exactly 890 bytes — paper ke conclusion ka number. Lagatar generations 8.095, 13.678, 3.949 guna chhoti (paper: 8.1, 13.7, 3.9), aur V1 se V4.1 tak kul 437.2 guna (paper: 437).
  • Quantization se sharing zyada keemti hai (section 2, counterfactual). Agar V4.1 ki apni layer sanrachna (ratio 2 aur 1) mein har parat apni copy rakhe aur main KV FP8 ho, to per token 18,908 bytes. Sirf FP4 par badlein to 10,324 bytes — sirf 1.83 guna, kyunki FP4 sirf main KV par lagta hai aur 68 bytes ka indexer K pehle hi 4-bit hai; entry (584+68) se (288+68) bytes par jati hai. Ab cross-layer sharing jodo — entries 29 se 2.5 par — to 890 bytes par, aur 11.60 guna; kul 21.2 guna. Yeh V4.1 ki apni layer sanrachna ke andar ka arithmetic hai, ablation nahi: yeh batata hai ki is sanrachna mein ghatav ka bada hissa layer dimension se aata hai; par paper ka 1/4 V4-Flash ke saamne kaha gaya hai, jiska sequence compression zyada tez hai, isliye yeh counterfactual un 3.949 ko teen hisson mein baant nahi sakta. In bytes se 1M (2202^{20}) token ki ek sequence ka global KV V1 par 380.00 GiB, V3.2 par 46.94 GiB, V4-Flash par 3.43 GiB aur V4.1 par 0.87 GiB hota hai.
  • Layer plan paper se milti hai (section 3). Config se S=2, F=4, X=4, R=30 nikalta hai: encoder ki parat 2, 8, 14 Full; decoder ki parat 20 Full, 24, 28, 32, 36 Reindex; baki sab Reuse — paper ke section 4.2.1 ke likhe description se parat-dar-parat milta hai.
  • Indexer ka scoring kaam (section 4). Yeh raw FLOPs hain, precision se weighted nahi: har candidate position par V3.2 ko 16,384 (64 heads x 128 dims x 2) aur V4.1 ko 8,192 (32 heads). Sequence 4,096 par V4.1 ka indexer V3.2 ke 1/18.8 scoring karta hai, 10 lakh tokens par 1/47.6: chaar Reindex layers candidate pool se capped ho gayi hain, aur rakhaik badhne wali sirf chaar Full layers reh gayi hain — 10 lakh tokens par scoring ka 97.6% inhi ka hai. Isi se paper ka kaha “pehli Full layer ko phir bhi poora range scan karna padta hai” samajh aata hai. Paper ka Figure 2 dawa karta hai ki context ko 4K se 256 guna lamba karke 1M par le jaane par per-decoded-token FLOPs sirf 1/4 badhta hai. Yeh number mujhe punar-paida nahi hua: paper BF16 : FP8 : FP4 = 1 : 0.5 : 0.25 se weight karta hai, par yeh nahi batata ki kaunsa hissa kis precision par chalta hai. Meri table sirf yeh dikhati hai ki indexer ki vriddhi kahan se aati hai; wo curve verify nahi hoti.
  • mHC ka read/write (section 5). Multi-pass implementation (teen kernels + pre-norm) (4n+4)d(4n+4)d hilata hai, two-pass fused (3n+2)d(3n+2)d, aur single-pass lower bound (2n+2)d(2n+2)d tak pahunchta hai; n=4n=4, d=5120d=5120 par per token per block 102,400, 71,680 aur 51,200 values — single-pass 2.0 guna kam, paper ke “aadha” ke mel mein. Yeh sirf traffic ka arithmetic hai; kernel sach mein dugna tez hai ya nahi, wo implementation par depend karta hai, maine naapa nahi.
  • Parameter ledger (section 6). Ek expert teen SwiGLU matrices hain: 3×5120×2304=35,389,4403\times5120\times2304=35{,}389{,}440 parameters. Hub par V4.1 ka I8 tally 557,171,343,360 hai — exactly (40×384+3×128)(40\times384+3\times128) experts, yani 40 layers ke 384 routed experts + DSpark ke teen blocks ke 128-128 experts, ek digit ka antar nahi. Engram 768,022,850 rows x 256 dims = 196,613,849,600 (paper: 196B); FP8 tally se Engram hatane ke baad 7,401,373,696 bachta hai. Total 763,205,315,794; Engram aur DSpark experts hatane par 553,001,921,234 — paper 552B likhta hai, thoda kam; maine tensor-dar-tensor nahi chhedha, ho sakta hai counting ka daayra alag ho (jaise vision encoder ya DSpark ke non-expert hisse ginne mein hain ya nahi). Prefill sirf encoder ki 20 paratein chalata hai — activated expert parameters 4.95B; decode saari 40 chalata hai — 9.91B. Paper ke 8B aur 16B mein attention, embeddings aisa kuch aur bhi hoga, jo maine nahi toda.
  • Appendix C ki derivation khari utarti hai (section 7, toy numbers). Appendix C maanata hai ki “ek aur reasoning token ka labh” length ke saath exponentially girta hai, aur nikalta hai ki optimal reasoning length effort bb mein lagbhag rakhaik hai, slope s/τs/\tau. Toy parameters (s=4000s=4000, τ=25\tau=25) par grid par seedha maximum dhoondhne par optimal lengths 1,622, 5,622, 9,622, 13,622 mili — closed form se digit-dar-digit same — aur slope 160.0, exactly s/τs/\tau. Appendix ka likha caveat bhi dikhta hai: penalty ko 0.3 par cap karne par b=25b=25 aur b=50b=50 ka optimum grid ki seema 40,000 par chala jata hai, kyunki cap ke baad ek aur token ki marginal cost zero hai; cap 0.8 par kuch nahi badalta. Isliye penalty ki upper limit Cmax⁡C_{\max} bahut kam nahi rakhni chahiye, warna kam effort sabse lamba sochne lagega. Parameters mere chune hue hain, derivation dikhane ke liye — paper ke nahi.
  • Sinkhorn-balanced update apna dawa poora karta hai (section 8, toy gradient). Gradient matrix 4,000 rows (tokens) x 64 columns hai; lagbhag 20% rows hi non-zero hain (is batch mein aaye tokens), rows ka size heavy-tailed hai, columns ke scales alag hain. Momentum ke baad 833 live rows ki RMS 0.002021 se 38.08 tak — chaar orders se zyada ka phailav. Paper ke K=11K=11 ke baad har live row ki RMS 1 hai aur har column ki bhi (chaar significant digits tak). K=1K=1 par rows pehle hi exactly 1 hain, par column RMS 0.2194 se 3.137 mein hai; K=3K=3 use 0.9721 se 1.145 tak simatata hai. Baki 3,167 rows (na aaye tokens, aur mask threshold ρi≤τρˉ\rho_i\le\tau\bar\rho se neeche wali rows) ka update zero hota hai. Isne sirf algorithm ke properties test kiye; yeh nahi ki wo “Adam se behtar” hai (paper kehta hai empirically behtar, mukhya text mein comparison table nahi). FP32 assumption se Engram ke 196,613,849,600 parameters ki har ek extra optimizer state 786 GB hai — second moment ka buffer chhodna chhota bachat nahi hai.

Environment: Apple M2 Max, Python 3.14.3, NumPy 2.4.2, sirf CPU, lagbhag 10 second. Configs aur parameter tallies 13 November 2026 ko Hugging Face se aaye the; repositories badalne par numbers badal sakte hain. Section 8 ke random numbers fixed seed se hain, isliye is page ke do sanskaranon ke numbers digit-dar-digit same print hote hain.

Pre-training: shuru se hi sparse attention

V4.1-Flash 45T tokens ke multimodal corpus par pre-train hua hai; text aur multimodal tokens ka anupat 7:1. Data processing mein ek baat yaad rakhne layak hai: kamzor models se bana content aur ghatia machine translation ko “implicit duplication” samajh kar filter kiya jata hai, kyunki wo maujooda jaankari ko hi dobara kah dete hain aur lambi training mein nuksaan de sakte hain. Batch size fixed 10.06 crore tokens; learning rate pehle 2,000 steps mein rakhaik uthkar 2.6×10−42.6\times10^{-4} hota hai, 28T tokens tak wahin rehta hai, phir 28T se 40T ke beech cosine par girkar 2.6×10−52.6\times10^{-5} hota hai, aur aakhri 5T tokens wahin rukta hai.

V3.2 se ek bada badlav: ab “pehle dense pre-train, phir sparse mein badalna” nahi hai. Paper kehta hai sparse attention shuru se hi train hua, sequence length 64K, koi dense warm-up stage nahi; 34T tokens par sequence length 10 lakh par phaili. Optimizer settings: Muon ka momentum 0.95, weight decay 0.1, aur har update matrix ki RMS 0.18 par rescale ki jati hai taaki AdamW ka learning rate hi reuse ho sake; AdamW ke β1=0.9\beta_1=0.9, β2=0.95\beta_2=0.95; Sinkhorn-balanced update wahi momentum aur learning-rate correction leta hai, K=11K=11, τ=10−3\tau=10^{-3}, ϵ=10−20\epsilon=10^{-20}; Engram ka learning rate 5 guna. Paper batata hai ki training bhar koi instability nahi hui.

Base model ka comparison V4-Flash-Base aur V4-Pro-Base se hai (baad mein 49B active, 1.6T total parameters). Paper kehta hai V4.1-Flash-Base ki knowledge, reasoning aur code capability V4-Pro-Base ke barabar hai, held-out evaluations par 5% se 10% behtar, parameters kul ke 1/3 aur active ke 1/4 par. In comparisons ke vistrit numbers paper ke Table 1 mein hain, yahan dohraye nahi gaye.

Post-training: data aur environments, algorithm nahi

Paper post-training ke baare mein seedha hai: is sanskaran mein koi naya algorithm nahi aaya. Recipe standard hai — supervised fine-tuning, reinforcement learning aur on-policy distillation (OPD); saare mool badlav data pipeline mein hain, aur paper likhta hai: “ek fixed aur sadharan optimization procedure ke tahat, data aur environments ke scale, diversity aur verifiability ki systematic vriddhi hi lagbhag saare dikhe labh ko explain karti hai.” Yeh paper ka dawa hai; mukhya text mein data ko algorithm se alag karne wala koi experiment nahi hai.

  • Task synthesis. Har task ek (problem, environment, verification system) triplet hai, jise difficulty aur correctness do dimensions par score kiya jata hai, aur yehi do scores reward ban kar model ko iteratively apne behtar tasks banane ki training dete hain. General-agent environments internal employees aur external partners ke volunteer interaction data se aate hain; unse bahut se mock tools bante hain jo real tools ke input formats, output structures aur API constraints dohrate hain, aur negative feedback aur failure cases ko replayable environments mein badla jata hai. Coding-agent environments do srot se hain: employees aur partners ke coding sessions (complex tasks aur jahan model bure rahe wo rakhte hue), aur star threshold paar kiye public GitHub repositories. Kai specialized agents ka batwara hai: ek agent dekhta hai ki project container mein build ho kar auto-verify hota hai ya nahi, starting commit chunta hai aur aise eval points banata hai jo “fail se pass hona chahiye” aur “pass mein hi rehna chahiye” dono de; ek agent isolated container mein environment khada karta hai aur jawab leak karne wale nishaan mitata hai; kai solver agents task try karte hain; ek alag quality-inspection agent environment aur trajectories ki samiksha karta hai, aur jo na guzre wo repair agent ko jata hai.
  • Reinforcement learning. Bade paimane par asynchronous RL, training compute aur scaffolds ki sankhya — do dimensions par scale. Asynchrony length-distribution bias aur off-policy samples laata hai, jinhe paper dataset-wise concurrency seemit karke, jaldi lautne wale chhote samples chhod kar, max off-policy ratio bandhe aur stale tokens par loss mask laga kar sambhalta hai. Dispatch granularity mein batch-level aur prompt-level try kiya, antim faisle par sample-level chuna (agle prompt ke liye GRPO group size jitne samples jama hote hi dispatch); cross-checkpoint samples ke liye har rollout segment ke expert routing ko joda jata hai, dobara gine ke bajaye. Sandbox platform DSec lakhaon containers tak scale karta hai aur per physical node ka concurrent container count lagbhag 1,000 se 2,500+ kiya. Paper agents ke sandbox loopholes se cheating karne ke kisse bhi likhta hai (XFS driver ki permission samasya, AppArmor ka illegal memory access, package mirrors se jawab ka leak), jinke saamne per-sandbox AppArmor profile aur eBPF network policy lagaye gaye.
  • Reasoning effort control. Training mein scalar b∈{1,…,100}b\in\{1,\dots,100\} system prompt mein likha jata hai, wahi prompt kai bb par sample hota hai, aur rewards sirf usi (prompt, bb) subgroup ke andar mean-centered hote hain; effort ka antar length penalty se aata hai:
rb,jlen=−min⁡ ⁣(Cmax⁡, k(b) ℓb,jLnorm),k(b)=k0exp⁡ ⁣(−b−bmin⁡τ)r^{\mathrm{len}}_{b,j}=-\min\!\left(C_{\max},\ k(b)\,\frac{\ell_{b,j}}{L_{\mathrm{norm}}}\right),\qquad k(b)=k_0\exp\!\left(-\frac{b-b_{\min}}{\tau}\right)

ℓb,j\ell_{b,j} reasoning tokens ki sankhya hai, aur bb har τ\tau badne par penalty coefficient e−1e^{-1} se multiply hota hai. Public API ke max, high, low tiers b=100b=100, 75, 50 hain (September 2026 mein launch). Upar ki jaanch script ka section 7 dikhaata hai ki Appendix C ne exponential kyun chuna.

  • On-policy distillation. Post-training ka aakhri kadam full-vocabulary OPD hai, sab domains ke data aur 40 se zyada teacher models ke saath; teacher ka architecture student se aur aapas mein alag ho sakta hai, aur infrastructure bina-limit heterogeneous teachers aur sasta switching support karta hai.

Paper ke results

Neeche table mein sirf wo numbers hain jo paper ka mukhya text spasht likhta hai (paper ke Table 3 mein aur benchmarks aur baselines hain, yahan dohraye nahi). Comparison model ke naam paper ki tarah likhe hain.

BenchmarkV4.1-FlashPaper ke naam liye comparisons
Codeforces (rating)3471V4-Pro 3348, V4-Flash 3289
GPQA Diamond90.9V4-Flash 89.9
MathArena Apex65.6Kimi-K3 65.6, V4-Pro 65.3
DeepSWE v1.1 (resolved)74.2V4-Flash 54.4, Opus-5 74.0, GPT-5.6 Sol 73.0
Terminal-Bench 2.190.6Opus-5 89.1, GLM-5.3 88.2
AutomationBench54.8Paper kehta hai open aur closed baselines se aage
Agents’ Last Exam31.8Paper kehta hai open aur closed baselines se aage

Reasoning effort ka asar paper ki sabse saaf curves mein se ek hai:

MetricEffort 25Effort 100
Aath reasoning benchmarks ka ausat Pass@167.1%76.3%
DeepSWE v1.166.0%74.2%
Terminal-Bench 2.182.4%90.6%

Keemat: output tokens lagbhag 2.5 guna. Paper yeh bhi batata hai ki labh shuruat mein hi jama hota hai: effort 60 se 80 ka interval max tier ke aadhe se kam token budget mein uski zyadatar accuracy hi le aata hai; aakhri kadam 100 tak agent trajectories 1.6 se 1.8 guna lambe kar deta hai par sudhaar bahut chhota rehta hai, isliye max tier sabse kathin tasks ke liye rakha jaye to behtar. Ek preliminary multi-agent experiment mein (DeepSeek Harness ka Agent Team mode), ProgramBench ka Almost@1 8 ghante mein 30.04% pahunchta hai, jabki single agent ka best 20.39%; FrontierSWE v2 ka Mean@5 20 ghante mein 32.90%, single agent 28.20%. Paper spasht kehta hai ki yeh results preliminary hain aur har taraf ke sabse majboot observed configuration ki tulna hai.

Seemaein aur answar na hue prashn

  1. Kisi ek design ka ablation nahi hai. CED, CSA2, hierarchical indexer, FP4 main KV, SWA Bounded Replay, Single-Pass mHC — har ek ke asar ke liye paper ke paas sirf “nagnah”, “marginal”, “lagbhag asar nahi” jaise shabd hain. Akela quantitative comparison poora model (base aur post-trained) vs V4-Flash, V4-Pro hai — jabki V4.1 ka backbone 552B hai, V4-Flash ka 284B, aur data aur post-training bhi alag. “Chhote cache ke saath behtar performance” ka evidence sirf yeh dikhata hai ki dono saath hue, kaaran ka alag nahi.
  2. Ek khaas curve main punar-paida nahi kar paya. Figure 2 ke decode FLOPs BF16 : FP8 : FP4 = 1 : 0.5 : 0.25 se weighted hain, bina yeh bataye ki har hisse ki precision kya hai aur bina kisi breakdown ke; is lekh ka section 4 sirf indexer ki vriddhi ka srot batata hai.
  3. Anuman ki keemat bina test hue boundaries par chhod di gayi hai. Conclusion mein paper khud likhta hai: CSA2 ke selection errors aur SWA Bounded Replay ka approximate reconstruction bina test hue boundary cases mein capability gira sakte hain, aur lambi avadhi ke sparse retrieval aur cache-resumption boundaries ko aage stress-test karne ki jagah batata hai.
  4. Evaluation ka daayra aur saturation. Comparison models aur evaluation harnesses paper ke apne chune hue hain; paper khud chetata hai ki standard benchmarks saturation ke paas hain aur “scores ke kareeb hona” complex, kathin reasoning aur edge cases par frontier se barabari ka saboot nahi. Introduction ka “95% se zyada real tasks kar sakta hai” wala dawa bina kisi bataye protocol ke hai. Paper evaluation ke dauran gaming behaviour bhi dikhaata hai (jaise CyberGym mein vulnerability dhoondhne ke liye Ubuntu ke core packages decompile karna); benchmark scores ko is vyavhaar ke saath padha jana chahiye.
  5. Reproduction ki deewar. Paper weights deta hai, par training infrastructure (shadow indexers, pipeline payload extension, micro-batch level shared-state management) aur DSec sandbox sirf design ke roop mein likhe gaye hain — khule hain ya nahi, nahi bataya; bahar se yeh numbers dobara nikalne ke liye kam se kam yeh layer khud banani padegi.

Is paper se sabse badi baat kya leni chahiye

  1. Cache ko multiply hone wale dimensions ki tarah socho. Kisi bhi long-context cost problem par pehle teen factors se poochho ki kahan aur jagah bachi hai: har entry kitni badi, har token kitni entries rakhta hai, kitni paratein apni copy rakhti hain. V4.1 ki apni layer sanrachna mein 29 entries se 2.5 par jaana 11.60 guna bachata hai, FP4 sirf 1.83 — layer dimension mein entry ke andar ke bit-width se bahut zyada jagah hai.
  2. Anuman ko sateekta ke badle lena ho, to boundary tests saath lo. Bounded Replay ne “128 tokens ka approximate replay” lekar persistent cache ka aadha hissa bachaya — engineering mein sauda achha hai, par natija ab cache-hit ki position par depend karta hai. Aisa har anuman apni fail hone ki boundaries ke saath hi jana chahiye; paper khud maanta hai ki testing adhoori hai.
  3. Data aur environments ka leverage. Paper ka dawa hai ki post-training ka saara labh data aur environments se aaya; ise conclusion nahi, hypothesis ki tarah bhi lein, to uska pipeline (task triplets, model se tasks ko difficulty aur correctness par rate karwana, multi-agent se environments banwana aur inspect karwana) tukde-tukde seekhne layak hai.
  4. Efficiency papers mein pehle woh numbers dhoondho jo dobara gine ja sakte hain. Is paper ke 890 bytes config se punarnirmit hote hain; “decode FLOPs sirf 1/4 badhte hain” nahi hote. Dono paper mein utne hi chamkeele hain, par check hone ki kshamata ek nahi.

Aage padhne ke liye

अक्सर पूछे जाने वाले सवाल

DeepSeek-V4.1-Flash ka KV cache 890 bytes per token kaise reh jata hai?
Global KV cache ka size teen factors ka gunakkal hai: har entry kitni badi hai, har token kitni entries rakhta hai, aur kitni paratein apni alag copy rakhti hain. Paper teeno ko ek saath nichorta hai: paraton ke beech sharing (40 mein se sirf 4 paratein global KV ki source hain, isliye har token ausat 2.5 entries rakhta hai, 29 ke bajaye), sequence compression (encoder mein ratio 2, decoder mein nahi), aur FP4 main KV (288 bytes, jabki V4 ke FP8 mein 584 bytes). Public configs aur yeh byte layout se mere paas poore 890 bytes nikalte hain, paper se mel. Counterfactual hisaab dikhata hai ki sharing 11.60 guna bachati hai, jabki FP4 sirf 1.83 guna.
CSA2 ke Full, Reindex aur Reuse modes mein kya antar hai?
Teeno modes mein har apni main query aur sliding-window KV khud nikalti hai; antar sirf global hisse mein hai. Full apna main KV aur indexer K khud banata hai aur naya Top-512 chunta hai. Reindex sabse haal ki Full parat ka main KV aur indexer K dobara istemaal karta hai, par apne indexer Q se punah-score karke naya Top-512 chunta hai. Reuse main KV aur haal ka Top-512 dono reuse karta hai aur koi indexer nahi chalata. 40 paraton mein 4 Full, 4 Reindex, 30 Reuse aur 2 sirf sliding-window hain. Cache sharing aur index reuse alag-alag hain: Reindex chunaav ko parat-dar-parat badalne deta hai, cache phir bhi shared rehta hai.
SWA Bounded Replay kya hai, aur wo kya kurbaan karta hai?
Sliding-window ki nirbharta paraton mein jama hoti hai, isliye L paraton ka sliding-window KV theek se dobara banane ke liye L x n_win tokens replay karne padte hain (yahan 40 x 128 = 5,120). Bounded Replay sirf haal ke n_win = 128 tokens replay karta hai aur window ko replayed hisse tak kaat deta hai, jisse anumit state milti hai; isliye natija cache-hit ki sthiti par depend karta hai aur positions ke beech bit-wise ek nahi. Badle mein sliding-window KV persistent cache mein nahi jata (jahan V4 mein uska lagbhag aadha hissa tha), aur persistent cache V4-Flash ke lagbhag 1/8 par aa jata hai. Paper kehta hai ki jawab ki gunvatta par asar nagnah (negligible) hai, par koi ablation number nahi deta, aur is anuman ko bina test hue boundary cases ke risk ke roop mein likha hai.
FP4 KV cache lagbhag lossless kaise hota hai?
Paper E2M1 format + har 16 channels par ek E4M3 scale use karta hai (NVFP4 ki tarah, par uska second-level global scale chhod kar), post-training mein quantization-aware training lagata hai, aur RoPE ke baad quantize karta hai. Global scale chhodne ki peeche magnitude bound hai: RMSNorm ke baad 512-channel latent vector ki L2 norm adhiktam lagbhag sqrt(512) hai, RoPE norm nahi badalta, isliye kisi channel ka parimap-moolak value lagbhag 22.6 se zyada nahi ho sakta (training mein sabse bada value lagbhag 10 dekha gaya), jabki format 448 x 6 = 2688 tak represent kar sakta hai. Sliding-window KV quantization ke liye zyada sensitive hai aur FP8 mein hi rehta hai. Paper sirf kehta hai ki giraavat bahut chhota hai, ablation table nahi deta.
Reasoning effort b kaise train hota hai?
Training mein b in {1, ..., 100} system prompt mein likha jata hai, har prompt kai b values par sample hota hai, aur rewards sirf usi (prompt, b) subgroup ke andar mean-centered hote hain. Effort levels ke beech vyavhaar ka antar ek length penalty se aata hai, jiska coefficient k(b) = k0 * exp(-(b - b_min)/tau) b ke saath exponentially girta hai. Paper ke Appendix C ka local derivation dikhata hai ki sabse uttam reasoning length b mein lagbhag rakhaik (linear) hai, slope s/tau. Public API ke max, high aur low tiers b = 100, 75 aur 50 ke hain. Paper batata hai ki b ko 25 se 100 karne par aath reasoning benchmarks ka ausat Pass@1 67.1% se 76.3% utha, output tokens lagbhag 2.5 guna hone par.