--- license: other language: - en - zh - ru - ja - ar - multilingual tags: - imatrix - quantization - calibration - gguf - agentic - tool-use task_categories: - text-generation --- # calib-corpora A pool of calibration material, the recipes that turn it into a calibration set for one specific model, and the measurement corpora those quants are scored against. This repository is **not a corpus**. Nothing here is meant to be fed to `llama-imatrix` as-is except the files under `builds/`, and each of those was made for one named model and is close to useless for any other. ## Why it is built this way The first version of this repository was a single `calib_train.txt`. It had DeepSeek-V4's chat markup baked into its agentic and reasoning slices and a vocabulary sweep built for DeepSeek's 129,280 embedding rows. Pointed at `meta-models/Muse-Glimmer-30B` it covered 47.56% of that model's 202,048 rows. Rebuilt from the same material under a Muse Glimmer recipe, it covered 97.22%. Two things are bound to a target model and nothing else is: the chat markup and the vocabulary. So those are the only two things a build re-derives. Everything else lives in the pool, model-agnostic, and is shared by every build. ## Layout ``` pool/ raw units, model-agnostic. One JSON object per line, each with licence and provenance. Dialogue is stored as structured `messages`, never as rendered markup. recipes/ one YAML file per target model: shares, budgets, tokenizer, seed builds/ the output of tools/build.py under a recipe, with a manifest eval/ measurement corpora, disjoint from every build by construction tools/ the pipeline archive/ material that has been imported into the pool and is kept only so its origin stays visible ``` `builds/dsv4-flash-0731/` also contains the pipeline that produced it. That code predates the pool and recipe split, held its budgets as Python constants, and is kept as it was. It is history, not an alternative to `tools/`. ## Builds | build | recipe | tokens | notes | | ------------------------ | ------------------------------------- | -----------: | ------------------------------------------------ | | `muse-glimmer-30b` | `recipes/muse-glimmer-30b.yaml` | 4,901,495 | first build under the pool and recipe split | | `nemotron-3.5-lightning` | `recipes/nemotron-3.5-lightning.yaml` | see manifest | hybrid Mamba2, expert rows do not divide by 256 | | `qwen3.8-27b` | `recipes/qwen3.8-27b.yaml` | 4,967,044 | 3,004 documents, 50.87% synthetic | | `dsv4-flash-0731` | `recipes/dsv4-flash-0731.yaml` | 1,868,626 | predates this format, recipe is a reconstruction | Every build carries a `manifest.json` with the recipe hash, the tokenizer hash, the corpus hash, requested against actual shares, per-category token counts, document length percentiles, and the hash of every pool shard that existed when it ran. Read that file rather than this table when the number has to be right. ## Running the imatrix ```bash llama-imatrix -m -BF16.gguf \ -f builds//calib_train.txt \ --parse-special -c 4096 -o imatrix.gguf ``` **`--parse-special` is not optional.** `llama-imatrix` defaults to `parse_special = false`. Without the flag every `<|im_start|>`, `<|start|>`, `` and `` in the agentic and reasoning slices is tokenized as literal punctuation, and the tokens the model actually emits appear zero times. For these recipes that is about 40% of the corpus calibrating nothing, and it fails silently. `calib_longctx.txt` is a separate file and a separate run. Documents in it are unbroken and 16k to 32k tokens, so it exercises the long-range path that a 4096 token window never reaches. ## Measurement corpora `eval/` never intersects a build. Verified pairwise with `tools/crosscheck.py`. | corpus | tokens | chunks @4096 | scored positions | vocab | dup lines | | ------------------------------- | ------: | -----------: | ---------------: | -----: | --------: | | `eval/neutral/eval_neutral.txt` | 353,771 | 86 | 176,128 | 19.43% | **1.37%** | | `eval/code/eval_code_full.txt` | 350,887 | 85 | 174,080 | 15.31% | 31.63% | | `eval/agentic/eval_agentic.txt` | 350,438 | 85 | 174,080 | 5.50% | 44.55% | `llama-perplexity` scores the second half of each context window, so a corpus has to be about twice the size of the measurement wanted out of it. **neutral.** 30 languages, no code. Latin script is 46.5% of letters, then Arabic 7.6%, Armenian 6.3%, Cyrillic 5.4%, Han 5.3%, Greek 4.3%, Hebrew 4.2%, Devanagari 3.7%, Myanmar 3.6%, then Bengali, Thai, Georgian, Tamil, Hangul, Hiragana, Katakana, Ethiopic. This is the default measurement set. **code.** `eval_code.txt` is the file previously called `eval_neutral.txt`, byte-identical so older measurements stay comparable. It was never neutral prose: measured, it is a source-code corpus. `eval_code_ext.txt` extends it from seven repositories that appear nowhere else, and `eval_code_full.txt` is the two concatenated. Measure against the full one. **agentic.** Conversations in a model's own markup, across four reasoning strengths, grounded in four repositories reserved for this purpose. Two things to know before using `eval/agentic`: 1. `llama-perplexity` has no `--parse-special`. Special tokens are scored as their literal characters. That is still a valid comparison between quants of one model, because the text is identical for all of them, but it is not what the model sees at inference. 2. Its duplicate-line share is 44.6%, or 30.3% excluding the chat template's own scaffolding. A conversation that declares tools has to repeat the template's tool-definition block verbatim. There is no way to have native markup and a low duplicate-line ceiling at once. The same applies to code. Only `eval/neutral` reaches 2%, at 1.37%. ## The pool 7,415 units after filtering, in `pool//*.jsonl`. Every line carries `source`, `license`, `path`, `origin` and a `provenance` object. Dialogue is stored as `messages`, not as rendered text. `tools/build.py` applies the target model's chat format at build time. Storing one model's special tokens in the pool is exactly what made the first version of this corpus single-use. `render` says what a unit is: - `text`, used verbatim - `chat`, `messages` are rendered by the renderer the recipe selects - `dsv4`, already rendered in DeepSeek markup. Kept, never built from. 203 such units are preserved for provenance and their conversations were regenerated structurally instead. `pool/_quarantine/` holds everything removed, with the reason on each record. Nothing is deleted. ### Provenance and licences Repository files keep their upstream licence (MIT, Apache-2.0, BSD-3-Clause, BSL-1.0) and record the commit they came from. Wikipedia is CC-BY-SA-4.0. Generated units are CC0-1.0 and live under a `synthetic/` subdirectory, with one caveat: agentic traces quote real repository files verbatim inside tool results, and those excerpts keep their own licence, recorded per unit. `patriciogonzalezvivo/thebookofshaders` is an obvious fit for the graphics slice and is all-rights-reserved. It is not here and must not be added. ### Deduplication and contamination All at 13-word shingles, `tools/dedupe.py`. | check | result | | -------------------------------------------- | ------------------------- | | wikitext-103-raw-v1 (superset of wikitext-2) | 6 documents removed | | pool against eval, any shared 13-gram | 3,672 documents | | pool against eval, distinctive 13-gram | 143 removed, **0 remain** | | exact duplicates within the pool | 379 removed | | near duplicates at J >= 0.8 | 202 removed | | total quarantined | 1,056 of 8,471 (12.5%) | The two eval rows differ by a factor of twenty-five and the difference matters. A 13-gram shared by thousands of documents is an MIT header or an SPDX line, not leaked measurement data. Treating those as contamination removed 43% of the pool on the first run and improved nothing. A gram counts as evidence only when it occurs in at most two pool documents. Both numbers are reported here rather than only the flattering one. No wikitext of any version is in any build. Grepping for the string proves nothing, because wikitext is a curated slice of English Wikipedia and this pool contains English Wikipedia, so the check is shingle overlap against the benchmark text itself. ## Vocabulary coverage Worked example, `muse-glimmer-30b`, against 202,048 embedding rows. | | old flat corpus | this build | | ----------------------- | ---------------: | -------------------: | | seen at least once | 96,099 (47.56%) | **196,430 (97.22%)** | | seen at least 10 times | 14,454 (7.15%) | 24,831 (12.29%) | | seen at least 100 times | 2,097 (1.04%) | 4,968 (2.46%) | | unseen | 105,949 (52.44%) | **5,618 (2.78%)** | The jump is the vocabulary sweep, regenerated for this tokenizer by `tools/vocab_sweep.py`: 200,185 of the 200,220 ids that have any standalone textual form, at 2.09 tokens per id. The remaining 1,828 ids are fragments of multi-byte characters and cannot appear alone in any text at all. That is the real ceiling, 99.08%, not 100%. A sweep is a function of the tokenizer, so there is one file per target under `pool/vocab_sweep/synthetic/.jsonl`, and `tools/build.py` selects the one matching the recipe name and drops every other. A sweep built for another model is not merely useless here, it is noise. ## Two tokenizers, one percent apart `llama-tokenize` and `tokenizer.json` disagree by about 1% on the same file (4,954,537 against 4,901,495 tokens on the muse-glimmer `calib_train.txt`). The disagreement is not spread evenly. It is almost entirely non-Latin text. | slice | `tokenizer.json` | `llama-tokenize` | | | ------------------------------- | ---------------: | ---------------: | ---------: | | multilingual | 34,988 | 37,072 | **+5.96%** | | vocab_sweep | 28,389 | 28,826 | **+1.54%** | | longctx | 356,401 | 356,215 | -0.05% | | code | 16,425 | 16,420 | -0.03% | | agentic | 34,950 | 34,948 | -0.01% | | graphics, reasoning, structured | | | 0.00% | Both sides run the same `llama4` split regex, but llama.cpp implements the Unicode property classes in it with its own tables rather than a regex engine, and on Han, Arabic, Devanagari and similar it splits more finely. Latin-script code and prose agree to within a rounding error. `llama-tokenize` is authoritative, because it is the vocabulary and pre-tokenizer `llama-imatrix` will actually use, and the coverage figures above come from it. The manifest's per-document token counts come from `tokenizer.json`, because a build needs an in-process tokenizer to hit a budget. Treat the manifest as sizing and the coverage report as measurement, and read the multilingual share as about 6% larger in practice than the manifest states. ## A llama.cpp crash worth knowing about `llama-tokenize` and `llama-imatrix` abort on some plain-ASCII input: ``` $ printf '\xF4\x91\x92\x93' > t.txt # sixteen ASCII characters terminate called after throwing an instance of 'std::invalid_argument' what(): invalid codepoint ``` The escape sequence is only described in the source file, not encoded. `F4 91 92 93` would decode to U+111493, past U+10FFFF, and `unicode_cpt_to_utf8` in `src/unicode.cpp` throws instead of substituting U+FFFD. UTF-8 conformance test suites are full of such literals. The first `calib_train.txt` contained one, from `nlohmann/json tests/src/unit-unicode1.cpp`, and it would have killed an imatrix run partway through. `tools/screen.py` finds and quarantines such documents by divide and conquer. It found exactly two. ## Adding a model ```bash # 1. write the recipe. See RECIPE.md for every field. $EDITOR recipes/.yaml # 2. regenerate the vocabulary sweep for this tokenizer python tools/vocab_sweep.py --tokenizer /path/to/tokenizer.json --name # 3. build export FOUNDRY_MODEL_DIR=/path/to/original/weights python tools/build.py --recipe recipes/.yaml # 4. check what came out python tools/coverage.py --gguf .gguf \ --tokenizer /path/to/tokenizer.json builds//calib_train.txt python tools/crosscheck.py builds//calib_*.txt eval/*/*.txt ``` The pool does not change. The recipe name must match the sweep filename exactly, because that is how the build finds it. ## Rebuilding the pool from scratch Order matters. Harvesting excludes the measurement split by `(source, path)`, and the generators draw from the pool, so an agentic trace cannot quote a held-out file. ```bash bash tools/clone.sh # shallow clone the sources python tools/pool_import.py # archive/ flat corpus -> pool python tools/harvest.py --raw --wiki python tools/gen_agentic.py python tools/gen_reasoning.py --scale 48 python tools/gen_structured.py python tools/dedupe.py --wikitext python tools/screen.py --gguf .gguf python tools/build_eval.py --build builds/ ... ``` ## Tools | tool | reads | writes | | ------------------- | ----------------------------- | ---------------------------------------------- | | `clone.sh` | its own registry | shallow clones on disk | | `pool_import.py` | `archive/legacy-flat-corpus/` | `pool/**/legacy-*.jsonl` | | `harvest.py` | cloned repos, Wikipedia | `pool/**/repos.jsonl`, `wikipedia.jsonl` | | `gen_agentic.py` | pool | `pool/agentic/synthetic/` | | `gen_reasoning.py` | pool | `pool/reasoning/synthetic/` | | `gen_structured.py` | pool | `pool/structured/synthetic/` | | `vocab_sweep.py` | a tokenizer | `pool/vocab_sweep/synthetic/.jsonl` | | `dedupe.py` | pool | `pool/_quarantine/`, `pool/dedupe-report.json` | | `screen.py` | pool, a GGUF | `pool/_quarantine/untokenizable.jsonl` | | `purge_overlap.py` | pool, eval | `pool/_quarantine/eval-residue.jsonl` | | `build.py` | a recipe, pool | `builds//` | | `build_eval.py` | pool | `eval/` | | `coverage.py` | a corpus, a GGUF | vocabulary coverage report | | `crosscheck.py` | builds, eval | `eval/crosscheck.json` | | `converge.py` | imatrix checkpoints | per-tensor cosine curve | | `imcompare.py` | two imatrix files | per-tensor cosine | | `poollib.py` | library, not a command | | | `auto_fmt.py` | a model's own chat template | renderer, selected by `format: auto` | `METHOD.md` holds what these tools measured: how much corpus is enough, how much the content matters against the volume, and which of `llama-imatrix`'s reported statistics mean anything.