Skip to content

Commit 35f9a10

Browse files
justinchubyCopilot
andcommitted
Refresh GGUF runtime evidence identities
Bind Qwen, LFM2, and inherited SmolLM evidence to their exact post-#641 import routes. Harden tokenizer cache containment and serialize HF, ORT, and OGA model lifetimes in real probes. Co-authored-by: Copilot App <[email protected]> Copilot-Session: af2b8208-9638-4f6e-9651-7d3da21c0af8 Signed-off-by: Justin Chu <[email protected]>
1 parent 15c766a commit 35f9a10

7 files changed

Lines changed: 174 additions & 100 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def _is_hex(value: str) -> bool:
174174

175175
_SMOLLM_F16_ROUTE = (
176176
'{"architecture":"llama","config_sha256":'
177-
'"b999a219ddf6046f1b6e5c082dab2d00b7ba1682169914430b1a3672fc735498",'
177+
'"d3f3f2abf531abde55e04a52b5c892c93943b7e260160c796c490618a2e84886",'
178178
'"execution_provider":"cpu","model_type":"llama","module_type":"llama",'
179179
'"preserve_quantization":false,"registry_import":{"config_key_map":null,'
180180
'"config_postprocessor":null,"llama_qk_permute":true,"offset_norm":false,'
@@ -296,7 +296,7 @@ def _is_hex(value: str) -> bool:
296296
),
297297
tensor_count=291,
298298
tensor_qtypes=(("F32", 121), ("Q8_0", 170)),
299-
import_route='{"architecture":"qwen2","config_sha256":"4002821420e74a522abaf921e064f23217eac71284d71d6d288171cf7802d068","execution_provider":"cpu","model_type":"qwen2","module_type":"qwen2","preserve_quantization":true,"registry_import":{"config_key_map":null,"config_postprocessor":null,"llama_qk_permute":false,"offset_norm":false,"required_metadata":[],"rope_interleave":false,"tensor_processor":null,"v_head_reorder":false,"vlm_builder":null},"route_schema":1,"static_cache":false,"task":{"class":"builtins.str","state":"text-generation"},"tensor_map_recipe":["llama"]}',
299+
import_route='{"architecture":"qwen2","config_sha256":"f7391f2aac9a7617c1c10e397e91b6f31b80bb3c5f338966b46e7d3935246500","execution_provider":"cpu","model_type":"qwen2","module_type":"qwen2","preserve_quantization":true,"registry_import":{"config_key_map":null,"config_postprocessor":null,"llama_qk_permute":false,"offset_norm":false,"required_metadata":[],"rope_interleave":false,"tensor_processor":null,"v_head_reorder":false,"vlm_builder":null},"route_schema":1,"static_cache":false,"task":{"class":"builtins.str","state":"text-generation"},"tensor_map_recipe":["llama"]}',
300300
graph_files=("model.onnx", "model.onnx.data"),
301301
graph_sha256="b0d1814ea69dddd405e30541e9009ba6fb73930f98538921d5c2eaa4a14f5d2c",
302302
runtime_package_files=(
@@ -354,7 +354,7 @@ def _is_hex(value: str) -> bool:
354354
),
355355
tensor_count=148,
356356
tensor_qtypes=(("F16", 93), ("F32", 55)),
357-
import_route='{"architecture":"lfm2","config_sha256":"69e63a13b046ca5658e4fbf1fac41b76e021ef768b16428cd2baa7c990bef21a","execution_provider":"cpu","model_type":"lfm2","module_type":"lfm2","preserve_quantization":false,"registry_import":{"config_key_map":null,"config_postprocessor":null,"llama_qk_permute":false,"offset_norm":false,"required_metadata":["attention.head_count_kv","attention.layer_norm_rms_epsilon","shortconv.l_cache"],"rope_interleave":false,"tensor_processor":null,"v_head_reorder":false,"vlm_builder":null},"route_schema":1,"static_cache":false,"task":{"class":"builtins.str","state":"hybrid-text-generation"},"tensor_map_recipe":["lfm2"]}',
357+
import_route='{"architecture":"lfm2","config_sha256":"c961bba579ea33a2472a7c5d3f469c76f1f8c7aae8440a7eaa86bc6e878a42f4","execution_provider":"cpu","model_type":"lfm2","module_type":"lfm2","preserve_quantization":false,"registry_import":{"config_key_map":null,"config_postprocessor":null,"llama_qk_permute":false,"offset_norm":false,"required_metadata":["attention.head_count_kv","attention.layer_norm_rms_epsilon","shortconv.l_cache"],"rope_interleave":false,"tensor_processor":null,"v_head_reorder":false,"vlm_builder":null},"route_schema":1,"static_cache":false,"task":{"class":"builtins.str","state":"hybrid-text-generation"},"tensor_map_recipe":["lfm2"]}',
358358
graph_files=("model.onnx", "model.onnx.data"),
359359
graph_sha256="2a15694cd5ff9f5c9f798feeca91cc41174842065ada80a18b288478725b3342",
360360
runtime_package_files=(

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ def test_matching_evidence_binds_arch_runtime_source_qtypes_and_route(
123123
tokenizer_repository="attacker/replacement",
124124
tokenizer_revision=record.tokenizer_revision,
125125
)
126+
with pytest.raises(ValueError, match="No unique GGUF runtime evidence"):
127+
matching_runtime_evidence(
128+
(record.evidence_id,),
129+
architecture="llama",
130+
runtime="onnx-genai",
131+
source_path=source,
132+
gguf_model=_model(),
133+
built_identity=gguf_artifact_identity(source, _model(), architecture="llama"),
134+
import_route='{"route_schema":2}',
135+
runtime_version="1.0.0",
136+
tokenizer_repository=record.tokenizer_repository,
137+
tokenizer_revision=record.tokenizer_revision,
138+
)
126139

127140

128141
def test_matching_evidence_rejects_source_replaced_after_build(tmp_path, monkeypatch) -> None:

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -639,16 +639,16 @@ def _download_tokenizer_assets(
639639
local_files_only=True,
640640
)
641641
)
642+
try:
643+
cache_root = Path(HF_HUB_CACHE).resolve(strict=True)
644+
path.parent.resolve(strict=True).relative_to(cache_root)
645+
resolved_path = path.resolve(strict=True)
646+
resolved_path.relative_to(cache_root)
647+
except ValueError as error:
648+
raise ValueError(
649+
f"Cached tokenizer asset is outside the trusted Hub cache: {path}"
650+
) from error
642651
if path.is_symlink():
643-
try:
644-
cache_root = Path(HF_HUB_CACHE).resolve(strict=True)
645-
path.parent.resolve(strict=True).relative_to(cache_root)
646-
resolved_path = path.resolve(strict=True)
647-
resolved_path.relative_to(cache_root)
648-
except ValueError as error:
649-
raise ValueError(
650-
f"Cached tokenizer asset is an untrusted symlink: {path}"
651-
) from error
652652
path = resolved_path
653653
else:
654654
url = hf_hub_url(source.repository, asset.filename, revision=source.revision)
@@ -799,15 +799,13 @@ def _validate_pinned_tokenizer(
799799
tokenizer.id_to_token(index)
800800
for index in range(tokenizer.get_vocab_size(with_added_tokens=True))
801801
]
802-
if (
803-
actual_tokens == expected_tokens[: len(actual_tokens)]
804-
and len(actual_tokens) < len(expected_tokens)
802+
if actual_tokens == expected_tokens[: len(actual_tokens)] and len(actual_tokens) < len(
803+
expected_tokens
805804
):
806805
suffix = expected_tokens[len(actual_tokens) :]
807806
added_tokens = tokenizer_json.get("added_tokens")
808807
if isinstance(added_tokens, list) and all(
809-
token == f"[PAD{index}]"
810-
for index, token in enumerate(suffix, len(actual_tokens))
808+
token == f"[PAD{index}]" for index, token in enumerate(suffix, len(actual_tokens))
811809
):
812810
token_types = metadata.get("tokenizer.ggml.token_type")
813811
if token_types is not None and any(
@@ -859,10 +857,14 @@ def _validate_pinned_tokenizer(
859857
"Pinned tokenizer merge order differs from GGUF tokenizer.ggml.merges"
860858
)
861859
pre = metadata.get("tokenizer.ggml.pre")
862-
if pre == "smollm" and {
863-
name: tokenizer_json.get(name)
864-
for name in ("normalizer", "pre_tokenizer", "post_processor", "decoder")
865-
} != _SMOLLM_PIPELINE:
860+
if (
861+
pre == "smollm"
862+
and {
863+
name: tokenizer_json.get(name)
864+
for name in ("normalizer", "pre_tokenizer", "post_processor", "decoder")
865+
}
866+
!= _SMOLLM_PIPELINE
867+
):
866868
raise ValueError(f"Pinned tokenizer pipeline differs from GGUF pre {pre!r}")
867869
token_types = metadata.get("tokenizer.ggml.token_type")
868870
if token_types is not None:
@@ -884,7 +886,9 @@ def _validate_pinned_tokenizer(
884886
or source_added_tokens[index].get("special") is not False
885887
for index in expected_non_special_added_ids
886888
):
887-
raise ValueError("Pinned tokenizer user-defined/unused-token inventory differs from GGUF")
889+
raise ValueError(
890+
"Pinned tokenizer user-defined/unused-token inventory differs from GGUF"
891+
)
888892
source_special_ids = {
889893
token["id"]
890894
for token in source_added_tokens.values()

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

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,7 @@ def test_non_smollm_pipeline_is_bound_by_exact_asset_hashes() -> None:
534534
tokenizer["pre_tokenizer"]["pretokenizers"].reverse()
535535
payloads["tokenizer.json"] = json.dumps(tokenizer).encode()
536536

537-
tokenizer_sha256, materialized = _tokenizer._validate_pinned_tokenizer(
538-
metadata, payloads
539-
)
537+
tokenizer_sha256, materialized = _tokenizer._validate_pinned_tokenizer(metadata, payloads)
540538

541539
assert hashlib.sha256(materialized).hexdigest() == tokenizer_sha256
542540

@@ -728,11 +726,7 @@ def test_local_hub_cache_symlink_is_resolved_inside_cache(
728726
blob.parent.mkdir(parents=True)
729727
blob.write_bytes(payload)
730728
snapshot = (
731-
cache
732-
/ "models--owner--tokenizer"
733-
/ "snapshots"
734-
/ source.revision
735-
/ "tokenizer.json"
729+
cache / "models--owner--tokenizer" / "snapshots" / source.revision / "tokenizer.json"
736730
)
737731
snapshot.parent.mkdir(parents=True)
738732
snapshot.symlink_to(blob)
@@ -762,16 +756,41 @@ def test_local_hub_cache_symlink_escape_rejects(
762756
escaped = tmp_path / "escaped.json"
763757
escaped.write_bytes(payload)
764758
snapshot = (
765-
cache
766-
/ "models--owner--tokenizer"
767-
/ "snapshots"
768-
/ source.revision
769-
/ "tokenizer.json"
759+
cache / "models--owner--tokenizer" / "snapshots" / source.revision / "tokenizer.json"
770760
)
771761
snapshot.parent.mkdir(parents=True)
772762
snapshot.symlink_to(escaped)
773763
monkeypatch.setattr("huggingface_hub.constants.HF_HUB_CACHE", str(cache))
774764
monkeypatch.setattr("huggingface_hub.hf_hub_download", lambda **_kwargs: str(snapshot))
775765

776-
with pytest.raises(ValueError, match="untrusted symlink"):
766+
with pytest.raises(ValueError, match="outside the trusted Hub cache"):
767+
_tokenizer._download_tokenizer_assets(source, local_files_only=True)
768+
769+
770+
def test_local_hub_cache_parent_symlink_escape_rejects(
771+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
772+
) -> None:
773+
payload = b"{}"
774+
source = GGUFTokenizerSource(
775+
"owner/tokenizer",
776+
"a" * 40,
777+
(
778+
GGUFTokenizerAsset(
779+
"tokenizer.json", len(payload), hashlib.sha256(payload).hexdigest()
780+
),
781+
),
782+
"b" * 64,
783+
)
784+
cache = tmp_path / "hub"
785+
escaped = tmp_path / "escaped"
786+
escaped.mkdir()
787+
(escaped / "tokenizer.json").write_bytes(payload)
788+
snapshots = cache / "models--owner--tokenizer" / "snapshots"
789+
snapshots.parent.mkdir(parents=True)
790+
snapshots.symlink_to(escaped, target_is_directory=True)
791+
path = snapshots / "tokenizer.json"
792+
monkeypatch.setattr("huggingface_hub.constants.HF_HUB_CACHE", str(cache))
793+
monkeypatch.setattr("huggingface_hub.hf_hub_download", lambda **_kwargs: str(path))
794+
795+
with pytest.raises(ValueError, match="outside the trusted Hub cache"):
777796
_tokenizer._download_tokenizer_assets(source, local_files_only=True)

‎testdata/cases/causal-lm/lfm2-350m-f16.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ gguf:
1515
F16: 93
1616
F32: 55
1717
execution_provider: "cpu"
18-
config_sha256: "69e63a13b046ca5658e4fbf1fac41b76e021ef768b16428cd2baa7c990bef21a"
18+
config_sha256: "c961bba579ea33a2472a7c5d3f469c76f1f8c7aae8440a7eaa86bc6e878a42f4"
1919
preserve_quantization: false
2020
keep_quantized: true
2121
tokenizer:

‎testdata/cases/causal-lm/qwen2.5-0.5b-instruct-q8.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ gguf:
1515
F32: 121
1616
Q8_0: 170
1717
execution_provider: "cpu"
18-
config_sha256: "4002821420e74a522abaf921e064f23217eac71284d71d6d288171cf7802d068"
18+
config_sha256: "f7391f2aac9a7617c1c10e397e91b6f31b80bb3c5f338966b46e7d3935246500"
1919
preserve_quantization: true
2020
keep_quantized: true
2121
tokenizer:

0 commit comments

Comments
 (0)