Skip to content

Commit 3ce6560

Browse files
justinchubyCopilot
andcommitted
Validate real draft transitions and token bounds
Move mutation discriminators into proposal, cache, and rollback execution; replay the complete target history from empty cache; and bound final speculative rounds so sessions, counters, and caches never advance past max_new_tokens. Regenerate both immutable direct-ORT traces under the corrected semantics. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
1 parent cf642a2 commit 3ce6560

12 files changed

Lines changed: 329 additions & 73 deletions

‎docs/api/build_from_gguf.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ a proven graph: the API returns the model, emits one structured warning, omits a
3333
and persists the exact component disposition in `export_report.json`. Lossy qtype
3434
conversion remains in `quantization_report.json`; use `keep_quantized=False` for float.
3535

36-
For target-coupled DFlash/EAGLE3, use `build_draft_pair_from_gguf`, `write_draft_pair_package`, and `DraftPairRunner`; the package carries independent caches, required target bridges, and an MTP-aligned `draft_runtime_status.json`, while `runtime_unvalidated` warns about higher-level runtimes without gating direct ORT. CLI: `mobius build-gguf draft.gguf --target-gguf target.gguf --target-config target-config --output output`. The committed real-pair evidence also uses a test-only direct ORT coordinator that reads remapping metadata from the raw immutable draft GGUF and does not import `DraftPairRunner` or its transition helpers. Per-round DFlash and EAGLE3 traces bind proposal/remap tokens, proposal-logit hashes, accepted prefixes, correction tokens, target replay, target/draft cache states, final counters, and four mutation discriminators. Beam reorder is reported unsupported for the batch-size-one reference coordinator rather than inferred.
36+
For target-coupled DFlash/EAGLE3, use `build_draft_pair_from_gguf`, `write_draft_pair_package`, and `DraftPairRunner`; the package carries independent caches, required target bridges, and an MTP-aligned `draft_runtime_status.json`, while `runtime_unvalidated` warns about higher-level runtimes without gating direct ORT. CLI: `mobius build-gguf draft.gguf --target-gguf target.gguf --target-config target-config --output output`. The committed real-pair evidence also uses a test-only direct ORT coordinator that reads remapping metadata from the raw immutable draft GGUF and does not import `DraftPairRunner` or its transition helpers. Per-round DFlash and EAGLE3 traces bind proposal/remap tokens, proposal-logit hashes, accepted prefixes, correction tokens, target replay, target/draft cache states, final counters, and four execution-mutating discriminators. Target replay starts from an empty cache, and final speculative rounds never process past the requested token count. Beam reorder is reported unsupported for the batch-size-one reference coordinator rather than inferred.
3737

