Datasets:
Upload METHOD.md with huggingface_hub
Browse files
METHOD.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Calibration methodology — what we measured
|
| 2 |
+
|
| 3 |
+
Findings from building `nemotron-3.5-lightning`. They are about calibration in general,
|
| 4 |
+
not about one model, and every number here is reproducible with the tools in this repo.
|
| 5 |
+
|
| 6 |
+
## A recipe is per-model, and the chat markup is the reason
|
| 7 |
+
|
| 8 |
+
The pool is model-agnostic: `pool/**/**.jsonl` holds dialogues as structured records, not
|
| 9 |
+
as text. Rendering into a model's chat template happens at build time, so one pool serves
|
| 10 |
+
every target.
|
| 11 |
+
|
| 12 |
+
This matters more than it sounds. Reusing a build made for another model puts that model's
|
| 13 |
+
special tokens in the corpus. For `muse-glimmer-30b` those are `<|start|>`, `<|message|>`,
|
| 14 |
+
`<|eot|>`; for `nemotron-3.5-lightning` they are `<|im_start|>`, `<|im_end|>`, `<think>`,
|
| 15 |
+
`<tool_call>`. **The two sets do not overlap at all.** Run `llama-imatrix --parse-special`
|
| 16 |
+
with the wrong build and the markup is tokenized as literal punctuation, while the tokens
|
| 17 |
+
the model will really see appear zero times — for these recipes that is the agentic plus
|
| 18 |
+
reasoning slices, about 40% of the corpus, calibrating nothing.
|
| 19 |
+
|
| 20 |
+
It also shows up in convergence. Same tool, same model, same chunk budget:
|
| 21 |
+
|
| 22 |
+
| corpus | step 1504 → 2000 | tensors still moving |
|
| 23 |
+
|---|---:|---:|
|
| 24 |
+
| rendered in another model's markup | mean cos 0.9928 | 22 |
|
| 25 |
+
| rendered in the target's own markup | mean cos 0.9985 | 10 |
|
| 26 |
+
|
| 27 |
+
Correct markup converges about twice as cleanly, because the wrong tokens were injecting
|
| 28 |
+
noise into the estimate.
|
| 29 |
+
|
| 30 |
+
Add a model with a recipe plus a renderer module; `chat.format` selects it. The vocabulary
|
| 31 |
+
sweep is per-tokenizer and auto-selected by recipe name, so adding a model never requires
|
| 32 |
+
editing recipes that already exist.
|
| 33 |
+
|
| 34 |
+
## Content matters ~100× more than volume
|
| 35 |
+
|
| 36 |
+
Cosine similarity between imatrix files, per tensor:
|
| 37 |
+
|
| 38 |
+
| comparison | mean cos |
|
| 39 |
+
|---|---:|
|
| 40 |
+
| same corpus, 823 vs 3000 chunks (3.6× the data) | 0.9819 |
|
| 41 |
+
| different corpora, both at 823 chunks | 0.8553 |
|
| 42 |
+
|
| 43 |
+
Tripling the data moves the importance vector by 0.018. Changing what is *in* the corpus
|
| 44 |
+
moves it by 0.145. Beyond the saturation point, more of the same text is close to free of
|
| 45 |
+
effect; a different mix is not.
|
| 46 |
+
|
| 47 |
+
The two corpora also do not converge toward each other as data grows (0.855 → 0.860 from
|
| 48 |
+
823 to 3000 chunks), so the difference is systematic, not sampling noise.
|
| 49 |
+
|
| 50 |
+
## When to stop: a criterion, not a feeling
|
| 51 |
+
|
| 52 |
+
The imatrix estimates a mean, and means converge. The question "have I collected enough"
|
| 53 |
+
has a definite answer.
|
| 54 |
+
|
| 55 |
+
**Necessary, cheap, no model needed.** Build at N and 2N chunks, take the per-tensor cosine
|
| 56 |
+
between them. Done when no tensor is still moving. `tools/converge.py` does this against
|
| 57 |
+
`--save-frequency` checkpoints, so one run produces the whole curve for free.
|
| 58 |
+
|
| 59 |
+
For `nemotron-3.5-lightning` that point is ~8,500 chunks (4.3M tokens): past it, zero of
|
| 60 |
+
186 tensors change measurably, min cosine 0.9963.
|
| 61 |
+
|
| 62 |
+
**Sufficient, expensive, final.** Quantize the same recipe twice, with the imatrix at N and
|
| 63 |
+
at 2N, and measure KL divergence of both against the unquantized model on held-out text.
|
| 64 |
+
Done when the difference between them is below the reported KLD error — at that point more
|
| 65 |
+
data provably cannot change the product.
|
| 66 |
+
|
| 67 |
+
Note what this criterion does *not* answer: whether the corpus has the right content. That
|
| 68 |
+
question is only well-posed once you fix the evaluation set, because "importance" is defined
|
| 69 |
+
relative to the text the model will actually see. A corpus tuned for agentic work should win
|
| 70 |
+
on agentic held-out and may lose on generic prose — that is the intended outcome, not a bug.
|
| 71 |
+
This is why `eval/` carries three independent sets rather than one.
|
| 72 |
+
|
| 73 |
+
## `% Active` is not a quality metric
|
| 74 |
+
|
| 75 |
+
`llama-imatrix --show-statistics` reports a `% Active` column. It is the fraction of columns
|
| 76 |
+
whose mean squared activation exceeds a hard threshold of `1e-5`
|
| 77 |
+
(`tools/imatrix/imatrix.cpp`, `compute_statistics`). It measures activation magnitude, not
|
| 78 |
+
calibration coverage.
|
| 79 |
+
|
| 80 |
+
Early layers score low on it because their activations are genuinely small — layer 1's
|
| 81 |
+
`ffn_down_shexp` has Σ(Act²) = 0.13. No corpus raises that; it is a property of the model.
|
| 82 |
+
Chasing the number optimizes for nothing.
|
| 83 |
+
|
| 84 |
+
Two checks that do mean something:
|
| 85 |
+
|
| 86 |
+
- **Dead experts** — the `.counts` array in the imatrix says how many times each expert was
|
| 87 |
+
routed to. `counts[i] == 0` is a genuine hole. Measured here: 0 dead of 5,888
|
| 88 |
+
(46 expert tensors × 128) at every corpus size tested, including 823 chunks. For this
|
| 89 |
+
model, expert coverage is not what a larger corpus buys.
|
| 90 |
+
- **Per-tensor cosine between imatrix files** — the convergence criterion above.
|
| 91 |
+
|
| 92 |
+
The per-layer Σ(Act²) curve is a model property, not a corpus property: two corpora with
|
| 93 |
+
cosine 0.855 between their imatrices produce per-layer curves within 8% of each other
|
| 94 |
+
(median 2.6%). Useful as a sanity check for a broken build, useless as a quality claim.
|
| 95 |
+
|
| 96 |
+
## Practical notes
|
| 97 |
+
|
| 98 |
+
- `llama-imatrix` defaults to `parse_special = false`. Without `--parse-special` all chat
|
| 99 |
+
markup is literal text.
|
| 100 |
+
- `-b 8192` instead of the default 512: 1h22m instead of 2h12m for 9.3k chunks on 2×RTX 5090.
|
| 101 |
+
It plateaus there; `-b 16384` saves another minute.
|
| 102 |
+
- MTP / NextN blocks are never executed in a normal forward pass, so they collect no imatrix
|
| 103 |
+
data at any corpus size. Pin them explicitly at quantize time.
|
| 104 |
+
- `max_doc_fraction` is not optional. Uncapped, one amalgamated header took 59.8% of a slice
|
| 105 |
+
— the imatrix then describes that file rather than that category.
|