Skip to content

Commit e38d502

Browse files
committed
Validate second GGUF tokenizer alias cohort
Pin llama.cpp dispatch evidence for all 38 requested identifiers and promote the 22 routes backed by exact artifact-to-source tokenizer parity. Keep the remaining 16 routes fail-closed with an artifact-specific blocker, add the GPT-2 witness, and generate network-free census documentation and tests.\n\nCo-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
1 parent cafb2f2 commit e38d502

9 files changed

Lines changed: 470 additions & 65 deletions

File tree

‎docs/api/build_from_gguf.md‎

Lines changed: 50 additions & 47 deletions
Large diffs are not rendered by default.

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
)
3232
from mobius.integrations.gguf._runtime_evidence import runtime_evidence
3333
from mobius.integrations.gguf._spec import GGUFArchitectureSpec, StorageRole, Support
34+
from mobius.integrations.gguf._tokenizer_alias_evidence import tokenizer_alias_evidence
3435
from mobius.integrations.gguf._tokenizer_census import tokenizer_route_census
3536
from mobius.integrations.gguf._tokenizer_evidence import iter_tokenizer_evidence
3637
from mobius.integrations.gguf._tokenizer_registry import tokenizer_pre_policies
@@ -239,12 +240,17 @@ def _tokenizers() -> str:
239240
),
240241
"|---|---|---|---|---|",
241242
]
243+
alias_proofs = tokenizer_alias_evidence()
242244
for record in tokenizer_route_census():
243245
disposition = (
244246
f"`{record.evidence_id}`"
245247
if record.evidence_id is not None
246248
else f"`{record.blocker_category}`"
247249
)
250+
if record.identifier in alias_proofs:
251+
disposition += (
252+
f"; `llama-vocab.cpp:L{alias_proofs[record.identifier].dispatch_line}`"
253+
)
248254
rows.append(
249255
f"| `{record.identifier}` | `{record.semantic_group}` / `{record.pre_type}` | "
250256
f"`{record.default_policy}` | `{record.current_status}` | {disposition} |"
@@ -326,6 +332,7 @@ def _tokenizer_evidence_table() -> str:
326332
f"`{evidence.source_config_asset[2]}`<br>{assets}"
327333
)
328334
proof = (
335+
f"validated identifiers `{list(evidence.validated_identifiers)}`<br>"
329336
f"metadata `{evidence.tokenizer_metadata_sha256}`<br>"
330337
f"tokens {evidence.token_count:,} `{evidence.ordered_vocabulary_sha256}`<br>"
331338
f"merges {evidence.merge_count:,} `{evidence.ordered_merges_sha256}`<br>"
@@ -428,8 +435,10 @@ def render_document() -> str:
428435
429436
Each row is independently artifact-scoped. Evidence proves ordered tokens, merges or scores,
430437
token types, special IDs, source pipeline/config assets, representative encodings, embedding
431-
alignment, any non-matchable padding extension, and the final materialized hash. It does not
432-
claim graph or runtime support.
438+
alignment, any non-matchable padding extension, and the final materialized hash. Shared rows
439+
additionally require every exact identifier to select the same implementation and flag overrides
440+
in pinned `llama-vocab.cpp`; the tokenizer matrix links each promoted route to its dispatch line.
441+
This does not claim graph or runtime support.
433442
434443
## Supported GGUF architectures
435444

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,11 @@ def _validate_pinned_tokenizer(
947947
for index in range(tokenizer.get_vocab_size(with_added_tokens=True))
948948
]
949949
token_types = metadata.get("tokenizer.ggml.token_type")
950+
source_added_tokens = {
951+
token["id"]: token
952+
for token in tokenizer_json.get("added_tokens", ())
953+
if isinstance(token, Mapping) and isinstance(token.get("id"), int)
954+
}
950955
reconstructed = _reconstruct_missing_added_tokens(
951956
tokenizer_json,
952957
config,
@@ -1008,11 +1013,6 @@ def _validate_pinned_tokenizer(
10081013
raise ValueError(
10091014
f"Pinned tokenizer identity cannot prove GGUF token types {unsupported_types}"
10101015
)
1011-
source_added_tokens = {
1012-
token["id"]: token
1013-
for token in tokenizer_json.get("added_tokens", ())
1014-
if isinstance(token, Mapping) and isinstance(token.get("id"), int)
1015-
}
10161016
expected_non_special_added_ids = {
10171017
index for index, token_type in enumerate(token_types) if token_type == 4
10181018
}
@@ -1047,6 +1047,13 @@ def _validate_pinned_tokenizer(
10471047
continue
10481048
raw_value = config.get(config_name, special_map.get(config_name))
10491049
if raw_value is None:
1050+
source_token = source_added_tokens.get(expected_id)
1051+
if (
1052+
source_token is not None
1053+
and source_token.get("content") == expected_tokens[expected_id]
1054+
and source_token.get("special") is True
1055+
):
1056+
continue
10501057
if (
10511058
config_name == "bos_token"
10521059
and metadata.get("tokenizer.ggml.add_bos_token") is False
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
"""Pinned llama.cpp dispatch evidence for tokenizer aliases validated in batch 2."""
5+
6+
from __future__ import annotations
7+
8+
__all__ = [
9+
"TOKENIZER_DISPATCH_SOURCE_PATH",
10+
"TOKENIZER_DISPATCH_SOURCE_SHA256",
11+
"TokenizerAliasEvidence",
12+
"tokenizer_alias_evidence",
13+
]
14+
15+
import dataclasses
16+
import functools
17+
18+
from mobius.integrations.gguf._tokenizer_registry import tokenizer_pre_policies
19+
from mobius.integrations.gguf._upstream import UPSTREAM_COMMIT
20+
21+
TOKENIZER_DISPATCH_SOURCE_PATH = "src/llama-vocab.cpp"
22+
TOKENIZER_DISPATCH_SOURCE_SHA256 = (
23+
"32b8b7ac4a023bc6367eb7832e56e988ab7373a676ddcca4977665f78932ab88"
24+
)
25+
26+
27+
@dataclasses.dataclass(frozen=True, slots=True)
28+
class TokenizerAliasEvidence:
29+
"""Exact dispatch line and effective non-default behavior at the pinned source."""
30+
31+
identifier: str
32+
source_commit: str
33+
source_path: str
34+
source_sha256: str
35+
dispatch_line: int
36+
pre_type: str
37+
flag_overrides: tuple[str, ...]
38+
39+
40+
_GROUP_BEHAVIOR = {
41+
"bailingmoe": ("clean_spaces=false",),
42+
"gemma4": ("escape_whitespaces=true",),
43+
"glm4": ("special_bos_id=null",),
44+
"gpt-2": (),
45+
"gpt-4o": ("clean_spaces=false",),
46+
"jina-v1-en": ("add_sep=true",),
47+
"llama3": ("add_bos=true", "ignore_merges=true"),
48+
"qwen2": ("clean_spaces=false",),
49+
"tiny_aya": ("clean_spaces=false",),
50+
}
51+
52+
# Line numbers refer to TOKENIZER_DISPATCH_SOURCE_SHA256, not a moving branch.
53+
_DISPATCH_LINES = {
54+
"llama3": 2148,
55+
"llama-v3": 2149,
56+
"llama-bpe": 2150,
57+
"falcon3": 2151,
58+
"falcon-h1": 2152,
59+
"pixtral": 2153,
60+
"midm-2.0": 2154,
61+
"lfm2": 2155,
62+
"jina-v5-nano": 2156,
63+
"gpt-2": 2187,
64+
"phi-2": 2188,
65+
"jina-es": 2189,
66+
"jina-de": 2190,
67+
"gigachat": 2191,
68+
"jina-v2-es": 2192,
69+
"jina-v2-de": 2193,
70+
"a.x-4.0": 2194,
71+
"mellum": 2195,
72+
"modern-bert": 2196,
73+
"gemma4": 2202,
74+
"granite-embed-multi-311m": 2203,
75+
"jina-v1-en": 2212,
76+
"jina-v2-code": 2213,
77+
"roberta-bpe": 2214,
78+
"qwen2": 2229,
79+
"deepseek-r1-qwen": 2230,
80+
"kormo": 2231,
81+
"f2llmv2": 2232,
82+
"glm4": 2256,
83+
"chatglm-bpe": 2257,
84+
"exaone4": 2290,
85+
"gpt-4o": 2307,
86+
"llama4": 2308,
87+
"kanana2": 2309,
88+
"talkie": 2310,
89+
"tiny_aya": 2319,
90+
"cohere2moe": 2320,
91+
"bailingmoe": 2336,
92+
"bailingmoe2": 2337,
93+
"llada-moe": 2338,
94+
}
95+
96+
97+
@functools.lru_cache(maxsize=1)
98+
def tokenizer_alias_evidence() -> dict[str, TokenizerAliasEvidence]:
99+
"""Return exact batch-2 identifier-to-implementation proofs."""
100+
policies = tokenizer_pre_policies()
101+
records = {
102+
identifier: TokenizerAliasEvidence(
103+
identifier=identifier,
104+
source_commit=UPSTREAM_COMMIT,
105+
source_path=TOKENIZER_DISPATCH_SOURCE_PATH,
106+
source_sha256=TOKENIZER_DISPATCH_SOURCE_SHA256,
107+
dispatch_line=line,
108+
pre_type=policies[identifier].pre_type,
109+
flag_overrides=_GROUP_BEHAVIOR[policies[identifier].canonical],
110+
)
111+
for identifier, line in _DISPATCH_LINES.items()
112+
}
113+
if set(records) != set(_DISPATCH_LINES):
114+
raise RuntimeError("Tokenizer alias evidence contains duplicate identifiers")
115+
return records

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

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@
1111
import functools
1212
from typing import Literal
1313

14+
from mobius.integrations.gguf._tokenizer_alias_evidence import tokenizer_alias_evidence
1415
from mobius.integrations.gguf._tokenizer_evidence import (
1516
GGUFTokenizerEvidence,
1617
iter_tokenizer_evidence,
1718
)
1819
from mobius.integrations.gguf._tokenizer_registry import tokenizer_pre_policies
1920

20-
TokenizerAuditStatus = Literal["validated-pinned-source", "deferred-compiled-semantics"]
21-
TokenizerBlocker = Literal["compiled-llama.cpp-semantic-dependency"]
21+
TokenizerAuditStatus = Literal[
22+
"validated-pinned-source",
23+
"deferred-pinned-artifact-evidence",
24+
"deferred-compiled-semantics",
25+
]
26+
TokenizerBlocker = Literal[
27+
"pinned-artifact-source-parity-pending",
28+
"compiled-llama.cpp-semantic-dependency",
29+
]
2230

2331

2432
@dataclasses.dataclass(frozen=True, slots=True)
@@ -42,8 +50,10 @@ class GGUFTokenizerRouteAudit:
4250
blocker_category: TokenizerBlocker | None
4351

4452

45-
def _evidenced_route(evidence: GGUFTokenizerEvidence) -> GGUFTokenizerRouteAudit:
46-
policy = tokenizer_pre_policies()[evidence.pre_identifier]
53+
def _evidenced_route(
54+
identifier: str, evidence: GGUFTokenizerEvidence
55+
) -> GGUFTokenizerRouteAudit:
56+
policy = tokenizer_pre_policies()[identifier]
4757
return GGUFTokenizerRouteAudit(
4858
identifier=policy.identifier,
4959
semantic_group=policy.canonical,
@@ -69,22 +79,32 @@ def _evidenced_route(evidence: GGUFTokenizerEvidence) -> GGUFTokenizerRouteAudit
6979
def tokenizer_route_census() -> tuple[GGUFTokenizerRouteAudit, ...]:
7080
"""Return all exact routes, including aliases, in identifier order."""
7181
evidenced = {
72-
evidence.pre_identifier: _evidenced_route(evidence)
82+
identifier: _evidenced_route(identifier, evidence)
7383
for evidence in iter_tokenizer_evidence()
84+
for identifier in evidence.validated_identifiers
7485
}
75-
if len(evidenced) != len(iter_tokenizer_evidence()):
76-
raise RuntimeError("Tokenizer evidence contains duplicate exact pre identifiers")
86+
expected_count = sum(
87+
len(evidence.validated_identifiers) for evidence in iter_tokenizer_evidence()
88+
)
89+
if len(evidenced) != expected_count:
90+
raise RuntimeError("Tokenizer evidence contains duplicate validated identifiers")
7791

7892
records = []
93+
alias_proofs = tokenizer_alias_evidence()
7994
for identifier, policy in sorted(tokenizer_pre_policies().items()):
8095
record = evidenced.get(identifier)
8196
if record is None:
97+
dispatch_proven = identifier in alias_proofs
8298
record = GGUFTokenizerRouteAudit(
8399
identifier=identifier,
84100
semantic_group=policy.canonical,
85101
pre_type=policy.pre_type,
86102
default_policy=policy.default_route,
87-
current_status="deferred-compiled-semantics",
103+
current_status=(
104+
"deferred-pinned-artifact-evidence"
105+
if dispatch_proven
106+
else "deferred-compiled-semantics"
107+
),
88108
evidence_id=None,
89109
artifact_repository=None,
90110
artifact_revision=None,
@@ -94,7 +114,11 @@ def tokenizer_route_census() -> tuple[GGUFTokenizerRouteAudit, ...]:
94114
tokenizer_repository=None,
95115
tokenizer_revision=None,
96116
tokenizer_assets=(),
97-
blocker_category="compiled-llama.cpp-semantic-dependency",
117+
blocker_category=(
118+
"pinned-artifact-source-parity-pending"
119+
if dispatch_proven
120+
else "compiled-llama.cpp-semantic-dependency"
121+
),
98122
)
99123
records.append(record)
100124
return tuple(records)

0 commit comments

Comments
 (0)