calib-corpora / README.md
worthant's picture
Rebuild calibration corpus for DeepSeek-V4-Flash-0731 imatrix
bf3d2af verified
|
Raw
History Blame Contribute Delete
22.3 kB
metadata
license: other
language:
  - en
  - zh
  - ru
  - ja
  - ar
  - multilingual
tags:
  - imatrix
  - quantization
  - calibration
  - gguf
  - deepseek-v4
  - three.js
  - webgl
task_categories:
  - text-generation

calib-corpora — imatrix calibration corpus for DeepSeek-V4-Flash-0731

Calibration text for building the importance matrix (imatrix) behind the dynamic GGUF quant line of deepseek-ai/DeepSeek-V4-Flash-0731.

An imatrix is activation statistics collected by running the model over a corpus. The corpus decides which weights the model treats as important, and therefore which weights get more bits. This corpus is deliberately not general web text — it is weighted toward 3D/graphics code generation and agentic tool-calling, because that is what these quants are for.

Why this composition

Three properties of this model drive the design, all confirmed against its config.json:

property value consequence for calibration
n_routed_experts / num_experts_per_tok 256 / 6 Any single expert sees ~2.3% of tokens. A dense-model-sized corpus gives most experts too few samples to be meaningful, so the budget has to be an order of magnitude larger.
num_hash_layers 3 In the first three MoE layers the expert is chosen by a fixed hash of the token id, not by a learned gate. Coverage there depends on vocabulary breadth, not on volume — an unseen token id means a never-activated expert, no matter how much text you feed it.
compress_ratios alternating 4/128 over 43 layers The CSA/HCA compression path is barely exercised by short chunks, so a real long-document slice is required rather than concatenated short ones.

The vocabulary is the binding constraint. It has 129,280 embedding rows, and by script the base vocabulary is 56.1% Latin, 27.6% CJK, 4.1% Cyrillic, 2.4% Arabic, 1.0% Thai, 0.9% Hangul, 0.7% Hebrew, 0.5% Greek, 0.4% Hiragana, 0.2% Devanagari. Covering every Latin token in the vocabulary would still only reach 55.5% of the embedding table, so a 60% coverage target is unreachable from English source code alone. That is why there is a 30-language Wikipedia slice and an explicit vocabulary sweep.

Files

file documents tokens purpose
calib_train.txt 1,087 1,868,626 fed to llama-imatrix
calib_heldout.txt 104 141,800 same distribution, not used for the imatrix — for measuring generalisation
eval_neutral.txt 66 189,407 disjoint neutral text and code, no overlap with calibration

Each .txt is flat UTF-8 with documents separated by a blank line, sharded at 500 MB (the corpus fits in one shard per split). Alongside each is a *.manifest.jsonl giving one record per document — id, domain, source, license, path, language, token count, character count — in the same order the documents appear in the .txt. The manifest exists because the flat format cannot express document boundaries unambiguously: many documents legitimately contain blank lines of their own.

legacy/ holds the previous revision of this dataset verbatim. Its content was re-split, deduplicated against the new material and carried forward into the build rather than discarded.

Composition

Shares are of tokens, not documents, over calib_train + calib_heldout (2,010,426 tokens).

domain target actual documents tokens what it is
graphics 35% 31.4% 448 631,310 three.js scenes/materials/loaders/post-processing, WebGL & WebGPU, GLSL & WGSL shaders, animation timelines, procedural generation, 3D maths
code 15% 13.4% 243 270,098 whole real source files — TypeScript, JavaScript, Python, Rust, C++ — plus configs, tests and build scripts
agentic 15% 13.4% 63 270,012 multi-turn tool-calling traces in the model's own DSML chat format: read/edit files, run commands, read output, recover from a failure
longctx 10% 13.4% 18 268,568 documents of 8k tokens and up (large real files, plus same-directory module bundles built to 8k-16k) to exercise the CSA/HCA compression path
vocab_sweep 9.0% 76 180,582 synthetic wordlists that carry the tail of the vocabulary; exists purely to cover the hash-routed layers
general 10% 9.0% 36 180,045 multilingual Wikipedia across 30 languages, plus markdown/tables/unicode from the previous revision
reasoning 10% 5.9% 189 117,682 step-by-step worked problems with reasoning kept inside <think> blocks: 3D maths, numerics, algorithms, graphics debugging
structured 5% 4.6% 118 92,129 JSON, YAML, TOML and SQL from the repositories, real git log -p diff patches, and the most regex-dense real sources

