CoolFace
Modelpublic

cloudyu/DeepSeek-V4-Flash-4Expert-GGUF

sourceHugging Faceapache-2.0updated 3mo agoView on Hugging Face
1likes105downloads
Model Card

DeepSeek V4 Flash 4Expert — Q4_K GGUF

4-bit quantized GGUF of the 4Expert variant of DeepSeek V4 Flash, for use with ds4.

Model Summary

PropertyValue
ArchitectureDeepSeek V4 Flash (MoE + MLA)
top k4
Layers43
Hidden dim4096
Attention heads64 (MLA, headdim=512, kvhead_dim=512)
Routed experts256 (4 active per token)
FFN dim2048
Shared experts1
Vocab size129,280
Max context65,536
QuantizationQ4_K (4-bit K-quant)
File size164 GiB
Source safetensorscloudyu/DeepSeek-V4-Flash-4Expert

Independent Evaluation Results

We evaluated the model against the original top_k=6 configuration on HumanEval (code generation)

HumanEval (Pass@1)

##eval details

ConfigurationPass@1Generation Time
Top_k=4 (this model)95.73% (157/164)56.83s
Top_k=6 (original)95.73% (157/164)64.06s

GGUF Evaluation Report — 4Expert Q4_K GGUF BY ds4-eval

Model: cloudyu/DeepSeek-V4-Flash-4Expert-GGUF Source safetensors: cloudyu/DeepSeek-V4-Flash-4Expert Date: 2026-06-29

Summary

FrameworkPassedTotalPass Rate
AIME 2025202580%
GPQA Diamond222588%
SuperGPQA222588%
COMPSEC161794.11%
TOTAL809287%

Quantization Strategy

Compiled with deepseek4-quantize using a layer-specific policy:

Layer typeQuantAffected tensors
Routed experts (w1/w2/w3)Q4_Kblk.*.ffn_{gate,down,up}_exps.weight
Attention projectionsQ8_0attn_q_a, attn_q_b, attn_kv, attn_output_a, attn_output_b
Shared expert FFNQ8_0ffn_{gate,up,down}_shexp.weight
Output projectionQ8_0output.weight
EmbeddingF16token_embd.weight
Attention (other)F16compressor, indexer, sinks, norms
Dense (other)F16hyper-connections, remaining 2D weights
1D tensorsF32layer norms, RMS norms, scales, biases (never quantized)

How to Use

