governed-inference-meter 0.3.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.
- governed_inference_meter-0.3.0/LICENSE +202 -0
- governed_inference_meter-0.3.0/PKG-INFO +405 -0
- governed_inference_meter-0.3.0/README.md +376 -0
- governed_inference_meter-0.3.0/build/torch-universal/governed_inference_meter.egg-info/PKG-INFO +405 -0
- governed_inference_meter-0.3.0/build/torch-universal/governed_inference_meter.egg-info/SOURCES.txt +14 -0
- governed_inference_meter-0.3.0/build/torch-universal/governed_inference_meter.egg-info/dependency_links.txt +1 -0
- governed_inference_meter-0.3.0/build/torch-universal/governed_inference_meter.egg-info/requires.txt +12 -0
- governed_inference_meter-0.3.0/build/torch-universal/governed_inference_meter.egg-info/top_level.txt +1 -0
- governed_inference_meter-0.3.0/pyproject.toml +62 -0
- governed_inference_meter-0.3.0/setup.cfg +4 -0
- governed_inference_meter-0.3.0/tests/test_attest.py +119 -0
- governed_inference_meter-0.3.0/tests/test_chain_hardening.py +118 -0
- governed_inference_meter-0.3.0/tests/test_hf_mirror_contract.py +518 -0
- governed_inference_meter-0.3.0/tests/test_meter.py +103 -0
- governed_inference_meter-0.3.0/tests/test_signing.py +57 -0
- governed_inference_meter-0.3.0/tests/test_spine.py +215 -0
|
@@ -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 [yyyy] [name of copyright owner]
|
|
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,405 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: governed-inference-meter
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Energy-metered, governed inference receipts: NVML joules, tokens/joule, an advisory policy gate, and a tamper-evident SHA-256 hash-chained receipt. Honest by design — MEASURED only with NVML.
|
|
5
|
+
Author-email: Stephen Lutar <stephenlutar2@gmail.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://a-11-oy.com
|
|
8
|
+
Project-URL: Repository, https://github.com/szl-holdings/governed-inference-meter
|
|
9
|
+
Project-URL: Hugging Face, https://huggingface.co/SZLHOLDINGS/governed-inference-meter
|
|
10
|
+
Project-URL: Successor, https://github.com/szl-holdings/szl-energy-attest
|
|
11
|
+
Keywords: kernel,inference,energy,nvml,governance,provenance,audit,receipts,tokens-per-joule,sovereign-ai
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering
|
|
17
|
+
Requires-Python: >=3.8
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Provides-Extra: gpu
|
|
21
|
+
Requires-Dist: pynvml>=11.0.0; extra == "gpu"
|
|
22
|
+
Provides-Extra: torch
|
|
23
|
+
Requires-Dist: torch; extra == "torch"
|
|
24
|
+
Provides-Extra: sign
|
|
25
|
+
Requires-Dist: szl-receipt>=0.2.0; extra == "sign"
|
|
26
|
+
Provides-Extra: test
|
|
27
|
+
Requires-Dist: pytest; extra == "test"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
license: apache-2.0
|
|
32
|
+
library_name: kernels
|
|
33
|
+
tags:
|
|
34
|
+
- kernel
|
|
35
|
+
- inference
|
|
36
|
+
- energy
|
|
37
|
+
- nvml
|
|
38
|
+
- governance
|
|
39
|
+
- provenance
|
|
40
|
+
- audit
|
|
41
|
+
- receipts
|
|
42
|
+
- tokens-per-joule
|
|
43
|
+
- sovereign-ai
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
> **SZL Holdings** · Doctrine v11 · Λ = Conjecture 1 (advisory, never "green"/theorem) · canonical [a-11-oy.com](https://a-11-oy.com)
|
|
47
|
+
|
|
48
|
+
# governed-inference-meter
|
|
49
|
+
|
|
50
|
+
> # ⚠️ DEPRECATED — consolidated into [`szl-energy-attest`](https://github.com/szl-holdings/szl-energy-attest)
|
|
51
|
+
>
|
|
52
|
+
> **This repository is deprecated.** Its live inference meter and meter-specific
|
|
53
|
+
> attestation, hardened receipt-chain, PCGI spine, and signing-facing compatibility
|
|
54
|
+
> APIs were folded into the canonical
|
|
55
|
+
> [`szl_energy_attest.inference_meter`](https://github.com/szl-holdings/szl-energy-attest/tree/4d8d105c3d5ea67b5eb25826e8a2a35ca35f4043/szl_energy_attest/inference_meter)
|
|
56
|
+
> package in verified merge
|
|
57
|
+
> [`4d8d105c3d5ea67b5eb25826e8a2a35ca35f4043`](https://github.com/szl-holdings/szl-energy-attest/commit/4d8d105c3d5ea67b5eb25826e8a2a35ca35f4043).
|
|
58
|
+
>
|
|
59
|
+
> Three legacy modules (`_energy.py`, `_policy.py`, `_receipt.py`) are exact
|
|
60
|
+
> hash-preserving copies; `_attest.py` and `_spine.py` carry only bounded
|
|
61
|
+
> package/import and install-guidance rewrites. The immutable
|
|
62
|
+
> [`MIGRATION_PROVENANCE.json`](https://github.com/szl-holdings/szl-energy-attest/blob/4d8d105c3d5ea67b5eb25826e8a2a35ca35f4043/MIGRATION_PROVENANCE.json)
|
|
63
|
+
> records every source and destination digest, and the
|
|
64
|
+
> [migration regressions](https://github.com/szl-holdings/szl-energy-attest/blob/4d8d105c3d5ea67b5eb25826e8a2a35ca35f4043/tests/test_inference_meter_migration.py)
|
|
65
|
+
> verify that boundary.
|
|
66
|
+
>
|
|
67
|
+
> **Boundary:** the successor's root energy receipt remains a different schema;
|
|
68
|
+
> compatibility does not imply schema equality, a configured signing key, or a
|
|
69
|
+
> signed receipt. This legacy repository and its Hugging Face artifact remain
|
|
70
|
+
> readable for provenance and rollback, but are not the target for new
|
|
71
|
+
> integrations. Archiving requires a separate owner decision after pointer and
|
|
72
|
+
> inbound-link gates are evidenced. See [`DEPRECATED.md`](./DEPRECATED.md).
|
|
73
|
+
> Λ remains **Conjecture 1 (advisory, uniqueness OPEN)** — never upgraded to proven.
|
|
74
|
+
|
|
75
|
+
## Artifact truth card
|
|
76
|
+
|
|
77
|
+
| Field | Truthful classification |
|
|
78
|
+
|---|---|
|
|
79
|
+
| Lifecycle | **Deprecated compatibility artifact.** Retained for provenance and rollback; new integrations belong in `szl-energy-attest`. |
|
|
80
|
+
| Artifact type | **Executable software**, not trained weights, not a model benchmark, and not a formal proof. |
|
|
81
|
+
| Hub role | Legacy Kernel Hub distribution/mirror. Its model-style listing is packaging, not a trained-model claim. |
|
|
82
|
+
| Evidence | Source, CPU-capable checks, receipt verification, migration digests, and an immutable loading contract in the successor repository. |
|
|
83
|
+
| Measurement | `MEASURED` only with a fresh supported NVML reading. Unmeasured base meter/attestation receipts retain null joule fields; canonical spine receipts instead emit `energy.joules = "UNAVAILABLE"`. |
|
|
84
|
+
| Limits | Hashes show internal consistency, not authorship; policies are host-enforced; this repository receives no new feature work. |
|
|
85
|
+
|
|
86
|
+
**Investor value.** The retained artifact preserves migration evidence and a
|
|
87
|
+
stable audit trail without presenting a deprecated package as the current
|
|
88
|
+
product lane.
|
|
89
|
+
|
|
90
|
+
**Developer/evaluator path.** Start with the
|
|
91
|
+
[`szl-energy-attest`](https://github.com/szl-holdings/szl-energy-attest)
|
|
92
|
+
successor. Evaluate this repository only when reproducing a legacy integration,
|
|
93
|
+
and pin the immutable Hub revision declared by the successor's loading contract.
|
|
94
|
+
|
|
95
|
+
**Energy-metered, governed inference receipts.** A lightweight, dependency-light
|
|
96
|
+
Python utility (and Hugging Face *universal* kernel) that wraps any inference
|
|
97
|
+
call and emits a **governed, energy-metered, tamper-evident receipt**:
|
|
98
|
+
|
|
99
|
+
- **measures GPU energy** via NVIDIA NVML (power/energy readback) integrated
|
|
100
|
+
over wall-time → **joules**,
|
|
101
|
+
- computes **tokens-per-joule**,
|
|
102
|
+
- runs a pluggable, **advisory policy gate** (allow/deny; defaults to allow),
|
|
103
|
+
- and emits a **SHA-256 hash-chained JSON receipt** so a sequence of calls is
|
|
104
|
+
independently auditable.
|
|
105
|
+
|
|
106
|
+
It is the energy + governance counterpart to
|
|
107
|
+
[`SZLHOLDINGS/szl-governed-norm`](https://huggingface.co/SZLHOLDINGS/szl-governed-norm)
|
|
108
|
+
— provenance at the inference boundary, in the spirit of the
|
|
109
|
+
[a11oy](https://a-11-oy.com) governed-AI platform: **receipts, not capability
|
|
110
|
+
claims.**
|
|
111
|
+
|
|
112
|
+
> **Why this remains available.** Existing integrations may still need to
|
|
113
|
+
> reproduce the legacy API and receipt behavior. The repository is retained for
|
|
114
|
+
> that bounded purpose; it makes no ecosystem-wide novelty claim.
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Honest scope (read this first)
|
|
119
|
+
|
|
120
|
+
This project follows a strict honesty doctrine. **Λ (the governance trust
|
|
121
|
+
quantity) is Conjecture 1 — advisory, not a theorem. Trust is never 100%.**
|
|
122
|
+
|
|
123
|
+
- **MEASURED only with NVML.** Energy is real **only** when NVML is present and
|
|
124
|
+
grants power/energy readback. Without it the receipt is labeled
|
|
125
|
+
`mode="unmeasured"` and `joules` / `tokens_per_joule` are `null`. **We never
|
|
126
|
+
fabricate a joule figure.**
|
|
127
|
+
- **Board-level power.** NVML reports whole-board power (compute die + memory +
|
|
128
|
+
losses). We report what the hardware reports and say so. No modeling, no
|
|
129
|
+
scaling factors.
|
|
130
|
+
- **The policy gate is advisory and host-enforced.** It records an allow/deny
|
|
131
|
+
decision into the receipt. It does **not**, and cannot, enforce anything by
|
|
132
|
+
itself — your host must actually skip a denied call. The bundled `meter()`
|
|
133
|
+
wrapper *does* fail-safe (it will not execute a denied call), but downstream
|
|
134
|
+
enforcement is still your responsibility.
|
|
135
|
+
- **The receipt digest is an integrity fingerprint, not a signature.** It is a
|
|
136
|
+
SHA-256 over the canonical record body and makes tampering *evident*. It does
|
|
137
|
+
**not** prove authorship. Cryptographic signing (e.g. DSSE/Sigstore) is a
|
|
138
|
+
separate, out-of-band concern, intentionally not done here.
|
|
139
|
+
- **This is a metering + receipt utility, not a safety guarantee.**
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Install / load
|
|
144
|
+
|
|
145
|
+
**Recommended successor:**
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
python -m pip install "git+https://github.com/szl-holdings/szl-energy-attest.git"
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Legacy compatibility load** (review the immutable contract first):
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
python -m pip install kernels
|
|
155
|
+
# Optional: real GPU energy measurement requires NVML bindings.
|
|
156
|
+
python -m pip install pynvml
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
from kernels import get_kernel
|
|
161
|
+
|
|
162
|
+
gim = get_kernel(
|
|
163
|
+
"SZLHOLDINGS/governed-inference-meter",
|
|
164
|
+
revision="6d546bfc6591b44ae5eb57d1209678454e52a3f5",
|
|
165
|
+
trust_remote_code=True,
|
|
166
|
+
)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
The pin is the retained compatibility revision declared by the successor
|
|
170
|
+
repository. Advance it only through the authorized publication and readback
|
|
171
|
+
process.
|
|
172
|
+
|
|
173
|
+
## Usage
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
from kernels import get_kernel
|
|
177
|
+
|
|
178
|
+
gim = get_kernel(
|
|
179
|
+
"SZLHOLDINGS/governed-inference-meter",
|
|
180
|
+
revision="6d546bfc6591b44ae5eb57d1209678454e52a3f5",
|
|
181
|
+
trust_remote_code=True,
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
print(gim.__version__)
|
|
185
|
+
print(gim.capability_report()) # what energy measurement is possible here
|
|
186
|
+
|
|
187
|
+
# Wrap ANY inference callable. You tell the meter the token counts.
|
|
188
|
+
def run(prompt):
|
|
189
|
+
# ... your real model.generate(...) call here ...
|
|
190
|
+
return "the model's response text"
|
|
191
|
+
|
|
192
|
+
receipt, output = gim.meter(
|
|
193
|
+
run, args=("hello",),
|
|
194
|
+
model="my-llm-7b",
|
|
195
|
+
tokens_in=2, tokens_out=7,
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
print(receipt["mode"]) # 'measured-energy' | 'measured-power-integral' | 'unmeasured'
|
|
199
|
+
print(receipt["joules"]) # float, or None when unmeasured
|
|
200
|
+
print(receipt["tokens_per_joule"]) # float, or None when unmeasured
|
|
201
|
+
print(receipt["policy_decision"]) # 'allow' | 'deny'
|
|
202
|
+
print(receipt["digest"]) # SHA-256 over the canonical record body
|
|
203
|
+
print(gim.receipt_verify()) # (ok, depth, first_break_seq) over the chain
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### A custom policy gate (advisory)
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
def my_gate(ctx):
|
|
210
|
+
# ctx has model, tokens_in, tokens_out, args, kwargs, ts
|
|
211
|
+
if ctx["tokens_in"] > 8192:
|
|
212
|
+
return ("deny", "prompt exceeds governed token budget")
|
|
213
|
+
return ("allow", "within budget")
|
|
214
|
+
|
|
215
|
+
receipt, output = gim.meter(run, args=("hi",), model="m",
|
|
216
|
+
tokens_in=2, tokens_out=7, policy=my_gate)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
A gate may return a `PolicyResult`, a `(decision, reason)` tuple, a bool, or a
|
|
220
|
+
string. **It runs fail-closed**: if your gate raises, the call is denied with
|
|
221
|
+
the exception text as the reason — a buggy policy can never silently allow.
|
|
222
|
+
|
|
223
|
+
### Per-request chain (no global-state contention)
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
chain = gim.ReceiptChain()
|
|
227
|
+
gim.meter(run, args=("a",), model="m", tokens_in=1, tokens_out=4, chain=chain)
|
|
228
|
+
gim.meter(run, args=("b",), model="m", tokens_in=1, tokens_out=6, chain=chain)
|
|
229
|
+
print(chain.verify()) # tamper-evident over YOUR chain only
|
|
230
|
+
print(chain.to_jsonl()) # export the chain for offline audit
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## MEASURED vs. `unmeasured` — what you get
|
|
236
|
+
|
|
237
|
+
| Environment | `mode` | `joules` | `tokens_per_joule` |
|
|
238
|
+
|---|---|---|---|
|
|
239
|
+
| NVIDIA GPU with energy counter (`nvmlDeviceGetTotalEnergyConsumption`) | `measured-energy` | hardware accumulator delta | computed |
|
|
240
|
+
| NVIDIA GPU, power readback only (`nvmlDeviceGetPowerUsage`) | `measured-power-integral` | trapezoidal integral of power samples | computed |
|
|
241
|
+
| No GPU / no driver / no permission / no `pynvml` | `unmeasured` | `null` | `null` |
|
|
242
|
+
|
|
243
|
+
### Sample receipt — `unmeasured` (illustrative; this build env has no GPU)
|
|
244
|
+
|
|
245
|
+
> **SAMPLE / illustrative.** Produced on a CPU-only box. Because NVML is
|
|
246
|
+
> unavailable, energy is honestly `unmeasured` and `joules` is `null` — exactly
|
|
247
|
+
> the honest-degrade behavior. **No energy number is invented.**
|
|
248
|
+
|
|
249
|
+
```json
|
|
250
|
+
{
|
|
251
|
+
"seq": 0,
|
|
252
|
+
"model": "my-llm-7b",
|
|
253
|
+
"tokens_in": 2,
|
|
254
|
+
"tokens_out": 7,
|
|
255
|
+
"mode": "unmeasured",
|
|
256
|
+
"joules": null,
|
|
257
|
+
"wall_seconds": 0.004182,
|
|
258
|
+
"tokens_per_joule": null,
|
|
259
|
+
"policy_decision": "allow",
|
|
260
|
+
"policy_reason": "default allow_all gate (no policy configured)",
|
|
261
|
+
"prev": "0000000000000000000000000000000000000000000000000000000000000000",
|
|
262
|
+
"digest": "<sha256 of the canonical body>",
|
|
263
|
+
"ts": 1750000000.0
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
On a real NVIDIA GPU the same call would carry e.g.
|
|
268
|
+
`"mode": "measured-energy"`, a positive `"joules"`, and a computed
|
|
269
|
+
`"tokens_per_joule"`. We do **not** print example GPU numbers here because this
|
|
270
|
+
build environment cannot measure them, and inventing them would violate the
|
|
271
|
+
honesty doctrine. Run `gim.selfcheck()` on your own hardware to see your numbers.
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## Self-test
|
|
276
|
+
|
|
277
|
+
```python
|
|
278
|
+
import governed_inference_meter as gim
|
|
279
|
+
print(gim.selfcheck()) # functional check (NOT a benchmark); no fabricated energy
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
`selfcheck()` runs a metered allow call, a denied call (verifying it does not
|
|
283
|
+
execute), checks tokens/joule honesty, verifies the hash chain, and confirms
|
|
284
|
+
that mutating a past record is detected. It requires no GPU.
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## Attestation & compliance evidence (interop layer)
|
|
289
|
+
|
|
290
|
+
A receipt is only as useful as the tools that can *carry* it. This module renders
|
|
291
|
+
any receipt into the formats the wider ecosystem already understands — without
|
|
292
|
+
changing a single measured value.
|
|
293
|
+
|
|
294
|
+
```python
|
|
295
|
+
import governed_inference_meter as gim
|
|
296
|
+
|
|
297
|
+
rec, out = gim.meter(run, args=("hi",), model="my-llm", tokens_in=2, tokens_out=7)
|
|
298
|
+
|
|
299
|
+
# 1) The receipt as an in-toto Statement v1 — the exact payload that
|
|
300
|
+
# Sigstore / DSSE / SCITT tooling signs and stores in a transparency log.
|
|
301
|
+
stmt = gim.to_intoto_statement(rec) # SLSA-shaped predicate, our own type URI
|
|
302
|
+
|
|
303
|
+
# 2) EU AI Act / NIST AI RMF controls this receipt provides EVIDENCE for,
|
|
304
|
+
# with an explicit does_not_establish note per control (honest, not a cert).
|
|
305
|
+
ev = gim.compliance_evidence(rec)
|
|
306
|
+
|
|
307
|
+
# 3) Confirm the Statement is cryptographically bound to this exact receipt.
|
|
308
|
+
ok, why = gim.verify_statement(stmt, rec) # -> (True, "ok")
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Honest boundaries (doctrine):
|
|
312
|
+
|
|
313
|
+
- The predicate uses **our own** `predicateType` URI and is only SLSA-*shaped*
|
|
314
|
+
for auditor recognizability — it is **not** a claim of official SLSA
|
|
315
|
+
conformance. Signing (DSSE/Sigstore) is out-of-band; this emits the unsigned
|
|
316
|
+
Statement payload a signer would then cover.
|
|
317
|
+
- Energy fields are copied **verbatim**. On an unmeasured receipt, energy-dependent
|
|
318
|
+
controls (e.g. `NIST-AI-RMF-MEASURE-2.x`) report **`UNAVAILABLE`** — never a
|
|
319
|
+
fabricated joule. Logging / record-keeping controls (EU AI Act Art. 12 & 19)
|
|
320
|
+
are supported regardless of GPU.
|
|
321
|
+
- A receipt is **evidence** toward a control, never a conformity assessment,
|
|
322
|
+
certification, or safety guarantee.
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
## Canonical PCGI receipt (spine fold)
|
|
327
|
+
|
|
328
|
+
The meter is also a first-class **Proof-Carrying Governed Intelligence (PCGI)**
|
|
329
|
+
receipt producer on the org-canonical [`szl-receipt`](https://huggingface.co/SZLHOLDINGS)
|
|
330
|
+
spine. One call folds a metered inference into a single signed receipt that binds
|
|
331
|
+
**model id + input digest + output digest + governing policy id + energy** — the
|
|
332
|
+
same shape every other decision producer emits, so provenance unifies.
|
|
333
|
+
|
|
334
|
+
```python
|
|
335
|
+
import governed_inference_meter as gim
|
|
336
|
+
from szl_receipt import generate_keypair
|
|
337
|
+
|
|
338
|
+
priv, pub = generate_keypair() # or sign_key=None for UNSIGNED-honest
|
|
339
|
+
|
|
340
|
+
# End-to-end: meter the call AND emit ONE canonical szl-receipt for it.
|
|
341
|
+
env, out = gim.meter_szl_receipt(
|
|
342
|
+
run, args=("hi",), model="my-llm",
|
|
343
|
+
policy_id="default-allow", sign_key=priv, organ="meter",
|
|
344
|
+
)
|
|
345
|
+
ok, why = gim.verify_szl_receipt(env, pub) # -> (True, "ok")
|
|
346
|
+
stmt = gim.to_statement(env) # in-toto Statement v1, SLSA-shaped
|
|
347
|
+
ok2, _ = gim.verify_szl_statement(stmt, env) # bound to this exact receipt
|
|
348
|
+
|
|
349
|
+
# Or fold an existing meter receipt you already have:
|
|
350
|
+
rec, out = gim.meter(run, args=("hi",), model="my-llm", tokens_in=2, tokens_out=7)
|
|
351
|
+
env = gim.from_meter_receipt(rec, input="hi", output=out, policy_id="default-allow")
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Honest boundaries (doctrine):
|
|
355
|
+
|
|
356
|
+
- Reuses szl-receipt's **canonicalization + signing + in-toto shapes** — it does
|
|
357
|
+
**not** invent a new receipt shape.
|
|
358
|
+
- **Energy** is bound **verbatim** only when the meter actually measured it
|
|
359
|
+
(NVML present). Otherwise `energy.joules` is the literal string
|
|
360
|
+
**`"UNAVAILABLE"`** and `energy.measured` is `False` — the meter is the one
|
|
361
|
+
place in the spine where energy *can* be real, and it is never fabricated.
|
|
362
|
+
- The canonical body is **deterministic**: identical inputs serialize to
|
|
363
|
+
byte-identical canonical JSON (no timestamps in the body).
|
|
364
|
+
- Keyless => **UNSIGNED-honest** (`signed=False`); a signature is never faked.
|
|
365
|
+
- The receipt is **evidence** binding a decision, **not** a proof the model's
|
|
366
|
+
output is correct.
|
|
367
|
+
|
|
368
|
+
Requires the shared `szl-receipt` library (install extra `[sign]`); the import is
|
|
369
|
+
lazy, so importing this package stays zero-hard-dependency.
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
## What's in the repo
|
|
374
|
+
|
|
375
|
+
```
|
|
376
|
+
build.toml # Kernel Hub universal-kernel manifest
|
|
377
|
+
build/torch-universal/governed_inference_meter/
|
|
378
|
+
__init__.py # meter() / metered() wrappers, selfcheck(), accessors
|
|
379
|
+
_energy.py # NVML energy + power-integral measurement, honest degrade
|
|
380
|
+
_receipt.py # SHA-256 hash-chained, tamper-evident receipts
|
|
381
|
+
_policy.py # advisory policy gate (allow_all default, fail-closed)
|
|
382
|
+
_attest.py # in-toto/SLSA-shaped Statements + EU AI Act / NIST AI RMF evidence
|
|
383
|
+
_spine.py # PCGI spine fold: metered inference -> ONE canonical szl-receipt
|
|
384
|
+
metadata.json
|
|
385
|
+
pyproject.toml # also pip-installable from source
|
|
386
|
+
tests/test_meter.py # runs on CPU, no GPU needed
|
|
387
|
+
tests/test_attest.py # attestation + compliance, no GPU needed
|
|
388
|
+
tests/test_spine.py # canonical PCGI receipt fold, no GPU needed
|
|
389
|
+
LICENSE # Apache-2.0
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
---
|
|
393
|
+
|
|
394
|
+
## Doctrine & honesty disclaimer
|
|
395
|
+
|
|
396
|
+
> SZL Holdings · governed, energy-metered inference receipts · **MEASURED only
|
|
397
|
+
> with NVML** · the policy gate is **advisory (host-enforced)** · **Λ =
|
|
398
|
+
> Conjecture 1** (advisory, *not* a theorem) · **trust never 100%** · honesty
|
|
399
|
+
> over checklist. This is a metering + receipt utility, **not** a safety
|
|
400
|
+
> guarantee. No fabricated benchmarks; energy is reported only when physically
|
|
401
|
+
> measured.
|
|
402
|
+
|
|
403
|
+
**License:** Apache-2.0 · **Maintainer:** Stephen Lutar
|
|
404
|
+
<stephenlutar2@gmail.com> · **Platform:** [a-11-oy.com](https://a-11-oy.com) — the
|
|
405
|
+
governed-inference substrate for hard missions.
|