Deviations from target are reported, not corrected. Notes on the ones that matter:

  • longctx is defined by length, not by topic: any document of 8k tokens or more is counted here whatever its subject. Most of it is graphics code, so the effective graphics share is higher than the graphics row alone suggests. The origin breakdown is in the manifest under content_domain.
  • vocab_sweep is over and above the seven requested domains. It is synthetic and is kept as its own domain so it can be filtered out via the manifest by anyone who wants to A/B an imatrix without it.

Sources and licences

source licence documents tokens share
synthetic/vocab-sweep CC0-1.0 (generated from tokenizer vocabulary) 76 180,582 9.0%
fmt MIT 43 133,281 6.6%
three.js MIT 67 132,759 6.6%
webgl-fundamentals BSD-3-Clause 61 123,355 6.1%
pixijs MIT 68 99,406 4.9%
gl-matrix MIT 39 93,756 4.7%
ripgrep MIT OR Unlicense 41 86,938 4.3%
drei MIT 64 79,436 4.0%
json-cpp MIT 43 71,097 3.5%
react-three-fiber MIT 66 69,393 3.5%
flask BSD-3-Clause 41 60,905 3.0%
tween.js MIT 51 59,526 3.0%
webgl-noise MIT 22 58,134 2.9%
webgpu-samples BSD-3-Clause 61 57,655 2.9%
requests Apache-2.0 40 40,938 2.0%
serde MIT OR Apache-2.0 37 37,921 1.9%
synthetic/agentic:webgl-fundamentals see embedded repo (tool results are verbatim repo content) 6 32,919 1.6%
synthetic/agentic:flask see embedded repo (tool results are verbatim repo content) 6 31,883 1.6%
synthetic/agentic:ripgrep see embedded repo (tool results are verbatim repo content) 6 31,681 1.6%
synthetic/agentic:pixijs see embedded repo (tool results are verbatim repo content) 6 27,468 1.4%
glTF-Sample-Viewer Apache-2.0 11 26,894 1.3%
vite MIT 42 25,248 1.3%
synthetic/agentic:json-cpp see embedded repo (tool results are verbatim repo content) 5 24,818 1.2%
synthetic/agentic:requests see embedded repo (tool results are verbatim repo content) 5 22,881 1.1%
synthetic/agentic:drei see embedded repo (tool results are verbatim repo content) 6 22,271 1.1%
wikimedia/wikipedia:20231101.el CC-BY-SA-4.0 2 21,861 1.1%
synthetic/agentic:three.js see embedded repo (tool results are verbatim repo content) 6 21,359 1.1%
wikimedia/wikipedia:20231101.uk CC-BY-SA-4.0 2 20,333 1.0%
synthetic/agentic:webgpu-samples see embedded repo (tool results are verbatim repo content) 6 18,563 0.9%
synthetic/agentic:react-three-fiber see embedded repo (tool results are verbatim repo content) 6 18,458 0.9%
synthetic/agentic:vite see embedded repo (tool results are verbatim repo content) 5 17,711 0.9%
wikimedia/wikipedia:20231101.my CC-BY-SA-4.0 1 16,783 0.8%
wikimedia/wikipedia:20231101.hi CC-BY-SA-4.0 1 14,126 0.7%
synthetic/reasoning:perlin-noise CC0-1.0 (generated) 15 11,671 0.6%
synthetic/reasoning:bezier-decasteljau CC0-1.0 (generated) 15 10,664 0.5%
wikimedia/wikipedia:20231101.fa CC-BY-SA-4.0 1 9,997 0.5%
synthetic/reasoning:cubic-bezier-easing CC0-1.0 (generated) 15 9,960 0.5%
synthetic/reasoning:quaternion-product CC0-1.0 (generated) 15 9,861 0.5%
synthetic/reasoning:moller-trumbore CC0-1.0 (generated) 18 9,215 0.5%
wikimedia/wikipedia:20231101.ar CC-BY-SA-4.0 1 9,073 0.5%
synthetic/reasoning:normal-matrix CC0-1.0 (generated) 12 8,417 0.4%
synthetic/reasoning:catmull-rom CC0-1.0 (generated) 11 8,342 0.4%
wikimedia/wikipedia:20231101.bn CC-BY-SA-4.0 1 8,067 0.4%
synthetic/reasoning:quaternion-slerp CC0-1.0 (generated) 15 7,872 0.4%
synthetic/reasoning:srgb-linear CC0-1.0 (generated) 12 7,396 0.4%
wikimedia/wikipedia:20231101.ta CC-BY-SA-4.0 2 7,363 0.4%
synthetic/reasoning:rodrigues-rotation CC0-1.0 (generated) 12 7,321 0.4%
synthetic/reasoning:look-at-basis CC0-1.0 (generated) 12 7,042 0.4%
wikimedia/wikipedia:20231101.fr CC-BY-SA-4.0 1 6,784 0.3%
wikimedia/wikipedia:20231101.th CC-BY-SA-4.0 2 6,242 0.3%
synthetic/reasoning:perspective-projection CC0-1.0 (generated) 11 6,171 0.3%
wikimedia/wikipedia:20231101.es CC-BY-SA-4.0 1 5,974 0.3%
wikimedia/wikipedia:20231101.nl CC-BY-SA-4.0 1 5,970 0.3%
wikimedia/wikipedia:20231101.id CC-BY-SA-4.0 1 5,649 0.3%
wikimedia/wikipedia:20231101.am CC-BY-SA-4.0 1 5,621 0.3%
AtomicChat/calib-corpora@previous CC-BY-SA-4.0 (StackOverflow-derived) / mixed 31 5,600 0.3%
synthetic/reasoning:fresnel-schlick CC0-1.0 (generated) 10 4,962 0.2%
wikimedia/wikipedia:20231101.en CC-BY-SA-4.0 1 4,735 0.2%
wikimedia/wikipedia:20231101.vi CC-BY-SA-4.0 1 4,468 0.2%
wikimedia/wikipedia:20231101.cs CC-BY-SA-4.0 1 4,467 0.2%
wikimedia/wikipedia:20231101.pt CC-BY-SA-4.0 1 3,217 0.2%
wikimedia/wikipedia:20231101.he CC-BY-SA-4.0 1 3,099 0.2%
wikimedia/wikipedia:20231101.ja CC-BY-SA-4.0 1 3,089 0.2%
wikimedia/wikipedia:20231101.tr CC-BY-SA-4.0 2 2,885 0.1%
wikimedia/wikipedia:20231101.hy CC-BY-SA-4.0 1 2,793 0.1%
synthetic/reasoning:instancing-vs-merging CC0-1.0 (generated) 3 1,865 0.1%
wikimedia/wikipedia:20231101.ko CC-BY-SA-4.0 1 1,739 0.1%
synthetic/reasoning:debug-zfighting CC0-1.0 (generated) 2 1,483 0.1%
wikimedia/wikipedia:20231101.pl CC-BY-SA-4.0 1 1,269 0.1%
synthetic/reasoning:ray-sphere CC0-1.0 (generated) 4 1,127 0.1%
synthetic/reasoning:transparency-sorting CC0-1.0 (generated) 2 1,122 0.1%
wikimedia/wikipedia:20231101.de CC-BY-SA-4.0 1 1,073 0.1%
synthetic/reasoning:debug-shader-black CC0-1.0 (generated) 1 839 0.0%
wikimedia/wikipedia:20231101.ka CC-BY-SA-4.0 1 831 0.0%
wikimedia/wikipedia:20231101.ru CC-BY-SA-4.0 1 799 0.0%
synthetic/reasoning:bvh-complexity CC0-1.0 (generated) 1 678 0.0%
synthetic/reasoning:float32-world-precision CC0-1.0 (generated) 1 591 0.0%
wikimedia/wikipedia:20231101.sv CC-BY-SA-4.0 1 579 0.0%
synthetic/reasoning:gpu-resource-disposal CC0-1.0 (generated) 1 565 0.0%
wikimedia/wikipedia:20231101.zh CC-BY-SA-4.0 1 565 0.0%
synthetic/reasoning:raycaster-stale-matrix CC0-1.0 (generated) 1 518 0.0%
wikimedia/wikipedia:20231101.it CC-BY-SA-4.0 1 457 0.0%

