betterwithage commited on
Commit
47c7eb2
·
verified ·
1 Parent(s): ee95bb3

Publish verified torch-cpu kernel v1

Browse files

Dedicated Kernel Hub migration from legacy model commit 70e796a774dbf1d8d06ac5f33295922768480bf2. Locally loaded with kernels 0.16.0 on CPU and passed its bounded verification.

LICENSE ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ Copyright 2026 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.
18
+
19
+ The full Apache License 2.0 text is available at the URL above.
README.md ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - kernel
4
+ - governance
5
+ - lambda
6
+ - gate
7
+ - provenance
8
+ - doi:10.5281/zenodo.19944926
9
+ library_name: kernels
10
+ license: apache-2.0
11
+ ---
12
+
13
+ <p align="center">
14
+ <a href="https://huggingface.co/SZLHOLDINGS/szl-lambda-gate/tree/main/build/torch-universal/szl_lambda_gate"><img src="https://img.shields.io/badge/kernel%20hub-torch--universal-5b8dee?style=flat-square" alt="kernel hub"></a>
15
+ <a href="https://huggingface.co/SZLHOLDINGS/szl-lambda-gate/blob/main/MODEL_PROVENANCE.json"><img src="https://img.shields.io/badge/provenance-MODEL_PROVENANCE.json-3af4c8?style=flat-square" alt="provenance"></a>
16
+ <a href="https://huggingface.co/SZLHOLDINGS/szl-lambda-gate/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-7e8aa3?style=flat-square" alt="license"></a>
17
+ </p>
18
+
19
+ # szl-lambda-gate
20
+
21
+ **Λ — a governance aggregator as a Hugging Face kernel.** A differentiable, torch.compile-friendly weighted-geometric-mean aggregator with an ADVISORY non-compensatory gate and runtime axiom self-checks, from [SZL Holdings](https://huggingface.co/SZLHOLDINGS).
22
+
23
+ > Companion to [`szl-governed-norm`](https://huggingface.co/SZLHOLDINGS/szl-governed-norm). Where that kernel makes a normalization *auditable*, this one makes a *governance decision* computable and checkable at the tensor layer.
24
+
25
+ ## Interactive demo
26
+
27
+ > **Live demos (in-browser, nothing to install)** — [`lambda-gate-holo`](https://szlholdings-lambda-gate-holo.static.hf.space) (this kernel's holographic gate demo) · [`szl-kernels-live`](https://szlholdings-szl-kernels-live.static.hf.space) (unified suite demo).
28
+ >
29
+ > The quickstart above runs fully locally. For a full governed-kernel suite demo, see [szl-kernels](https://huggingface.co/SZLHOLDINGS/szl-kernels). For the live a11oy substrate, see [a11oy Space](https://huggingface.co/spaces/SZLHOLDINGS/a11oy).
30
+
31
+ ## What Λ is — and is NOT (read this first)
32
+
33
+ Λ is the **weighted geometric mean** over axis scores in [0,1]:
34
+
35
+ \[ \Lambda(x) = \prod_i x_i^{w_i}, \quad \sum_i w_i = 1, \; w_i > 0, \; x_i \in [0,1] \]
36
+
37
+ It is a **non-compensatory, ADVISORY** roll-up: any single zeroed (or non-finite) axis drives the whole aggregate to 0 — a conservative "one bad axis fails the gate" signal. **Λ is NOT "proven trust" and NOT a closed theorem.** Its *uniqueness* (that the weighted geometric mean is the only aggregator satisfying the carried axioms) remains **Conjecture 1 — OPEN**. A gate "pass" is an advisory signal, never a guarantee. We label this honestly everywhere.
38
+
39
+ ## Quickstart
40
+
41
+ ```bash
42
+ pip install kernels torch
43
+ ```
44
+
45
+ ```python
46
+ import torch
47
+ from kernels import get_kernel
48
+
49
+ # Current `kernels` (>=0.15) requires an explicit revision/version + trust flag for org kernels:
50
+ lg = get_kernel("SZLHOLDINGS/szl-lambda-gate", revision="main", trust_remote_code=True)
51
+ # (once a tag is published you can pin it, e.g. revision="v0.2.0")
52
+
53
+ axes = torch.tensor([0.9, 0.8, 0.95]) # axis scores in [0,1]
54
+ score = lg.lambda_aggregate(axes) # Λ(x) ∈ [0,1]
55
+ res = lg.lambda_gate(axes, threshold=0.5)
56
+ print(res.score, res.passed, res.advisory) # advisory is always True
57
+
58
+ print(lg.selfcheck()) # empirical A1–A4 checks + version
59
+ ```
60
+
61
+ ## API
62
+
63
+ | Function | Notes |
64
+ |---|---|
65
+ | `lambda_aggregate(axes, weights=None)` | Λ over the last dim. Differentiable, batched, torch.compile-friendly. |
66
+ | `lambda_gate(axes, weights=None, threshold=0.5)` | Advisory gate → `LambdaGateResult(score, passed, threshold, advisory)`. |
67
+ | `lambda_gate_batch(candidates, weights=None, threshold=0.5)` | Score many candidate vectors `(..., N, k)` in one call; returns the advisory pass mask. |
68
+ | `selfcheck()` | Empirical A1–A4 axiom checks + adversarial falsification search + version. NOT a uniqueness proof. |
69
+ | `is_monotone / is_homogeneous / is_egyptian_exact / is_bounded_by_max` | The four carried axioms as real runtime checks. |
70
+ | `yuyay_weights()`, `YUYAY_AXES`, `YUYAY_FLOORS` | Canonical 13-axis Yuyay preset (advisory). |
71
+ | layers: `LambdaGate`, `LambdaAggregate` | Pure `nn.Module` for the Kernel Hub layer-mapping mechanism. |
72
+
73
+ ## Carried axioms (verifiable, not a proof)
74
+
75
+ - **A1 IsMonotone** — Λ is non-decreasing in each axis.
76
+ - **A2 IsHomogeneous (deg 1)** — Λ(t·x) = t·Λ(x).
77
+ - **A3 IsEgyptianExact** — Λ(c,…,c) = c.
78
+ - **A4 IsBounded** — Λ(x) ≤ maxᵢ xᵢ.
79
+
80
+ `selfcheck()` verifies these empirically on sampled inputs and runs a random falsification search. A clean run is **evidence, not proof** — Λ-uniqueness is Conjecture 1 (open).
81
+
82
+ ## Provenance
83
+
84
+ Backed by the Lean 4 formalization [szl-holdings/lutar-lean](https://github.com/szl-holdings/lutar-lean) (749 declarations / 14 axioms / 163 tracked sorries), DOI [10.5281/zenodo.20434308](https://doi.org/10.5281/zenodo.20434308). Λ uniqueness = Conjecture 1 (open).
85
+
86
+ ## Honesty
87
+
88
+ - Pure-Python universal kernel — a correctness reference, not a CUDA speed record. No fabricated benchmarks (50 passing tests).
89
+ - Λ is advisory; never "proven trust."
90
+ - Prior art honestly attributed: the weighted geometric mean as a less-compensatory composite indicator is established practice (UN HDI 2010, OECD Composite Indicators Handbook 2008); the veto/cut-off idea is ELECTRE. The 13-axis conjunctive form is SZL's own yuyay_v3 gate.
91
+
92
+ ## Compatibility
93
+
94
+ Python 3.9+, `torch>=2.5`, standard library + torch only.
95
+
96
+ ## License
97
+
98
+ Apache-2.0. Copyright 2026 SZL Holdings.
99
+
100
+ ---
101
+
102
+ ## SZL Kernels Suite
103
+
104
+ Part of the [`szl-kernels`](https://huggingface.co/SZLHOLDINGS/szl-kernels) governed-kernel suite — the hub links every member, and each member links back to the hub so no leaf is orphaned:
105
+
106
+ | Kernel | Lane |
107
+ |---|---|
108
+ | [`szl-kernels`](https://huggingface.co/SZLHOLDINGS/szl-kernels) | **hub** — unified suite, cross-kernel `UnifiedReceiptChain` |
109
+ | [`szl-governed-norm`](https://huggingface.co/SZLHOLDINGS/szl-governed-norm) | RMSNorm/LayerNorm + SHA3-256 receipts |
110
+ | **`szl-lambda-gate`** (this repo) | **advisory Λ gate (Conjecture 1, OPEN)** |
111
+ | [`governed-inference-meter`](https://huggingface.co/SZLHOLDINGS/governed-inference-meter) | MEASURED-joule energy accounting (NVML) |
112
+ | [`szl-govsign`](https://huggingface.co/SZLHOLDINGS/szl-govsign) | signed governance attestation (DSSE / in-toto) |
113
+ | [`szl-blocked`](https://huggingface.co/SZLHOLDINGS/szl-blocked) | honest-BLOCKED state + EU AI Act Annex IV DRAFT |
114
+ | [`szl-provctl`](https://huggingface.co/SZLHOLDINGS/szl-provctl) | provenance-DAG verify + in-toto/SLSA interop |
115
+
116
+ **Live Spaces:** [a11oy](https://huggingface.co/spaces/SZLHOLDINGS/a11oy) · [hatun-mcp](https://huggingface.co/spaces/SZLHOLDINGS/hatun-mcp).
117
+
118
+ **Related — Governed Kernels collection:** [Governed Kernels — verifiable AI building blocks](https://huggingface.co/collections/SZLHOLDINGS/governed-kernels-verifiable-ai-building-blocks-6a41d3936cfce4fba83ce378) groups the whole family in one page. **Live console:** [a11oy](https://szlholdings-a11oy.hf.space) · [a-11-oy.com](https://a-11-oy.com) · [llm-router](https://szlholdings-llm-router-live.hf.space) · [receipt verifier](https://szlholdings-governed-receipt-verifier.static.hf.space) · [receipt spec (hub)](https://github.com/szl-holdings/governed-receipt-spec).
119
+
120
+
121
+ ---
122
+
123
+ <sub><b>SZL Holdings</b> · Λ governance aggregator · advisory, not proven trust · <a href="https://a-11-oy.com">a-11-oy.com</a> · <a href="https://github.com/szl-holdings">github.com/szl-holdings</a> · <a href="https://huggingface.co/SZLHOLDINGS">huggingface.co/SZLHOLDINGS</a></sub>
124
+
125
+ ---
126
+
127
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.19944926.svg)](https://doi.org/10.5281/zenodo.19944926)
128
+
129
+ ## Citation
130
+
131
+
132
+ **Cite this.** Part of the SZL Holdings *Ouroboros Thesis* (Governed Post-Determinism).
133
+ Concept DOI (always-latest): [10.5281/zenodo.19944926](https://doi.org/10.5281/zenodo.19944926).
134
+ Author: Stephen P. Lutar Jr. · [ORCID 0009-0001-0110-4173](https://orcid.org/0009-0001-0110-4173) · License CC-BY-4.0.
135
+ Full DOI-pinned lineage (v1→v26) + the 8 papers: [szl-papers PAPERS_INDEX](https://github.com/szl-holdings/szl-papers/blob/main/PAPERS_INDEX.md).
136
+ No artifact-specific DOI is minted for this model; the concept DOI above covers the program.
137
+
138
+ Honesty (Doctrine v11): Λ unconditional uniqueness is **Conjecture 1** (machine-checked FALSE as stated) — never a theorem; conditional uniqueness is **Theorem U** (axiom-free). Locked-proven formulas = **exactly 8** {F1,F4,F7,F11,F12,F18,F19,F22}; ~185 experimental theorems are a separate CI-green tier; Khipu BFT safety = Conjecture 2. Trust never 100%.
139
+
140
+ ```bibtex
141
+ @misc{lutar_szl_ouroboros,
142
+ author = {Lutar, Stephen P., Jr.},
143
+ title = {SZL Holdings --- The Ouroboros Thesis (Governed Post-Determinism)},
144
+ year = {2026},
145
+ publisher = {Zenodo},
146
+ doi = {10.5281/zenodo.19944926},
147
+ url = {https://doi.org/10.5281/zenodo.19944926},
148
+ note = {Concept DOI --- always resolves to the latest version. ORCID 0009-0001-0110-4173. CC-BY-4.0.}
149
+ }
150
+ ```
151
+
152
+ *Signed-off-by: Stephen Lutar <stephenlutar2@gmail.com>*
153
+
154
+ ## Files in this repo
155
+
156
+ | Path | What it is |
157
+ |---|---|
158
+ | `build/torch-universal/szl_lambda_gate/__init__.py` | public API — `lambda_aggregate`, `lambda_gate`, `selfcheck()` |
159
+ | `build/torch-universal/szl_lambda_gate/_lambda.py` | the weighted-geometric-mean aggregator + A1–A4 empirical checks |
160
+ | `build/torch-universal/szl_lambda_gate/layers.py` | `nn.Module` wrapper |
161
+ | `build.toml` · `metadata.json` | Kernel Hub build/metadata manifests |
162
+ | `LICENSE` · `SECURITY.md` | Apache-2.0 · security policy |
163
+
164
+ ---
165
+
166
+ <p align="center">
167
+ <a href="https://huggingface.co/SZLHOLDINGS">SZL Holdings</a> ·
168
+ <a href="https://a-11-oy.com">a-11-oy.com</a> ·
169
+ <a href="https://huggingface.co/SZLHOLDINGS/szl-kernels">szl-kernels</a>
170
+ </p>
171
+
172
+ <p align="center"><sub>SLSA: L1 honest · L2 attested · L3 roadmap. Λ = Conjecture 1. Trust ceiling 0.97.</sub></p>
build/torch-cpu/metadata.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "szl-lambda-gate",
3
+ "id": "_szl_lambda_gate_cpu_9cf02fddf8",
4
+ "version": 1,
5
+ "license": "Apache-2.0",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cpu"
9
+ }
10
+ }
build/torch-cpu/szl_lambda_gate/__init__.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # © 2026 SZL Holdings · Stephen P. Lutar · ORCID 0009-0001-0110-4173
3
+ """szl_lambda_gate — the Lambda-Spine aggregator (Λ) as a universal kernel.
4
+
5
+ A pure-PyTorch (universal) kernel from SZL Holdings for the Hugging Face
6
+ Kernel Hub. It ports the canonical Λ aggregator into a differentiable,
7
+ torch.compile-friendly torch op:
8
+
9
+ Λ(x) = ∏ xᵢ^{wᵢ}, Σwᵢ = 1, wᵢ > 0, xᵢ ∈ [0,1] (weighted geometric mean)
10
+
11
+ plus an ADVISORY governance gate (Λ vs threshold), the four carried axioms as
12
+ real runtime self-checks, and pure nn.Module layers.
13
+
14
+ Load from the Hub:
15
+
16
+ import torch
17
+ from kernels import get_kernel
18
+
19
+ lg = get_kernel("SZLHOLDINGS/szl-lambda-gate")
20
+ axes = torch.tensor([0.9, 0.8, 0.95]) # axis scores in [0,1]
21
+ score = lg.lambda_aggregate(axes) # Λ(x) ∈ [0,1]
22
+ res = lg.lambda_gate(axes, threshold=0.5) # ADVISORY pass/fail
23
+ print(res.score, res.passed, res.advisory)
24
+
25
+ WHAT Λ IS / IS NOT (HONESTY — SZL Holdings doctrine v11):
26
+ Λ is the weighted-geometric-mean aggregator — a non-compensatory, ADVISORY
27
+ way to roll axis scores in [0,1] into one number (any zeroed axis zeroes the
28
+ aggregate). It is NOT "proven trust" and NOT a closed theorem: Λ-uniqueness
29
+ remains Conjecture 1 (OPEN — an unresolved CAUCHY_ND step plus a missing
30
+ symmetry axiom). Label it honestly everywhere; a gate "pass" is advisory.
31
+
32
+ PROVENANCE: backed by the Lean 4 formalization szl-holdings/lutar-lean
33
+ (749 declarations / 14 axioms / 163 tracked sorries),
34
+ DOI 10.5281/zenodo.20434308 (lutar-lean). Λ uniqueness = Conjecture 1 (open).
35
+ """
36
+ from typing import Optional
37
+
38
+ import torch
39
+
40
+ from . import layers # noqa: F401 (must be importable for Hub layer mapping)
41
+ from ._lambda import YUYAY_AXES, YUYAY_FLOORS, LambdaGateResult
42
+ from ._lambda import find_axiom_violation as _find_axiom_violation
43
+ from ._lambda import is_bounded_by_max as _is_bounded_by_max
44
+ from ._lambda import is_egyptian_exact as _is_egyptian_exact
45
+ from ._lambda import is_homogeneous as _is_homogeneous
46
+ from ._lambda import is_monotone as _is_monotone
47
+ from ._lambda import lambda_aggregate as _lambda_aggregate
48
+ from ._lambda import lambda_gate as _lambda_gate
49
+ from ._lambda import lambda_gate_batch as _lambda_gate_batch
50
+ from ._lambda import selfcheck as _selfcheck
51
+ from ._lambda import yuyay_weights as _yuyay_weights
52
+
53
+ __all__ = [
54
+ "lambda_aggregate",
55
+ "lambda_gate",
56
+ "lambda_gate_batch",
57
+ "LambdaGateResult",
58
+ "is_monotone",
59
+ "is_egyptian_exact",
60
+ "is_bounded_by_max",
61
+ "is_homogeneous",
62
+ "find_axiom_violation",
63
+ "selfcheck",
64
+ "yuyay_weights",
65
+ "YUYAY_AXES",
66
+ "YUYAY_FLOORS",
67
+ "layers",
68
+ "DOCTRINE_FOOTER",
69
+ "PROVENANCE",
70
+ "__version__",
71
+ ]
72
+
73
+ __version__ = "0.2.0"
74
+ DOCTRINE_FOOTER = (
75
+ "SZL Holdings · Λ = Conjecture 1 (ADVISORY, weighted geometric mean) · "
76
+ "uniqueness OPEN · NOT proven trust · honesty over checklist"
77
+ )
78
+ PROVENANCE = {
79
+ "lean_repo": "szl-holdings/lutar-lean",
80
+ "lean_declarations": 749,
81
+ "lean_axioms": 14,
82
+ "lean_tracked_sorries": 163,
83
+ "doi_lutar_lean": "10.5281/zenodo.20434308",
84
+ "lambda_status": "Conjecture 1 (open) — uniqueness unproven; advisory only",
85
+ }
86
+
87
+
88
+ def lambda_aggregate(
89
+ axes: torch.Tensor,
90
+ weights: Optional[torch.Tensor] = None,
91
+ ) -> torch.Tensor:
92
+ """Λ(x) = ∏ xᵢ^{wᵢ}, the weighted geometric mean over the last dim of axes.
93
+
94
+ See ``szl_lambda_gate._lambda.lambda_aggregate``. Axis scores in [0,1],
95
+ uniform weights when ``weights`` is None. Differentiable, batched, and
96
+ torch.compile-friendly. ADVISORY — NOT proven trust.
97
+ """
98
+ return _lambda_aggregate(axes, weights=weights)
99
+
100
+
101
+ def lambda_gate(
102
+ axes: torch.Tensor,
103
+ weights: Optional[torch.Tensor] = None,
104
+ threshold: float = 0.5,
105
+ ) -> LambdaGateResult:
106
+ """ADVISORY Λ governance gate: returns LambdaGateResult(score, passed,
107
+ threshold, advisory). ``passed`` = Λ(axes) >= threshold. A pass is an
108
+ advisory, non-compensatory signal — NOT proven trust (Λ = Conjecture 1).
109
+ """
110
+ return _lambda_gate(axes, weights=weights, threshold=threshold)
111
+
112
+
113
+ def lambda_gate_batch(
114
+ candidates: torch.Tensor,
115
+ weights: Optional[torch.Tensor] = None,
116
+ threshold: float = 0.5,
117
+ ) -> LambdaGateResult:
118
+ """ADVISORY batch gate over many candidate action-vectors (shape (..., N, k)).
119
+
120
+ The realistic per-inference-step call: score all N candidates at once and
121
+ return the advisory pass mask. Returns LambdaGateResult(score, passed,
122
+ threshold, advisory) with score/passed of shape (..., N). NOT proven trust.
123
+ """
124
+ return _lambda_gate_batch(candidates, weights=weights, threshold=threshold)
125
+
126
+
127
+ def yuyay_weights(dtype: torch.dtype = torch.float64, device=None) -> torch.Tensor:
128
+ """Canonical 13-axis Yuyay Λ weight vector (uniform 1/13), ADVISORY only.
129
+
130
+ Use as ``weights`` over the 13 ``YUYAY_AXES``. The yuyay_v3 gate is a
131
+ conjunctive AND with per-axis floors (``YUYAY_FLOORS``); this Λ roll-up is
132
+ the weighted geometric mean and is ADVISORY — NOT proven trust.
133
+ """
134
+ return _yuyay_weights(dtype=dtype, device=device)
135
+
136
+
137
+ def find_axiom_violation(k=5, trials=200, weights=None, seed=0, tol=1e-6):
138
+ """Random-search for any A1–A4 violation; returns (axiom, axes, weights) or
139
+ None. An honest falsification attempt — finding nothing is evidence, not a
140
+ proof (Λ-uniqueness is Conjecture 1, open).
141
+ """
142
+ return _find_axiom_violation(k=k, trials=trials, weights=weights, seed=seed, tol=tol)
143
+
144
+
145
+ def selfcheck(k=5, trials=64, seed=0) -> dict:
146
+ """Expose the A1–A4 empirical self-checks + version as a single verdict dict.
147
+
148
+ Callable as get_kernel(...).selfcheck(). EMPIRICAL checks on sampled inputs,
149
+ NOT a proof of Λ-uniqueness (Conjecture 1, open). Advisory only.
150
+ """
151
+ return _selfcheck(k=k, trials=trials, seed=seed)
152
+
153
+
154
+ # ---- axiom runtime self-checks (real, verifiable; NOT a uniqueness proof) -- #
155
+ def is_monotone(axes, weights=None, delta=0.05, tol=1e-7) -> bool:
156
+ """A1 IsMonotone self-check: Λ is non-decreasing in each axis (on this data)."""
157
+ return _is_monotone(axes, weights=weights, delta=delta, tol=tol)
158
+
159
+
160
+ def is_egyptian_exact(c, k=3, weights=None, tol=1e-5) -> bool:
161
+ """A3 IsEgyptianExact self-check: Λ(c, …, c) = c."""
162
+ return _is_egyptian_exact(c, k=k, weights=weights, tol=tol)
163
+
164
+
165
+ def is_bounded_by_max(axes, weights=None, tol=1e-6) -> bool:
166
+ """A4 IsBounded self-check: Λ(x) ≤ maxᵢ xᵢ."""
167
+ return _is_bounded_by_max(axes, weights=weights, tol=tol)
168
+
169
+
170
+ def is_homogeneous(axes, t, weights=None, tol=1e-5) -> bool:
171
+ """A2 IsHomogeneous(degree 1) self-check: Λ(t·x) = t·Λ(x)."""
172
+ return _is_homogeneous(axes, t, weights=weights, tol=tol)
build/torch-cpu/szl_lambda_gate/_lambda.py ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # © 2026 SZL Holdings · Stephen P. Lutar · ORCID 0009-0001-0110-4173
3
+ """Pure-PyTorch Lambda-Spine aggregator (Λ) for the szl-lambda-gate kernel.
4
+
5
+ Λ(x) = ∏ xᵢ^{wᵢ}, Σwᵢ = 1, wᵢ > 0, xᵢ ∈ [0,1] (weighted geometric mean)
6
+
7
+ This is a TORCH port of the canonical pure-Python reference. It is a
8
+ correctness reference, computed via logs in float32 for stability,
9
+ differentiable (autograd works), and torch.compile-friendly. Depends ONLY on
10
+ torch + the Python standard library (a Kernel Hub requirement for universal
11
+ kernels).
12
+
13
+ WHAT Λ IS / IS NOT (HONESTY — SZL Holdings doctrine v11):
14
+ Λ is the *weighted-geometric-mean aggregator*: a non-compensatory way to
15
+ combine axis scores in [0,1] into one number. It is an ADVISORY governance
16
+ signal — a conservative roll-up where any single zeroed axis drives the
17
+ aggregate to 0. It is NOT "proven trust" and NOT a closed theorem. Its
18
+ *uniqueness* remains Conjecture 1 — OPEN (an unresolved CAUCHY_ND step plus a
19
+ missing symmetry axiom in the Lean development). Do not describe Λ as proven
20
+ trust anywhere.
21
+
22
+ PRIOR ART (honest attribution): the weighted geometric mean as a less-
23
+ compensatory composite-indicator aggregator is established practice — the UN
24
+ HDI (arithmetic→geometric switch, 2010) and the OECD Handbook on Constructing
25
+ Composite Indicators (2008) both use it to limit the compensation effect. The
26
+ veto / cut-off idea (a single failing criterion blocks a pass) is the ELECTRE
27
+ veto threshold. The 13-axis conjunctive form (yuyay_weights) is SZL's own
28
+ yuyay_v3 gate. None of this makes Λ "proven trust"; the gate is ADVISORY.
29
+
30
+ PROVENANCE: backed by the Lean 4 formalization szl-holdings/lutar-lean
31
+ (749 declarations / 14 axioms / 163 tracked sorries),
32
+ DOI 10.5281/zenodo.20434308 (lutar-lean). Λ uniqueness = Conjecture 1 (open).
33
+
34
+ Axioms carried (Lutar/Axioms.lean), available below as runtime self-checks:
35
+ A1 IsMonotone — Λ is non-decreasing in each axis
36
+ A2 IsHomogeneous — Λ(t·x) = t·Λ(x) (degree 1)
37
+ A3 IsEgyptianExact — Λ(c,…,c) = c (the uniform-diagonal fixpoint)
38
+ A4 IsBounded(by max) — Λ(x) ≤ maxᵢ xᵢ
39
+ """
40
+ from typing import Optional
41
+
42
+ import torch
43
+
44
+ _SUPPORTED_DTYPES = (torch.float16, torch.bfloat16, torch.float32, torch.float64)
45
+
46
+
47
+ def _compute_dtype(in_dtype: torch.dtype) -> torch.dtype:
48
+ return torch.float32 if in_dtype in (torch.float16, torch.bfloat16) else in_dtype
49
+
50
+
51
+ def _check_axes(axes: torch.Tensor) -> None:
52
+ """Cheap, allocation-free metadata guards on the axis-score tensor."""
53
+ if not isinstance(axes, torch.Tensor):
54
+ raise TypeError(f"axes must be a torch.Tensor, got {type(axes).__name__}")
55
+ if axes.dtype not in _SUPPORTED_DTYPES:
56
+ raise TypeError(
57
+ f"axes has unsupported dtype {axes.dtype}; "
58
+ f"expected one of {tuple(str(d) for d in _SUPPORTED_DTYPES)}"
59
+ )
60
+ if axes.dim() < 1:
61
+ raise ValueError(
62
+ "axes must have at least 1 dimension (the k axis scores live on "
63
+ f"the last dim); got a {axes.dim()}-d tensor"
64
+ )
65
+ if axes.shape[-1] < 1:
66
+ raise ValueError("axes last dimension (k = number of axes) must be >= 1")
67
+
68
+
69
+ def _resolve_weights(
70
+ axes: torch.Tensor,
71
+ weights: Optional[torch.Tensor],
72
+ cdt: torch.dtype,
73
+ ) -> torch.Tensor:
74
+ """Return a normalized (Σw = 1) weight vector of shape (k,) in compute dtype."""
75
+ k = axes.shape[-1]
76
+ if weights is None:
77
+ return torch.full((k,), 1.0 / k, dtype=cdt, device=axes.device)
78
+ if not isinstance(weights, torch.Tensor):
79
+ raise TypeError(f"weights must be a torch.Tensor or None, got {type(weights).__name__}")
80
+ if weights.device != axes.device:
81
+ raise ValueError(
82
+ f"weights is on device {weights.device} but axes is on {axes.device}; "
83
+ "move them to the same device"
84
+ )
85
+ if weights.dim() != 1 or weights.shape[0] != k:
86
+ raise ValueError(
87
+ f"weights must be 1-D with shape ({k},) to match the last dim of axes; "
88
+ f"got shape {tuple(weights.shape)}"
89
+ )
90
+ wf = weights.to(cdt)
91
+ if not bool(torch.all(torch.isfinite(wf))):
92
+ raise ValueError("weights must all be finite (no NaN/Inf)")
93
+ if bool(torch.any(wf <= 0.0)):
94
+ raise ValueError("weights must be strictly positive (wᵢ > 0)")
95
+ sw = wf.sum()
96
+ if not bool(sw > 0.0):
97
+ raise ValueError("weights must sum to a positive value")
98
+ return wf / sw
99
+
100
+
101
+ def lambda_aggregate(
102
+ axes: torch.Tensor,
103
+ weights: Optional[torch.Tensor] = None,
104
+ ) -> torch.Tensor:
105
+ """Weighted geometric mean Λ(x) = ∏ xᵢ^{wᵢ} over the last dim of ``axes``.
106
+
107
+ Axis scores expected in [0,1] and clamped into [0,1]; uniform weights (1/k)
108
+ when ``weights`` is None. Computed via logs for stability:
109
+
110
+ Λ(x) = exp( Σᵢ wᵢ · log(clamp(xᵢ, 0, 1)) )
111
+
112
+ Non-compensatory zero-routing (A4-consistent): any axis that is zero, OR
113
+ that is NON-FINITE (NaN / ±Inf), is treated as a FAILING axis and drives
114
+ the whole aggregate to exactly 0. A garbage/invalid axis must never silently
115
+ pass as a perfect (clamped-to-1) axis; output and gradient stay finite and
116
+ in [0,1] for every input.
117
+
118
+ Returns a tensor of shape (...) — Λ(x) ∈ [0,1] per batch row, differentiable
119
+ w.r.t. ``axes``.
120
+
121
+ HONESTY: a non-compensatory governance roll-up, NOT proven trust.
122
+ Λ-uniqueness is Conjecture 1 (open).
123
+ """
124
+ _check_axes(axes)
125
+ in_dtype = axes.dtype
126
+ cdt = _compute_dtype(in_dtype)
127
+ xf = axes.to(cdt)
128
+ w = _resolve_weights(axes, weights, cdt) # (k,), Σw=1
129
+
130
+ finite_mask = torch.isfinite(xf)
131
+ xc = xf.clamp(0.0, 1.0)
132
+ bad_mask = (~finite_mask) | (xc <= 0.0)
133
+ any_bad = torch.any(bad_mask, dim=-1) # (...)
134
+
135
+ safe = torch.where(bad_mask, torch.ones_like(xc), xc)
136
+ logx = torch.log(safe) # (..., k)
137
+ acc = (logx * w).sum(dim=-1) # (...)
138
+ val = torch.exp(acc) # (...)
139
+
140
+ out = torch.where(any_bad, torch.zeros_like(val), val)
141
+ out = out.clamp(0.0, 1.0)
142
+ return out.to(in_dtype)
143
+
144
+
145
+ def lambda_gate(
146
+ axes: torch.Tensor,
147
+ weights: Optional[torch.Tensor] = None,
148
+ threshold: float = 0.5,
149
+ ):
150
+ """ADVISORY governance gate over Λ(x): score plus a pass/fail vs threshold.
151
+
152
+ Returns a :class:`LambdaGateResult` namedtuple (score, passed, threshold,
153
+ advisory). ``passed`` := Λ(x) >= threshold; ``advisory`` is always True.
154
+
155
+ HONESTY: a "pass" is an ADVISORY signal only. Λ is the weighted-geometric-
156
+ mean aggregator; its uniqueness is Conjecture 1 (open). Do not treat a pass
157
+ as proven trust or a closed theorem.
158
+ """
159
+ t = float(threshold)
160
+ if t != t or t == float("inf") or t == float("-inf"):
161
+ raise ValueError(f"threshold must be a finite float, got {threshold!r}")
162
+ score = lambda_aggregate(axes, weights)
163
+ passed = score >= t
164
+ return LambdaGateResult(score=score, passed=passed, threshold=t, advisory=True)
165
+
166
+
167
+ def lambda_gate_batch(
168
+ candidates: torch.Tensor,
169
+ weights: Optional[torch.Tensor] = None,
170
+ threshold: float = 0.5,
171
+ ):
172
+ """ADVISORY batch gate: score MANY candidate action-vectors in one call.
173
+
174
+ ``candidates`` is shape (..., N, k): last dim ``k`` is per-axis scores of one
175
+ candidate, the dim before it enumerates the N candidates. Returns a
176
+ :class:`LambdaGateResult` with score/passed of shape (..., N).
177
+
178
+ HONESTY: the pass mask is ADVISORY, non-compensatory. NOT proven trust;
179
+ Λ-uniqueness is Conjecture 1 (open).
180
+ """
181
+ _check_axes(candidates)
182
+ if candidates.dim() < 2:
183
+ raise ValueError(
184
+ "candidates must be at least 2-D, shape (..., N, k); "
185
+ f"got a {candidates.dim()}-d tensor"
186
+ )
187
+ return lambda_gate(candidates, weights=weights, threshold=threshold)
188
+
189
+
190
+ # ---- A1..A4 axiom RUNTIME self-checks (real, verifiable) ------------------- #
191
+ def is_egyptian_exact(c, k: int = 3, weights=None, tol: float = 1e-5) -> bool:
192
+ """A3 IsEgyptianExact: Λ(c, …, c) = c for a constant axis vector of length k."""
193
+ if k < 1:
194
+ raise ValueError("k must be >= 1")
195
+ cc = min(max(float(c), 0.0), 1.0)
196
+ axes = torch.full((k,), cc, dtype=torch.float64)
197
+ val = lambda_aggregate(axes, weights)
198
+ return bool(torch.abs(val - cc) <= tol)
199
+
200
+
201
+ def is_bounded_by_max(axes: torch.Tensor, weights=None, tol: float = 1e-6) -> bool:
202
+ """A4 IsBounded: Λ(x) ≤ maxᵢ xᵢ (over the last dim), within ``tol``."""
203
+ _check_axes(axes)
204
+ val = lambda_aggregate(axes, weights)
205
+ xf = axes.to(_compute_dtype(axes.dtype))
206
+ xf = torch.where(torch.isfinite(xf), xf, torch.zeros_like(xf))
207
+ mx = xf.clamp(0.0, 1.0).amax(dim=-1)
208
+ return bool(torch.all(val.to(mx.dtype) <= mx + tol))
209
+
210
+
211
+ def is_homogeneous(axes: torch.Tensor, t, weights=None, tol: float = 1e-5) -> bool:
212
+ """A2 IsHomogeneous (degree 1): Λ(t·x) = t·Λ(x) for scalar t in [0,1]."""
213
+ _check_axes(axes)
214
+ tt = min(max(float(t), 0.0), 1.0)
215
+ x = axes.to(torch.float64).clamp(0.0, 1.0)
216
+ lhs = lambda_aggregate(x * tt, weights)
217
+ rhs = tt * lambda_aggregate(x, weights)
218
+ return bool(torch.all(torch.abs(lhs - rhs) <= tol))
219
+
220
+
221
+ def is_monotone(axes: torch.Tensor, weights=None, delta: float = 0.05, tol: float = 1e-7) -> bool:
222
+ """A1 IsMonotone: Λ is non-decreasing in each axis."""
223
+ _check_axes(axes)
224
+ x = axes.to(torch.float64).clamp(0.0, 1.0)
225
+ base = lambda_aggregate(x, weights)
226
+ k = x.shape[-1]
227
+ ok = True
228
+ for j in range(k):
229
+ bumped = x.clone()
230
+ bumped[..., j] = (bumped[..., j] + float(delta)).clamp(0.0, 1.0)
231
+ bumped_val = lambda_aggregate(bumped, weights)
232
+ ok = ok and bool(torch.all(bumped_val - base >= -tol))
233
+ return ok
234
+
235
+
236
+ def find_axiom_violation(k: int = 5, trials: int = 200, weights=None, seed=0, tol: float = 1e-6):
237
+ """Random-search for ANY A1–A4 violation. Returns the first violating triple
238
+ ``(axiom, axes, weights)`` or ``None``. An honest FALSIFICATION attempt —
239
+ finding nothing is empirical evidence, NOT a proof (Λ-uniqueness = Conjecture 1).
240
+ """
241
+ gen = torch.Generator()
242
+ if seed is not None:
243
+ gen.manual_seed(int(seed))
244
+ for _ in range(int(trials)):
245
+ x = torch.rand(k, generator=gen, dtype=torch.float64)
246
+ w = weights
247
+ if w is None:
248
+ w = torch.rand(k, generator=gen, dtype=torch.float64) + 1e-3
249
+ c = float(torch.rand(1, generator=gen).item())
250
+ if not is_egyptian_exact(c, k=k, weights=w, tol=max(tol, 1e-5)):
251
+ return ("A3_IsEgyptianExact", torch.full((k,), c, dtype=torch.float64), w)
252
+ if not is_bounded_by_max(x, w, tol=max(tol, 1e-6)):
253
+ return ("A4_IsBounded", x, w)
254
+ t = float(torch.rand(1, generator=gen).item())
255
+ if not is_homogeneous(x, t, weights=w, tol=max(tol, 1e-5)):
256
+ return ("A2_IsHomogeneous", x, w)
257
+ if not is_monotone(x * 0.9, w, tol=max(tol, 1e-7)):
258
+ return ("A1_IsMonotone", x * 0.9, w)
259
+ return None
260
+
261
+
262
+ # ---- Canonical 13-axis Yuyay preset (ADVISORY ONLY) ------------------------ #
263
+ YUYAY_AXES = (
264
+ "moralGrounding", "measurabilityHonesty", "empiricalGrounding",
265
+ "logicalConsistency", "sourceTransparency", "reproducibility",
266
+ "licenseHygiene", "scopeDiscipline", "claimCalibration", "evalAwareness",
267
+ "deceptionKeywords", "conflictingDirectives", "reversalDirective",
268
+ )
269
+ YUYAY_FLOORS = (
270
+ 0.95, 0.95,
271
+ 0.90, 0.90, 0.90, 0.90, 0.90, 0.90, 0.90,
272
+ 0.90, 0.90, 0.90, 0.90,
273
+ )
274
+
275
+
276
+ def yuyay_weights(dtype: torch.dtype = torch.float64, device=None) -> torch.Tensor:
277
+ """Canonical 13-axis Yuyay Λ weight vector (uniform 1/13), ADVISORY only."""
278
+ k = len(YUYAY_AXES)
279
+ return torch.full((k,), 1.0 / k, dtype=dtype, device=device)
280
+
281
+
282
+ def selfcheck(k: int = 5, trials: int = 64, seed=0) -> dict:
283
+ """Run the A1–A4 empirical self-checks and report a verdict + version.
284
+
285
+ HONESTY: EMPIRICAL checks on sampled inputs, NOT a proof of Λ-uniqueness
286
+ (Conjecture 1, open). A clean run is evidence, not proof.
287
+ """
288
+ x = torch.rand(k, dtype=torch.float64) * 0.9
289
+ w = torch.rand(k, dtype=torch.float64) + 1e-3
290
+ axioms = {
291
+ "A1_IsMonotone": is_monotone(x, w),
292
+ "A2_IsHomogeneous": is_homogeneous(x, float(torch.rand(1).item()), weights=w),
293
+ "A3_IsEgyptianExact": is_egyptian_exact(float(torch.rand(1).item()), k=k, weights=w),
294
+ "A4_IsBounded": is_bounded_by_max(x, w),
295
+ }
296
+ violation = find_axiom_violation(k=k, trials=trials, seed=seed)
297
+ return {
298
+ "version": __version__,
299
+ "axioms": axioms,
300
+ "all_axioms_hold": all(axioms.values()) and violation is None,
301
+ "adversarial": {"trials": int(trials), "violation": violation},
302
+ "advisory": True,
303
+ "lambda_status": "Conjecture 1 (open) — uniqueness unproven; advisory only",
304
+ }
305
+
306
+
307
+ __version__ = "0.2.0"
308
+
309
+ from collections import namedtuple # noqa: E402
310
+
311
+ LambdaGateResult = namedtuple(
312
+ "LambdaGateResult", ["score", "passed", "threshold", "advisory"]
313
+ )
build/torch-cpu/szl_lambda_gate/_ops.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Auto-style ops namespace shim for the universal kernel. Unique suffix lets
3
+ # multiple versions load in the same process (Kernel Hub requirement).
4
+ import torch
5
+
6
+ ops = torch.ops._szl_lambda_gate_20260623081355
7
+
8
+
9
+ def add_op_namespace_prefix(op_name: str) -> str:
10
+ return f"_szl_lambda_gate_20260623081355::{op_name}"
build/torch-cpu/szl_lambda_gate/layers.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # © 2026 SZL Holdings · Stephen P. Lutar · ORCID 0009-0001-0110-4173
3
+ """Hub-compliant kernel layer for the szl-lambda-gate kernel.
4
+
5
+ Per the Kernel Hub `kernel-requirements`, layers exposed for extension must be
6
+ PURE torch.nn.Module subclasses:
7
+ - no custom __init__,
8
+ - no class variables,
9
+ - only a `forward` method.
10
+
11
+ The layer therefore reads its parameters (weights / threshold) off the module
12
+ instance it is bound to (set by the host model) and only defines `forward`.
13
+
14
+ HONESTY: `LambdaGate` emits an ADVISORY governance signal (the weighted
15
+ geometric mean Λ plus a pass/fail vs threshold). Λ is NOT proven trust; its
16
+ uniqueness is Conjecture 1 (open).
17
+ """
18
+ import torch
19
+ from torch import nn
20
+
21
+ from ._lambda import lambda_aggregate, lambda_gate
22
+
23
+
24
+ class LambdaGate(nn.Module):
25
+ """Pure Λ-gate layer.
26
+
27
+ Reads optional ``self.weights`` (1-D, length k) and ``self.threshold``
28
+ (float, default 0.5) off the bound module instance.
29
+
30
+ forward(axes) -> LambdaGateResult(score, passed, threshold, advisory) where
31
+ ``score`` = Λ(axes) over the last dim and ``passed`` = score >= threshold.
32
+ Differentiable in ``score`` w.r.t. ``axes``.
33
+ """
34
+
35
+ def forward(self, axes: torch.Tensor):
36
+ weights = getattr(self, "weights", None)
37
+ threshold = getattr(self, "threshold", 0.5)
38
+ return lambda_gate(axes, weights=weights, threshold=float(threshold))
39
+
40
+
41
+ class LambdaAggregate(nn.Module):
42
+ """Pure Λ-aggregator layer: forward(axes) -> Λ(axes) tensor in [0,1].
43
+
44
+ Reads optional ``self.weights`` (1-D, length k) off the bound module
45
+ instance; uniform weights when absent. Returns just the score (no gate),
46
+ fully differentiable w.r.t. ``axes``.
47
+ """
48
+
49
+ def forward(self, axes: torch.Tensor) -> torch.Tensor:
50
+ weights = getattr(self, "weights", None)
51
+ return lambda_aggregate(axes, weights=weights)