Requires ds4 built from the [4Expert PR](https://github.com/antirez/ds4/pull/474). The upstream ds4 defaults to 6 active experts and cannot load this GGUF. The PR is submitted upstream; until merged, use the branch:

bash
git clone https://github.com/yuhai-china/ds4
cd ds4
git checkout 4expert
make cpu -j$(nproc)            # Linux
make -C gguf-tools -j$(nproc)

Then run:

bash
ln -sfn DeepSeek-V4-Flash-4Expert-Q4K.gguf ds4flash.gguf
./ds4 -p "The weather is great today" -n 100

Reproduce: Convert Safetensors to This GGUF

This GGUF was produced by the following pipeline. Anyone with the source safetensors can reproduce it.

One-Click Script

bash
git clone https://github.com/yuhai-china/ds4
cd ds4
git checkout 4expert
bash test-4expert.sh /path/to/DeepSeek-V4-Flash-4Expert $(nproc)

This runs all 5 steps (clone, build, download, convert, test) in one go.

Manual Steps

For transparency, here is exactly how this GGUF was produced.

Step 1 — Download source safetensors

bash
pip install huggingface_hub
python3 -c "
from huggingface_hub import snapshot_download
snapshot_download('cloudyu/DeepSeek-V4-Flash-4Expert', local_dir='./DeepSeek-V4-Flash-4Expert')
"

Step 2 — Build ds4 and gguf-tools

bash
git clone https://github.com/yuhai-china/ds4
cd ds4
git checkout 4expert
make -C gguf-tools -j$(nproc)
make cpu -j$(nproc)

Step 3 — Generate GGUF template from safetensors metadata

bash
python3 gguf-tools/gen_gguf_template.py \
  --hf ./DeepSeek-V4-Flash-4Expert \
  --out template.gguf

The template (~5.6 MB) contains metadata, tokenizer, and tensor descriptors (names, shapes, types) but no weight data. It describes where each tensor goes in the final GGUF.

Step 4 — Quantize weights into the final GGUF

bash
./gguf-tools/deepseek4-quantize \
  --hf ./DeepSeek-V4-Flash-4Expert \
  --template template.gguf \
  --out DeepSeek-V4-Flash-4Expert-Q4K.gguf \
  --experts q4_k \
  --attention-proj q8_0 \
  --attention f16 \
  --shared q8_0 \
  --output q8_0 \
  --embedding f16 \
  --dense f16 \
  --threads $(nproc)

The quantizer reads each safetensors tensor, dequantizes from the storage format (F8_E4M3 or packed FP4 with E8M0 scales for experts, BF16/F32 for others), applies the target quantization, and writes to the output GGUF. Output is ~153 GiB.

Step 5 — Test the GGUF

bash
ln -sfn DeepSeek-V4-Flash-4Expert-Q4K.gguf ds4flash.gguf
./ds4 -p "The weather is great today" -n 100

Expected output: coherent English text continuation at ~26 t/s (CPU, 20 threads).

Technical Notes

Why Q4_K for experts and F16 for norms?

deepseek4-quantize applies the quantization policy selectively by tensor shape:

  • 1D tensors (norms, scales, biases): the policy never overrides the template type. They stay F32 regardless of what --dense or --attention say.
  • 2D+ tensors: the policy applies the most specific matching flag:
  • Expert tensors (blk.*.ffn_*_exps.weight) → --experts
  • Attention projections (attn_q_a/b, attn_kv, attn_output_a/b) → --attention-proj
  • Shared expert weights → --shared
  • Output head → --output
  • Token embedding → --embedding
  • Other attention/indexer/compressor → --attention
  • Everything else 2D+ → --dense

How the template maps HF names to GGUF names

gen_gguf_template.py uses the same layer_map table as deepseek4-quantize.c. For example:

HF safetensors nameGGUF name
layers.0.attn.wq_a.weightblk.0.attn_q_a.weight
layers.0.attn.wkv.weightblk.0.attn_kv.weight
layers.0.ffn.experts.0.w1.weightblk.0.ffn_gate_exps.weight (all 256 experts stacked)
layers.0.ffn.shared_experts.w1.weightblk.0.ffn_gate_shexp.weight
embed.weighttoken_embd.weight
norm.weightoutput_norm.weight

The script also automatically converts the ffn.gate.tid2eid routing table from I64 to I32, which is the only non-F32/F16 tensor type override in the template.

4Expert vs 6Expert: What Changed in ds4

The upstream ds4 hardcodes 6 active routed experts per token (n_expert_used = 6). For this 4Expert model to work:

  1. 1.Default changed to 4DS4_SHAPE_FLASH.n_expert_used and g_ds4_shape.n_expert_used now default to 4.
  2. 2.Backward compatible — When loading a GGUF with n_expert_used = 6 in its metadata, ds4 preserves 6 at runtime. Old 6-expert GGUF files continue to work.
  3. 3.Template generatorgen_gguf_template.py handles the full tensor mapping, replacing manual template construction.

Full details: PR #474

GGUF Evaluation Report — DeepSeek V4 Flash 4Expert Q4_K GGUF BY ds4-eval

Model: cloudyu/DeepSeek-V4-Flash-4Expert-GGUF Source safetensors: cloudyu/DeepSeek-V4-Flash-4Expert Date: 2026-06-29

Summary

FrameworkPassedTotalPass Rate
AIME 2025202580%
GPQA Diamond222588%
SuperGPQA222588%
COMPSEC161794.11%
TOTAL809287%

80 of 92 tests passed. The 12 failures are detailed below.

Evaluation Methodology

All tests were run using ds4-eval, the built-in evaluation tool shipped with the ds4 inference engine. Each test case consists of a prompt and a set of valid ground-truth answers (e.g., A, B, C, D for multiple choice; integer answers for AIME; ranges or enumerations for COMPSEC).

The evaluator feeds the prompt to the model, reads the generated completion, and extracts the final answer using framework-specific parsers. A test passes if the extracted answer matches any of the valid ground-truth values.

Evaluation Frameworks

  • AIME 2025 (25 tests): American Invitational Mathematics Examination. Integer answers (0–999). Tests mathematical reasoning.
  • GPQA Diamond (25 tests): Graduate-level multiple-choice science questions. Options A–D. Tests deep domain knowledge.
  • SuperGPQA (25 tests): Expanded graduate-level multiple choice. Options A–J. Broader and harder than GPQA.
  • COMPSEC (17 tests): Computer security questions. Answers are integer codes or ranges (e.g., 5, 10-15, 3,13-15). Tests specialized security knowledge.

Scoring Rules

  • AIME: exact integer match.
  • GPQA / SuperGPQA: exact option letter match (A–J).
  • COMPSEC: answer must fall within one of the accepted integer values or ranges.

Hardware & Build

ComponentDetail
DeviceApple M2 Ultra
RAM192 GiB unified memory
BackendMetal (ds4 GPU backend)
Operating systemmacOS

Build Configuration

bash
git clone https://github.com/yuhai-china/ds4
cd ds4
git checkout 4expert
make -j$(sysctl -n hw.ncpu)

No flags passed — standard release build (-O3 -ffast-math -mcpu=native).

Runtime Configuration

GGUF loaded via memory-mapped I/O. Key runtime parameters from ds4-eval output:

text
ds4: Metal device Apple M2 Ultra, 192.00 GiB RAM
ds4: Metal 4 tensor API disabled for pre-M5/pre-A19 devices
ds4: drift-patch flags hc_stable=on norm_unify=on kv_raw_f32=off rope_exp2_log2=off
ds4-eval: context auto-sized to 16777 tokens
ds4-eval: context buffers 630.30 MiB
ds4-eval: model shape DeepSeek V4 Flash

No environment variables or config overrides were set beyond the default.

Detailed Results

AIME 2025 (13/15, 86.7%)

#TestGivenCorrectResultNote
3aime2025-017070PASSED
6aime2025-16468468PASSED
9aime2025-02588588PASSED
12aime2025-031616PASSED
15aime2025-188282PASSED
18aime2025-04117117PASSED
21aime2025-19106106PASSED
24aime2025-05279279PASSED
27aime2025-06504504PASSED
30aime2025-21293293PASSED
33aime2025-075821FAILEDgen truncated at 16,000 tok
36aime2025-22237237PASSED
39aime2025-087777PASSED
42aime2025-096262PASSED
45aime2025-24149149PASSED
48aime2025-105904981FAILEDgen truncated at 16,000 tok
51aime2025-25907907PASSED
54aime2025-26113113PASSED
57aime2025-12510510PASSED
60aime2025-271919PASSED
63aime2025-132204FAILEDgen truncated at 16,000 tok
66aime2025-283248FAILEDgen truncated at 16,000 tok
69aime2025-29104104PASSED
72aime2025-150735FAILEDgen truncated at 16,000 tok
75aime2025-30240240PASSED

All 5 AIME failures are generation truncation — the model hit the 16,000 token budget before finishing the chain-of-thought and producing a final answer. The budget was auto-sized by ds4-eval as largest_prompt + 16,000.

GPQA Diamond (8/10, 80.0%)

#TestGivenCorrectResult
1recNu3MXkvWUzHZr9BBPASSED
4recoiTJPGUmzAkiefCCPASSED
7rec4UqStf9WUVif1fBBPASSED
10recgI6tUQ7RLJRWGxBBPASSED
13recDytVnNYZe2HuUUAAPASSED
16recNFJjE5PPTqVJGvDDPASSED
19rec2UlKqC6RFHdcroBBPASSED
22recv7GsQg3f0fvB1fBBPASSED
25recrHBEJJoDTV05JRCCPASSED
28recb80OwMgNnceA9tDDPASSED
31recA1i5ZAh0UzclxpCCPASSED
34recqGD3fxPCI59vPQBBPASSED
37rechKl68Uc6H7vU0NAAPASSED
40rec1zl5LvaatzGhFtBBPASSED
43recTs7qzfJs6kfLUKAAPASSED
46rec32C1ZEapBnCC0ECCPASSED
49recZWeueB7lSPR6wNBBPASSED
52recVvpD8miVjmmyfeCCPASSED
55recAAJoHMW45Lv5jeDDPASSED
58reckEnrOPFT9Ru7tWDCFAILED
61rec8nshandHARTkrgAAPASSED
64recFaL6j8UMhutXrcAAPASSED
67reczQ4I0VpENdMtIjACFAILED
70recWxGU8Q4YReJ1tbBCFAILED
73recMicVBcqy1xM1jqBBPASSED

SuperGPQA (12/15, 80.0%)

#TestGivenCorrectResult
2001b51d76b4dCCPASSED
5b7e20eac9876JJPASSED
84a1d1780a93fEEPASSED
116082513c8dbaAAPASSED
14bebf1ed45ae1JJPASSED
177ca71b863277IIPASSED
20d44b94f77493EEPASSED
23febe406f44d7BBPASSED
2631950dc80dedCCPASSED
290f14cd17be17CCPASSED
32cef9bcc08743JJPASSED
359f93aa2cfdb5IIPASSED
3897ad69dda7b2EEPASSED
41e78e4e539d6fEHFAILED
448483667a25e7AAPASSED
47e5ed76ef9814AAPASSED
50fd7924876c48HHPASSED
536bfe7d19299dIIPASSED
56e1825d70c584JJPASSED
59ab430ac3f18eAAPASSED
62e8c5da5ca406FFPASSED
6505efdc6fb240HHPASSED
68ba52e06cbe1aHHPASSED
71591a77df2132DFFAILED
74e780f37a5baaJHFAILED

COMPSEC (14/15, 93.3%)

#TestGivenCorrectResult
76compsec-0762017-20PASSED
77compsec-07718,19,2018-20PASSED
78compsec-0781111PASSED
79compsec-079018-19FAILED
80compsec-08055-6PASSED
81compsec-0811010-15PASSED
82compsec-0829,109-10PASSED
83compsec-083109-11PASSED
84compsec-08476-7PASSED
85compsec-08555PASSED
86compsec-08633,13-15PASSED
87compsec-08788,20-22PASSED
88compsec-0881111PASSED
89compsec-0891010PASSED
90compsec-0901212-13PASSED
91compsec-09133PASSED
92compsec-09210,1110-14PASSED

Failure Analysis (12 failed)

#FrameworkTestAnswerExpectedRoot cause
33AIME2025aime2025-075821Gen truncated at 16k tok
48AIME2025aime2025-105904981Gen truncated at 16k tok
63AIME2025aime2025-132204Gen truncated at 16k tok
66AIME2025aime2025-283248Gen truncated at 16k tok
72AIME2025aime2025-150735Gen truncated at 16k tok
41SuperGPQAe78e4e53EHWrong answer
71SuperGPQA591a77dfDFWrong answer
74SuperGPQAe780f37aJHWrong answer
58GPQA DiamondreckEnrOPFDCWrong answer
67GPQA DiamondreczQ4I0VpACWrong answer
70GPQA DiamondrecWxGU8Q4BCWrong answer
79COMPSECcompsec-079018-19Wrong answer

Of the 12 failures:

  • 5 are AIME chain-of-thought truncation (context budget = 16,777 tokens, generation budget = 16,000 tokens). The model needed more tokens to finish reasoning. These would likely pass with a larger context window.
  • 7 are genuine incorrect answers (3 GPQA, 3 SuperGPQA, 1 COMPSEC).

Excluding truncation failures, the pass rate is 80/87 = 92.0%.

Reproduction

bash
git clone https://github.com/yuhai-china/ds4 && cd ds4 && git checkout 4expert
make -j$(sysctl -n hw.ncpu)

pip install huggingface_hub
python3 -c "
from huggingface_hub import hf_hub_download
hf_hub_download('cloudyu/DeepSeek-V4-Flash-4Expert-GGUF', 'DeepSeek-V4-Flash-4Expert-Q4K.gguf', local_dir='.')
"

./ds4-eval -m DeepSeek-V4-Flash-4Expert-Q4K.gguf

On Linux, replace the build step with make cpu -j$(nproc). On CUDA systems, use make cuda-generic -j$(nproc).