3838
Packed MatMulNBits storage may use a native op or portable nibble unpack,
3939
`DequantizeLinear`, and float `MatMul`; neither implies dense storage or a specific kernel.
@@ -100,7 +100,7 @@ network-free selection, budget, exclusions, and fail-closed candidate reasons ar
100100
| `hy3-iq1-m-mtp-runtime-unvalidated` | combined: `AngelSlim/Hy3-GGUF@31b453f4d9b647c74e4c4f5cba632eb512332c91/Hy3-IQ1_M-mtp.gguf` 91,756,066,272 B `c1fe984fef6f23fd9eb144e41ce6824e3941ed0a8b6b8f9f3e63da0c2a1320c2`<br>total 91,756,066,272 B; above 16 GiB<br>target-only discriminator: `Hy3-IQ1_M.gguf` 89,446,312,384 B `8c4195718dc24384a38de1c492f4bca7d21447789714d232b0a4d9cd0bb0c806` | `tencent/Hy3@a960ebc3da325ba167f069f76c41eb62c9280d22` `0c9daab42bff9cce1b6f058b10d7b730f76d583e583e28ad56e92b36373246f0` | `tencent/Hy3@a960ebc3da325ba167f069f76c41eb62c9280d22`; separately deferred; metadata `bff10dd3b99c0d4098b28fbeb1af46804184cefc2920895969b6f1ad2e548fa3` | status=runtime_unvalidated; graph/package hashes unclaimed; ORT 1.29.0 `CPUExecutionProvider`; ort-genai 0.15.2 source `ed5f4e87147731e5b07810f9f5c90103b3603cdf`; The smallest pinned public complete Hunyuan-V3 MTP artifact is 91,756,066,272 bytes, above the 17,179,869,184-byte bounded-artifact policy. The matching target-only discriminator is 89,446,312,384 bytes.<br>ORT GenAI 0.15.2 exposes no two-model draft/target binding, independent target/MTP cache orchestration, proposal rollback, or acceptance statistics.<br>The embedded tokenizer uses pre=hunyuan-dense, whose compiled llama.cpp behavior is not serialized in GGUF. This is separate from the real-artifact budget and downstream two-model runtime validation gaps.<br>Bounded headers prove that the -mtp file has 81 physical blocks with trailing block 80 while the target-only file has exactly 80 blocks. No payload values, standalone MTP forward, graph, or package is promoted as runtime evidence. |
101101
| `qwen3.6-27b-mtp-runtime-unvalidated` | combined: `localweights/Qwen3.6-27B-MTP-Q4_K_M-Q8nextn-GGUF@bdc8bc1ca4d45e1152d54c4e5f1389bc7bf6e439/Qwen3.6-27B-MTP-Q4_K_M-Q8nextn.gguf` 16,998,719,584 B `6cdb1aabb6ee711938df4192938b51228df9274f01c8d7a5ff404915ad342a7c`<br>total 16,998,719,584 B; within 16 GiB<br>split: `ggml-org/Qwen3.6-27B-GGUF@8a7ee08e8b9bfb857107ecc25a5599d2f38b76f8/Qwen3.6-27B-Q4_K_M.gguf` 19,095,766,304 B `65b753ea835627f7b511143c6ceb976525c7f21f5df8c664bc0a9c23d1c49921`, `ggml-org/Qwen3.6-27B-GGUF@8a7ee08e8b9bfb857107ecc25a5599d2f38b76f8/mtp-Qwen3.6-27B-Q4_0.gguf` 1,680,270,560 B `3d593f9e2788d59bb30d6024706b1efd5219fea466b6397c46159e3540937173`<br>total 20,776,036,864 B; above 16 GiB | `Qwen/Qwen3.6-27B@6a9e13bd6fc8f0983b9b99948120bc37f49c13e9` `69db4eb7196bc8190813231b3018ca05d8c2e3abc7b1af19d55c157af44a9d9c` | `Qwen/Qwen3.6-27B@6a9e13bd6fc8f0983b9b99948120bc37f49c13e9`; separately deferred; metadata `8d1070c727a7e6a03726687aa5746acece0255060a2a61a905c4c2285d353b68` | status=runtime_unvalidated; graph/package hashes unclaimed; ORT 1.29.0 `CPUExecutionProvider`; ort-genai 0.15.2 source `ed5f4e87147731e5b07810f9f5c90103b3603cdf`; reduced direct-ORT coordinator {'accepted': 1, 'proposal_steps': 51, 'rejected': 50, 'rollbacks': 50}; ORT GenAI 0.15.2 constructs one Model per Generator and exposes no two-model draft/target binding, independent MTP-cache orchestration, proposal accept/reject rollback, or observable acceptance statistics. Its pinned release matrix places speculative decoding on the roadmap; Generator.rewind_to only rewinds the single target generator and is not an MTP acceptance loop.<br>The embedded tokenizer uses pre=qwen35, whose compiled llama.cpp behavior is not serialized in GGUF. This tokenizer limitation is separate from downstream two-model runtime validation.<br>The under-budget combined artifact proves immutable header, physical trailing block, and layout identity only. No payload values, production tensor mapping, quantized storage execution, standalone MTP forward, graph, or package is promoted as runtime evidence. A separate tiny direct-ORT coordinator exercises target/MTP cache threading, accept/reject rollback, replay, reorder, and target-only equality without upgrading the real-artifact status.<br>The 2026-08-28 qualification transfer fetched 2,167,418,880 of 16,998,719,584 bytes before measured throughput implied a multi-hour transfer ahead of any 32 GiB-host build/runtime attempt. The partial payload was deleted; this operational deferral does not restrict export support. |
102102

