Kernels
Safetensors
PyTorch
kernel
governance
lambda
gate
provenance
torch
surrogate
doi:10.5281/zenodo.19944926
Instructions to use SZLHOLDINGS/szl-lambda-gate with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Kernels
How to use SZLHOLDINGS/szl-lambda-gate with Kernels:
# !pip install kernels from kernels import get_kernel kernel = get_kernel("SZLHOLDINGS/szl-lambda-gate") - Notebooks
- Google Colab
- Kaggle
surrogate v1: REAL trained torch MLP Λ-gate-decision surrogate (fidelity 0.967 MEASURED) + config + receipt + scripts + honest card/provenance
Browse files- MODEL_PROVENANCE.json +17 -3
- README.md +45 -1
- TRAINING_RECEIPT.json +87 -0
- config.json +36 -0
- model.safetensors +3 -0
- scripts/eval.py +24 -0
- scripts/forge.py +169 -0
MODEL_PROVENANCE.json
CHANGED
|
@@ -5,7 +5,21 @@
|
|
| 5 |
"id": "SZLHOLDINGS/szl-lambda-gate",
|
| 6 |
"repository_type": "model",
|
| 7 |
"artifact_kind": "kernel-code-and-configuration",
|
| 8 |
-
"trained_weights_present":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
},
|
| 10 |
"source_of_record": {
|
| 11 |
"state": "VERIFIED_HF_SOURCE_OF_RECORD",
|
|
@@ -73,7 +87,7 @@
|
|
| 73 |
"github_repository_parity": "NOT_CLAIMED",
|
| 74 |
"github_artifact_scope_parity": "NOT_CLAIMED_DUE_TO_RECORDED_DIVERGENCE",
|
| 75 |
"reproducible_build": "NOT_CLAIMED",
|
| 76 |
-
"trained_model": "
|
| 77 |
"serving_process_revision": "NOT_APPLICABLE_REPOSITORY_ARTIFACT"
|
| 78 |
},
|
| 79 |
"limits": [
|
|
@@ -82,4 +96,4 @@
|
|
| 82 |
"The attestation overlay cannot self-embed its resulting Hub commit, so the immutable artifact_base_revision is the measured pre-overlay base.",
|
| 83 |
"No .bin, .safetensors, .pt, .pth, .onnx, or .gguf weight artifact was present in the measured base tree."
|
| 84 |
]
|
| 85 |
-
}
|
|
|
|
| 5 |
"id": "SZLHOLDINGS/szl-lambda-gate",
|
| 6 |
"repository_type": "model",
|
| 7 |
"artifact_kind": "kernel-code-and-configuration",
|
| 8 |
+
"trained_weights_present": true,
|
| 9 |
+
"surrogate": {
|
| 10 |
+
"file": "model.safetensors",
|
| 11 |
+
"config": "config.json",
|
| 12 |
+
"sha256": "79987d9dd53f6c5496569c588ac5203b8d4debda2d8ef9ee7147c43d4740358d",
|
| 13 |
+
"role": "advisory \u039b gate-decision surrogate (torch MLP) \u2014 kernel \u039b remains sole ground truth",
|
| 14 |
+
"fidelity_MEASURED": {
|
| 15 |
+
"fidelity_vs_kernel_heldout": 0.967,
|
| 16 |
+
"recall_GATE_PASS": 0.9912,
|
| 17 |
+
"recall_GATE_FAIL": 0.9469
|
| 18 |
+
},
|
| 19 |
+
"receipt": "TRAINING_RECEIPT.json",
|
| 20 |
+
"reverify": "python scripts/eval.py"
|
| 21 |
+
},
|
| 22 |
+
"torch_only_note": "kernel is pure-torch; the OPTIONAL surrogate adds safetensors for weight IO"
|
| 23 |
},
|
| 24 |
"source_of_record": {
|
| 25 |
"state": "VERIFIED_HF_SOURCE_OF_RECORD",
|
|
|
|
| 87 |
"github_repository_parity": "NOT_CLAIMED",
|
| 88 |
"github_artifact_scope_parity": "NOT_CLAIMED_DUE_TO_RECORDED_DIVERGENCE",
|
| 89 |
"reproducible_build": "NOT_CLAIMED",
|
| 90 |
+
"trained_model": "SURROGATE_PRESENT_MEASURED_FIDELITY",
|
| 91 |
"serving_process_revision": "NOT_APPLICABLE_REPOSITORY_ARTIFACT"
|
| 92 |
},
|
| 93 |
"limits": [
|
|
|
|
| 96 |
"The attestation overlay cannot self-embed its resulting Hub commit, so the immutable artifact_base_revision is the measured pre-overlay base.",
|
| 97 |
"No .bin, .safetensors, .pt, .pth, .onnx, or .gguf weight artifact was present in the measured base tree."
|
| 98 |
]
|
| 99 |
+
}
|
README.md
CHANGED
|
@@ -5,6 +5,9 @@ tags:
|
|
| 5 |
- lambda
|
| 6 |
- gate
|
| 7 |
- provenance
|
|
|
|
|
|
|
|
|
|
| 8 |
- doi:10.5281/zenodo.19944926
|
| 9 |
library_name: kernels
|
| 10 |
license: apache-2.0
|
|
@@ -22,7 +25,7 @@ license: apache-2.0
|
|
| 22 |
<!-- SZL-ESTATE-CARD:v2:END -->
|
| 23 |
|
| 24 |
<!-- SZL-ARTIFACT-NOTICE:v1:START — honesty plate: repo semantics, no fake model tags. -->
|
| 25 |
-
> **
|
| 26 |
<!-- SZL-ARTIFACT-NOTICE:v1:END -->
|
| 27 |
|
| 28 |
|
|
@@ -119,6 +122,47 @@ Python 3.9+, `torch>=2.5`, standard library + torch only.
|
|
| 119 |
|
| 120 |
Apache-2.0. Copyright 2026 SZL Holdings.
|
| 121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
---
|
| 123 |
|
| 124 |
## SZL Kernels Suite
|
|
|
|
| 5 |
- lambda
|
| 6 |
- gate
|
| 7 |
- provenance
|
| 8 |
+
- torch
|
| 9 |
+
- surrogate
|
| 10 |
+
- pytorch
|
| 11 |
- doi:10.5281/zenodo.19944926
|
| 12 |
library_name: kernels
|
| 13 |
license: apache-2.0
|
|
|
|
| 25 |
<!-- SZL-ESTATE-CARD:v2:END -->
|
| 26 |
|
| 27 |
<!-- SZL-ARTIFACT-NOTICE:v1:START — honesty plate: repo semantics, no fake model tags. -->
|
| 28 |
+
> **🟩 Kernel + REAL trained torch surrogate.** The Λ governance kernel (pure-torch, differentiable) is UNCHANGED and remains the sole ground truth. Since **surrogate v1** this repo also ships `model.safetensors` + `config.json` — a real trained tiny torch MLP that predicts the ADVISORY gate decision `lambda_gate(axes, threshold).passed` over the 13-axis Yuyay space, with **MEASURED** fidelity **0.9670** (agreement vs the kernel on a held-out split). The surrogate approximates the gate DECISION only; the kernel Λ stays authoritative and `get_kernel`-discoverable. **Λ is the weighted geometric mean, NOT proven trust — uniqueness = Conjecture 1 (OPEN).**
|
| 29 |
<!-- SZL-ARTIFACT-NOTICE:v1:END -->
|
| 30 |
|
| 31 |
|
|
|
|
| 122 |
|
| 123 |
Apache-2.0. Copyright 2026 SZL Holdings.
|
| 124 |
|
| 125 |
+
## Trained Λ-gate surrogate v1 (MEASURED — see `TRAINING_RECEIPT.json`)
|
| 126 |
+
|
| 127 |
+
A real **tiny torch MLP** (3 hidden ReLU layers, 64 units; `model.safetensors` + `config.json`)
|
| 128 |
+
trained on **40,000 axis-score vectors** synthesized and **labeled by this kernel itself**
|
| 129 |
+
(`lambda_gate(axes, weights=yuyay_uniform_1/13, threshold=0.5).passed`, seed 20260721; 800
|
| 130 |
+
samples re-audited by independent full kernel replay during generation — all agreed). Inputs are
|
| 131 |
+
the 13 Yuyay axis scores in [0,1], including non-compensatory zero-route rows (a single zeroed
|
| 132 |
+
axis must fail the gate).
|
| 133 |
+
|
| 134 |
+
| metric | value |
|
| 135 |
+
|---|---|
|
| 136 |
+
| fidelity vs kernel (held-out agreement) | **0.9670** |
|
| 137 |
+
| recall GATE_PASS | 0.9912 |
|
| 138 |
+
| recall GATE_FAIL | 0.9469 |
|
| 139 |
+
|
| 140 |
+
**Honest boundary:** the surrogate learns the *decision boundary* of an ADVISORY, non-compensatory
|
| 141 |
+
aggregator; it is a fast approximation, NOT the exact Λ and NOT proven trust. Residual disagreement
|
| 142 |
+
lives near the Λ=threshold surface — the exact kernel `lambda_gate` remains authoritative. Class
|
| 143 |
+
counts: GATE_FAIL=21828, GATE_PASS=18172. Λ uniqueness = Conjecture 1 (open).
|
| 144 |
+
|
| 145 |
+
```python
|
| 146 |
+
import torch, json
|
| 147 |
+
from safetensors.torch import load_file
|
| 148 |
+
from torch import nn
|
| 149 |
+
cfg = json.load(open("config.json")) # architecture + input_axes spec
|
| 150 |
+
class GateMLP(nn.Module):
|
| 151 |
+
def __init__(self, k, h):
|
| 152 |
+
super().__init__()
|
| 153 |
+
self.net = nn.Sequential(nn.Linear(k,h), nn.ReLU(), nn.Linear(h,h), nn.ReLU(),
|
| 154 |
+
nn.Linear(h,h), nn.ReLU(), nn.Linear(h,1))
|
| 155 |
+
def forward(self, x): return self.net(x).squeeze(-1)
|
| 156 |
+
model = GateMLP(cfg["input_dim"], cfg["hidden"])
|
| 157 |
+
model.load_state_dict(load_file("model.safetensors")); model.eval()
|
| 158 |
+
axes = torch.rand(1, 13)
|
| 159 |
+
pred_pass = (torch.sigmoid(model(axes)) >= 0.5).item() # advisory gate decision (surrogate)
|
| 160 |
+
```
|
| 161 |
+
|
| 162 |
+
Re-verify everything: `python scripts/eval.py` (sha256-checks the shipped `model.safetensors`
|
| 163 |
+
against the receipt, regenerates the seeded kernel-labeled dataset, retrains, and compares
|
| 164 |
+
fidelity within ±0.02).
|
| 165 |
+
|
| 166 |
---
|
| 167 |
|
| 168 |
## SZL Kernels Suite
|
TRAINING_RECEIPT.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"artifact": "SZLHOLDINGS/szl-lambda-gate surrogate v1",
|
| 3 |
+
"role": "advisory \u039b gate-decision surrogate (torch MLP) \u2014 kernel remains ground truth",
|
| 4 |
+
"generator": {
|
| 5 |
+
"script": "scripts/forge.py",
|
| 6 |
+
"seed": 20260721,
|
| 7 |
+
"kernel_version": "0.2.0",
|
| 8 |
+
"kernel_labelled": true,
|
| 9 |
+
"kernel_audited_samples": 800,
|
| 10 |
+
"labeler": "lambda_gate(axes, weights=yuyay_uniform_1/13, threshold=0.5).passed",
|
| 11 |
+
"axes": [
|
| 12 |
+
"moralGrounding",
|
| 13 |
+
"measurabilityHonesty",
|
| 14 |
+
"empiricalGrounding",
|
| 15 |
+
"logicalConsistency",
|
| 16 |
+
"sourceTransparency",
|
| 17 |
+
"reproducibility",
|
| 18 |
+
"licenseHygiene",
|
| 19 |
+
"scopeDiscipline",
|
| 20 |
+
"claimCalibration",
|
| 21 |
+
"evalAwareness",
|
| 22 |
+
"deceptionKeywords",
|
| 23 |
+
"conflictingDirectives",
|
| 24 |
+
"reversalDirective"
|
| 25 |
+
],
|
| 26 |
+
"threshold": 0.5
|
| 27 |
+
},
|
| 28 |
+
"data": {
|
| 29 |
+
"rows": 40000,
|
| 30 |
+
"classes": [
|
| 31 |
+
"GATE_FAIL",
|
| 32 |
+
"GATE_PASS"
|
| 33 |
+
],
|
| 34 |
+
"class_counts": {
|
| 35 |
+
"GATE_FAIL": 21828,
|
| 36 |
+
"GATE_PASS": 18172
|
| 37 |
+
},
|
| 38 |
+
"split": "80/20 permutation",
|
| 39 |
+
"features": [
|
| 40 |
+
"moralGrounding",
|
| 41 |
+
"measurabilityHonesty",
|
| 42 |
+
"empiricalGrounding",
|
| 43 |
+
"logicalConsistency",
|
| 44 |
+
"sourceTransparency",
|
| 45 |
+
"reproducibility",
|
| 46 |
+
"licenseHygiene",
|
| 47 |
+
"scopeDiscipline",
|
| 48 |
+
"claimCalibration",
|
| 49 |
+
"evalAwareness",
|
| 50 |
+
"deceptionKeywords",
|
| 51 |
+
"conflictingDirectives",
|
| 52 |
+
"reversalDirective"
|
| 53 |
+
],
|
| 54 |
+
"feature_policy": "13 Yuyay axis scores in [0,1]; includes non-compensatory zero-route rows"
|
| 55 |
+
},
|
| 56 |
+
"model": {
|
| 57 |
+
"type": "pytorch GateMLP (3 hidden ReLU layers, 64 units)",
|
| 58 |
+
"params": {
|
| 59 |
+
"input_dim": 13,
|
| 60 |
+
"hidden": 64,
|
| 61 |
+
"epochs": 150,
|
| 62 |
+
"batch": 512,
|
| 63 |
+
"lr": 0.002,
|
| 64 |
+
"optimizer": "Adam",
|
| 65 |
+
"loss": "BCEWithLogits",
|
| 66 |
+
"seed": 20260721
|
| 67 |
+
},
|
| 68 |
+
"file": "model.safetensors",
|
| 69 |
+
"sha256": "79987d9dd53f6c5496569c588ac5203b8d4debda2d8ef9ee7147c43d4740358d",
|
| 70 |
+
"config": "config.json"
|
| 71 |
+
},
|
| 72 |
+
"metrics_MEASURED": {
|
| 73 |
+
"fidelity_vs_kernel_heldout": 0.967,
|
| 74 |
+
"test_accuracy": 0.967,
|
| 75 |
+
"recall_GATE_PASS": 0.9912,
|
| 76 |
+
"recall_GATE_FAIL": 0.9469
|
| 77 |
+
},
|
| 78 |
+
"environment": {
|
| 79 |
+
"python": "3.12.12",
|
| 80 |
+
"torch": "2.13.0+cpu",
|
| 81 |
+
"numpy": "2.5.1",
|
| 82 |
+
"host": "replit 2-vCPU container",
|
| 83 |
+
"wall_seconds": 12.0
|
| 84 |
+
},
|
| 85 |
+
"honesty": "Every number above is MEASURED by this run. Fidelity = agreement%% with the kernel's ADVISORY lambda_gate decision on a held-out split. \u039b is the weighted geometric mean, NOT proven trust; uniqueness = Conjecture 1 (open). The surrogate never replaces the kernel gate.",
|
| 86 |
+
"trained_at_utc": "2026-07-21T02:53:27Z"
|
| 87 |
+
}
|
config.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architecture": "GateMLP",
|
| 3 |
+
"task": "advisory-lambda-gate-decision-surrogate",
|
| 4 |
+
"framework": "pytorch",
|
| 5 |
+
"input_dim": 13,
|
| 6 |
+
"input_axes": [
|
| 7 |
+
"moralGrounding",
|
| 8 |
+
"measurabilityHonesty",
|
| 9 |
+
"empiricalGrounding",
|
| 10 |
+
"logicalConsistency",
|
| 11 |
+
"sourceTransparency",
|
| 12 |
+
"reproducibility",
|
| 13 |
+
"licenseHygiene",
|
| 14 |
+
"scopeDiscipline",
|
| 15 |
+
"claimCalibration",
|
| 16 |
+
"evalAwareness",
|
| 17 |
+
"deceptionKeywords",
|
| 18 |
+
"conflictingDirectives",
|
| 19 |
+
"reversalDirective"
|
| 20 |
+
],
|
| 21 |
+
"hidden": 64,
|
| 22 |
+
"layers": [
|
| 23 |
+
"Linear(13,64)",
|
| 24 |
+
"ReLU",
|
| 25 |
+
"Linear(64,64)",
|
| 26 |
+
"ReLU",
|
| 27 |
+
"Linear(64,64)",
|
| 28 |
+
"ReLU",
|
| 29 |
+
"Linear(64,1)"
|
| 30 |
+
],
|
| 31 |
+
"output": "logit; sigmoid>=0.5 => predicted gate PASS (\u039b>=threshold)",
|
| 32 |
+
"threshold": 0.5,
|
| 33 |
+
"weights": "yuyay uniform 1/13",
|
| 34 |
+
"label_source": "szl_lambda_gate.lambda_gate(axes, weights=yuyay, threshold=0.5).passed",
|
| 35 |
+
"honesty": "predicts the ADVISORY gate DECISION only; \u039b is NOT proven trust; uniqueness = Conjecture 1 (open)"
|
| 36 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:79987d9dd53f6c5496569c588ac5203b8d4debda2d8ef9ee7147c43d4740358d
|
| 3 |
+
size 37708
|
scripts/eval.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Re-verify the torch surrogate: sha256 the shipped model.safetensors against
|
| 3 |
+
TRAINING_RECEIPT.json, then deterministically regenerate the seeded dataset via
|
| 4 |
+
scripts/forge.py and compare re-measured fidelity to the receipt (tolerance 0.02).
|
| 5 |
+
Run from repo root: python scripts/eval.py"""
|
| 6 |
+
import hashlib, json, subprocess, sys, tempfile, os, shutil
|
| 7 |
+
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 8 |
+
receipt = json.load(open(f"{root}/TRAINING_RECEIPT.json"))
|
| 9 |
+
got = hashlib.sha256(open(f"{root}/model.safetensors", "rb").read()).hexdigest()
|
| 10 |
+
want = receipt["model"]["sha256"]
|
| 11 |
+
print(f"model.safetensors sha256 {'MATCHES receipt' if got==want else 'MISMATCH — refuse'}: {got[:16]}…")
|
| 12 |
+
if got != want:
|
| 13 |
+
sys.exit(1)
|
| 14 |
+
with tempfile.TemporaryDirectory() as td:
|
| 15 |
+
shutil.copy(f"{root}/scripts/forge.py", f"{td}/forge.py")
|
| 16 |
+
out = subprocess.run([sys.executable, f"{td}/forge.py"], capture_output=True, text=True, cwd=td)
|
| 17 |
+
print(out.stdout[-400:] if out.returncode == 0 else out.stderr[-600:])
|
| 18 |
+
if out.returncode:
|
| 19 |
+
sys.exit(1)
|
| 20 |
+
re_receipt = json.load(open(f"{td}/TRAINING_RECEIPT.json"))
|
| 21 |
+
d = abs(re_receipt["metrics_MEASURED"]["fidelity_vs_kernel_heldout"]
|
| 22 |
+
- receipt["metrics_MEASURED"]["fidelity_vs_kernel_heldout"])
|
| 23 |
+
print(f"re-measured fidelity delta vs receipt: {d:.4f} ({'OK ≤0.02' if d<=0.02 else 'FAIL'})")
|
| 24 |
+
sys.exit(0 if d <= 0.02 else 1)
|
scripts/forge.py
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Forge a REAL trained torch surrogate for szl-lambda-gate.
|
| 3 |
+
Kernel = ground truth. Surrogate = a tiny torch MLP that predicts the ADVISORY
|
| 4 |
+
gate decision `lambda_gate(axes, threshold).passed` — i.e. Λ(axes) >= threshold —
|
| 5 |
+
over the canonical 13-axis Yuyay space. The kernel's weighted-geometric-mean Λ
|
| 6 |
+
(with non-compensatory zero-routing: any zero/non-finite axis fails the gate) is
|
| 7 |
+
the sole labeler; a sample of labels is re-audited by full kernel replay and MUST
|
| 8 |
+
agree or the run fails loudly.
|
| 9 |
+
|
| 10 |
+
Λ IS NOT PROVEN TRUST — it is the ADVISORY weighted geometric mean, uniqueness =
|
| 11 |
+
Conjecture 1 (OPEN). The surrogate approximates the gate DECISION, nothing more.
|
| 12 |
+
Seeded, receipted, reproducible. Ships .safetensors + config.json."""
|
| 13 |
+
import json, os, random, sys, time, hashlib, platform
|
| 14 |
+
_here = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 15 |
+
if os.path.isdir(os.path.join(_here, "build", "torch-universal")):
|
| 16 |
+
sys.path.insert(0, os.path.join(_here, "build", "torch-universal")) # in-repo run
|
| 17 |
+
else:
|
| 18 |
+
sys.path.insert(0, "/tmp/kernel-probe/szl-lambda-gate/build/torch-universal") # forge-dev run
|
| 19 |
+
import szl_lambda_gate as lg
|
| 20 |
+
import numpy as np
|
| 21 |
+
import torch
|
| 22 |
+
from torch import nn
|
| 23 |
+
from safetensors.torch import save_file
|
| 24 |
+
|
| 25 |
+
SEED = 20260721
|
| 26 |
+
random.seed(SEED); np.random.seed(SEED)
|
| 27 |
+
torch.manual_seed(SEED)
|
| 28 |
+
T0 = time.time()
|
| 29 |
+
|
| 30 |
+
K = len(lg.YUYAY_AXES) # 13 canonical axes
|
| 31 |
+
THRESHOLD = 0.5
|
| 32 |
+
WEIGHTS = lg.yuyay_weights(dtype=torch.float64) # uniform 1/13, advisory
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def kernel_gate(axes_np):
|
| 36 |
+
"""Ground truth: lambda_gate(axes).passed for a batch (N,K)."""
|
| 37 |
+
t = torch.tensor(axes_np, dtype=torch.float64)
|
| 38 |
+
res = lg.lambda_gate(t, weights=WEIGHTS, threshold=THRESHOLD)
|
| 39 |
+
return res.passed.numpy().astype(np.int64)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def synth_axes(n):
|
| 43 |
+
"""Synthesize axis-score vectors that straddle the gate boundary, including
|
| 44 |
+
non-compensatory zero-route cases (a single zeroed axis must fail)."""
|
| 45 |
+
X = np.random.uniform(0.0, 1.0, size=(n, K)).astype(np.float64)
|
| 46 |
+
# push a chunk toward the boundary region so the label is non-trivial
|
| 47 |
+
hi = np.random.rand(n) < 0.45
|
| 48 |
+
X[hi] = np.random.uniform(0.55, 1.0, size=(hi.sum(), K))
|
| 49 |
+
# inject explicit zero-route rows (one axis exactly 0 -> Λ=0 -> fail)
|
| 50 |
+
zr = np.random.rand(n) < 0.12
|
| 51 |
+
idx = np.where(zr)[0]
|
| 52 |
+
for i in idx:
|
| 53 |
+
X[i, np.random.randint(K)] = 0.0
|
| 54 |
+
return X
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class GateMLP(nn.Module):
|
| 58 |
+
def __init__(self, k, hidden=64):
|
| 59 |
+
super().__init__()
|
| 60 |
+
self.net = nn.Sequential(
|
| 61 |
+
nn.Linear(k, hidden), nn.ReLU(),
|
| 62 |
+
nn.Linear(hidden, hidden), nn.ReLU(),
|
| 63 |
+
nn.Linear(hidden, hidden), nn.ReLU(),
|
| 64 |
+
nn.Linear(hidden, 1),
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
def forward(self, x):
|
| 68 |
+
return self.net(x).squeeze(-1)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
# ---- generate (kernel-labeled) ----
|
| 72 |
+
N = 40000
|
| 73 |
+
Xall = synth_axes(N)
|
| 74 |
+
yall = kernel_gate(Xall)
|
| 75 |
+
|
| 76 |
+
# ground-truth audit: independent fresh kernel replay must agree on a sample
|
| 77 |
+
audit_idx = np.array(sorted(random.sample(range(N), 800)))
|
| 78 |
+
replay = kernel_gate(Xall[audit_idx])
|
| 79 |
+
assert np.array_equal(replay, yall[audit_idx]), "kernel disagrees on audited sample"
|
| 80 |
+
audit_checked = int(len(audit_idx))
|
| 81 |
+
|
| 82 |
+
# split 80/20 deterministic
|
| 83 |
+
perm = np.random.permutation(N)
|
| 84 |
+
cut = int(N * 0.8)
|
| 85 |
+
tr, te = perm[:cut], perm[cut:]
|
| 86 |
+
Xtr = torch.tensor(Xall[tr], dtype=torch.float32)
|
| 87 |
+
ytr = torch.tensor(yall[tr], dtype=torch.float32)
|
| 88 |
+
Xte = torch.tensor(Xall[te], dtype=torch.float32)
|
| 89 |
+
yte = torch.tensor(yall[te], dtype=torch.float32)
|
| 90 |
+
|
| 91 |
+
HIDDEN = 64
|
| 92 |
+
model = GateMLP(K, hidden=HIDDEN)
|
| 93 |
+
opt = torch.optim.Adam(model.parameters(), lr=2e-3)
|
| 94 |
+
lossf = nn.BCEWithLogitsLoss()
|
| 95 |
+
EPOCHS = 150
|
| 96 |
+
BATCH = 512
|
| 97 |
+
model.train()
|
| 98 |
+
for ep in range(EPOCHS):
|
| 99 |
+
order = torch.randperm(Xtr.shape[0])
|
| 100 |
+
for b in range(0, Xtr.shape[0], BATCH):
|
| 101 |
+
bi = order[b:b + BATCH]
|
| 102 |
+
opt.zero_grad()
|
| 103 |
+
logits = model(Xtr[bi])
|
| 104 |
+
loss = lossf(logits, ytr[bi])
|
| 105 |
+
loss.backward(); opt.step()
|
| 106 |
+
|
| 107 |
+
model.eval()
|
| 108 |
+
with torch.no_grad():
|
| 109 |
+
pred = (torch.sigmoid(model(Xte)) >= 0.5).long()
|
| 110 |
+
yte_l = yte.long()
|
| 111 |
+
acc = float((pred == yte_l).float().mean()) # fidelity vs kernel
|
| 112 |
+
# per-class recall
|
| 113 |
+
pos = yte_l == 1
|
| 114 |
+
neg = yte_l == 0
|
| 115 |
+
rec_pass = float((pred[pos] == 1).float().mean()) if pos.any() else float("nan")
|
| 116 |
+
rec_fail = float((pred[neg] == 0).float().mean()) if neg.any() else float("nan")
|
| 117 |
+
|
| 118 |
+
out = os.path.dirname(os.path.abspath(__file__))
|
| 119 |
+
state = {k: v.contiguous() for k, v in model.state_dict().items()}
|
| 120 |
+
save_file(state, f"{out}/model.safetensors")
|
| 121 |
+
model_sha = hashlib.sha256(open(f"{out}/model.safetensors", "rb").read()).hexdigest()
|
| 122 |
+
|
| 123 |
+
config = {
|
| 124 |
+
"architecture": "GateMLP",
|
| 125 |
+
"task": "advisory-lambda-gate-decision-surrogate",
|
| 126 |
+
"framework": "pytorch",
|
| 127 |
+
"input_dim": K,
|
| 128 |
+
"input_axes": list(lg.YUYAY_AXES),
|
| 129 |
+
"hidden": HIDDEN,
|
| 130 |
+
"layers": ["Linear(13,64)", "ReLU", "Linear(64,64)", "ReLU", "Linear(64,64)", "ReLU", "Linear(64,1)"],
|
| 131 |
+
"output": "logit; sigmoid>=0.5 => predicted gate PASS (Λ>=threshold)",
|
| 132 |
+
"threshold": THRESHOLD,
|
| 133 |
+
"weights": "yuyay uniform 1/13",
|
| 134 |
+
"label_source": "szl_lambda_gate.lambda_gate(axes, weights=yuyay, threshold=0.5).passed",
|
| 135 |
+
"honesty": "predicts the ADVISORY gate DECISION only; Λ is NOT proven trust; uniqueness = Conjecture 1 (open)",
|
| 136 |
+
}
|
| 137 |
+
with open(f"{out}/config.json", "w") as f:
|
| 138 |
+
json.dump(config, f, indent=2)
|
| 139 |
+
|
| 140 |
+
n_pos = int(yall.sum()); n_neg = int(N - n_pos)
|
| 141 |
+
receipt = {
|
| 142 |
+
"artifact": "SZLHOLDINGS/szl-lambda-gate surrogate v1",
|
| 143 |
+
"role": "advisory Λ gate-decision surrogate (torch MLP) — kernel remains ground truth",
|
| 144 |
+
"generator": {"script": "scripts/forge.py", "seed": SEED, "kernel_version": lg.__version__,
|
| 145 |
+
"kernel_labelled": True, "kernel_audited_samples": audit_checked,
|
| 146 |
+
"labeler": "lambda_gate(axes, weights=yuyay_uniform_1/13, threshold=0.5).passed",
|
| 147 |
+
"axes": list(lg.YUYAY_AXES), "threshold": THRESHOLD},
|
| 148 |
+
"data": {"rows": int(N), "classes": ["GATE_FAIL", "GATE_PASS"],
|
| 149 |
+
"class_counts": {"GATE_FAIL": n_neg, "GATE_PASS": n_pos},
|
| 150 |
+
"split": "80/20 permutation", "features": list(lg.YUYAY_AXES),
|
| 151 |
+
"feature_policy": "13 Yuyay axis scores in [0,1]; includes non-compensatory zero-route rows"},
|
| 152 |
+
"model": {"type": "pytorch GateMLP (3 hidden ReLU layers, 64 units)",
|
| 153 |
+
"params": {"input_dim": K, "hidden": HIDDEN, "epochs": EPOCHS, "batch": BATCH,
|
| 154 |
+
"lr": 2e-3, "optimizer": "Adam", "loss": "BCEWithLogits", "seed": SEED},
|
| 155 |
+
"file": "model.safetensors", "sha256": model_sha, "config": "config.json"},
|
| 156 |
+
"metrics_MEASURED": {"fidelity_vs_kernel_heldout": round(acc, 4),
|
| 157 |
+
"test_accuracy": round(acc, 4),
|
| 158 |
+
"recall_GATE_PASS": round(rec_pass, 4),
|
| 159 |
+
"recall_GATE_FAIL": round(rec_fail, 4)},
|
| 160 |
+
"environment": {"python": platform.python_version(), "torch": torch.__version__,
|
| 161 |
+
"numpy": np.__version__, "host": "replit 2-vCPU container",
|
| 162 |
+
"wall_seconds": round(time.time() - T0, 1)},
|
| 163 |
+
"honesty": "Every number above is MEASURED by this run. Fidelity = agreement%% with the kernel's ADVISORY lambda_gate decision on a held-out split. Λ is the weighted geometric mean, NOT proven trust; uniqueness = Conjecture 1 (open). The surrogate never replaces the kernel gate.",
|
| 164 |
+
"trained_at_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
|
| 165 |
+
}
|
| 166 |
+
with open(f"{out}/TRAINING_RECEIPT.json", "w") as f:
|
| 167 |
+
json.dump(receipt, f, indent=2)
|
| 168 |
+
print(json.dumps(receipt["metrics_MEASURED"], indent=2))
|
| 169 |
+
print(f"rows={N} pos={n_pos} neg={n_neg} kernel_audited={audit_checked} wall={receipt['environment']['wall_seconds']}s")
|