Instructions to use SZLHOLDINGS/szl-ouroboros with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Kernels
How to use SZLHOLDINGS/szl-ouroboros with Kernels:
# !pip install kernels from kernels import get_kernel kernel = get_kernel("SZLHOLDINGS/szl-ouroboros") - Notebooks
- Google Colab
- Kaggle
forge: ship REAL trained surrogate v1 for szl-ouroboros (model.joblib + receipt + scripts; honest card + provenance)
Browse files- MODEL_PROVENANCE.json +28 -13
- README.md +37 -1
- TRAINING_RECEIPT.json +65 -0
- model.joblib +3 -0
- scripts/eval.py +26 -0
- scripts/forge.py +140 -0
MODEL_PROVENANCE.json
CHANGED
|
@@ -3,10 +3,23 @@
|
|
| 3 |
"model": {
|
| 4 |
"id": "SZLHOLDINGS/szl-ouroboros",
|
| 5 |
"repository_type": "model",
|
| 6 |
-
"artifact_kind": "kernel-code-and-configuration",
|
| 7 |
-
"trained_weights_present":
|
| 8 |
-
"stdlib_only":
|
| 9 |
-
"torch_required": false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
},
|
| 11 |
"source_of_record": {
|
| 12 |
"state": "VERIFIED_HF_SOURCE_OF_RECORD",
|
|
@@ -25,20 +38,22 @@
|
|
| 25 |
"falsifiability": "arithmetic is falsifiable (a wrong split flips the asserts); an unmeasured wall yields overheadMs=None (UNAVAILABLE, not fabricated); a missing latency raises; a budget violation is surfaced"
|
| 26 |
},
|
| 27 |
"lambda": {
|
| 28 |
-
"status": "Conjecture 1 (open)
|
| 29 |
"touched_by_this_artifact": false
|
| 30 |
},
|
| 31 |
"claims": {
|
| 32 |
-
"trained_model": "
|
| 33 |
"reproducible_build": "NOT_CLAIMED",
|
| 34 |
-
"weights_present": "
|
| 35 |
},
|
| 36 |
"limits": [
|
| 37 |
-
"
|
| 38 |
-
"
|
| 39 |
-
"deadHopMs
|
| 40 |
-
"
|
|
|
|
|
|
|
| 41 |
"No .bin, .safetensors, .pt, .pth, .onnx, or .gguf weight artifact is present.",
|
| 42 |
-
"Loop-tax accounting does not prove or upgrade
|
| 43 |
]
|
| 44 |
-
}
|
|
|
|
| 3 |
"model": {
|
| 4 |
"id": "SZLHOLDINGS/szl-ouroboros",
|
| 5 |
"repository_type": "model",
|
| 6 |
+
"artifact_kind": "kernel-code-and-configuration + trained surrogate (model.joblib)",
|
| 7 |
+
"trained_weights_present": true,
|
| 8 |
+
"stdlib_only": false,
|
| 9 |
+
"torch_required": false,
|
| 10 |
+
"surrogate": {
|
| 11 |
+
"file": "model.joblib",
|
| 12 |
+
"sha256": "6c4067810eb508dfb61f3cfaf84b6db81cf2f7c78286f02e786205e0b014ac65",
|
| 13 |
+
"role": "loop-tax regressor (predicts kernel-derived overheadMs) \u2014 kernel remains sole ground truth",
|
| 14 |
+
"fidelity_MEASURED": {
|
| 15 |
+
"held_out_MAE_ms": 15.5853,
|
| 16 |
+
"held_out_R2": 0.9822,
|
| 17 |
+
"held_out_target_std_ms": 191.079
|
| 18 |
+
},
|
| 19 |
+
"receipt": "TRAINING_RECEIPT.json",
|
| 20 |
+
"reverify": "python scripts/eval.py"
|
| 21 |
+
},
|
| 22 |
+
"stdlib_only_note": "kernel package itself stays stdlib-only; the OPTIONAL surrogate needs sklearn+joblib"
|
| 23 |
},
|
| 24 |
"source_of_record": {
|
| 25 |
"state": "VERIFIED_HF_SOURCE_OF_RECORD",
|
|
|
|
| 38 |
"falsifiability": "arithmetic is falsifiable (a wrong split flips the asserts); an unmeasured wall yields overheadMs=None (UNAVAILABLE, not fabricated); a missing latency raises; a budget violation is surfaced"
|
| 39 |
},
|
| 40 |
"lambda": {
|
| 41 |
+
"status": "Conjecture 1 (open) \u2014 uniqueness unproven",
|
| 42 |
"touched_by_this_artifact": false
|
| 43 |
},
|
| 44 |
"claims": {
|
| 45 |
+
"trained_model": "CLAIMED \u2014 sklearn HistGradientBoostingRegressor, MEASURED, receipted",
|
| 46 |
"reproducible_build": "NOT_CLAIMED",
|
| 47 |
+
"weights_present": "model.joblib (sklearn surrogate; kernel stays weightless)"
|
| 48 |
},
|
| 49 |
"limits": [
|
| 50 |
+
"The trained surrogate APPROXIMATES the kernel's DERIVED overheadMs from trace shape; it does NOT replace the kernel's exact arithmetic, which remains authoritative.",
|
| 51 |
+
"Runs with an unmeasured wall (overheadMs=None / UNAVAILABLE) are dropped from training \u2014 never fabricated.",
|
| 52 |
+
"modelMs and peakAttemptMs are MEASURED (upstream wall windows); overheadMs, serializationTaxMs and deadHopMs are DERIVED arithmetic on those measurements \u2014 never new claims.",
|
| 53 |
+
"serializationTaxMs is a COUNTERFACTUAL (what a perfectly-parallel loop could save), never a realized saving \u2014 Alloy's loop is strictly sequential.",
|
| 54 |
+
"deadHopMs is an upper bound only \u2014 Alloy does not prefetch.",
|
| 55 |
+
"overheadMs is UNAVAILABLE (None) when the run wall was not measured \u2014 never fabricated.",
|
| 56 |
"No .bin, .safetensors, .pt, .pth, .onnx, or .gguf weight artifact is present.",
|
| 57 |
+
"Loop-tax accounting does not prove or upgrade \u039b, which remains Conjecture 1 (open)."
|
| 58 |
]
|
| 59 |
+
}
|
README.md
CHANGED
|
@@ -6,8 +6,12 @@ tags:
|
|
| 6 |
- ouroboros
|
| 7 |
- loop-tax
|
| 8 |
- provenance
|
|
|
|
|
|
|
|
|
|
| 9 |
- doi:10.5281/zenodo.19944926
|
| 10 |
library_name: kernels
|
|
|
|
| 11 |
license: apache-2.0
|
| 12 |
szl-governance:
|
| 13 |
verdict: ADVISORY
|
|
@@ -27,7 +31,7 @@ szl-governance:
|
|
| 27 |
|
| 28 |
</div>
|
| 29 |
|
| 30 |
-
> **
|
| 31 |
|
| 32 |
> **Kernel Hub migration (verified 2026-07-15):** `get_kernel(...)` resolves the first-class [Kernel Hub repo](https://huggingface.co/kernels/SZLHOLDINGS/szl-ouroboros); `main` and `v1` pin verified revision `756678f0bf096bde25054336c8e1ff78a9eb9172`.
|
| 33 |
|
|
@@ -75,6 +79,38 @@ Mirrors the live a11oy loop-tax accounting (`backbone.ts` — `buildLoopTrace`,
|
|
| 75 |
|
| 76 |
Apache-2.0 · © 2026 SZL Holdings · Stephen P. Lutar · ORCID [0009-0001-0110-4173](https://orcid.org/0009-0001-0110-4173).
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
---
|
| 79 |
|
| 80 |
<sub><b>SZL Holdings honesty footer.</b> Λ = Conjecture 1 (advisory, never a theorem). locked-proven = exactly 8 {F1,F4,F7,F11,F12,F18,F19,F22}. Honesty labels: MEASURED / REPORTED / MODELED / HEURISTIC / UNKNOWN / UNAVAILABLE. Trust never 100% (ceiling 0.97). serializationTax is a counterfactual, never a saving. <a href="https://a-11-oy.com">a-11-oy.com</a> · <a href="https://huggingface.co/SZLHOLDINGS">huggingface.co/SZLHOLDINGS</a></sub>
|
|
|
|
| 6 |
- ouroboros
|
| 7 |
- loop-tax
|
| 8 |
- provenance
|
| 9 |
+
- sklearn
|
| 10 |
+
- surrogate
|
| 11 |
+
- tabular-regression
|
| 12 |
- doi:10.5281/zenodo.19944926
|
| 13 |
library_name: kernels
|
| 14 |
+
pipeline_tag: tabular-regression
|
| 15 |
license: apache-2.0
|
| 16 |
szl-governance:
|
| 17 |
verdict: ADVISORY
|
|
|
|
| 31 |
|
| 32 |
</div>
|
| 33 |
|
| 34 |
+
> **🟩 Kernel + REAL trained surrogate.** The governance kernel (pure-Python, **stdlib-only**) is UNCHANGED and remains the sole ground truth — it reconstructs the a11oy agent-loop trace and its **loop-tax** decomposition from a run's provider-attempt windows (sums, max, subtraction only). Since **surrogate v1** this repo ALSO ships `model.joblib` — a real trained sklearn regressor that predicts the kernel's DERIVED `overheadMs` from trace observables, with **MEASURED** held-out **MAE 15.59 ms** / **R² 0.9822** (target std 191.1 ms). The surrogate never replaces the kernel's exact arithmetic. **Λ is not touched here and stays Conjecture 1 (open).**
|
| 35 |
|
| 36 |
> **Kernel Hub migration (verified 2026-07-15):** `get_kernel(...)` resolves the first-class [Kernel Hub repo](https://huggingface.co/kernels/SZLHOLDINGS/szl-ouroboros); `main` and `v1` pin verified revision `756678f0bf096bde25054336c8e1ff78a9eb9172`.
|
| 37 |
|
|
|
|
| 79 |
|
| 80 |
Apache-2.0 · © 2026 SZL Holdings · Stephen P. Lutar · ORCID [0009-0001-0110-4173](https://orcid.org/0009-0001-0110-4173).
|
| 81 |
|
| 82 |
+
|
| 83 |
+
## Trained loop-tax regressor v1 (MEASURED — see `TRAINING_RECEIPT.json`)
|
| 84 |
+
|
| 85 |
+
A real sklearn `HistGradientBoostingRegressor` trained on **11,841 runs**
|
| 86 |
+
generated as bounded agent loops and **labeled by this kernel itself**: the target is
|
| 87 |
+
`ou.loop_tax(attempts, wall_ms)["overheadMs"]` — the kernel's own DERIVED
|
| 88 |
+
`max(0, wall − modelMs)` (seed 20260721;
|
| 89 |
+
40 runs re-audited by full kernel replay).
|
| 90 |
+
Runs with an **unmeasured wall** (`overheadMs` honestly `None`/UNAVAILABLE) are **dropped,
|
| 91 |
+
never fabricated**. Features are observable trace fields only (per-attempt latencies + ok
|
| 92 |
+
flags + run wall + budget).
|
| 93 |
+
|
| 94 |
+
| metric | value |
|
| 95 |
+
|---|---|
|
| 96 |
+
| held-out MAE (ms) | **15.5853** |
|
| 97 |
+
| held-out R² | **0.9822** |
|
| 98 |
+
| target std (ms) | 191.0790 |
|
| 99 |
+
|
| 100 |
+
R² is the **fidelity of the surrogate to the kernel's DERIVED `overheadMs`** — a fast
|
| 101 |
+
approximation of the loop-tax derivation, not a new measurement. The kernel's exact
|
| 102 |
+
arithmetic remains authoritative; `serializationTaxMs` stays a **counterfactual, never a
|
| 103 |
+
realized saving**. Λ untouched = Conjecture 1.
|
| 104 |
+
|
| 105 |
+
```python
|
| 106 |
+
import joblib
|
| 107 |
+
reg = joblib.load("model.joblib") # feature spec: TRAINING_RECEIPT.json data.features
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
Re-verify everything: `python scripts/eval.py` (sha256-checks the shipped model against the
|
| 111 |
+
receipt, regenerates the seeded dataset via the in-repo kernel, retrains, and compares R²
|
| 112 |
+
within ±0.02).
|
| 113 |
+
|
| 114 |
---
|
| 115 |
|
| 116 |
<sub><b>SZL Holdings honesty footer.</b> Λ = Conjecture 1 (advisory, never a theorem). locked-proven = exactly 8 {F1,F4,F7,F11,F12,F18,F19,F22}. Honesty labels: MEASURED / REPORTED / MODELED / HEURISTIC / UNKNOWN / UNAVAILABLE. Trust never 100% (ceiling 0.97). serializationTax is a counterfactual, never a saving. <a href="https://a-11-oy.com">a-11-oy.com</a> · <a href="https://huggingface.co/SZLHOLDINGS">huggingface.co/SZLHOLDINGS</a></sub>
|
TRAINING_RECEIPT.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"artifact": "SZLHOLDINGS/szl-ouroboros surrogate v1",
|
| 3 |
+
"role": "loop-tax regressor (predicts kernel-derived overheadMs from trace observables) \u2014 kernel remains ground truth",
|
| 4 |
+
"generator": {
|
| 5 |
+
"script": "scripts/forge.py",
|
| 6 |
+
"seed": 20260721,
|
| 7 |
+
"kernel_version": "0.1.0",
|
| 8 |
+
"kernel_labelled": true,
|
| 9 |
+
"kernel_replay_audited_runs": 40,
|
| 10 |
+
"target": "overheadMs",
|
| 11 |
+
"target_source": "ou.loop_tax(attempts, wall_ms)['overheadMs'] (DERIVED = max(0, wall - modelMs))",
|
| 12 |
+
"unavailable_policy": "runs with unmeasured wall (overheadMs=None) are DROPPED, never fabricated"
|
| 13 |
+
},
|
| 14 |
+
"data": {
|
| 15 |
+
"rows": 11841,
|
| 16 |
+
"runs_generated": 14000,
|
| 17 |
+
"rows_after_dropping_unavailable": 11841,
|
| 18 |
+
"split": "80/20 random",
|
| 19 |
+
"features": [
|
| 20 |
+
"n_attempts",
|
| 21 |
+
"wall_ms",
|
| 22 |
+
"sum_latency",
|
| 23 |
+
"max_latency",
|
| 24 |
+
"min_latency",
|
| 25 |
+
"mean_latency",
|
| 26 |
+
"std_latency",
|
| 27 |
+
"median_latency",
|
| 28 |
+
"served_hop_index",
|
| 29 |
+
"n_failed_before_served",
|
| 30 |
+
"n_ok",
|
| 31 |
+
"n_missing_model",
|
| 32 |
+
"max_budget",
|
| 33 |
+
"aborted"
|
| 34 |
+
],
|
| 35 |
+
"target_units": "milliseconds",
|
| 36 |
+
"target_mean_ms": 379.68,
|
| 37 |
+
"target_std_ms": 188.66,
|
| 38 |
+
"feature_policy": "observable trace fields only (per-attempt latencies + ok flags + wall + budget); target is the kernel's own DERIVED arithmetic"
|
| 39 |
+
},
|
| 40 |
+
"model": {
|
| 41 |
+
"type": "sklearn.HistGradientBoostingRegressor",
|
| 42 |
+
"params": {
|
| 43 |
+
"max_iter": 400,
|
| 44 |
+
"early_stopping": true,
|
| 45 |
+
"random_state": 20260721
|
| 46 |
+
},
|
| 47 |
+
"file": "model.joblib",
|
| 48 |
+
"sha256": "6c4067810eb508dfb61f3cfaf84b6db81cf2f7c78286f02e786205e0b014ac65"
|
| 49 |
+
},
|
| 50 |
+
"metrics_MEASURED": {
|
| 51 |
+
"held_out_MAE_ms": 15.5853,
|
| 52 |
+
"held_out_R2": 0.9822,
|
| 53 |
+
"held_out_target_std_ms": 191.079,
|
| 54 |
+
"interpretation": "R2 is fidelity of the surrogate to the kernel's DERIVED overheadMs; the kernel's exact arithmetic remains authoritative"
|
| 55 |
+
},
|
| 56 |
+
"environment": {
|
| 57 |
+
"python": "3.12.12",
|
| 58 |
+
"sklearn": "1.9.0",
|
| 59 |
+
"numpy": "2.5.1",
|
| 60 |
+
"host": "replit 2-vCPU container",
|
| 61 |
+
"wall_seconds": 1.0
|
| 62 |
+
},
|
| 63 |
+
"honesty": "Every number above is MEASURED by this run. The surrogate approximates the kernel's loop-tax derivation from trace shape; it never replaces the kernel's exact arithmetic. serializationTax stays a counterfactual. \u039b untouched = Conjecture 1.",
|
| 64 |
+
"trained_at_utc": "2026-07-21T02:53:08Z"
|
| 65 |
+
}
|
model.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6c4067810eb508dfb61f3cfaf84b6db81cf2f7c78286f02e786205e0b014ac65
|
| 3 |
+
size 834152
|
scripts/eval.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Re-verify the szl-ouroboros surrogate: sha256 the shipped model against
|
| 3 |
+
TRAINING_RECEIPT.json, then deterministically regenerate the seeded dataset via
|
| 4 |
+
scripts/forge.py (kernel resolved from this repo's own build/ dir) and compare
|
| 5 |
+
re-measured R² to the receipt (tolerance 0.02). Run from repo root:
|
| 6 |
+
python scripts/eval.py"""
|
| 7 |
+
import hashlib, json, subprocess, sys, tempfile, os, shutil
|
| 8 |
+
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 9 |
+
receipt = json.load(open(f"{root}/TRAINING_RECEIPT.json"))
|
| 10 |
+
got = hashlib.sha256(open(f"{root}/model.joblib", "rb").read()).hexdigest()
|
| 11 |
+
want = receipt["model"]["sha256"]
|
| 12 |
+
print(f"model.joblib sha256 {'MATCHES receipt' if got==want else 'MISMATCH — refuse'}: {got[:16]}…")
|
| 13 |
+
if got != want: sys.exit(1)
|
| 14 |
+
with tempfile.TemporaryDirectory() as td:
|
| 15 |
+
os.makedirs(f"{td}/repo/scripts")
|
| 16 |
+
os.symlink(f"{root}/build", f"{td}/repo/build")
|
| 17 |
+
shutil.copy(f"{root}/scripts/forge.py", f"{td}/repo/scripts/forge.py")
|
| 18 |
+
out = subprocess.run([sys.executable, f"{td}/repo/scripts/forge.py"],
|
| 19 |
+
capture_output=True, text=True)
|
| 20 |
+
print(out.stdout[-500:] if out.returncode == 0 else out.stderr[-500:])
|
| 21 |
+
if out.returncode: sys.exit(1)
|
| 22 |
+
re_receipt = json.load(open(f"{td}/repo/scripts/TRAINING_RECEIPT.json"))
|
| 23 |
+
d = abs(re_receipt["metrics_MEASURED"]["held_out_R2"]
|
| 24 |
+
- receipt["metrics_MEASURED"]["held_out_R2"])
|
| 25 |
+
print(f"re-measured R² delta vs receipt: {d:.4f} ({'OK ≤0.02' if d<=0.02 else 'FAIL'})")
|
| 26 |
+
sys.exit(0 if d <= 0.02 else 1)
|
scripts/forge.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Forge a REAL trained surrogate for szl-ouroboros.
|
| 3 |
+
Kernel = ground truth. Surrogate = a loop-tax REGRESSOR: given the observable
|
| 4 |
+
attempt-window trace of a bounded agent loop (per-attempt latencies, ok flags,
|
| 5 |
+
run wall), predict the kernel's DERIVED `overheadMs` loop-tax field. The label
|
| 6 |
+
is computed by the REAL kernel (`loop_tax`), so the target is definitionally the
|
| 7 |
+
kernel's own arithmetic; the regressor's job is to reproduce that derivation from
|
| 8 |
+
trace observables — its skill (MAE / R²) is MEASURED against held-out kernel labels.
|
| 9 |
+
A sample of traces is re-audited by full kernel replay. Seeded, receipted."""
|
| 10 |
+
import json, os, random, sys, time, hashlib, platform
|
| 11 |
+
_here = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 12 |
+
if os.path.isdir(os.path.join(_here, "build", "torch-universal")):
|
| 13 |
+
sys.path.insert(0, os.path.join(_here, "build", "torch-universal")) # in-repo run
|
| 14 |
+
else:
|
| 15 |
+
sys.path.insert(0, "/tmp/kernel-probe/szl-ouroboros/build/torch-universal") # forge-dev run
|
| 16 |
+
import szl_ouroboros as ou
|
| 17 |
+
import numpy as np
|
| 18 |
+
from sklearn.ensemble import HistGradientBoostingRegressor
|
| 19 |
+
from sklearn.model_selection import train_test_split
|
| 20 |
+
from sklearn.metrics import mean_absolute_error, r2_score
|
| 21 |
+
import joblib
|
| 22 |
+
|
| 23 |
+
SEED = 20260721
|
| 24 |
+
random.seed(SEED); np.random.seed(SEED)
|
| 25 |
+
T0 = time.time()
|
| 26 |
+
|
| 27 |
+
EXITS = ou.LOOP_EXITS # ("converged","budgetExhausted","aborted","error")
|
| 28 |
+
EXIT_IX = {e: i for i, e in enumerate(EXITS)}
|
| 29 |
+
|
| 30 |
+
def make_run(run_id):
|
| 31 |
+
"""Generate one realistic bounded-loop run. wall_ms is modeled as
|
| 32 |
+
modelMs + a genuine orchestration overhead + noise, so overheadMs is NOT a
|
| 33 |
+
trivial constant. Returns (attempts, wall_ms, aborted)."""
|
| 34 |
+
max_budget = random.randint(1, 6)
|
| 35 |
+
n = random.randint(1, max_budget)
|
| 36 |
+
aborted = random.random() < 0.08
|
| 37 |
+
demo = random.random() < 0.06 # demo run: no model call
|
| 38 |
+
if demo:
|
| 39 |
+
return [], (None if random.random() < 0.3 else float(random.randint(5, 120))), aborted
|
| 40 |
+
served_at = None
|
| 41 |
+
if not aborted and random.random() < 0.85:
|
| 42 |
+
served_at = random.randrange(n) # a hop that succeeds
|
| 43 |
+
attempts = []
|
| 44 |
+
for i in range(n):
|
| 45 |
+
lat = float(random.randint(30, 1500))
|
| 46 |
+
ok = (i == served_at)
|
| 47 |
+
attempts.append({"provider": random.choice(["sovereign", "own", "fallback"]),
|
| 48 |
+
"model": random.choice(["own-metal", "khipu-1.5b", None]),
|
| 49 |
+
"ok": ok, "latency_ms": lat,
|
| 50 |
+
"node": random.choice(["tower", "laptop", "node-a"])})
|
| 51 |
+
model_ms = sum(a["latency_ms"] for a in attempts)
|
| 52 |
+
# genuine orchestration overhead: energy-meter samples + self-verify pass
|
| 53 |
+
true_overhead = random.uniform(20, 600) + 0.05 * model_ms
|
| 54 |
+
wall = model_ms + true_overhead + random.gauss(0, 15)
|
| 55 |
+
wall = max(wall, model_ms) # sequential loop: wall >= modelMs
|
| 56 |
+
if random.random() < 0.15:
|
| 57 |
+
wall = None # unmeasured wall -> overheadMs UNAVAILABLE (dropped from training)
|
| 58 |
+
return attempts, (None if wall is None else float(wall)), aborted
|
| 59 |
+
|
| 60 |
+
def features(attempts, wall_ms, max_budget, aborted):
|
| 61 |
+
lats = [float(a["latency_ms"]) for a in attempts]
|
| 62 |
+
n = len(lats)
|
| 63 |
+
la = np.array(lats) if lats else np.array([0.0])
|
| 64 |
+
served_ix = next((i for i, a in enumerate(attempts) if a.get("ok")), -1)
|
| 65 |
+
n_failed_before = served_ix if served_ix >= 0 else n
|
| 66 |
+
return [
|
| 67 |
+
float(n),
|
| 68 |
+
float(wall_ms) if wall_ms is not None else -1.0,
|
| 69 |
+
float(la.sum()), float(la.max()), float(la.min()), float(la.mean()),
|
| 70 |
+
float(la.std()), float(np.median(la)),
|
| 71 |
+
float(served_ix), float(n_failed_before),
|
| 72 |
+
float(sum(1 for a in attempts if a.get("ok"))),
|
| 73 |
+
float(sum(1 for a in attempts if a.get("model") is None)),
|
| 74 |
+
float(max_budget), float(aborted),
|
| 75 |
+
]
|
| 76 |
+
|
| 77 |
+
FEATURE_NAMES = ["n_attempts", "wall_ms", "sum_latency", "max_latency", "min_latency",
|
| 78 |
+
"mean_latency", "std_latency", "median_latency", "served_hop_index",
|
| 79 |
+
"n_failed_before_served", "n_ok", "n_missing_model", "max_budget", "aborted"]
|
| 80 |
+
|
| 81 |
+
# ---- generate (target = kernel-derived overheadMs; drop UNAVAILABLE rows) ----
|
| 82 |
+
N_RUNS = 14000
|
| 83 |
+
X, y, audited = [], [], 0
|
| 84 |
+
audit_bank = []
|
| 85 |
+
for rid in range(N_RUNS):
|
| 86 |
+
attempts, wall_ms, aborted = make_run(rid)
|
| 87 |
+
max_budget = max(len(attempts), random.randint(len(attempts), len(attempts) + 3)) or 1
|
| 88 |
+
tax = ou.loop_tax(attempts, wall_ms) # REAL kernel computation == ground truth
|
| 89 |
+
overhead = tax["overheadMs"]
|
| 90 |
+
if overhead is None: # wall unmeasured -> honestly UNAVAILABLE
|
| 91 |
+
continue
|
| 92 |
+
X.append(features(attempts, wall_ms, max_budget, aborted))
|
| 93 |
+
y.append(float(overhead))
|
| 94 |
+
if len(audit_bank) < 40:
|
| 95 |
+
audit_bank.append((attempts, wall_ms, overhead))
|
| 96 |
+
|
| 97 |
+
# kernel-replay audit
|
| 98 |
+
for attempts, wall_ms, recorded in audit_bank:
|
| 99 |
+
replay = ou.loop_tax(attempts, wall_ms)["overheadMs"]
|
| 100 |
+
assert abs(replay - recorded) <= 1e-9, f"kernel replay disagreement: {replay} != {recorded}"
|
| 101 |
+
audited += 1
|
| 102 |
+
|
| 103 |
+
X = np.array(X, dtype=np.float64); y = np.array(y, dtype=np.float64)
|
| 104 |
+
Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.2, random_state=SEED)
|
| 105 |
+
reg = HistGradientBoostingRegressor(random_state=SEED, max_iter=400, early_stopping=True)
|
| 106 |
+
reg.fit(Xtr, ytr)
|
| 107 |
+
pred = reg.predict(Xte)
|
| 108 |
+
mae = float(mean_absolute_error(yte, pred))
|
| 109 |
+
r2 = float(r2_score(yte, pred))
|
| 110 |
+
target_std = float(np.std(yte))
|
| 111 |
+
|
| 112 |
+
out_dir = os.path.dirname(os.path.abspath(__file__))
|
| 113 |
+
joblib.dump(reg, f"{out_dir}/model.joblib")
|
| 114 |
+
model_sha = hashlib.sha256(open(f"{out_dir}/model.joblib", "rb").read()).hexdigest()
|
| 115 |
+
receipt = {
|
| 116 |
+
"artifact": "SZLHOLDINGS/szl-ouroboros surrogate v1",
|
| 117 |
+
"role": "loop-tax regressor (predicts kernel-derived overheadMs from trace observables) — kernel remains ground truth",
|
| 118 |
+
"generator": {"script": "scripts/forge.py", "seed": SEED, "kernel_version": ou.__version__,
|
| 119 |
+
"kernel_labelled": True, "kernel_replay_audited_runs": audited,
|
| 120 |
+
"target": "overheadMs", "target_source": "ou.loop_tax(attempts, wall_ms)['overheadMs'] (DERIVED = max(0, wall - modelMs))",
|
| 121 |
+
"unavailable_policy": "runs with unmeasured wall (overheadMs=None) are DROPPED, never fabricated"},
|
| 122 |
+
"data": {"rows": int(len(y)), "runs_generated": N_RUNS, "rows_after_dropping_unavailable": int(len(y)),
|
| 123 |
+
"split": "80/20 random", "features": FEATURE_NAMES,
|
| 124 |
+
"target_units": "milliseconds", "target_mean_ms": round(float(np.mean(y)), 2),
|
| 125 |
+
"target_std_ms": round(float(np.std(y)), 2),
|
| 126 |
+
"feature_policy": "observable trace fields only (per-attempt latencies + ok flags + wall + budget); target is the kernel's own DERIVED arithmetic"},
|
| 127 |
+
"model": {"type": "sklearn.HistGradientBoostingRegressor",
|
| 128 |
+
"params": {"max_iter": 400, "early_stopping": True, "random_state": SEED},
|
| 129 |
+
"file": "model.joblib", "sha256": model_sha},
|
| 130 |
+
"metrics_MEASURED": {"held_out_MAE_ms": round(mae, 4), "held_out_R2": round(r2, 4),
|
| 131 |
+
"held_out_target_std_ms": round(target_std, 4),
|
| 132 |
+
"interpretation": "R2 is fidelity of the surrogate to the kernel's DERIVED overheadMs; the kernel's exact arithmetic remains authoritative"},
|
| 133 |
+
"environment": {"python": platform.python_version(), "sklearn": __import__("sklearn").__version__,
|
| 134 |
+
"numpy": np.__version__, "host": "replit 2-vCPU container", "wall_seconds": round(time.time()-T0, 1)},
|
| 135 |
+
"honesty": "Every number above is MEASURED by this run. The surrogate approximates the kernel's loop-tax derivation from trace shape; it never replaces the kernel's exact arithmetic. serializationTax stays a counterfactual. Λ untouched = Conjecture 1.",
|
| 136 |
+
"trained_at_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
|
| 137 |
+
}
|
| 138 |
+
with open(f"{out_dir}/TRAINING_RECEIPT.json", "w") as f: json.dump(receipt, f, indent=2)
|
| 139 |
+
print(json.dumps(receipt["metrics_MEASURED"], indent=2))
|
| 140 |
+
print(f"rows={len(y)} audited={audited} wall={receipt['environment']['wall_seconds']}s")
|