Every repository was shallow-cloned and had its LICENSE file read before use. patriciogonzalezvivo/thebookofshaders was cloned, inspected and dropped: its licence is all-rights-reserved ("You cannot host, display, distribute or share this Work in any form"), so none of it appears here despite being an obvious fit for the domain.

Synthetic slices (synthetic/agentic:*, synthetic/reasoning:*, synthetic/vocab-sweep) are generated by the build scripts in pipeline/. The agentic traces embed verbatim file content from the listed repositories as tool results, so they inherit those repositories' licences; the surrounding dialogue is generated. See Synthetic slices.

Tokenizer

  • Model: deepseek-ai/DeepSeek-V4-Flash-0731
  • Revision: 9e165c30e2704aec5d9d593cce3eebd58bbef1cb
  • vocab_size: 129,280 (from config.json; this is the denominator for all coverage numbers below — it is the size of the embedding table, and therefore the domain the layer-0-2 hash router indexes into)

Counting is done with special tokens parsed, not escaped — the equivalent of llama-imatrix --parse-special. <|begin▁of▁sentence|> becomes id 0 rather than a run of literal characters. This matters for the agentic and reasoning slices, which are full of them.

The model ships no chat_template. tokenizer_config.json has no such field and there is no chat_template.jinja in the repo, so apply_chat_template() does not work. The authoritative prompt format is the reference implementation at encoding/encoding_dsv4.py in the model repo, and this build imports it directly rather than reimplementing it. Its own test suite (encoding/test_encoding_dsv4.py, 4 cases) passes against the pinned revision, and all chat-formatted documents here are produced by encode_messages(...) from that file.

