Skip to content

Commit 50bb373

Browse files
authored
Decouple export from downstream runtime capability gates (#688)
## Summary - remove GGUF, ORT GenAI, and onnx-genai export admission checks tied to downstream runtime versions, registries, processors, speculative/MTP APIs, topology, and heterogeneous cache orchestration - preserve graph-derived component/config/package contracts and emit machine-readable `runtime_validation_status` plus clear warnings without over-claiming exact validation - keep intrinsic graph/config/tensor, source-identity, unsupported storage-transform, and unexpected-error failures intact - separate GGUF graph exportability from real-artifact runtime evidence in the generated capability census and documentation ## Validation - `python -m pytest tests/build_graph_test.py tests/cli_test.py src/ -q -k "not phi4mm and not apply_weights_unknown" --tb=short -n auto` - `lintrunner --output oneline --all-files` - `python scripts/generate_gguf_support_docs.py --check` - `git diff --check` - targeted export, GGUF package, Qwen4, Parakeet, draft/MTP, API, and CLI suites - two independent medium-effort code reviews, with findings addressed ## Notes This is compatible with a future partial-export manifest but does not depend on that work. Runtime evidence remains exact-artifact evidence rather than an export gate. --------- Signed-off-by: Justin Chu <[email protected]>
1 parent 49c6c71 commit 50bb373

19 files changed

Lines changed: 1004 additions & 521 deletions

‎docs/api/build_from_gguf.md‎

Lines changed: 10 additions & 11 deletions
Large diffs are not rendered by default.

‎docs/cli_reference.md‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ tokenizer files to the output directory:
162162
directory.
163163

164164
For a graph-representable, single-model decoder-only text graph, Mobius emits the
165-
architecture-neutral `model.type: "decoder"` contract supported by
166-
onnxruntime-genai 0.14.0 and newer. Validation targets only the latest stable
167-
release, currently 0.15.2.
165+
architecture-neutral `model.type: "decoder"` contract. Validation currently targets
166+
onnxruntime-genai 0.15.2, but the tested runtime version and registry are evidence,
167+
not export admission checks.
168168
The graph determines the exact semantic input names, output names, cache templates,
169169
and global cache indices, so dense, MoE, tied-weight, quantized, and unknown
170170
architecture names do not need a runtime registry entry.
@@ -187,21 +187,20 @@ its [dedicated runtime model](https://github.com/microsoft/onnxruntime-genai/blo
187187
The Phi-3 LongRoPE threshold dispatch is in the released
188188
[`Generator`](https://github.com/microsoft/onnxruntime-genai/blob/v0.15.2/src/generators.cpp).
189189

190-
Released generic recurrent state is enabled only when the optimized graph exposes
191-
matching `conv_state` and `recurrent_state` names derived from the same cache
192-
template. Mobius rejects static-cache names and heterogeneous state layouts that
193-
the released config schema cannot represent rather than emitting a misleading
194-
dense cache. The deferred state-manifest work is tracked by
190+
Mobius preserves graph-derived recurrent and heterogeneous state names even when the
191+
tested runtime cannot orchestrate them. The generated compatibility sidecar records
192+
the complete component input/output contract and marks such packages
193+
`unsupported-by-tested-runtime`; the state-manifest work is tracked by
195194
[#605](https://github.com/onnxruntime/mobius/issues/605).
196195

197-
Each export also writes `runtime_compatibility.json`. Generic decoder metadata
198-
records the minimum runtime version and the latest stable release exercised by
199-
Mobius (0.15.2); it never emits the unreleased `decoder.state_groups` field.
200-
Generic config availability does not promote a GGUF runtime verdict. Runtime
201-
admission is restricted to exact artifacts named by the generated GGUF evidence
202-
matrix, which now includes GPT-2 and other independently verified decoder routes in
203-
addition to SmolLM. SmolLM2 remains rejected because its GGUF padding-token metadata
204-
conflicts with the official pinned tokenizer.
196+
Each export also writes `runtime_compatibility.json` with
197+
`runtime_validation_status`, warnings, the requested and tested versions, and the
198+
graph-derived component contract. `validated` means the exact requested runtime was
199+
exercised; `unvalidated` means no matching evidence exists; and
200+
`unsupported-by-tested-runtime` records a known downstream limitation without
201+
blocking export. GGUF runtime evidence remains an independent exact-artifact matrix.
202+
Source identity and tokenizer semantic mismatches still fail because they would make
203+
the package metadata incorrect.
205204

206205
#### Example
207206

‎src/mobius/__main__.py‎

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -511,15 +511,6 @@ def _save_package(
511511
) -> None:
512512
"""Save a ModelPackage to disk, applying optimizations and runtime configs."""
513513
runtime = getattr(args, "runtime", None)
514-
if runtime == "ort-genai":
515-
from mobius.integrations.ort_genai.auto_export import (
516-
_validate_ort_genai_compatibility,
517-
)
518-
519-
try:
520-
_validate_ort_genai_compatibility(pkg)
521-
except ValueError as error:
522-
raise SystemExit(f"Error: {error}") from error
523514

524515
components = (lambda name: name == component_filter) if component_filter else None
525516
for name, model in pkg.items():
@@ -703,11 +694,6 @@ def _cmd_build_gguf(args: argparse.Namespace) -> None:
703694
raise SystemExit("Error: --max-workers must be a positive integer.")
704695
if mmproj_path is not None and args.static_cache:
705696
raise SystemExit("Error: --static-cache cannot be used with --mmproj.")
706-
if target_config is not None and runtime is not None:
707-
raise SystemExit(
708-
"Error: dflash/eagle3 target-coupled drafts do not support standalone "
709-
"runtime packaging; omit --runtime to save the auxiliary graph and manifest."
710-
)
711697
tokenizer_repository = getattr(args, "tokenizer_repository", None)
712698
tokenizer_revision = getattr(args, "tokenizer_revision", None)
713699
if (tokenizer_repository is None) != (tokenizer_revision is None):
@@ -720,35 +706,26 @@ def _cmd_build_gguf(args: argparse.Namespace) -> None:
720706
)
721707

722708
if runtime is not None:
723-
from mobius.integrations.gguf._arch_registry import get_arch_spec
724709
from mobius.integrations.gguf._builder import (
725710
_resolve_gguf_path,
726711
_validate_gguf_model,
727712
)
728713
from mobius.integrations.gguf._shard_set import open_gguf_model
729-
from mobius.integrations.gguf._spec import Support
730714

731-
# Resolve and validate the exact selected source before graph construction
732-
# so a deferred tokenizer cannot leave a graph-only directory behind.
715+
# Resolve and validate the exact selected source before graph construction.
733716
resolved_gguf_path = _resolve_gguf_path(gguf_path)
734717
gguf_model = open_gguf_model(resolved_gguf_path)
735718
_validate_gguf_model(gguf_model, source=str(resolved_gguf_path))
736-
architecture_spec = get_arch_spec(gguf_model.architecture)
737-
if architecture_spec.runtime is not Support.SUPPORTED:
738-
raise SystemExit(
739-
f"Error: GGUF runtime packaging for {architecture_spec.gguf_arch!r} is "
740-
f"{architecture_spec.runtime.value}: {architecture_spec.reason}"
741-
)
742-
if tokenizer_repository is None or tokenizer_revision is None:
743-
raise SystemExit(
744-
"Error: GGUF runtime packaging requires --tokenizer-repository and an "
745-
"immutable --tokenizer-revision."
746-
)
747-
if tokenizer_repository.count("/") != 1 or not all(tokenizer_repository.split("/")):
719+
if tokenizer_repository is not None and (
720+
tokenizer_repository.count("/") != 1 or not all(tokenizer_repository.split("/"))
721+
):
748722
raise SystemExit(
749723
"Error: --tokenizer-repository must be an owner/repository Hub ID."
750724
)
751-
if re.fullmatch(r"[0-9a-f]{40}", tokenizer_revision) is None:
725+
if (
726+
tokenizer_revision is not None
727+
and re.fullmatch(r"[0-9a-f]{40}", tokenizer_revision) is None
728+
):
752729
raise SystemExit(
753730
"Error: --tokenizer-revision must be an immutable 40-hex commit SHA."
754731
)

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,8 @@
13551355
"full-vector Q/K RMSNorm, partial NeoX RoPE, standard dynamic/static KV cache, "
13561356
"and F32 selection-biased sigmoid MoE routing. Loader-accepted Q/K/V biases "
13571357
"and fused QKV are rejected because the pinned graph ignores or cannot execute "
1358-
"them. Packed projection/expert import and runtime packaging remain deferred; "
1358+
"them. Packed projection/expert import and real-artifact runtime validation remain "
1359+
"deferred; "
13591360
"the smallest immutable public GGUF is 46,514,882,176 bytes, above the "
13601361
"16 GiB evidence budget. Use keep_quantized=False."
13611362
),
@@ -1412,7 +1413,8 @@
14121413
"Mamba1/attention layers and mixed state ABI. ORT GenAI 0.15.2 discovers "
14131414
"sparse KV and conv/recurrent slots, but its recurrent-state naming, beam "
14141415
"reorder, and nonzero-rewind contracts do not yet match this export. Runtime "
1415-
"packaging remains deferred to onnxruntime/mobius#605."
1416+
"validation remains deferred to onnxruntime/mobius#605; export remains available "
1417+
"with the exact graph state contract."
14161418
),
14171419
),
14181420
GGUFArchitectureSpec(
@@ -1442,9 +1444,10 @@
14421444
runtime=Support.DEFERRED,
14431445
reason=(
14441446
"The dedicated graph and GGUF importer preserve parallel Attention+Mamba2 "
1445-
"layers and their four-state ABI, but runtime packaging remains deferred "
1446-
"pending heterogeneous-state schema support (onnxruntime/mobius#605) and "
1447-
"real full-logit plus deterministic stateful-generation evidence."
1447+
"layers and their four-state ABI. Export records that exact state contract; "
1448+
"runtime validation remains pending heterogeneous-state executor support "
1449+
"(onnxruntime/mobius#605) and real full-logit plus deterministic "
1450+
"stateful-generation evidence."
14481451
),
14491452
),
14501453
# --------------------------------------------------------- Encoder-only

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7618,8 +7618,9 @@ def combine_mtp_report(mtp_report) -> None:
76187618
separators=(",", ":"),
76197619
sort_keys=True,
76207620
)
7621-
if spec.runtime is Support.SUPPORTED:
7622-
if not gguf_model.source_matches_path():
7621+
source_matches_path = getattr(gguf_model, "source_matches_path", None)
7622+
if source_matches_path is not None:
7623+
if not source_matches_path():
76237624
raise ValueError(
76247625
"GGUF source changed after the reader opened it; refusing to bind the graph "
76257626
"to a different artifact identity."
@@ -7632,7 +7633,7 @@ def combine_mtp_report(mtp_report) -> None:
76327633
architecture=spec.gguf_arch,
76337634
filename=logical_source_filename,
76347635
)
7635-
if not gguf_model.source_matches_path():
7636+
if not source_matches_path():
76367637
raise ValueError(
76377638
"GGUF source changed while its graph and artifact identity were being built."
76387639
)

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7689,26 +7689,29 @@ def test_float_import_preserves_expert_order_state_and_roundtrip(
76897689
assert outputs["present.0.ssm_state"].shape == (2, 4, 4, 16)
76907690
session.close()
76917691

7692-
def test_runtime_package_remains_fail_closed(self, tmp_path: Path) -> None:
7692+
def test_runtime_package_exports_with_unvalidated_state_contract(
7693+
self, tmp_path: Path
7694+
) -> None:
76937695
from mobius.integrations.gguf import build_from_gguf, write_gguf_runtime_package
76947696

76957697
path = tmp_path / "nemotron-h-moe-f32.gguf"
76967698
_write_nemotron_h_moe_gguf(path, quantized=False)
76977699
package = build_from_gguf(path)
76987700

7699-
with pytest.raises(
7700-
ValueError,
7701-
match=r"runtime packaging for 'nemotron_h_moe' is deferred",
7702-
):
7703-
write_gguf_runtime_package(
7704-
package,
7705-
path,
7706-
tmp_path / "runtime-package",
7707-
tokenizer_repository="nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16",
7708-
tokenizer_revision="bf77c3174f68ad409e1c2aa60daeb46e32d1c606",
7709-
runtime_version="0.15.2",
7710-
)
7711-
assert not (tmp_path / "runtime-package").exists()
7701+
output = tmp_path / "runtime-package"
7702+
write_gguf_runtime_package(
7703+
package,
7704+
path,
7705+
output,
7706+
tokenizer_repository="nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16",
7707+
tokenizer_revision="bf77c3174f68ad409e1c2aa60daeb46e32d1c606",
7708+
runtime_version="0.15.2",
7709+
)
7710+
compatibility = json.loads(
7711+
(output / "runtime_compatibility.json").read_text(encoding="utf-8")
7712+
)
7713+
assert compatibility["runtime_validation_status"] == "unvalidated"
7714+
assert compatibility["gguf_architecture"] == "nemotron_h_moe"
77127715

77137716
def test_latent_projection_imports_and_executes(self, tmp_path: Path) -> None:
77147717
from mobius._testing.ort_inference import OnnxModelSession

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _summary() -> str:
8585
quantized_import_counts = Counter(spec.quantized_import.value for spec in architectures)
8686
projector_counts = {
8787
"graph-importable": sum(spec.is_importable for spec in projectors),
88-
"runtime-supported": sum(spec.runtime is Support.SUPPORTED for spec in projectors),
88+
"runtime-evidenced": sum(spec.runtime is Support.SUPPORTED for spec in projectors),
8989
}
9090
return "\n".join(
9191
(
@@ -117,9 +117,10 @@ def _summary() -> str:
117117
(
118118
"`SUPPORTED` means the named capability is implemented and mechanically tested. "
119119
"`DEFERRED` means it is intentionally unavailable pending the stated work. "
120-
"`REJECTED` means the input or route is invalid by policy. Graph support proves "
121-
"construction/execution only; runtime support additionally requires a pinned real "
122-
"artifact, independent parity, and deterministic generation or stateful semantics. "
120+
"`REJECTED` means the input or route is invalid by policy. Graph support controls "
121+
"export. The separate runtime verdict records pinned real-artifact validation, "
122+
"independent parity, and deterministic generation or stateful semantics; it never "
123+
"gates export of a faithfully represented graph and package contract. "
123124
"Tokenizer `copy` requires embedded ordered-vocabulary identity; `pinned-source` "
124125
"also binds the complete GGUF artifact, immutable Hub assets, reconstruction "
125126
"policy, semantic hashes, and representative token-ID vectors."
@@ -149,7 +150,7 @@ def _reason_code(verdicts: dict[str, Support]) -> str:
149150
if graph is not Support.SUPPORTED:
150151
return "GRAPH_DEFERRED — Executable graph construction is not implemented."
151152
if runtime is Support.REJECTED:
152-
return "RUNTIME_REJECTED — Runtime package publication is deliberately refused."
153+
return "RUNTIME_EVIDENCE_REJECTED — The recorded runtime route is invalid."
153154
if runtime is not Support.SUPPORTED and quantized is Support.REJECTED:
154155
return (
155156
"RUNTIME_EVIDENCE_PENDING / FLOAT_IMPORT_ONLY — Runtime evidence is incomplete, "
@@ -162,7 +163,7 @@ def _reason_code(verdicts: dict[str, Support]) -> str:
162163
)
163164
if quantized is Support.REJECTED:
164165
return "FLOAT_IMPORT_ONLY — Runtime is evidenced only through explicit float import."
165-
return "EVIDENCED_SCOPE — Runtime publication is limited to registry-linked immutable evidence."
166+
return "EVIDENCED_SCOPE — Registry-linked immutable runtime evidence is available."
166167

167168

168169
def _architecture_reason(spec: GGUFArchitectureSpec) -> str:

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import json
99
from pathlib import Path
10+
from unittest import mock
1011

1112
import numpy as np
1213
import pytest
@@ -832,7 +833,7 @@ def test_cli_bad_target_never_mutates_output(tmp_path: Path, existing_output: bo
832833

833834

834835
@pytest.mark.parametrize("existing_output", [False, True])
835-
def test_cli_draft_runtime_rejection_never_mutates_output(
836+
def test_cli_draft_runtime_export_reaches_advisory_package_writer(
836837
tmp_path: Path,
837838
monkeypatch,
838839
existing_output: bool,
@@ -848,25 +849,32 @@ def test_cli_draft_runtime_rejection_never_mutates_output(
848849
output.mkdir()
849850
(output / "sentinel.bin").write_bytes(b"unchanged")
850851
before = _directory_bytes(output) if existing_output else None
852+
package = mock.MagicMock()
853+
package.__iter__.return_value = iter(("model",))
851854
monkeypatch.setattr(
852855
"mobius.integrations.gguf.build_from_gguf",
853-
lambda *args, **kwargs: pytest.fail("build must not start"),
856+
lambda *args, **kwargs: package,
857+
)
858+
writer_calls = []
859+
monkeypatch.setattr(
860+
"mobius.integrations.gguf.write_gguf_runtime_package",
861+
lambda *args, **kwargs: writer_calls.append((args, kwargs)) or {},
854862
)
855863

856-
with pytest.raises(SystemExit, match="do not support standalone runtime packaging"):
857-
main(
858-
[
859-
"build-gguf",
860-
str(draft),
861-
"--target-config",
862-
str(target),
863-
"--runtime",
864-
"onnx-genai",
865-
"--output",
866-
str(output),
867-
]
868-
)
864+
main(
865+
[
866+
"build-gguf",
867+
str(draft),
868+
"--target-config",
869+
str(target),
870+
"--runtime",
871+
"onnx-genai",
872+
"--output",
873+
str(output),
874+
]
875+
)
869876

877+
assert writer_calls
870878
assert output.exists() is existing_output
871879
if existing_output:
872880
assert _directory_bytes(output) == before

0 commit comments

Comments
 (0)