szl-specdecode 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 SZL Holdings
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,17 @@
1
+ SZL Holdings
2
+ Copyright 2026 SZL Holdings
3
+
4
+ This product includes software developed at SZL Holdings
5
+ (https://github.com/szl-holdings).
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
@@ -0,0 +1,81 @@
1
+ Metadata-Version: 2.4
2
+ Name: szl-specdecode
3
+ Version: 0.1.0
4
+ Summary: Original SZL draft-then-verify speculative decoding silhouette with SHA3 acceptance receipts. Not a rehost of Medusa/EAGLE/vLLM.
5
+ Author: Stephen P. Lutar Jr. / SZL Holdings
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://a-11-oy.com
8
+ Project-URL: Source, https://github.com/szl-holdings/szl-specdecode
9
+ Project-URL: Repository, https://github.com/szl-holdings/szl-specdecode
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ License-File: NOTICE
14
+ Provides-Extra: dev
15
+ Requires-Dist: pytest>=7.0; extra == "dev"
16
+ Dynamic: license-file
17
+
18
+ # szl-specdecode
19
+ <!-- szl:header v1 -->
20
+ <!-- Native identity: szl-brand orbit-v2. -->
21
+ <p>
22
+ <a href="https://github.com/szl-holdings">
23
+ <img src="https://raw.githubusercontent.com/szl-holdings/szl-brand/4309f6fce89179331b0b3ed8c99494e76c5be256/kit/logos/orbit-v2/suite/szl-icon-32.svg" alt="SZL Holdings — Orbit v2" width="32" height="32" />
24
+ </a>
25
+ </p>
26
+
27
+ **Control before action. Evidence after.**
28
+
29
+ [Product](https://a-11-oy.com) · [Proof](https://a11oy.net) · [GitHub organization](https://github.com/szl-holdings)
30
+ <!-- /szl:header -->
31
+
32
+ **Original SZL construction in the speculative-decoding category.** Inspired by Leviathan et al. Fast Inference from Transformers via Speculative Decoding https://arxiv.org/abs/2211.17192. **NOT a rehost** of Medusa, EAGLE, TensorRT-LLM speculative decoding, vLLM speculators, Modular MAX, Together, or Fireworks FireOptimizer.
33
+
34
+ Doctrine v11. **Λ = Conjecture 1 OPEN** (advisory; uniqueness unproven). MEASURED-or-null.
35
+
36
+ ## Status
37
+
38
+ | Thing | Label | Method / what-NOT |
39
+ |---|---|---|
40
+ | CPU draft-verify accept rule + SHA3 receipts | **import-LIVE** | `selfcheck()` deterministic; no model weights bundled |
41
+ | GPU / fused draft kernels | **UNAVAILABLE** | Not claimed |
42
+ | Speedup vs autoregressive | **null** | No tokens/s claim until MEASURED draft/target pair receipt |
43
+ | Energy | **UNAVAILABLE** | No meter attached |
44
+
45
+ ## Cookie
46
+
47
+ Thanks to the authors of speculative decoding, Medusa, EAGLE, NVIDIA TensorRT-LLM, vLLM, Modular MAX, Together, and Fireworks for productizing draft-then-verify. SZL builds a clean-room governance silhouette: acceptance ledgers with SHA3 receipts and honest nulls for speed and joules.
48
+
49
+ Credit **Stephen Lutar**.
50
+
51
+ ## Quick start
52
+
53
+ ```bash
54
+ pip install -e '.[dev]'
55
+ python -c 'from szl_specdecode import selfcheck; print(selfcheck())'
56
+ pytest -q
57
+ ```
58
+
59
+ ```python
60
+ from szl_specdecode import verify_draft
61
+
62
+ receipt = verify_draft(
63
+ prompt_token_ids=[1, 2, 3],
64
+ draft_token_ids=[10, 11, 12],
65
+ target_token_ids=[10, 11, 12, 99], # target continuation (+ bonus)
66
+ )
67
+ print(receipt.status, receipt.accepted_prefix_len, receipt.receipt_digest[:16])
68
+ ```
69
+
70
+ ## What this is / is not
71
+
72
+ - **Is:** lossless accept-prefix rule + append-only `AcceptanceLedger` + digest-bound `DraftVerifyReceipt`.
73
+ - **Is not:** a draft model, a target model, a CUDA kernel, a drop-in vLLM replacement, or a fabricated throughput number.
74
+
75
+ Wire real draft/target models at the call site; keep the receipt.
76
+
77
+ Estate on Hugging Face: models, datasets and Spaces are published under the [SZLHOLDINGS](https://huggingface.co/SZLHOLDINGS) org.
78
+
79
+ ## License
80
+
81
+ Apache-2.0 — see [LICENSE](LICENSE).
@@ -0,0 +1,64 @@
1
+ # szl-specdecode
2
+ <!-- szl:header v1 -->
3
+ <!-- Native identity: szl-brand orbit-v2. -->
4
+ <p>
5
+ <a href="https://github.com/szl-holdings">
6
+ <img src="https://raw.githubusercontent.com/szl-holdings/szl-brand/4309f6fce89179331b0b3ed8c99494e76c5be256/kit/logos/orbit-v2/suite/szl-icon-32.svg" alt="SZL Holdings — Orbit v2" width="32" height="32" />
7
+ </a>
8
+ </p>
9
+
10
+ **Control before action. Evidence after.**
11
+
12
+ [Product](https://a-11-oy.com) · [Proof](https://a11oy.net) · [GitHub organization](https://github.com/szl-holdings)
13
+ <!-- /szl:header -->
14
+
15
+ **Original SZL construction in the speculative-decoding category.** Inspired by Leviathan et al. Fast Inference from Transformers via Speculative Decoding https://arxiv.org/abs/2211.17192. **NOT a rehost** of Medusa, EAGLE, TensorRT-LLM speculative decoding, vLLM speculators, Modular MAX, Together, or Fireworks FireOptimizer.
16
+
17
+ Doctrine v11. **Λ = Conjecture 1 OPEN** (advisory; uniqueness unproven). MEASURED-or-null.
18
+
19
+ ## Status
20
+
21
+ | Thing | Label | Method / what-NOT |
22
+ |---|---|---|
23
+ | CPU draft-verify accept rule + SHA3 receipts | **import-LIVE** | `selfcheck()` deterministic; no model weights bundled |
24
+ | GPU / fused draft kernels | **UNAVAILABLE** | Not claimed |
25
+ | Speedup vs autoregressive | **null** | No tokens/s claim until MEASURED draft/target pair receipt |
26
+ | Energy | **UNAVAILABLE** | No meter attached |
27
+
28
+ ## Cookie
29
+
30
+ Thanks to the authors of speculative decoding, Medusa, EAGLE, NVIDIA TensorRT-LLM, vLLM, Modular MAX, Together, and Fireworks for productizing draft-then-verify. SZL builds a clean-room governance silhouette: acceptance ledgers with SHA3 receipts and honest nulls for speed and joules.
31
+
32
+ Credit **Stephen Lutar**.
33
+
34
+ ## Quick start
35
+
36
+ ```bash
37
+ pip install -e '.[dev]'
38
+ python -c 'from szl_specdecode import selfcheck; print(selfcheck())'
39
+ pytest -q
40
+ ```
41
+
42
+ ```python
43
+ from szl_specdecode import verify_draft
44
+
45
+ receipt = verify_draft(
46
+ prompt_token_ids=[1, 2, 3],
47
+ draft_token_ids=[10, 11, 12],
48
+ target_token_ids=[10, 11, 12, 99], # target continuation (+ bonus)
49
+ )
50
+ print(receipt.status, receipt.accepted_prefix_len, receipt.receipt_digest[:16])
51
+ ```
52
+
53
+ ## What this is / is not
54
+
55
+ - **Is:** lossless accept-prefix rule + append-only `AcceptanceLedger` + digest-bound `DraftVerifyReceipt`.
56
+ - **Is not:** a draft model, a target model, a CUDA kernel, a drop-in vLLM replacement, or a fabricated throughput number.
57
+
58
+ Wire real draft/target models at the call site; keep the receipt.
59
+
60
+ Estate on Hugging Face: models, datasets and Spaces are published under the [SZLHOLDINGS](https://huggingface.co/SZLHOLDINGS) org.
61
+
62
+ ## License
63
+
64
+ Apache-2.0 — see [LICENSE](LICENSE).
@@ -0,0 +1,25 @@
1
+ [project]
2
+ name = "szl-specdecode"
3
+ version = "0.1.0"
4
+ description = "Original SZL draft-then-verify speculative decoding silhouette with SHA3 acceptance receipts. Not a rehost of Medusa/EAGLE/vLLM."
5
+ readme = "README.md"
6
+ license = { text = "Apache-2.0" }
7
+ requires-python = ">=3.9"
8
+ authors = [
9
+ { name = "Stephen P. Lutar Jr. / SZL Holdings" },
10
+ ]
11
+ urls = { Homepage = "https://a-11-oy.com", Source = "https://github.com/szl-holdings/szl-specdecode", Repository = "https://github.com/szl-holdings/szl-specdecode" }
12
+ dependencies = []
13
+
14
+ [project.optional-dependencies]
15
+ dev = ["pytest>=7.0"]
16
+
17
+ [tool.pytest.ini_options]
18
+ testpaths = ["tests"]
19
+
20
+ [build-system]
21
+ requires = ["setuptools>=61"]
22
+ build-backend = "setuptools.build_meta"
23
+
24
+ [tool.setuptools.packages.find]
25
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,23 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 SZL Holdings
3
+ """SZL speculative decoding silhouette — draft-then-verify with receipts.
4
+
5
+ Inspired by Leviathan et al. speculative decoding (arXiv:2211.17192).
6
+ NOT a rehost of Medusa, EAGLE, TensorRT-LLM, vLLM, or Modular MAX.
7
+ CPU reference only. No speedup claim. No GPU kernel claim.
8
+ """
9
+
10
+ from ._verify import (
11
+ DraftVerifyReceipt,
12
+ AcceptanceLedger,
13
+ verify_draft,
14
+ selfcheck,
15
+ )
16
+
17
+ __all__ = [
18
+ "DraftVerifyReceipt",
19
+ "AcceptanceLedger",
20
+ "verify_draft",
21
+ "selfcheck",
22
+ ]
23
+ __version__ = "0.1.0"
@@ -0,0 +1,201 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 SZL Holdings
3
+ """Lossless draft-then-verify acceptance with SHA3 receipts.
4
+
5
+ Math silhouette (Leviathan et al.): a draft model proposes K tokens;
6
+ the target model scores them in one parallel forward; the longest
7
+ prefix that matches the target's greedy (or sampled) continuation is
8
+ accepted; one bonus target token may be emitted. Acceptance is lossless
9
+ w.r.t. the target distribution when the verify rule matches the target
10
+ sampler.
11
+
12
+ This module implements the *governance* cut: every accept/reject step
13
+ emits a digest-bound receipt. It does not ship draft/target weights.
14
+ """
15
+ from __future__ import annotations
16
+
17
+ from dataclasses import dataclass, field
18
+ from hashlib import sha3_256
19
+ from typing import Iterable, List, Optional, Sequence, Tuple
20
+ import json
21
+
22
+ DOMAIN = b"szl.specdecode.draft-verify.v1"
23
+
24
+
25
+ def _canon_ints(xs: Sequence[int]) -> bytes:
26
+ if not all(isinstance(x, int) and not isinstance(x, bool) for x in xs):
27
+ raise TypeError("token ids must be non-bool ints")
28
+ return b",".join(str(int(x)).encode("ascii") for x in xs)
29
+
30
+
31
+ def _digest(*parts: bytes) -> str:
32
+ h = sha3_256()
33
+ h.update(DOMAIN)
34
+ for p in parts:
35
+ h.update(b"\x1f")
36
+ h.update(p)
37
+ return h.hexdigest()
38
+
39
+
40
+ @dataclass(frozen=True)
41
+ class DraftVerifyReceipt:
42
+ """One draft-verify round receipt (MEASURED structure, not a GPU claim)."""
43
+
44
+ prompt_digest: str
45
+ draft_tokens: Tuple[int, ...]
46
+ target_tokens: Tuple[int, ...]
47
+ accepted_prefix_len: int
48
+ bonus_token: Optional[int]
49
+ receipt_digest: str
50
+ status: str # ACCEPTED_PARTIAL | ACCEPTED_FULL | REJECTED_ALL
51
+
52
+ def to_dict(self) -> dict:
53
+ return {
54
+ "prompt_digest": self.prompt_digest,
55
+ "draft_tokens": list(self.draft_tokens),
56
+ "target_tokens": list(self.target_tokens),
57
+ "accepted_prefix_len": self.accepted_prefix_len,
58
+ "bonus_token": self.bonus_token,
59
+ "receipt_digest": self.receipt_digest,
60
+ "status": self.status,
61
+ "domain": DOMAIN.decode("ascii"),
62
+ "energy": "UNAVAILABLE",
63
+ "speedup_claim": None,
64
+ "credit": "Stephen Lutar",
65
+ "lambda": "Conjecture 1 advisory",
66
+ }
67
+
68
+
69
+ @dataclass
70
+ class AcceptanceLedger:
71
+ """Append-only ledger of draft-verify receipts."""
72
+
73
+ rounds: List[DraftVerifyReceipt] = field(default_factory=list)
74
+
75
+ def append(self, receipt: DraftVerifyReceipt) -> None:
76
+ self.rounds.append(receipt)
77
+
78
+ @property
79
+ def mean_accept_len(self) -> Optional[float]:
80
+ if not self.rounds:
81
+ return None
82
+ return sum(r.accepted_prefix_len for r in self.rounds) / len(self.rounds)
83
+
84
+ def chain_digest(self) -> str:
85
+ payload = json.dumps([r.to_dict() for r in self.rounds], sort_keys=True, separators=(",", ":"))
86
+ return _digest(b"ledger", payload.encode("utf-8"))
87
+
88
+
89
+ def _require_int_tokens(xs: Sequence[int], *, name: str) -> Tuple[int, ...]:
90
+ out = []
91
+ for i, x in enumerate(xs):
92
+ if isinstance(x, bool) or not isinstance(x, int):
93
+ raise TypeError(f"{name}[{i}] must be a non-bool int, got {type(x).__name__}")
94
+ out.append(x)
95
+ return tuple(out)
96
+
97
+
98
+ def verify_draft(
99
+ prompt_token_ids: Sequence[int],
100
+ draft_token_ids: Sequence[int],
101
+ target_token_ids: Sequence[int],
102
+ *,
103
+ emit_bonus: bool = True,
104
+ ) -> DraftVerifyReceipt:
105
+ """Accept the longest draft prefix that equals the target continuation.
106
+
107
+ ``target_token_ids`` must be the target model's continuation for the
108
+ same prompt, length >= len(draft) (and +1 if emit_bonus for the bonus
109
+ token after the accepted prefix). This is a CPU reference for the
110
+ lossless accept rule — callers supply both sequences from their models.
111
+ """
112
+ prompt = _require_int_tokens(prompt_token_ids, name="prompt_token_ids")
113
+ draft = _require_int_tokens(draft_token_ids, name="draft_token_ids")
114
+ target = _require_int_tokens(target_token_ids, name="target_token_ids")
115
+
116
+ if not draft:
117
+ raise ValueError("draft_token_ids must be non-empty")
118
+ if len(target) < len(draft):
119
+ raise ValueError("target_token_ids must cover the draft length")
120
+
121
+ accepted = 0
122
+ for i, tok in enumerate(draft):
123
+ if target[i] == tok:
124
+ accepted += 1
125
+ else:
126
+ break
127
+
128
+ bonus: Optional[int] = None
129
+ if emit_bonus:
130
+ # Leviathan: after accepting γ tokens, take the next target token as bonus.
131
+ # If rejected at position j, the target token at j is the recovery token
132
+ # (counted as bonus here for ledger uniformity).
133
+ bonus_index = accepted if accepted < len(draft) else accepted
134
+ if bonus_index < len(target):
135
+ bonus = target[bonus_index]
136
+ elif accepted == len(draft) and len(target) > len(draft):
137
+ bonus = target[len(draft)]
138
+
139
+ if accepted == 0:
140
+ status = "REJECTED_ALL"
141
+ elif accepted == len(draft):
142
+ status = "ACCEPTED_FULL"
143
+ else:
144
+ status = "ACCEPTED_PARTIAL"
145
+
146
+ prompt_digest = _digest(b"prompt", _canon_ints(prompt))
147
+ receipt_digest = _digest(
148
+ b"receipt",
149
+ prompt_digest.encode("ascii"),
150
+ _canon_ints(draft),
151
+ _canon_ints(target[: max(len(draft), (accepted + 1))]),
152
+ str(accepted).encode("ascii"),
153
+ b"" if bonus is None else str(bonus).encode("ascii"),
154
+ status.encode("ascii"),
155
+ )
156
+
157
+ return DraftVerifyReceipt(
158
+ prompt_digest=prompt_digest,
159
+ draft_tokens=draft,
160
+ target_tokens=target,
161
+ accepted_prefix_len=accepted,
162
+ bonus_token=bonus,
163
+ receipt_digest=receipt_digest,
164
+ status=status,
165
+ )
166
+
167
+
168
+ def selfcheck() -> dict:
169
+ """Deterministic CPU self-check. No GPU. No speedup claim."""
170
+ prompt = [1, 2, 3]
171
+ # full accept
172
+ r1 = verify_draft(prompt, [10, 11, 12], [10, 11, 12, 99])
173
+ assert r1.status == "ACCEPTED_FULL" and r1.accepted_prefix_len == 3
174
+ assert r1.bonus_token == 99
175
+ # partial
176
+ r2 = verify_draft(prompt, [10, 11, 12], [10, 11, 77, 88])
177
+ assert r2.status == "ACCEPTED_PARTIAL" and r2.accepted_prefix_len == 2
178
+ assert r2.bonus_token == 77
179
+ # reject all
180
+ r3 = verify_draft(prompt, [10, 11], [20, 21, 22])
181
+ assert r3.status == "REJECTED_ALL" and r3.accepted_prefix_len == 0
182
+ assert r3.bonus_token == 20
183
+ # digests stable
184
+ r1b = verify_draft(prompt, [10, 11, 12], [10, 11, 12, 99])
185
+ assert r1.receipt_digest == r1b.receipt_digest
186
+ ledger = AcceptanceLedger()
187
+ for r in (r1, r2, r3):
188
+ ledger.append(r)
189
+ return {
190
+ "ok": True,
191
+ "rounds": 3,
192
+ "mean_accept_len": ledger.mean_accept_len,
193
+ "chain_digest": ledger.chain_digest(),
194
+ "path": "cpu_reference",
195
+ "gpu_kernel": "UNAVAILABLE",
196
+ "speedup_claim": None,
197
+ "energy": "UNAVAILABLE",
198
+ "credit": "Stephen Lutar",
199
+ "doctrine": "v11",
200
+ "lambda": "Conjecture 1 advisory",
201
+ }
@@ -0,0 +1,81 @@
1
+ Metadata-Version: 2.4
2
+ Name: szl-specdecode
3
+ Version: 0.1.0
4
+ Summary: Original SZL draft-then-verify speculative decoding silhouette with SHA3 acceptance receipts. Not a rehost of Medusa/EAGLE/vLLM.
5
+ Author: Stephen P. Lutar Jr. / SZL Holdings
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://a-11-oy.com
8
+ Project-URL: Source, https://github.com/szl-holdings/szl-specdecode
9
+ Project-URL: Repository, https://github.com/szl-holdings/szl-specdecode
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ License-File: NOTICE
14
+ Provides-Extra: dev
15
+ Requires-Dist: pytest>=7.0; extra == "dev"
16
+ Dynamic: license-file
17
+
18
+ # szl-specdecode
19
+ <!-- szl:header v1 -->
20
+ <!-- Native identity: szl-brand orbit-v2. -->
21
+ <p>
22
+ <a href="https://github.com/szl-holdings">
23
+ <img src="https://raw.githubusercontent.com/szl-holdings/szl-brand/4309f6fce89179331b0b3ed8c99494e76c5be256/kit/logos/orbit-v2/suite/szl-icon-32.svg" alt="SZL Holdings — Orbit v2" width="32" height="32" />
24
+ </a>
25
+ </p>
26
+
27
+ **Control before action. Evidence after.**
28
+
29
+ [Product](https://a-11-oy.com) · [Proof](https://a11oy.net) · [GitHub organization](https://github.com/szl-holdings)
30
+ <!-- /szl:header -->
31
+
32
+ **Original SZL construction in the speculative-decoding category.** Inspired by Leviathan et al. Fast Inference from Transformers via Speculative Decoding https://arxiv.org/abs/2211.17192. **NOT a rehost** of Medusa, EAGLE, TensorRT-LLM speculative decoding, vLLM speculators, Modular MAX, Together, or Fireworks FireOptimizer.
33
+
34
+ Doctrine v11. **Λ = Conjecture 1 OPEN** (advisory; uniqueness unproven). MEASURED-or-null.
35
+
36
+ ## Status
37
+
38
+ | Thing | Label | Method / what-NOT |
39
+ |---|---|---|
40
+ | CPU draft-verify accept rule + SHA3 receipts | **import-LIVE** | `selfcheck()` deterministic; no model weights bundled |
41
+ | GPU / fused draft kernels | **UNAVAILABLE** | Not claimed |
42
+ | Speedup vs autoregressive | **null** | No tokens/s claim until MEASURED draft/target pair receipt |
43
+ | Energy | **UNAVAILABLE** | No meter attached |
44
+
45
+ ## Cookie
46
+
47
+ Thanks to the authors of speculative decoding, Medusa, EAGLE, NVIDIA TensorRT-LLM, vLLM, Modular MAX, Together, and Fireworks for productizing draft-then-verify. SZL builds a clean-room governance silhouette: acceptance ledgers with SHA3 receipts and honest nulls for speed and joules.
48
+
49
+ Credit **Stephen Lutar**.
50
+
51
+ ## Quick start
52
+
53
+ ```bash
54
+ pip install -e '.[dev]'
55
+ python -c 'from szl_specdecode import selfcheck; print(selfcheck())'
56
+ pytest -q
57
+ ```
58
+
59
+ ```python
60
+ from szl_specdecode import verify_draft
61
+
62
+ receipt = verify_draft(
63
+ prompt_token_ids=[1, 2, 3],
64
+ draft_token_ids=[10, 11, 12],
65
+ target_token_ids=[10, 11, 12, 99], # target continuation (+ bonus)
66
+ )
67
+ print(receipt.status, receipt.accepted_prefix_len, receipt.receipt_digest[:16])
68
+ ```
69
+
70
+ ## What this is / is not
71
+
72
+ - **Is:** lossless accept-prefix rule + append-only `AcceptanceLedger` + digest-bound `DraftVerifyReceipt`.
73
+ - **Is not:** a draft model, a target model, a CUDA kernel, a drop-in vLLM replacement, or a fabricated throughput number.
74
+
75
+ Wire real draft/target models at the call site; keep the receipt.
76
+
77
+ Estate on Hugging Face: models, datasets and Spaces are published under the [SZLHOLDINGS](https://huggingface.co/SZLHOLDINGS) org.
78
+
79
+ ## License
80
+
81
+ Apache-2.0 — see [LICENSE](LICENSE).
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ NOTICE
3
+ README.md
4
+ pyproject.toml
5
+ src/szl_specdecode/__init__.py
6
+ src/szl_specdecode/_verify.py
7
+ src/szl_specdecode.egg-info/PKG-INFO
8
+ src/szl_specdecode.egg-info/SOURCES.txt
9
+ src/szl_specdecode.egg-info/dependency_links.txt
10
+ src/szl_specdecode.egg-info/requires.txt
11
+ src/szl_specdecode.egg-info/top_level.txt
12
+ tests/test_honesty.py
13
+ tests/test_verify.py
@@ -0,0 +1,3 @@
1
+
2
+ [dev]
3
+ pytest>=7.0
@@ -0,0 +1 @@
1
+ szl_specdecode
@@ -0,0 +1,29 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 SZL Holdings
3
+ """Honesty labels. Not a Λ proof. Not a speedup claim."""
4
+ from pathlib import Path
5
+
6
+ ROOT = Path(__file__).resolve().parents[1]
7
+ README = (ROOT / "README.md").read_text(encoding="utf-8")
8
+
9
+ REQUIRED = [
10
+ "Doctrine v11",
11
+ "Conjecture 1",
12
+ "Original SZL construction",
13
+ "https://arxiv.org/abs/2211.17192",
14
+ "NOT a rehost",
15
+ "UNAVAILABLE",
16
+ "Stephen Lutar",
17
+ "MEASURED-or-null",
18
+ ]
19
+
20
+
21
+ def test_readme_honesty_phrases():
22
+ for phrase in REQUIRED:
23
+ assert phrase in README, f"missing honesty phrase: {phrase}"
24
+
25
+
26
+ def test_no_fabricated_speedup():
27
+ lower = README.lower()
28
+ assert "tokens/s MEASURED" not in README
29
+ assert "x faster than vllm" not in lower
@@ -0,0 +1,40 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 SZL Holdings
3
+ from szl_specdecode import verify_draft, selfcheck, AcceptanceLedger
4
+
5
+
6
+ def test_full_accept_with_bonus():
7
+ r = verify_draft([1], [5, 6], [5, 6, 7])
8
+ assert r.status == "ACCEPTED_FULL"
9
+ assert r.accepted_prefix_len == 2
10
+ assert r.bonus_token == 7
11
+ assert len(r.receipt_digest) == 64
12
+
13
+
14
+ def test_partial_and_reject():
15
+ assert verify_draft([1], [5, 6, 7], [5, 9, 9]).accepted_prefix_len == 1
16
+ assert verify_draft([1], [5, 6], [8, 9]).status == "REJECTED_ALL"
17
+
18
+
19
+ def test_rejects_non_int_tokens():
20
+ try:
21
+ verify_draft([1.0], [2], [2]) # type: ignore[list-item]
22
+ assert False, "expected TypeError"
23
+ except TypeError:
24
+ pass
25
+
26
+
27
+ def test_selfcheck():
28
+ out = selfcheck()
29
+ assert out["ok"] is True
30
+ assert out["gpu_kernel"] == "UNAVAILABLE"
31
+ assert out["speedup_claim"] is None
32
+ assert out["energy"] == "UNAVAILABLE"
33
+
34
+
35
+ def test_ledger_chain_stable():
36
+ led = AcceptanceLedger()
37
+ led.append(verify_draft([1], [2], [2, 3]))
38
+ a = led.chain_digest()
39
+ b = led.chain_digest()
40
+ assert a == b