Deduplication

  • Exact: SHA-256 over the document with trailing intra-line whitespace normalised. 59 documents removed.
  • Near: MinHash + LSH banding. 121 permutations, 11 bands × 11 rows, shingles of 5 whitespace-delimited tokens. Jaccard threshold 0.8 — the banding is chosen so the LSH S-curve is centred there ((1/11)^(1/11) ≈ 0.80). Longest document in each cluster is kept. 565 documents removed.
  • Combined drop rate: 5.09% of 12,262 candidate documents.

Two structural steps prevent duplication that document-level dedup cannot see:

  • three.js and webgl-fundamentals ship thousands of example pages sharing an identical ~600-byte HTML head. Bodies genuinely differ, so MinHash does not flag them. For most example pages only the <script type="module"> body is kept; a deterministic 1-in-7 sample keeps the whole page so the scaffold stays represented.
  • Files used as tool results in agentic traces come from a reserved partition (sha1(path+repo) % 10 == 7) that is excluded from the code and graphics slices, so no file content is counted in two domains.

Splits

Split is by document, never by chunk, so no file has pieces on both sides.

  • calib_train / calib_heldout: key is sha1("split:" + document_id), heldout when int(key, 16) % 10 == 0. Deterministic and stable across rebuilds. Target 90/10; actual 92.9% / 7.1% by tokens (the split is by document count, so the token split drifts slightly).
  • eval_neutral is not a random slice of the same pool. It is drawn from sources held apart from calibration entirely: four repositories never used above (click, lodash, rust-log, Catch2), plus Wikipedia articles routed to eval by sha1("wiki:"+article_id) before any calibration sampling. Documents already selected for calibration are additionally filtered out by id.

Measured metrics

Totals and vocabulary coverage

Coverage is the share of the 129,280-row embedding table observed at least N times. This is the direct proxy for hash-routed expert coverage in layers 0-2.

split documents tokens ids seen ≥1 ≥10 ≥100
calib_train 1,087 1,868,626 112,574 (87.1%) 12,522 (9.7%) 2,407 (1.9%)
calib_heldout 104 141,800 23,139 (17.9%) 1,896 (1.5%) 155 (0.1%)
eval_neutral 66 189,407 21,748 (16.8%) 3,039 (2.4%) 261 (0.2%)

Document length in tokens

split p50 p90 p99
calib_train 708 4,335 12,251
calib_heldout 689 2,523 7,959
eval_neutral 966 6,830 17,503

Acceptance criteria

criterion result value
≥ 1,000,000 tokens in calib_train pass 1,868,626
≥ 60% of vocabulary seen at least once pass 87.1%
p99 document length ≥ 8,000 tokens pass 12,251

Per-domain tables, the full top-50 token frequency list and the raw numbers behind all of the above are in metrics.txt and metrics.json.

Synthetic slices

Three slices are generated rather than harvested, because no public corpus exists in this model's prompt format. What is real and what is not:

Agentic traces (pipeline/agentic.py)

  • Real: every read_file, grep and list_dir result is computed from the actual cloned repository at build time — verbatim file bytes, real regex matches with real line numbers, real directory listings. edit_file anchors are exact unique substrings of the real file, so the edits would genuinely apply.
  • Generated: run_command outputs (vitest, pytest, cargo, cmake, eslint) are written to match each tool's real output format; the dialogue and reasoning blocks are generated.
  • Every trace is multi-step and contains a failure followed by a recovery, since that is the shape of real agent work.