103-
Pinned DFlash/EAGLE3 source, artifact, tokenizer, graph, and package hashes live in `testdata/evidence/gguf_draft_runtime_evidence.json`: `dflash`: 32 target-only-equal greedy tokens; 24/105 accepted; 4 multi-token rounds; 7 rollbacks; source cosine=0.999879, relative-L2=0.005406; `eagle3`: 32 target-only-equal greedy tokens; 21/44 accepted; 7 multi-token rounds; 10 rollbacks; source tensors exact. Both use separate target/draft caches; higher-level runtime=`runtime_unvalidated`.
103+
Pinned DFlash/EAGLE3 source, artifact, tokenizer, graph, and package hashes live in `testdata/evidence/gguf_draft_runtime_evidence.json`: `dflash`: 32 target-only-equal greedy tokens; 18/75 accepted; 3 multi-token rounds; 5 rollbacks; source cosine=0.999879, relative-L2=0.005406; `eagle3`: 32 target-only-equal greedy tokens; 20/43 accepted; 7 multi-token rounds; 10 rollbacks; source tensors exact. Both use separate target/draft caches; higher-level runtime=`runtime_unvalidated`.
104104

105105
Runtime support above is independent from tokenizer materialization support below.
106106
### Fail-closed runtime evidence

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4896,6 +4896,7 @@ def _dflash_postprocess(
48964896
vocab_size=len(metadata.get("tokenizer.ggml.tokens", ())),
48974897
target_layer_ids=target_layers,
48984898
block_size=int(metadata["dflash.block_size"]),
4899+
mask_token_id=int(metadata["tokenizer.ggml.mask_token_id"]),
48994900
num_target_layers=None,
49004901
draft_vocab_size=draft_vocab,
49014902
use_draft_lm_head="output.weight" in model.tensor_names,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,10 @@ def render_document() -> str:
766766
"and does not import `DraftPairRunner` or its transition helpers. Per-round",
767767
"DFlash and EAGLE3 traces bind proposal/remap tokens, proposal-logit hashes,",
768768
"accepted prefixes, correction tokens, target replay, target/draft cache",
769-
"states, final counters, and four mutation discriminators. Beam reorder is",
770-
"reported unsupported for the batch-size-one reference coordinator rather",
771-
"than inferred.",
769+
"states, final counters, and four execution-mutating discriminators. Target",
770+
"replay starts from an empty cache, and final speculative rounds never process",
771+
"past the requested token count. Beam reorder is reported unsupported for the",
772+
"batch-size-one reference coordinator rather than inferred.",
772773
)
773774
)
774775
return f"""# `build_from_gguf()`

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,20 @@ def _result(
567567
),
568568
)
569569

570+
def _finish_target_only(
571+
self,
572+
generated: list[int],
573+
target_cache: dict[str, np.ndarray],
574+
max_new_tokens: int,
575+
) -> dict[str, np.ndarray]:
576+
while len(generated) < max_new_tokens:
577+
outputs, target_cache = self._run_target(
578+
np.array([[generated[-1]]], dtype=np.int64),
579+
target_cache,
580+
)
581+
generated.append(int(np.argmax(outputs["logits"][0, -1])))
582+
return target_cache
583+
570584
def _generate_dflash(
571585
self,
572586
input_ids: np.ndarray,
@@ -588,6 +602,13 @@ def _generate_dflash(
588602
rollbacks: list[tuple[int, int, int, int]] = []
589603

590604
while len(generated) < max_new_tokens:
605+
if max_new_tokens - len(generated) < block_size:
606+
target_cache = self._finish_target_only(
607+
generated,
608+
target_cache,
609+
max_new_tokens,
610+
)
611+
break
591612
start = input_ids.shape[1] + len(generated) - 1
592613
block = np.array(
593614
[[generated[-1], *([mask_token_id] * (block_size - 1))]],
@@ -686,13 +707,22 @@ def _generate_eagle3(
686707
rollbacks: list[tuple[int, int, int, int]] = []
687708

688709
while len(generated) < max_new_tokens:
710+
remaining = max_new_tokens - len(generated)
711+
if remaining == 1:
712+
target_cache = self._finish_target_only(
713+
generated,
714+
target_cache,
715+
max_new_tokens,
716+
)
717+
break
718+
round_width = min(width, remaining - 1)
689719
start = input_ids.shape[1] + len(generated) - 1
690720
base_cache = draft_cache
691721
proposals: list[int] = []
692722
recycled = np.zeros((1, 1, hidden_size), dtype=draft_dtype)
693723
token = generated[-1]
694724
tentative = draft_cache
695-
for step in range(width):
725+
for step in range(round_width):
696726
features = (
697727
pending_features
698728
if step == 0
@@ -751,7 +781,7 @@ def _generate_eagle3(
751781
verified,
752782
slice(accepted, accepted + 1),
753783
)
754-
if accepted < width:
784+
if accepted < round_width:
755785
rollbacks.append(
756786
(
757787
next(iter(tentative.values())).shape[2],
@@ -760,7 +790,7 @@ def _generate_eagle3(
760790
new_length,
761791
)
762792
)
763-
rounds.append((accepted, width))
793+
rounds.append((accepted, round_width))
764794
return self._result(generated, max_new_tokens, rounds, rollbacks)
765795

766796
def _run_eagle_step(

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,27 @@ def test_draft_runtime_evidence_proves_real_speculative_work() -> None:
9696
}
9797
assert trace["reorder"]["supported"] is False
9898
assert record["independent_direct_ort_trace"]["mutation_discriminators"] == {
99-
"draft_mapping": "trace.counters.accepted",
100-
"proposal_order": "trace.rounds[0].proposal_tokens[0]",
101-
"cache_copy": "trace.rounds[0].draft.committed_sha256",
102-
"rollback": "trace.rounds[0].target.committed_length",
99+
"draft_mapping": "semantic.draft_mapping",
100+
"proposal_order": "semantic.proposal_order",
101+
"cache_copy": "semantic.draft_cache_replay",
102+
"rollback": "semantic.target_replay_tokens",
103103
}
104104
assert any(round_trace["accepted_prefix"] > 1 for round_trace in trace["rounds"])
105105
assert any(round_trace["accepted_prefix"] == 0 for round_trace in trace["rounds"])
106+
assert trace["final_target_cache"]["length"] == 47
107+
assert (
108+
sum(len(item["proposal_ids"]) for item in trace["rounds"])
109+
== result["proposed_tokens"]
110+
)
106111
for round_trace in trace["rounds"]:
107-
assert len(round_trace["proposal_ids"]) == result["draft_width"]
108-
assert len(round_trace["proposal_tokens"]) == result["draft_width"]
112+
assert 0 < len(round_trace["proposal_ids"]) <= result["draft_width"]
113+
assert len(round_trace["proposal_tokens"]) == len(round_trace["proposal_ids"])
109114
assert re.fullmatch(r"[0-9a-f]{64}", round_trace["proposal_logits_sha256"])
110115
assert round_trace["target"]["replay_tokens_match"] is True
116+
assert (
117+
round_trace["target"]["tentative_length"]
118+
<= trace["final_target_cache"]["length"]
119+
)
111120
assert (
112121
round_trace["target"]["before_length"]
113122
< (round_trace["target"]["tentative_length"])

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

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,138 @@ def run(self, names, feeds):
3838
return [self._outputs[name] for name in names]
3939

4040

41+
class _BoundedGenerationRunner(DraftPairRunner):
42+
def _run_target(self, input_ids, cache):
43+
tokens = np.asarray(input_ids, dtype=np.int64)
44+
past = next(iter(cache.values())).shape[2]
45+
total = past + tokens.shape[1]
46+
self.max_target_length = max(self.max_target_length, total)
47+
logits = np.full((1, tokens.shape[1], 64), -1.0, dtype=np.float32)
48+
for index, token in enumerate(tokens[0]):
49+
logits[0, index, (int(token) + 1) % 64] = 1.0
50+
present = {
51+
name.replace("past_key_values.", "present."): np.zeros(
52+
(1, 1, total, 4),
53+
dtype=np.float32,
54+
)
55+
for name in cache
56+
}
57+
self._target_forwards += 1
58+
return {"logits": logits, **present}, {
59+
name: present[name.replace("past_key_values.", "present.")] for name in cache
60+
}
61+
62+
def _target_features(self, outputs, selection=slice(None)):
63+
return np.zeros((1, outputs["logits"][:, selection].shape[1], 12), dtype=np.float32)
64+
65+
def _outputs(self, session, feeds):
66+
if session is self.target_embedding:
67+
return {
68+
"inputs_embeds": np.asarray(feeds["input_ids"], dtype=np.float32)[..., None]
69+
}
70+
return super()._outputs(session, feeds)
71+
72+
def _run_draft(self, feeds, cache):
73+
block_size = int(self.manifest["draft"]["block_size"])
74+
start = int(feeds["noise_embedding"][0, 0, 0])
75+
logits = np.full((1, block_size, 64), -1.0, dtype=np.float32)
76+
for index in range(1, block_size):
77+
logits[0, index, (start + index) % 64] = 1.0
78+
total = int(feeds["q_position_ids"][0, -1]) + 1
79+
present = {
80+
name.replace("past_key_values.", "present."): np.zeros(
81+
(1, 1, total, 4),
82+
dtype=np.float32,
83+
)
84+
for name in cache
85+
}
86+
self._draft_forwards += 1
87+
return {"draft_logits": logits, **present}, {
88+
name: present[name.replace("past_key_values.", "present.")] for name in cache
89+
}
90+
91+
def _run_eagle_step(self, input_ids, fused_hidden, recycled_hidden, cache):
92+
tokens = np.asarray(input_ids, dtype=np.int64)
93+
past = next(iter(cache.values())).shape[2]
94+
total = past + tokens.shape[1]
95+
logits = np.full((1, tokens.shape[1], 64), -1.0, dtype=np.float32)
96+
for index, token in enumerate(tokens[0]):
97+
logits[0, index, (int(token) + 1) % 64] = 1.0
98+
present = {
99+
name.replace("past_key_values.", "present."): np.zeros(
100+
(1, 1, total, 4),
101+
dtype=np.float32,
102+
)
103+
for name in cache
104+
}
105+
outputs = {
106+
"draft_logits": logits,
107+
"next_hidden": np.zeros((1, tokens.shape[1], 4), dtype=np.float32),
108+
**present,
109+
}
110+
self._draft_forwards += 1
111+
return outputs, {
112+
name: present[name.replace("past_key_values.", "present.")] for name in cache
113+
}
114+
115+
116+
def _bounded_runner(architecture: str) -> _BoundedGenerationRunner:
117+
cache_inputs = [
118+
("past_key_values.0.key", "tensor(float)", [1, 1, "past", 4]),
119+
("past_key_values.0.value", "tensor(float)", [1, 1, "past", 4]),
120+
]
121+
runner = object.__new__(_BoundedGenerationRunner)
122+
runner.target = _FakeSession(cache_inputs, {})
123+
runner.draft = _FakeSession(
124+
[
125+
("fused_hidden", "tensor(float)", [1, "sequence", 12]),
126+
("recycled_hidden", "tensor(float)", [1, "sequence", 4]),
127+
("q_position_ids", "tensor(int64)", [1, "sequence"]),
128+
*cache_inputs,
129+
],
130+
{},
131+
)
132+
runner.target_embedding = object()
133+
runner.target_lm_head = None
134+
runner.manifest = {
135+
"architecture": architecture,
136+
"draft": {"block_size": 16, "mask_token_id": 63, "hidden_size": 4},
137+
"draft_to_target": None,
138+
}
139+
runner._target_forwards = 0
140+
runner._draft_forwards = 0
141+
runner.max_target_length = 0
142+
return runner
143+
144+
145+
@pytest.mark.parametrize("max_new_tokens", range(1, 18))
146+
def test_dflash_final_tail_never_processes_beyond_requested_tokens(
147+
max_new_tokens: int,
148+
) -> None:
149+
runner = _bounded_runner("dflash")
150+
result = runner._generate_dflash(np.array([[0]], dtype=np.int64), max_new_tokens)
151+
152+
assert result.tokens == tuple(range(1, max_new_tokens + 1))
153+
assert runner.max_target_length == max_new_tokens
154+
assert result.stats.proposed_tokens == (15 if max_new_tokens == 17 else 0)
155+
156+
157+
@pytest.mark.parametrize("max_new_tokens", range(1, 7))
158+
def test_eagle_final_round_never_processes_beyond_requested_tokens(
159+
max_new_tokens: int,
160+
) -> None:
161+
runner = _bounded_runner("eagle3")
162+
result = runner._generate_eagle3(
163+
np.array([[0]], dtype=np.int64),
164+
max_new_tokens,
165+
width=4,
166+
)
167+
168+
assert result.tokens == tuple(range(1, max_new_tokens + 1))
169+
assert runner.max_target_length == max_new_tokens
170+
assert result.stats.proposed_tokens == max(0, max_new_tokens - 2)
171+
172+
41173
def test_eagle_step_uses_target_embedding_when_draft_borrows_it() -> None:
42174
embedding = _FakeSession(
43175
[("input_ids", "tensor(int64)", [1, "sequence"])],

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def _write_draft(
111111
target_hidden = target_hidden_size or hidden
112112
if architecture == "dflash":
113113
writer.add_uint32("dflash.block_size", 4)
114+
writer.add_uint32("tokenizer.ggml.mask_token_id", len(tokens) - 1)
114115
else:
115116
writer.add_uint32("eagle3.target_hidden_size", target_hidden)
116117
writer.add_bool("eagle3.norm_before_residual", False)

0 commit comments

Comments
 (0)