Skip to content

Commit 2c981f2

Browse files
justinchubyCopilot
andauthored
Promote evidenced GGUF tokenizers independently of runtime evidence (#697)
## Summary - promote a tokenizer from deferred to `pinned-source` only when the complete immutable GGUF identity matches existing exact tokenizer evidence - materialize exact tokenizer evidence during runtime package export independently of graph/runtime evidence - preserve machine-readable deferred/blocked tokenizer warnings without blocking model or component export - regenerate the synchronized GGUF API documentation ## Authoritative tokenizer census - 87 exact identifiers across 56 semantic groups - 31 `validated-pinned-source` identifiers, conditionally promoted only for their evidenced complete artifacts - 45 `deferred-compiled-semantics` identifiers - 4 `deferred-pinned-artifact-evidence` identifiers - 7 `deferred-pinned-artifact-mismatch` identifiers The 56 remaining tokenizer work items therefore have no currently feasible promotion under the existing immutable-evidence and 16 GiB/session policy. Identifier-only inspection remains deferred because it cannot prove artifact identity. ## Validation - focused tokenizer/evidence/runtime package tests: 157 passed - broad serial suite: 9,670 passed, 64 skipped, 12 deselected, 1 subtest passed - focused mypy: clean - generated docs: synchronized - lintrunner formatting/lint: clean - independent medium review: no findings Base: `027fd42bb89e970defde0098792df104cd83b541` Head: `8bebbaa8ae1fad23e776c03f6f2db4eea53ef5c4` Local pytest/mypy caches were removed; workspace footprint is 81 MiB. No CI monitoring or merge requested. --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
1 parent 027fd42 commit 2c981f2

7 files changed

Lines changed: 238 additions & 15 deletions

File tree

‎docs/api/build_from_gguf.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ build_from_gguf(
6565
The function returns a `ModelPackage`. Mobius-side graph/semantic inability, corruption,
6666
identity, I/O, malformed tokenizer, and unexpected errors remain fail-closed. Authoritative
6767
tokenizer blockers become partial exports with exact reasons and no unverified assets.
68+
Exact tokenizer evidence is matched independently from runtime evidence, so a proven tokenizer
69+
is exported even when downstream runtime execution remains unvalidated.
6870
Downstream runtime, version, registry, or executor limitations preserve the accurate model
6971
package and record distinct `export_status` and `runtime_validation_status` fields instead of
7072
blocking export. Only exact artifact, graph, tokenizer, version, parity, and state evidence
@@ -157,7 +159,7 @@ from mobius.integrations.gguf import materialize_evidenced_gguf_tokenizer
157159
materialize_evidenced_gguf_tokenizer("Qwen3.5-0.8B-Q4_0.gguf", "tokenizer")
158160
```
159161

160-
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.
162+
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. A matching complete immutable GGUF is automatically promoted to the pinned-source route during model and runtime package export; identifier-only inspection remains deferred because an identifier cannot prove artifact identity. This does not claim graph or runtime support.
161163

162164
### Fail-closed tokenizer evidence
163165

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ def resolve_tokenizer_export_verdict(
5959
verdict: GGUFTokenizerVerdict | None = None,
6060
artifact_identity: Any | None = None,
6161
) -> GGUFTokenizerVerdict:
62-
"""Add an exact artifact blocker to an otherwise validated tokenizer verdict."""
62+
"""Apply exact artifact evidence to promote or block a tokenizer verdict."""
6363
if verdict is None:
6464
verdict = inspect_gguf_tokenizer(gguf_model.metadata, source=str(source_path))
6565
if verdict.materialized or verdict.metadata_sha256 is None:
6666
return verdict
6767

6868
from mobius.integrations.gguf._tokenizer_evidence import (
69+
find_matching_tokenizer_evidence,
6970
matching_tokenizer_blocker_evidence,
7071
)
7172

@@ -76,7 +77,26 @@ def resolve_tokenizer_export_verdict(
7677
artifact_identity=artifact_identity,
7778
)
7879
if blocker is None:
79-
return verdict
80+
evidence = find_matching_tokenizer_evidence(
81+
Path(source_path),
82+
gguf_model,
83+
metadata_sha256=verdict.metadata_sha256,
84+
artifact_identity=artifact_identity,
85+
)
86+
if evidence is None:
87+
return verdict
88+
return dataclasses.replace(
89+
verdict,
90+
route="pinned-source",
91+
reason=(
92+
"complete immutable GGUF identity matches independently validated tokenizer "
93+
f"evidence {evidence.evidence_id!r}"
94+
),
95+
tokenizer_sha256=evidence.materialized_tokenizer_sha256,
96+
audit_status="validated-pinned-source",
97+
blocker_category=None,
98+
evidence_id=evidence.evidence_id,
99+
)
80100
return dataclasses.replace(
81101
verdict,
82102
reason=blocker.disposition,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,9 @@ def render_document() -> str:
739739
"Each row is independently artifact-scoped and proves ordered tokenizer semantics,",
740740
"source assets, embedding alignment, and the final materialized hash.",
741741
"Shared rows also require identical pinned llama.cpp dispatch.",
742+
"A matching complete immutable GGUF is automatically promoted to the pinned-source",
743+
"route during model and runtime package export; identifier-only inspection remains",
744+
"deferred because an identifier cannot prove artifact identity.",
742745
"This does not claim graph or runtime support.",
743746
)
744747
)
@@ -830,6 +833,8 @@ def render_document() -> str:
830833
The function returns a `ModelPackage`. Mobius-side graph/semantic inability, corruption,
831834
identity, I/O, malformed tokenizer, and unexpected errors remain fail-closed. Authoritative
832835
tokenizer blockers become partial exports with exact reasons and no unverified assets.
836+
Exact tokenizer evidence is matched independently from runtime evidence, so a proven tokenizer
837+
is exported even when downstream runtime execution remains unvalidated.
833838
Downstream runtime, version, registry, or executor limitations preserve the accurate model
834839
package and record distinct `export_status` and `runtime_validation_status` fields instead of
835840
blocking export. Only exact artifact, graph, tokenizer, version, parity, and state evidence

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
materialize_gguf_tokenizer,
4747
write_gguf_tokenizer_json,
4848
)
49+
from mobius.integrations.gguf._tokenizer_evidence import tokenizer_evidence
4950

5051
__all__ = ["write_gguf_runtime_package"]
5152

@@ -412,8 +413,22 @@ def write_gguf_runtime_package(
412413
source=str(source_path),
413414
require_complete=False,
414415
)
416+
from mobius.integrations.gguf._component_export import resolve_tokenizer_export_verdict
417+
418+
verdict = resolve_tokenizer_export_verdict(
419+
source_model,
420+
source_path,
421+
verdict=verdict,
422+
artifact_identity=built_identity,
423+
)
415424
built_verdict = getattr(pkg, "gguf_tokenizer_verdict", None)
416-
if built_verdict is None or built_verdict.metadata_sha256 != verdict.metadata_sha256:
425+
if (
426+
built_verdict is None
427+
or built_verdict.metadata_sha256 != verdict.metadata_sha256
428+
or built_verdict.route != verdict.route
429+
or built_verdict.evidence_id != verdict.evidence_id
430+
or built_verdict.tokenizer_sha256 != verdict.tokenizer_sha256
431+
):
417432
raise ValueError(
418433
"The GGUF tokenizer metadata no longer matches the identity captured during "
419434
"graph construction; refusing to pair the graph with a replaced tokenizer source."
@@ -462,7 +477,28 @@ def write_gguf_runtime_package(
462477

463478
tokenizer_exported = False
464479
tokenizer_warning: str | None = None
465-
if evidence is not None:
480+
tokenizer_route_evidence = (
481+
tokenizer_evidence(verdict.evidence_id)
482+
if verdict.route == "pinned-source" and verdict.evidence_id is not None
483+
else None
484+
)
485+
if verdict.route == "pinned-source":
486+
if tokenizer_route_evidence is None:
487+
raise ValueError(
488+
"Pinned-source tokenizer verdict references missing exact evidence "
489+
f"{verdict.evidence_id!r}."
490+
)
491+
tokenizer_path = materialize_gguf_tokenizer(
492+
source_path,
493+
stage,
494+
source=tokenizer_route_evidence.source,
495+
metadata=source_metadata,
496+
source_identity=(f"sha256:{built_identity.sha256}/{built_identity.filename}"),
497+
local_files_only=local_files_only,
498+
)
499+
artifacts["tokenizer"] = tokenizer_path
500+
tokenizer_exported = True
501+
elif evidence is not None:
466502
tokenizer_source = GGUFTokenizerSource(
467503
repository=evidence.tokenizer_repository,
468504
revision=evidence.tokenizer_revision,
@@ -482,7 +518,7 @@ def write_gguf_runtime_package(
482518
)
483519
artifacts["tokenizer"] = tokenizer_path
484520
tokenizer_exported = True
485-
elif verdict.materialized:
521+
elif verdict.route == "copy":
486522
artifacts["tokenizer"] = write_gguf_tokenizer_json(
487523
source_path,
488524
stage,

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from __future__ import annotations
77

8+
import dataclasses
89
import json
910
from contextlib import contextmanager
1011
from pathlib import Path
@@ -54,9 +55,12 @@ def __iter__(self):
5455
def _materialized():
5556
return SimpleNamespace(
5657
materialized=True,
58+
route="copy",
5759
route_identifier="embedded",
5860
reason="exact embedded tokenizer",
61+
tokenizer_sha256="e" * 64,
5962
metadata_sha256="f" * 64,
63+
evidence_id=None,
6064
)
6165

6266

@@ -177,6 +181,80 @@ def _runtime_supported():
177181

178182

179183
class TestWriteGgufRuntimePackage:
184+
def test_exact_tokenizer_evidence_exports_without_runtime_evidence(self, tmp_path):
185+
pkg = _FakePackage()
186+
pinned = GGUFTokenizerVerdict(
187+
route="pinned-source",
188+
model="gpt2",
189+
pre="qwen2",
190+
canonical_pre="qwen2",
191+
reason="exact tokenizer evidence",
192+
token_count=2,
193+
tokenizer_sha256="a" * 64,
194+
metadata_sha256="f" * 64,
195+
audit_status="validated-pinned-source",
196+
evidence_id="tokenizer-only-evidence",
197+
)
198+
pkg.gguf_tokenizer_verdict = pinned
199+
tokenizer_source = object()
200+
out = tmp_path / "out"
201+
with (
202+
_successful_runtime_dependencies(),
203+
mock.patch(
204+
"mobius.integrations.gguf._runtime_package.matching_runtime_evidence",
205+
return_value=None,
206+
),
207+
mock.patch(
208+
"mobius.integrations.gguf._component_export.resolve_tokenizer_export_verdict",
209+
return_value=pinned,
210+
),
211+
mock.patch(
212+
"mobius.integrations.gguf._runtime_package.tokenizer_evidence",
213+
return_value=SimpleNamespace(source=tokenizer_source),
214+
),
215+
mock.patch(
216+
"mobius.integrations.gguf._runtime_package.materialize_gguf_tokenizer",
217+
side_effect=_write_tokenizer,
218+
) as materialize,
219+
):
220+
artifacts = _write_runtime(pkg, tmp_path / "m.gguf", out)
221+
222+
assert Path(artifacts["tokenizer"]).is_file()
223+
assert pkg.export_report.component("tokenizer").output == "exported"
224+
assert (
225+
pkg.export_report.component("runtime").runtime_validation_status == "unvalidated"
226+
)
227+
assert materialize.call_args.kwargs["source"] is tokenizer_source
228+
229+
def test_changed_pinned_tokenizer_digest_rejects_before_package_save(self, tmp_path):
230+
pkg = _FakePackage()
231+
built = GGUFTokenizerVerdict(
232+
route="pinned-source",
233+
model="gpt2",
234+
pre="qwen2",
235+
canonical_pre="qwen2",
236+
reason="exact tokenizer evidence",
237+
token_count=2,
238+
tokenizer_sha256="a" * 64,
239+
metadata_sha256="f" * 64,
240+
audit_status="validated-pinned-source",
241+
evidence_id="tokenizer-only-evidence",
242+
)
243+
current = dataclasses.replace(built, tokenizer_sha256="b" * 64)
244+
pkg.gguf_tokenizer_verdict = built
245+
with (
246+
_successful_runtime_dependencies(),
247+
mock.patch(
248+
"mobius.integrations.gguf._component_export.resolve_tokenizer_export_verdict",
249+
return_value=current,
250+
),
251+
pytest.raises(ValueError, match="replaced tokenizer source"),
252+
):
253+
_write_runtime(pkg, tmp_path / "m.gguf", tmp_path / "out")
254+
255+
assert pkg.saved_to is None
256+
assert not (tmp_path / "out").exists()
257+
180258
def test_runtime_disposition_is_replaced_when_runtime_changes(self):
181259
from mobius.integrations.gguf._component_export import (
182260
attach_runtime_unvalidated_report,

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

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
__all__ = [
99
"GGUFTokenizerBlockerEvidence",
1010
"GGUFTokenizerEvidence",
11+
"find_matching_tokenizer_evidence",
1112
"iter_tokenizer_blocker_evidence",
1213
"iter_tokenizer_evidence",
1314
"matching_tokenizer_blocker_evidence",
@@ -2392,19 +2393,22 @@ def matching_tokenizer_blocker_evidence(
23922393
return None
23932394

23942395

2395-
def matching_tokenizer_evidence(
2396+
def _matching_tokenizer_evidence_records(
23962397
source_path: Path,
23972398
gguf_model: Any,
23982399
*,
23992400
metadata_sha256: str | None,
2400-
) -> GGUFTokenizerEvidence:
2401-
"""Return the unique evidence record matching the complete artifact identity."""
2401+
artifact_identity: Any | None = None,
2402+
) -> tuple[list[GGUFTokenizerEvidence], list[GGUFTokenizerBlockerEvidence], Any]:
2403+
"""Return exact evidence candidates after complete artifact and tokenizer matching."""
24022404
architecture = gguf_model.architecture
2403-
identity = gguf_artifact_identity(
2404-
source_path,
2405-
gguf_model,
2406-
architecture=architecture,
2407-
)
2405+
identity = artifact_identity
2406+
if identity is None:
2407+
identity = gguf_artifact_identity(
2408+
source_path,
2409+
gguf_model,
2410+
architecture=architecture,
2411+
)
24082412
metadata = gguf_model.metadata
24092413

24102414
token_count, vocabulary_sha256 = _sequence_digest(metadata, "tokenizer.ggml.tokens")
@@ -2458,6 +2462,50 @@ def matching_tokenizer_evidence(
24582462
gguf_model,
24592463
metadata_sha256=metadata_sha256,
24602464
)
2465+
return matches, blockers, identity
2466+
2467+
2468+
def find_matching_tokenizer_evidence(
2469+
source_path: Path,
2470+
gguf_model: Any,
2471+
*,
2472+
metadata_sha256: str | None,
2473+
artifact_identity: Any | None = None,
2474+
) -> GGUFTokenizerEvidence | None:
2475+
"""Return exact tokenizer evidence when this complete artifact is allowlisted."""
2476+
matches, blockers, _ = _matching_tokenizer_evidence_records(
2477+
source_path,
2478+
gguf_model,
2479+
metadata_sha256=metadata_sha256,
2480+
artifact_identity=artifact_identity,
2481+
)
2482+
if len(blockers) == 1:
2483+
blocker = blockers[0]
2484+
raise ValueError(
2485+
f"Tokenizer materialization is explicitly blocked by {blocker.evidence_id!r}: "
2486+
f"{blocker.disposition}"
2487+
)
2488+
if blockers:
2489+
raise RuntimeError("Tokenizer blocker evidence contains duplicate artifact identities")
2490+
if len(matches) > 1:
2491+
raise RuntimeError("Tokenizer evidence contains duplicate artifact identities")
2492+
return matches[0] if matches else None
2493+
2494+
2495+
def matching_tokenizer_evidence(
2496+
source_path: Path,
2497+
gguf_model: Any,
2498+
*,
2499+
metadata_sha256: str | None,
2500+
artifact_identity: Any | None = None,
2501+
) -> GGUFTokenizerEvidence:
2502+
"""Return the unique evidence record matching the complete artifact identity."""
2503+
matches, blockers, identity = _matching_tokenizer_evidence_records(
2504+
source_path,
2505+
gguf_model,
2506+
metadata_sha256=metadata_sha256,
2507+
artifact_identity=artifact_identity,
2508+
)
24612509
if len(blockers) == 1:
24622510
blocker = blockers[0]
24632511
raise ValueError(
@@ -2469,7 +2517,7 @@ def matching_tokenizer_evidence(
24692517
if len(matches) != 1:
24702518
raise ValueError(
24712519
"No unique exact tokenizer evidence matches "
2472-
f"architecture={architecture!r}, artifact={identity!r}, "
2520+
f"architecture={gguf_model.architecture!r}, artifact={identity!r}, "
24732521
f"metadata_sha256={metadata_sha256!r}."
24742522
)
24752523
return matches[0]

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,40 @@ def materialize(_gguf_path, stage, **_kwargs):
13961396
assert not list(tmp_path.glob(".output.*.tmp"))
13971397

13981398

1399+
def test_exact_artifact_evidence_promotes_deferred_identifier_to_pinned_source(
1400+
tmp_path: Path, monkeypatch
1401+
) -> None:
1402+
from mobius.integrations.gguf._component_export import resolve_tokenizer_export_verdict
1403+
1404+
verdict = inspect_gguf_tokenizer(_metadata(pre="qwen2"))
1405+
evidence = SimpleNamespace(
1406+
evidence_id="exact-tokenizer-evidence",
1407+
materialized_tokenizer_sha256="a" * 64,
1408+
)
1409+
monkeypatch.setattr(
1410+
"mobius.integrations.gguf._tokenizer_evidence.matching_tokenizer_blocker_evidence",
1411+
lambda *_a, **_k: None,
1412+
)
1413+
monkeypatch.setattr(
1414+
"mobius.integrations.gguf._tokenizer_evidence.find_matching_tokenizer_evidence",
1415+
lambda *_a, **_k: evidence,
1416+
)
1417+
1418+
promoted = resolve_tokenizer_export_verdict(
1419+
SimpleNamespace(metadata=_metadata(pre="qwen2")),
1420+
tmp_path / "model.gguf",
1421+
verdict=verdict,
1422+
artifact_identity=object(),
1423+
)
1424+
1425+
assert promoted.route == "pinned-source"
1426+
assert promoted.materialized
1427+
assert promoted.audit_status == "validated-pinned-source"
1428+
assert promoted.evidence_id == evidence.evidence_id
1429+
assert promoted.tokenizer_sha256 == evidence.materialized_tokenizer_sha256
1430+
assert promoted.blocker_category is None
1431+
1432+
13991433
@pytest.mark.parametrize(
14001434
("token", "token_type", "message"),
14011435
[

0 commit comments

Comments
 (0)