Reasoning traces (pipeline/reasoning.py, pipeline/reasoning_extra.py)

  • 22 topic generators across 3D maths, numerics, shading and graphics debugging. Every numeric result is computed with numpy/math at build time, so the arithmetic inside the <think> blocks is correct by construction rather than written by hand.

Vocabulary sweep (pipeline/vocab.py)

  • Runs after the natural slices are measured, takes the set of ids still unseen, and emits compact wordlists containing them. Each emitted document is re-tokenized and verified: an id only counts once it has actually been observed in tokenizer output, because BPE re-merges adjacent pieces and naive concatenation does not reproduce the tokens you started from.
  • This is the honest trade in this dataset. It buys hash-layer coverage that natural text cannot reach at this budget, at the cost of a block of text that is off-distribution for the learned routers in layers 3-42. It is a single filterable domain in the manifest for exactly that reason.

Benchmark contamination

Checked explicitly. Every candidate document — 12,330 of them, calibration and eval alike — was scanned against 17 regex families before selection. 1 document matched and was removed.

Families covered: agent-benches, aime, apps-bench, bigbench-canary, codecontests, deepswe, gpqa, gsm8k, humaneval, livecodebench, math-dataset, mbpp, mmlu, multimodal-benches, reasoning-benches, swebench, terminalbench.

This includes all of the sets named as disqualifying — Terminal Bench, SWE-bench, DeepSWE, GPQA, MMLU, HumanEval, AIME — plus GSM8K, MATH, MBPP, LiveCodeBench, CodeContests, APPS, HellaSwag, WinoGrande, TruthfulQA, BIG-Bench (including its canary GUID), BBH, IFEval, MuSR, AGIEval, C-Eval, CMMLU, ARC, LAMBADA, WebArena, OSWorld, AgentBench, τ-bench, SWE-Lancer, Aider polyglot, MMMU, MathVista, MGSM and DocVQA.

Patterns are deliberately narrow so that ordinary code is not flagged — DROP only matches as "DROP benchmark", ARC only as ARC-Challenge/ARC-Easy, and so on. The full pattern list, the hit count and a quoted context window for every single hit are in contamination_report.txt, so the claim is auditable rather than asserted.

Two structural points also reduce exposure: no evaluation dataset was downloaded at any stage of this build, and the reasoning slice is generated from parameterised derivations rather than sourced from any problem set.

Reproducing

# 1. tokenizer + the official prompt-format reference implementation
hf download deepseek-ai/DeepSeek-V4-Flash-0731 \
    --revision 9e165c30e2704aec5d9d593cce3eebd58bbef1cb \
    tokenizer.json tokenizer_config.json config.json \
    encoding/encoding_dsv4.py encoding/README.md \
    --local-dir ./tok

# 2. source repositories (shallow clones, ~1.3 GB)
bash clone.sh

# 3. previous revision of this dataset, carried forward
hf download AtomicChat/calib-corpora --repo-type dataset --local-dir ./existing

# 4. build: collect -> generate -> dedup -> scan -> balance -> sweep -> split -> measure
python pipeline/build.py --out ./out

Requires transformers, tokenizers, datasets, huggingface_hub, numpy. No GPU and no PyTorch — tokenizer-only. The Wikipedia pull is cached to ~/.cache/calib-build/wiki_cache.jsonl after the first run; delete it to force a fresh stream.

The build is deterministic given the same inputs: all sampling, splitting and generation is seeded (seed=20260731) and every hash key is content-derived. The one source of drift between rebuilds is upstream — the repositories are cloned at --depth 1 from a moving HEAD, so a rebuild months later picks up whatever those projects have merged since.

Known limitations

  • Clone pinning. Source repositories are shallow-cloned from HEAD rather than pinned to commit SHAs, so exact byte reproduction of this revision is not possible after upstream moves. The manifests record the exact path of every document, and licence and provenance are fixed regardless.
  • The vocab_sweep trade-off described above: it is off-distribution text bought deliberately for hash-layer coverage.
  • run_command outputs in agentic traces are generated, not captured from real runs. File content in those same traces is real.
  • Reasoning is under target at the measured share rather than the requested 10%; the generators produce genuinely distinct documents and were not padded with near-duplicates to hit the number.
  • Wikipedia is CC-BY-SA-4.0, which is share-alike. The corpus as a whole is therefore mixed-licence, not permissive — see the per-source table. Anything derived from calib_train inherits those terms.