Skip to content

Commit 44daccf

Browse files
committed
Integrate MiniCPM tokenizer blockers
Move MiniCPM and MiniCPM3 negative tokenizer evidence into the shared blocker registry introduced for PLaMo. Generalize that registry for zero-merge SentencePiece metadata while preserving bounded-header, source divergence, and reproducible oracle closure. Co-authored-by: Copilot App <[email protected]> Copilot-Session: efad223f-3973-40c7-b001-e292e139f0bf Signed-off-by: Justin Chu <[email protected]>
1 parent 34d0b1b commit 44daccf

8 files changed

Lines changed: 400 additions & 417 deletions

‎docs/api/build_from_gguf.md‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,22 +124,15 @@ from mobius.integrations.gguf import materialize_evidenced_gguf_tokenizer
124124
materialize_evidenced_gguf_tokenizer("Qwen3.5-0.8B-Q4_0.gguf", "tokenizer")
125125
```
126126

127-
Each row is independently artifact-scoped. Evidence proves ordered tokens, merges or scores,
128-
token types, special IDs, source pipeline/config assets, representative encodings, embedding
129-
alignment, any non-matchable padding extension, and the final materialized hash. Shared rows
130-
additionally require every exact identifier to select the same implementation and flag overrides
131-
in pinned `llama-vocab.cpp`; the tokenizer matrix links each promoted route to its dispatch line.
132-
This does not claim graph or runtime support.
127+
Each row is independently artifact-scoped and proves ordered tokenizer semantics, source assets, embedding alignment, and the final materialized hash. Shared rows also require identical pinned llama.cpp dispatch. This does not claim graph or runtime support.
133128

134129
### Fail-closed tokenizer evidence
135130

131+
- `minicpm-2b-q2-k-tokenizer-mismatch` — **GGUF/source:** `mzwing/MiniCPM-2B-sft-bf16-GGUF@121e7290609857006939fca0ec64981009b806b9`<br>`MiniCPM-2B-sft-bf16.Q2_K.gguf`<br>1,204,392,288 B<br>`9e87235097895a22894c32a1e211f94b93b798d715cc7d99c8e846637927fd13`<br>`openbmb/MiniCPM-2B-sft-bf16@4ec16344ac13e6ef5010aeecaa533369ac8eb53c`<br>`special_tokens_map.json` 414 B `6fa06efa2785e450051989a6f8fb4416b10149ded485ddd3f127a40734f5cfd0`, `tokenizer.json` 6,202,715 B `42f73d01995bd71c88647b13ac696b36d84d5126d0c7cbaef6f8d872d5c97dff`, `tokenizer.model` 1,994,871 B `c9aafcd7da1f5611dab6be545db74d5552a2ccc9c2a12c72ea7be63aac4a25d7`, `tokenizer_config.json` 1,117 B `9c87efade54e9b26d3374a42f294d266722cbf9e97c748a12183d8317da074c9`<br>`config.json` 1,010 B `41cf26cfdca93f49209a6c0c26c00b281d6408e010ddc8cca9531c825cc17fc4`<br>first 16,777,216 B `ff140dcf42ce544e61a8e3bd23a09edbfb1a573d7df3f266081bcbd06e33ab66`; **closure:** architecture `minicpm`; pre `default`<br>metadata `1a596fac46038c46f2fa273fd8ec10cf0721acd2ed6daf2121cfc0840da9ee3e`<br>tokens 122,753 `154c42653082e70f4a98ed1708e8a71d41494dc1de32fe9316bcb6046b993dbe`; source 122,753 `154c42653082e70f4a98ed1708e8a71d41494dc1de32fe9316bcb6046b993dbe`<br>merges 0 `None`; source `4551998aaa2aa2468fc189317e85b7149a1999f38a9eddde19b523c3fa74e4b8`<br>scores=122753; types `e89c4d81e916e4d1bee6e7d7842463429004c559d9106d7e8af73934e9e4e0eb`<br>added tokens `8d90db0e62037d2ae62d998473452f7d104f8f5a03322d4589fc20d86da97602`; chat `ae9b050c5a5b0295cb09269e67bf832fa08675dd845c7b3ea4c2130bcacc5c26`<br>normalizer `Sequence(Prepend('\u2581'), Replace(' ', '\u2581'))`; pipeline `9cc85610fe636d4f21d99413627f6fcf6960886af506a3c537664ae01b421174`<br>source model tokens=122,753; source merges=171,540; score mismatches=122,752; type mismatches=1,087<br>GGUF chat `ae9b050c5a5b0295cb09269e67bf832fa08675dd845c7b3ea4c2130bcacc5c26` vs source `d9f25394f8be2d8a5fb234670a8596c7a12fa0d21896b5a757d77da8b8686944`; **witness:** fail-closed: all GGUF scores are -1000, GGUF merges are absent, token types and chat whitespace semantics diverge, and pinned llama.cpp disagrees with the official tokenizer on multilingual and whitespace inputs<br>`\u4f60\u597d\uff0c\u4e16\u754c\uff01`: llama.cpp `[29951, 95495, 65, 2925, 67]` vs source `[95320, 23523, 65, 2925, 67]`<br>corpus `dd6d2aa959ab8b74111c704559252bc8ef02aa5ec13f40ef23d0b65e03233413`; llama.cpp oracle `8d9af256337d1a501250f9bbf4c0859a654bddd6`: 444 cases `8959cbd62821def331adc77db30e8b351e8fad221547e74804dc7aecb188df1a`<br>18 mismatches [6, 6, 6] by mode; source oracle `a61293d6ad6fb5637f4ceafe225ac822897482d5ef5333b87f63b0e40611e9c2`
132+
- `minicpm3-4b-q4-k-m-tokenizer-mismatch` — **GGUF/source:** `openbmb/MiniCPM3-4B-GGUF@816dc79b35f92827e0d2d87aacea3567e49661a8`<br>`minicpm3-4b-q4_k_m.gguf`<br>2,469,791,584 B<br>`64913247e927414ecf47fd3e9ea8e3f0c9acae293f583dfa7e24b8872e20fa4c`<br>`openbmb/MiniCPM3-4B@d6b14ddaefdb11c624dd75c3c779549bc90b08cb`<br>`added_tokens.json` 216 B `4760fcbf90bc193f33827ffe02f2e7ba1af1ec43644cc02ac22fdd611f6cca15`, `special_tokens_map.json` 1,632 B `068594063e37662c02b21acf42ebb334ef6a74fb810e68a2368f88f08351de76`, `tokenizer.json` 3,676,758 B `b00802b71a613e3f7df3899fe9643a3ff949736d333a2b892448a974383fe372`, `tokenizer.model` 1,181,204 B `bb74d51116831c3bf65db812c553f94ab0c88dcf97a5bbb37e3504f6d359c530`, `tokenizer_config.json` 10,413 B `25620d5a3f5727bba2fb403624f2c9a7bba55a7d00205829650cd1e3c646aae0`<br>`config.json` 1,929 B `cf1d08cb7c1815c676e685bd6ce94eb8b85a57d53871e6e159ee8c650717d98a`<br>first 16,777,216 B `505ce706e29108bef3579b1b4dc38695fe44923b63f453163175d5024b4ea12e`; **closure:** architecture `minicpm3`; pre `default`<br>metadata `6dc004393b6fd1dd27f81c505cadbd8be953244999f8b6fde281fb68dff94c34`<br>tokens 73,448 `1046ac4e64873087a848a2e033be381d18a35974f1ec0c139326c3073ad6744c`; source 73,448 `1046ac4e64873087a848a2e033be381d18a35974f1ec0c139326c3073ad6744c`<br>merges 0 `None`; source `a6ae9d2ba560703a2f5933b92307f80f9fdebfabc052df1cb5c3542a98441cbc`<br>scores=73448; types `ae14c00dfeff5f86796d58db7e91a7eee8fd44605d2cd3ec9846f56e52540a7e`<br>added tokens `b6fad720564107c65861ede9747fa08a03efba82c42268e963b4883abaf4f6d0`; chat `153280e3ff55d19da1398bdb3914ee2a51b80429bfaedde11d7d216c39db80f3`<br>normalizer `Sequence(Prepend('\u2581'), Replace(' ', '\u2581'))`; pipeline `9cc85610fe636d4f21d99413627f6fcf6960886af506a3c537664ae01b421174`<br>source model tokens=73,440; source merges=104,297; score mismatches=73,439; type mismatches=1,088<br>GGUF chat `153280e3ff55d19da1398bdb3914ee2a51b80429bfaedde11d7d216c39db80f3` vs source `dbd75fe18b14711fa5968600a6f5c974d7d3e63e75fe163ecb99a1e5f94c38c9`; **witness:** fail-closed: all GGUF scores are -1000, GGUF merges are absent, token types diverge, the GGUF drops the official tool-aware chat template, and pinned llama.cpp disagrees with the official tokenizer on multilingual and whitespace inputs<br>`\u4f60\u597d\uff0c\u4e16\u754c\uff01`: llama.cpp `[29951, 59495, 65, 2925, 67]` vs source `[59320, 23523, 65, 2925, 67]`<br>corpus `dd6d2aa959ab8b74111c704559252bc8ef02aa5ec13f40ef23d0b65e03233413`; llama.cpp oracle `8d9af256337d1a501250f9bbf4c0859a654bddd6`: 444 cases `d55374a7956f5379448b802ac23888c91f22aeb5fb6814f5b73efe74058fd475`<br>9 mismatches [3, 3, 3] by mode; source oracle `d6beee40e9257575b1333e43f67709920eda0cd6249fa74cfbd8a5eaa978b4af`
136133
- `plm-1.8b-instruct-q4-k-m-tokenizer-blocker` — **GGUF/source:** `PLM-Team/PLM-1.8B-Instruct-gguf@7bec6546983bcf0d99526c943580bd49e2237445`<br>`PLM-1.8B-Instruct-Q4_K_M.gguf`<br>1,182,708,992 B<br>`b38570ee56ebec82a1e9ef45ab408c0d8230ececef1d7f1b267c49cff35638b8`<br>`PLM-Team/PLM-1.8B-Instruct@62d188c7d58843d7013d5b3ffe198db448787860`<br>`merges.txt` 1,671,853 B `8831e4f1a044471340f7c0a83d7bd71306a5b867e95fd870f74d0c5308a904d5`, `special_tokens_map.json` 410 B `c83747485fba9ef20c42793b4b02b05001f214250f0d787f573df216c91047a3`, `tokenizer.json` 11,418,266 B `bcfe42da0a4497e8b2b172c1f9f4ec423a46dc12907f4349c55025f670422ba9`, `tokenizer_config.json` 1,327 B `1becffcfa09c98935043f1724d988887c618c5f6e7a249087d3ae29eb70e2a6f`, `vocab.json` 2,776,833 B `ca10d7e9fb3ed18575dd1e277a2579c16d108e32f27439684afa0e10b1440910`<br>`config.json` 934 B `91e6e13695a6de82556438667e64b60d9910269f300cd97f8c667d19e75f115e`; **closure:** architecture `plm`; pre `qwen2`<br>metadata `698bfa31cd069292437bc3509fea7be2445324a536d95a6e813d947c283bd989`<br>tokens 151,936 `f3ea8e8cf45bd58a8d5ad420306a3ccd925894cdb61a89062fd9e3a6de255a0e`; source 151,646 `696f26322524de87f49427fd1be6d1afce910574d9656c5d3f4f64064bdb83c1`<br>merges 151,387 `24fa2ae2a398e50784a1fff678482094af4f63e6783d35686726abacda8dc371`; source `cc098baa4a74ce5156487605aa048a34e54f0eee6a704691a738c8fb22dafdd5`<br>scores=0; types `0286431feb975d95a59a3f39957f8183d929295635fb627b6940627c63918bf1`<br>added tokens `e7b5f7013431aa26739424d92f40423f175a46f6d1fdc8453edf6005c99412f7`; chat `af9c0233881b083b52ff773580215222b5440ac3d0beeeca99b76329b048f8db`<br>normalizer `NFC`; pipeline `97c53ee89fb584b10798f44b02c60c9a8b746165a32dc34737d178fc20618a69`; **witness:** official tokenizer.json applies NFC normalization, but pinned llama.cpp qwen2 preserves decomposed Unicode; exact materialization is blocked<br>`e\u0301 \xe9`: llama.cpp `[68, 53839, 3958]` vs source `[963, 3958]`<br>corpus `0f3c77d24208f2ac0833668128cb2a00adcb7e6b4b4eedc6e4783e3ec7b41f5a`; llama.cpp oracle `8d9af256337d1a501250f9bbf4c0859a654bddd6`: 72 cases `66513168812575ccac974ecb454e916def5f4492d558c1866b8811d4f587a41d`
137134

138-
The compact fixture is reproducible with
139-
`python scripts/generate_minicpm_tokenizer_oracle.py --help`. The refresh command validates
140-
the immutable 16 MiB header slices and official tokenizer hashes, constructs temporary
141-
tokenizer-only GGUFs, invokes a tokenizer binary from the pinned llama.cpp checkout, and
142-
recomputes the complete ordered-result hashes and mismatch witnesses.
135+
The compact MiniCPM fixture is reproducible through `scripts/generate_minicpm_tokenizer_oracle.py`, which validates immutable 16 MiB header slices and official tokenizer hashes, builds tokenizer-only GGUFs and the pinned llama.cpp tokenizer tool, then recomputes hashes and mismatch witnesses.
143136

144137
## Supported GGUF architectures
145138

‎scripts/generate_minicpm_tokenizer_oracle.py‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
from pathlib import Path
2525
from typing import Any
2626

27-
from mobius.integrations.gguf._tokenizer_mismatch_evidence import (
28-
GGUFTokenizerMismatchEvidence,
29-
tokenizer_mismatch_evidence,
27+
from mobius.integrations.gguf._tokenizer_evidence import (
28+
GGUFTokenizerBlockerEvidence,
29+
tokenizer_blocker_evidence,
3030
)
3131
from mobius.integrations.gguf._upstream import UPSTREAM_COMMIT
3232

@@ -189,9 +189,9 @@ def value(self, value_type: int) -> Any:
189189
return self.unpack(value_format)
190190

191191

192-
def _read_bounded_header(
193-
path: Path, evidence: GGUFTokenizerMismatchEvidence
194-
) -> dict[str, Any]:
192+
def _read_bounded_header(path: Path, evidence: GGUFTokenizerBlockerEvidence) -> dict[str, Any]:
193+
if evidence.bounded_header_bytes is None or evidence.bounded_header_sha256 is None:
194+
raise ValueError(f"{evidence.evidence_id!r} has no bounded-header evidence")
195195
with path.open("rb") as stream:
196196
data = stream.read(evidence.bounded_header_bytes + 1)
197197
if len(data) != evidence.bounded_header_bytes:
@@ -317,7 +317,9 @@ def tokenize(item: tuple[tuple[str, str], str]) -> list[int]:
317317
if not outputs:
318318
raise ValueError("llama-tokenize emitted no Python-parseable ID list")
319319
token_ids = json.loads(outputs[-1])
320-
if not isinstance(token_ids, list) or any(type(value) is not int for value in token_ids):
320+
if not isinstance(token_ids, list) or any(
321+
type(value) is not int for value in token_ids
322+
):
321323
raise ValueError("llama-tokenize emitted a malformed ID list")
322324
return token_ids
323325

@@ -342,7 +344,7 @@ def _source_results(path: Path, corpus: Sequence[str]) -> list[list[int]]:
342344

343345

344346
def _route_fixture(
345-
evidence: GGUFTokenizerMismatchEvidence,
347+
evidence: GGUFTokenizerBlockerEvidence,
346348
*,
347349
header: Path,
348350
tokenizer_json: Path,
@@ -360,7 +362,9 @@ def _route_fixture(
360362
):
361363
raise ValueError(f"{tokenizer_json} differs from pinned official tokenizer.json")
362364
metadata = _read_bounded_header(header, evidence)
363-
with tempfile.TemporaryDirectory(prefix=f"{evidence.architecture}-tokenizer-oracle-") as temp:
365+
with tempfile.TemporaryDirectory(
366+
prefix=f"{evidence.architecture}-tokenizer-oracle-"
367+
) as temp:
364368
tokenizer_only = Path(temp) / "tokenizer-only.gguf"
365369
_write_tokenizer_only_gguf(
366370
tokenizer_only,
@@ -469,7 +473,7 @@ def main() -> None:
469473
jobs=args.jobs,
470474
)
471475
for evidence_id, header, tokenizer_json in route_inputs:
472-
evidence = tokenizer_mismatch_evidence(evidence_id)
476+
evidence = tokenizer_blocker_evidence(evidence_id)
473477
if evidence is None:
474478
raise ValueError(f"Missing mismatch evidence {evidence_id!r}")
475479
routes.append(

‎src/mobius/integrations/gguf/_docs.py‎

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ def _tokenizer_blocker_evidence_table() -> str:
405405
f"<br>`{evidence.source_config_asset[0]}` "
406406
f"{evidence.source_config_asset[1]:,} B `{evidence.source_config_asset[2]}`"
407407
)
408+
if evidence.bounded_header_bytes is not None:
409+
identity += (
410+
f"<br>first {evidence.bounded_header_bytes:,} B "
411+
f"`{evidence.bounded_header_sha256}`"
412+
)
408413
closure = (
409414
f"architecture `{evidence.architecture}`; pre `{evidence.pre_identifier}`<br>"
410415
f"metadata `{evidence.tokenizer_metadata_sha256}`<br>"
@@ -418,6 +423,21 @@ def _tokenizer_blocker_evidence_table() -> str:
418423
f"normalizer `{evidence.source_normalizer}`; "
419424
f"pipeline `{evidence.source_pipeline_sha256}`"
420425
)
426+
if (
427+
evidence.source_model_token_count is not None
428+
and evidence.source_merge_count is not None
429+
and evidence.source_score_mismatch_count is not None
430+
and evidence.source_type_mismatch_count is not None
431+
and evidence.source_chat_template_sha256 is not None
432+
):
433+
closure += (
434+
f"<br>source model tokens={evidence.source_model_token_count:,}; "
435+
f"source merges={evidence.source_merge_count:,}; "
436+
f"score mismatches={evidence.source_score_mismatch_count:,}; "
437+
f"type mismatches={evidence.source_type_mismatch_count:,}<br>"
438+
f"GGUF chat `{evidence.chat_template_sha256}` vs source "
439+
f"`{evidence.source_chat_template_sha256}`"
440+
)
421441
witness = (
422442
f"{evidence.disposition}<br>"
423443
f"`{text.encode('unicode_escape').decode()}`: llama.cpp `{list(llamacpp_ids)}` "
@@ -426,6 +446,12 @@ def _tokenizer_blocker_evidence_table() -> str:
426446
f"llama.cpp oracle `{evidence.llamacpp_oracle[0]}`: "
427447
f"{evidence.llamacpp_oracle[1]} cases `{evidence.llamacpp_oracle[2]}`"
428448
)
449+
if evidence.oracle_mismatch_count is not None:
450+
witness += (
451+
f"<br>{evidence.oracle_mismatch_count} mismatches "
452+
f"{list(evidence.oracle_mismatch_count_by_mode)} by mode; "
453+
f"source oracle `{evidence.source_oracle_sha256}`"
454+
)
429455
rows.append(
430456
f"- `{evidence.evidence_id}` — **GGUF/source:** {_cell(identity)}; "
431457
f"**closure:** {_cell(closure)}; **witness:** {_cell(witness)}"
@@ -467,6 +493,22 @@ def render_document() -> str:
467493
f"#{record.number} ({record.state_at_audit}) — {record.dependency}"
468494
for record in RECENT_PR_DEPENDENCIES
469495
)
496+
tokenizer_scope_note = " ".join(
497+
(
498+
"Each row is independently artifact-scoped and proves ordered tokenizer semantics,",
499+
"source assets, embedding alignment, and the final materialized hash.",
500+
"Shared rows also require identical pinned llama.cpp dispatch.",
501+
"This does not claim graph or runtime support.",
502+
)
503+
)
504+
tokenizer_refresh_note = " ".join(
505+
(
506+
"The compact MiniCPM fixture is reproducible through",
507+
"`scripts/generate_minicpm_tokenizer_oracle.py`, which validates immutable 16 MiB",
508+
"header slices and official tokenizer hashes, builds tokenizer-only GGUFs and the",
509+
"pinned llama.cpp tokenizer tool, then recomputes hashes and mismatch witnesses.",
510+
)
511+
)
470512
return f"""# `build_from_gguf()`
471513
472514
Build ONNX packages directly from GGUF metadata and tensors without tracing PyTorch.
@@ -548,22 +590,13 @@ def render_document() -> str:
548590
materialize_evidenced_gguf_tokenizer("Qwen3.5-0.8B-Q4_0.gguf", "tokenizer")
549591
```
550592
551-
Each row is independently artifact-scoped. Evidence proves ordered tokens, merges or scores,
552-
token types, special IDs, source pipeline/config assets, representative encodings, embedding
553-
alignment, any non-matchable padding extension, and the final materialized hash. Shared rows
554-
additionally require every exact identifier to select the same implementation and flag overrides
555-
in pinned `llama-vocab.cpp`; the tokenizer matrix links each promoted route to its dispatch line.
556-
This does not claim graph or runtime support.
593+
{tokenizer_scope_note}
557594
558595
### Fail-closed tokenizer evidence
559596
560597
{_tokenizer_blocker_evidence_table()}
561598
562-
The compact fixture is reproducible with
563-
`python scripts/generate_minicpm_tokenizer_oracle.py --help`. The refresh command validates
564-
the immutable 16 MiB header slices and official tokenizer hashes, constructs temporary
565-
tokenizer-only GGUFs, invokes a tokenizer binary from the pinned llama.cpp checkout, and
566-
recomputes the complete ordered-result hashes and mismatch witnesses.
599+
{tokenizer_refresh_note}
567600
568601
## Supported GGUF architectures
569602

0 commit comments

Comments
 (0)