Spaces:
Running
Running
deploy(hf): sync szl-holdings/a11oy@main derived COPY set
Browse filesReusable Dockerfile-COPY-derived deploy from szl-holdings/a11oy main.
Files: 871 Pruned: 0
Derived from Dockerfile COPY sources (NO hand-maintained allowlist).
Signed-off-by: SZL Holdings <noreply@szlholdings.ai>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- static/3d/holographic.html +4 -0
- static/3d/surfaces/agentcoh.js +457 -0
- static/3d/surfaces/catq.js +514 -0
- static/3d/surfaces/rauq.js +501 -0
- static/3d/surfaces/slidesparse.js +616 -0
static/3d/holographic.html
CHANGED
|
@@ -107,6 +107,10 @@ const SURFACES = [
|
|
| 107 |
{ id: "graphmem", title: "Multi-Graph Agentic Memory", mod: "/static/3d/surfaces/graphmem.js" },
|
| 108 |
{ id: "elf", title: "Continuous-Embedding Flow LM", mod: "/static/3d/surfaces/elf.js" },
|
| 109 |
{ id: "s3search", title: "Stratified Denoise Search", mod: "/static/3d/surfaces/s3search.js" },
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
{ id: "energy", title: "Energy", mod: "/static/3d/surfaces/energy.js" },
|
| 111 |
{ id: "fabric", title: "Fabric", mod: "/static/3d/surfaces/fabric.js" },
|
| 112 |
{ id: "pnt", title: "PNT", mod: "/static/3d/surfaces/pnt.js" },
|
|
|
|
| 107 |
{ id: "graphmem", title: "Multi-Graph Agentic Memory", mod: "/static/3d/surfaces/graphmem.js" },
|
| 108 |
{ id: "elf", title: "Continuous-Embedding Flow LM", mod: "/static/3d/surfaces/elf.js" },
|
| 109 |
{ id: "s3search", title: "Stratified Denoise Search", mod: "/static/3d/surfaces/s3search.js" },
|
| 110 |
+
{ id: "slidesparse", title: "Structured-Sparse Layout Packing", mod: "/static/3d/surfaces/slidesparse.js" },
|
| 111 |
+
{ id: "catq", title: "Calibration Ternary Quant", mod: "/static/3d/surfaces/catq.js" },
|
| 112 |
+
{ id: "rauq", title: "Attention-Pattern Uncertainty", mod: "/static/3d/surfaces/rauq.js" },
|
| 113 |
+
{ id: "agentcoh", title: "Multi-Agent Memory Coherence", mod: "/static/3d/surfaces/agentcoh.js" },
|
| 114 |
{ id: "energy", title: "Energy", mod: "/static/3d/surfaces/energy.js" },
|
| 115 |
{ id: "fabric", title: "Fabric", mod: "/static/3d/surfaces/fabric.js" },
|
| 116 |
{ id: "pnt", title: "PNT", mod: "/static/3d/surfaces/pnt.js" },
|
static/3d/surfaces/agentcoh.js
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 0009-0001-0110-4173 · Doctrine v11
|
| 3 |
+
//
|
| 4 |
+
// surfaces/agentcoh.js — MULTI-AGENT MEMORY COHERENCE organ (NEW AXIS) for the
|
| 5 |
+
// holographic frontier ring, clean-room-inspired by (NOT a reproduction of) the
|
| 6 |
+
// TOKEN COHERENCE idea (arXiv:2603.15183, Parakhin): naive multi-agent LLM
|
| 7 |
+
// orchestration rebroadcasts full shared state on every update, costing O(n·S·|D|);
|
| 8 |
+
// this maps onto SHARED-MEMORY CACHE COHERENCE — an artifact held by several agents
|
| 9 |
+
// is a cache line held by several cores. This organ ports the MESI protocol
|
| 10 |
+
// (Modified/Exclusive/Shared/Invalid + LAZY INVALIDATION) to artifacts.
|
| 11 |
+
//
|
| 12 |
+
// Visual: a grid of MESI state LANES — one row per (agent, artifact) cache entry —
|
| 13 |
+
// advancing left-to-right along the operation trace. Each cell's colour encodes its
|
| 14 |
+
// MESI state; invalidation events flash on the writer→peer links. A side panel shows
|
| 15 |
+
// the naive-vs-MESI cost curve as write_fraction sweeps, and the three invariant
|
| 16 |
+
// PASS/FAIL lights (mesi_buggy surfaces a stale-read FAIL). Honesty label "MODELED"
|
| 17 |
+
// is read VERBATIM from the JSON and displayed as-is; it is never upgraded.
|
| 18 |
+
//
|
| 19 |
+
// Surface export shape (mirrors episodic.js / graphmem.js exactly):
|
| 20 |
+
// export default { id, title, endpoints, mount(ctx), unmount() }
|
| 21 |
+
// ctx = { stage, container, live, label, THREE, szl3d }
|
| 22 |
+
//
|
| 23 |
+
// DATA SHOWN (all from live endpoint):
|
| 24 |
+
// timeline[] — per-artifact { artifact, lanes:[{agent, states:[...]}] }
|
| 25 |
+
// naive / mesi — { coordinator, cost, invalidations, refetches, ... }
|
| 26 |
+
// invariants — { single_writer, monotonic_versioning, bounded_staleness }
|
| 27 |
+
// cost_curve[] — { write_fraction, naive_cost, mesi_cost, savings_ratio }
|
| 28 |
+
// invalidation_events[] — { step, artifact, from, to }
|
| 29 |
+
//
|
| 30 |
+
// LEADERS ADOPTED & CITED (clean-room; NOT claimed as SZL's own):
|
| 31 |
+
// Token Coherence (MESI→artifact protocol; Parakhin): https://arxiv.org/abs/2603.15183
|
| 32 |
+
// Multi-Agent Memory from a Computer Architecture Perspective (Yu et al.):
|
| 33 |
+
// https://arxiv.org/abs/2603.10062
|
| 34 |
+
// Governed Shared Memory for Multi-Agent LLM Systems: https://arxiv.org/abs/2606.24535
|
| 35 |
+
//
|
| 36 |
+
// HONESTY LABELS: MODELED (toy deterministic sim of the MESI→artifact coherence
|
| 37 |
+
// MECHANISM; integer-versioned dict entries; cost is a counted token/byte proxy, not
|
| 38 |
+
// measured LLM tokens; invariants via in-sim assertions, NOT a TLA+ checker; no
|
| 39 |
+
// LangGraph/CrewAI/AutoGen). Read verbatim from JSON; never upgraded here.
|
| 40 |
+
// COLOURS: lattice-blue 0x5b8dee (Shared / Exclusive lanes + naive cost), violet-blue
|
| 41 |
+
// 0x8a6bff (Modified writer lane + invalidation flash — data-viz only), proof-teal
|
| 42 |
+
// 0x3af4c8 (MESI cost / invariant-PASS accent), greys for Invalid / degraded / no-data.
|
| 43 |
+
// Purple BANNED as UI/background.
|
| 44 |
+
// 0 RUNTIME CDN. three.js via ctx.THREE (vendored r170 through the page importmap).
|
| 45 |
+
// DOCTRINE v11: degrades gracefully (grey) on 404/error; honesty label still shown.
|
| 46 |
+
|
| 47 |
+
const ID = "agentcoh";
|
| 48 |
+
const TITLE = "Multi-Agent Memory Coherence · MESI→artifact (live)";
|
| 49 |
+
|
| 50 |
+
// Endpoint on the dedicated killinchu Space (isolated compute), reached cross-origin.
|
| 51 |
+
const EP = "https://szlholdings-killinchu.hf.space/api/killinchu/v1/agentcoh/sync?seed=42&num_agents=3&num_artifacts=4&write_fraction=0.35&mode=mesi";
|
| 52 |
+
|
| 53 |
+
// data-viz hues — purple BANNED
|
| 54 |
+
const C_SHARED = 0x5b8dee; // lattice-blue (Shared / Exclusive lane + naive cost bar)
|
| 55 |
+
const C_MOD = 0x8a6bff; // violet-blue (Modified writer lane + invalidation flash — data-viz only)
|
| 56 |
+
const C_ACCENT = 0x3af4c8; // proof-teal (MESI cost bar / invariant-PASS accent)
|
| 57 |
+
const C_DIM = 0x42505d; // grey (Invalid lane / degraded / no-live-data)
|
| 58 |
+
const C_GRID = 0x1b3a44; // floor / link colour
|
| 59 |
+
|
| 60 |
+
const N_ART = 4; // artifact rows (matches endpoint default cap of visualization)
|
| 61 |
+
const N_AGENT = 3; // agent sub-lanes per artifact
|
| 62 |
+
const N_STEP = 24; // visible trace steps (columns) along the x-axis
|
| 63 |
+
const SPAN_X = 18; // world-unit span of the trace axis
|
| 64 |
+
const LANE_DY = 0.9; // vertical spacing between agent lanes
|
| 65 |
+
const ART_DY = 3.4; // vertical spacing between artifact blocks
|
| 66 |
+
|
| 67 |
+
let _stage = null, _THREE = null, _ctx = null, _group = null, _overlay = null;
|
| 68 |
+
let _frameReg = false, _polls = [], _el = {}, _badge = null;
|
| 69 |
+
let _plain = false;
|
| 70 |
+
|
| 71 |
+
// geometry handles
|
| 72 |
+
let _cells = []; // Array<THREE.Mesh> — one cell per (artifact, agent, step)
|
| 73 |
+
let _links = null; // THREE.LineSegments — invalidation event links
|
| 74 |
+
let _flash = []; // per-cell flash timer (invalidation highlight)
|
| 75 |
+
|
| 76 |
+
// live state
|
| 77 |
+
const S = {
|
| 78 |
+
label: null,
|
| 79 |
+
timeline: null, // Array<{artifact, lanes:[{agent, states:[...]}]}>
|
| 80 |
+
naive: null, // {coordinator, cost, ...}
|
| 81 |
+
mesi: null, // {coordinator, cost, invalidations, refetches, ...}
|
| 82 |
+
invariants: null, // {single_writer, monotonic_versioning, bounded_staleness, all_hold}
|
| 83 |
+
costCurve: null, // Array<{write_fraction, naive_cost, mesi_cost, savings_ratio}>
|
| 84 |
+
invEvents: null, // Array<{step, artifact, from, to}>
|
| 85 |
+
mode: null,
|
| 86 |
+
state: "init",
|
| 87 |
+
};
|
| 88 |
+
|
| 89 |
+
// map a MESI state string to a data-viz colour
|
| 90 |
+
function _stateColor(st, live) {
|
| 91 |
+
if (!live) return C_DIM;
|
| 92 |
+
if (st === "Modified") return C_MOD;
|
| 93 |
+
if (st === "Exclusive") return C_SHARED;
|
| 94 |
+
if (st === "Shared") return C_SHARED;
|
| 95 |
+
if (st === "Invalid") return C_DIM;
|
| 96 |
+
return C_DIM;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
// =============================================================================
|
| 100 |
+
// mount(ctx)
|
| 101 |
+
// =============================================================================
|
| 102 |
+
export function mount(ctx) {
|
| 103 |
+
_ctx = ctx; _stage = ctx.stage; _THREE = ctx.THREE;
|
| 104 |
+
_group = new _THREE.Group();
|
| 105 |
+
_stage.scene.add(_group);
|
| 106 |
+
_stage.camera.position.set(0, 9, 26);
|
| 107 |
+
try { if (_stage.controls && _stage.controls.target) { _stage.controls.target.set(0, 3, 0); _stage.controls.update(); } } catch (_) {}
|
| 108 |
+
try { _stage.setBloom(true); } catch (_) {}
|
| 109 |
+
|
| 110 |
+
_buildFloor();
|
| 111 |
+
_buildCells();
|
| 112 |
+
|
| 113 |
+
if (!_frameReg) { _stage.onFrame(_onFrame); _frameReg = true; }
|
| 114 |
+
|
| 115 |
+
_badge = ctx.live.createBadge();
|
| 116 |
+
_polls.push(ctx.live.poll(EP, 5000, _onSync, { badge: _badge, onState: (m) => { S.state = m.state; _paintOverlay(); _paintCells(); } }));
|
| 117 |
+
|
| 118 |
+
_buildOverlay();
|
| 119 |
+
return { id: ID, started: true };
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
// =============================================================================
|
| 123 |
+
// builders
|
| 124 |
+
// =============================================================================
|
| 125 |
+
function _buildFloor() {
|
| 126 |
+
const THREE = _THREE;
|
| 127 |
+
const grid = new THREE.GridHelper(44, 44, C_GRID, 0x0f2027);
|
| 128 |
+
grid.material.opacity = 0.16; grid.material.transparent = true; grid.position.y = -0.01;
|
| 129 |
+
_group.add(grid);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
function _buildCells() {
|
| 133 |
+
const THREE = _THREE;
|
| 134 |
+
const geo = new THREE.BoxGeometry(0.5, 0.28, 0.5);
|
| 135 |
+
_cells = [];
|
| 136 |
+
_flash = [];
|
| 137 |
+
// rows: artifact block (N_ART), each with N_AGENT lanes; columns: N_STEP trace steps
|
| 138 |
+
for (let art = 0; art < N_ART; art++) {
|
| 139 |
+
for (let ag = 0; ag < N_AGENT; ag++) {
|
| 140 |
+
for (let st = 0; st < N_STEP; st++) {
|
| 141 |
+
const mat = new THREE.MeshStandardMaterial({
|
| 142 |
+
color: C_DIM, emissive: C_DIM, emissiveIntensity: 0.12,
|
| 143 |
+
metalness: 0.2, roughness: 0.6,
|
| 144 |
+
});
|
| 145 |
+
const mesh = new THREE.Mesh(geo, mat);
|
| 146 |
+
const x = (st / (N_STEP - 1)) * SPAN_X - SPAN_X / 2;
|
| 147 |
+
const y = art * ART_DY + ag * LANE_DY + 0.6;
|
| 148 |
+
mesh.position.set(x, y, 0);
|
| 149 |
+
mesh.userData = { art, ag, st };
|
| 150 |
+
_group.add(mesh);
|
| 151 |
+
_cells.push(mesh);
|
| 152 |
+
_flash.push(0);
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
// =============================================================================
|
| 159 |
+
// live data handler
|
| 160 |
+
// =============================================================================
|
| 161 |
+
function _onSync(j) {
|
| 162 |
+
// read honesty label VERBATIM — never upgrade
|
| 163 |
+
S.label = (j.label || "MODELED").toUpperCase();
|
| 164 |
+
S.timeline = Array.isArray(j.timeline) ? j.timeline : null;
|
| 165 |
+
S.naive = j.naive || null;
|
| 166 |
+
S.mesi = j.mesi || null;
|
| 167 |
+
S.invariants = j.invariants || null;
|
| 168 |
+
S.costCurve = Array.isArray(j.cost_curve) ? j.cost_curve : null;
|
| 169 |
+
S.invEvents = Array.isArray(j.invalidation_events) ? j.invalidation_events : null;
|
| 170 |
+
S.mode = j.mode || null;
|
| 171 |
+
|
| 172 |
+
_paintCells();
|
| 173 |
+
_paintOverlay();
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
// =============================================================================
|
| 177 |
+
// geometry updater — colours each cell by its MESI state at that trace step
|
| 178 |
+
// =============================================================================
|
| 179 |
+
function _cellIndex(art, ag, st) {
|
| 180 |
+
return (art * N_AGENT + ag) * N_STEP + st;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
function _paintCells() {
|
| 184 |
+
const live = S.state === "live";
|
| 185 |
+
const tl = S.timeline || [];
|
| 186 |
+
|
| 187 |
+
// default: dim everything
|
| 188 |
+
_cells.forEach((mesh) => {
|
| 189 |
+
mesh.material.color.setHex(C_DIM);
|
| 190 |
+
mesh.material.emissive.setHex(C_DIM);
|
| 191 |
+
mesh.material.emissiveIntensity = 0.1;
|
| 192 |
+
mesh.scale.set(1, 1, 1);
|
| 193 |
+
});
|
| 194 |
+
|
| 195 |
+
if (tl.length) {
|
| 196 |
+
for (let art = 0; art < Math.min(N_ART, tl.length); art++) {
|
| 197 |
+
const lanes = (tl[art] && tl[art].lanes) || [];
|
| 198 |
+
for (let ag = 0; ag < Math.min(N_AGENT, lanes.length); ag++) {
|
| 199 |
+
const states = (lanes[ag] && lanes[ag].states) || [];
|
| 200 |
+
for (let st = 0; st < N_STEP; st++) {
|
| 201 |
+
const stName = states[st];
|
| 202 |
+
if (stName === undefined) continue;
|
| 203 |
+
const mesh = _cells[_cellIndex(art, ag, st)];
|
| 204 |
+
if (!mesh) continue;
|
| 205 |
+
const col = _stateColor(stName, live);
|
| 206 |
+
mesh.material.color.setHex(col);
|
| 207 |
+
mesh.material.emissive.setHex(col);
|
| 208 |
+
const isMod = live && stName === "Modified";
|
| 209 |
+
const isInv = stName === "Invalid";
|
| 210 |
+
mesh.material.emissiveIntensity = live ? (isMod ? 0.85 : (isInv ? 0.08 : 0.35)) : 0.1;
|
| 211 |
+
mesh.scale.set(1, isMod ? 2.0 : (isInv ? 0.5 : 1.0), 1);
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
// rebuild invalidation-event links (writer step -> flash on the invalidated lanes)
|
| 218 |
+
if (_links) { _group.remove(_links); _links.geometry.dispose(); _links.material.dispose(); _links = null; }
|
| 219 |
+
const evs = S.invEvents || [];
|
| 220 |
+
if (live && evs.length) {
|
| 221 |
+
const THREE = _THREE;
|
| 222 |
+
const pts = [];
|
| 223 |
+
evs.forEach((e) => {
|
| 224 |
+
if (e.step >= N_STEP || e.artifact >= N_ART) return;
|
| 225 |
+
if (e.from >= N_AGENT || e.to >= N_AGENT) return;
|
| 226 |
+
const a = _cells[_cellIndex(e.artifact, e.from, e.step)];
|
| 227 |
+
const b = _cells[_cellIndex(e.artifact, e.to, e.step)];
|
| 228 |
+
if (!a || !b) return;
|
| 229 |
+
pts.push(a.position.clone(), b.position.clone());
|
| 230 |
+
const bi = _cellIndex(e.artifact, e.to, e.step);
|
| 231 |
+
_flash[bi] = 60;
|
| 232 |
+
});
|
| 233 |
+
if (pts.length) {
|
| 234 |
+
const g = new THREE.BufferGeometry().setFromPoints(pts);
|
| 235 |
+
_links = new THREE.LineSegments(g, new THREE.LineBasicMaterial({ color: C_MOD, transparent: true, opacity: 0.4 }));
|
| 236 |
+
_group.add(_links);
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
// =============================================================================
|
| 242 |
+
// per-frame animation
|
| 243 |
+
// =============================================================================
|
| 244 |
+
function _onFrame() {
|
| 245 |
+
const t = performance.now();
|
| 246 |
+
if (_group) _group.rotation.y = Math.sin(t * 0.0001) * 0.12;
|
| 247 |
+
const live = S.state === "live";
|
| 248 |
+
for (let i = 0; i < _cells.length; i++) {
|
| 249 |
+
if (_flash[i] > 0) {
|
| 250 |
+
_flash[i] -= 1;
|
| 251 |
+
const f = _flash[i] / 60;
|
| 252 |
+
const col = live ? C_MOD : C_DIM;
|
| 253 |
+
_cells[i].material.emissive.setHex(col);
|
| 254 |
+
_cells[i].material.emissiveIntensity = Math.max(_cells[i].material.emissiveIntensity, 0.2 + 0.8 * f);
|
| 255 |
+
}
|
| 256 |
+
}
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
// =============================================================================
|
| 260 |
+
// overlay
|
| 261 |
+
// =============================================================================
|
| 262 |
+
function _buildOverlay() {
|
| 263 |
+
const ctx = _ctx;
|
| 264 |
+
_overlay = document.createElement("div");
|
| 265 |
+
Object.assign(_overlay.style, {
|
| 266 |
+
position: "absolute", left: "14px", top: "14px", zIndex: "6",
|
| 267 |
+
display: "flex", flexDirection: "column", gap: "8px",
|
| 268 |
+
maxWidth: "min(94%,460px)",
|
| 269 |
+
font: "12px ui-sans-serif,system-ui,Segoe UI,Roboto,Arial",
|
| 270 |
+
color: "#eef3f6",
|
| 271 |
+
});
|
| 272 |
+
|
| 273 |
+
const h = document.createElement("div");
|
| 274 |
+
h.style.cssText = "font:600 13px ui-sans-serif,system-ui;letter-spacing:.4px";
|
| 275 |
+
h.textContent = TITLE;
|
| 276 |
+
_overlay.appendChild(h);
|
| 277 |
+
|
| 278 |
+
const sub = document.createElement("div");
|
| 279 |
+
sub.style.cssText = "color:#9fb1bf;font-size:11px;line-height:1.55";
|
| 280 |
+
sub.innerHTML =
|
| 281 |
+
'A grid of <b>MESI state lanes</b> \u2014 one row per (agent, artifact) cache entry \u2014 ' +
|
| 282 |
+
'advancing along a fixed seeded op trace. Two coordinators run the SAME trace: ' +
|
| 283 |
+
'<b>naive broadcast</b> (re-sends the full artifact to all agents on every write) vs ' +
|
| 284 |
+
'<b>MESI-ACS</b> (lazy invalidation + on-demand re-fetch). Three invariants are ' +
|
| 285 |
+
'asserted; <b>mesi_buggy</b> drops an invalidation to expose a stale read. Honesty ' +
|
| 286 |
+
'label <b>MODELED</b> (Token-Coherence-inspired \u2014 not a reproduction). 0 runtime CDN.';
|
| 287 |
+
_overlay.appendChild(sub);
|
| 288 |
+
|
| 289 |
+
const brow = document.createElement("div");
|
| 290 |
+
brow.style.cssText = "display:flex;gap:8px;align-items:center;flex-wrap:wrap";
|
| 291 |
+
if (_badge && _badge.el) brow.appendChild(_badge.el);
|
| 292 |
+
_overlay.appendChild(brow);
|
| 293 |
+
|
| 294 |
+
const card = document.createElement("div");
|
| 295 |
+
card.style.cssText = "background:#0a1117;border:1px solid #1d2a36;border-radius:9px;padding:9px 10px;display:flex;flex-direction:column;gap:6px";
|
| 296 |
+
|
| 297 |
+
const chead = document.createElement("div");
|
| 298 |
+
chead.style.cssText = "display:flex;align-items:center;gap:8px;flex-wrap:wrap";
|
| 299 |
+
const dot = document.createElement("span");
|
| 300 |
+
dot.style.cssText = "width:9px;height:9px;border-radius:50%;background:#5b8dee;box-shadow:0 0 7px #5b8dee";
|
| 301 |
+
const nm = document.createElement("b");
|
| 302 |
+
nm.style.cssText = "font-size:12px;color:#5b8dee;letter-spacing:.3px";
|
| 303 |
+
nm.textContent = "agentcoh";
|
| 304 |
+
chead.appendChild(dot); chead.appendChild(nm);
|
| 305 |
+
card.appendChild(chead);
|
| 306 |
+
|
| 307 |
+
const grid = document.createElement("div");
|
| 308 |
+
grid.style.cssText = "display:grid;grid-template-columns:1fr;gap:4px";
|
| 309 |
+
|
| 310 |
+
function kpiRow(id, label) {
|
| 311 |
+
const r = document.createElement("div");
|
| 312 |
+
r.style.cssText = "display:flex;justify-content:space-between;gap:10px;font-size:11px";
|
| 313 |
+
const l = document.createElement("span"); l.style.cssText = "color:#9fb1bf"; l.textContent = label;
|
| 314 |
+
const v = document.createElement("b");
|
| 315 |
+
v.id = id;
|
| 316 |
+
v.style.cssText = "font-variant-numeric:tabular-nums;color:#eef3f6;text-align:right;max-width:60%";
|
| 317 |
+
v.textContent = "\u2014";
|
| 318 |
+
_el[id] = v;
|
| 319 |
+
r.appendChild(l); r.appendChild(v); return r;
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
grid.appendChild(kpiRow("ac-mode", "mode"));
|
| 323 |
+
grid.appendChild(kpiRow("ac-naive", "naive-broadcast cost"));
|
| 324 |
+
grid.appendChild(kpiRow("ac-mesi", "MESI-ACS cost"));
|
| 325 |
+
grid.appendChild(kpiRow("ac-save", "cost saved (this trace)"));
|
| 326 |
+
grid.appendChild(kpiRow("ac-inv", "invariants (SW / MV / BS)"));
|
| 327 |
+
grid.appendChild(kpiRow("ac-label", "honesty label"));
|
| 328 |
+
card.appendChild(grid);
|
| 329 |
+
|
| 330 |
+
const fn = document.createElement("div");
|
| 331 |
+
fn.style.cssText = "font-size:9.5px;color:#6b7a86;line-height:1.5";
|
| 332 |
+
fn.textContent = "Token Coherence arXiv:2603.15183 (Parakhin) \u00b7 Multi-Agent Memory / Comp-Arch arXiv:2603.10062 (Yu et al.) \u00b7 Governed Shared Memory arXiv:2606.24535. MODELED \u00b7 not claimed-as.";
|
| 333 |
+
card.appendChild(fn);
|
| 334 |
+
_overlay.appendChild(card);
|
| 335 |
+
|
| 336 |
+
const pl = document.createElement("button");
|
| 337 |
+
pl.textContent = "\u25d1 what this means";
|
| 338 |
+
pl.title = "Toggle plain-language explanation for investors & consumers.";
|
| 339 |
+
pl.style.cssText = "font:11px ui-monospace,monospace;padding:5px 11px;border-radius:7px;border:1px solid #3af4c8;background:#08140f;color:#3af4c8;cursor:pointer;width:fit-content";
|
| 340 |
+
pl.addEventListener("click", () => {
|
| 341 |
+
_plain = !_plain;
|
| 342 |
+
pl.style.background = _plain ? "#0f2a20" : "#08140f";
|
| 343 |
+
_applyPlain();
|
| 344 |
+
});
|
| 345 |
+
_overlay.appendChild(pl);
|
| 346 |
+
|
| 347 |
+
const pd = document.createElement("div");
|
| 348 |
+
pd.id = "ac-plain";
|
| 349 |
+
pd.style.cssText = "font-size:10.5px;color:#c9d6df;line-height:1.55;border:1px dashed #26333f;border-radius:7px;padding:7px 9px;display:none";
|
| 350 |
+
_el["plain"] = pd;
|
| 351 |
+
_overlay.appendChild(pd);
|
| 352 |
+
|
| 353 |
+
(ctx.container || document.body).appendChild(_overlay);
|
| 354 |
+
_paintOverlay();
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
function _applyPlain() {
|
| 358 |
+
const pd = _el["plain"];
|
| 359 |
+
if (!pd) return;
|
| 360 |
+
pd.style.display = _plain ? "block" : "none";
|
| 361 |
+
if (!_plain) return;
|
| 362 |
+
const nc = (S.naive && typeof S.naive.cost === "number") ? String(S.naive.cost) : "loading\u2026";
|
| 363 |
+
const mc = (S.mesi && typeof S.mesi.cost === "number") ? String(S.mesi.cost) : "loading\u2026";
|
| 364 |
+
let save = "loading\u2026";
|
| 365 |
+
if (S.naive && S.mesi && S.naive.cost) {
|
| 366 |
+
save = (100 * (1 - S.mesi.cost / S.naive.cost)).toFixed(0) + "%";
|
| 367 |
+
}
|
| 368 |
+
const allHold = S.invariants ? (S.invariants.all_hold ? "all HOLD" : "one FAILS (see BS)") : "loading\u2026";
|
| 369 |
+
pd.innerHTML =
|
| 370 |
+
"<b>What this means:</b> When several AI agents share the same working memory, the " +
|
| 371 |
+
"naive fix is to re-send the entire shared state to everyone on every change \u2014 " +
|
| 372 |
+
"expensive and slow (here it costs <b>" + nc + "</b> proxy units on this trace). " +
|
| 373 |
+
"Borrowing a 40-year-old trick from computer CPUs (the <b>MESI cache-coherence " +
|
| 374 |
+
"protocol</b>), we instead send tiny \u201cyour copy is stale\u201d notices and only re-fetch " +
|
| 375 |
+
"the full data when an agent actually reads it \u2014 dropping the cost to <b>" + mc + "</b> " +
|
| 376 |
+
"(about <b>" + save + "</b> cheaper) while still guaranteeing only one agent writes at a " +
|
| 377 |
+
"time, versions never go backwards, and reads are never too stale (" + allHold + "). " +
|
| 378 |
+
"The <b>mesi_buggy</b> mode deliberately skips one \u201cstale\u201d notice so you can watch a " +
|
| 379 |
+
"guarantee break. " +
|
| 380 |
+
"<br><br><b>Honesty (MODELED):</b> Inspired-not-real. This is a toy deterministic " +
|
| 381 |
+
"simulation of the MESI\u2192artifact coherence MECHANISM, not the paper\u2019s Artifact " +
|
| 382 |
+
"Coherence System. \u201cArtifacts\u201d are integer-versioned dict entries over 3\u20134 items and " +
|
| 383 |
+
"a handful of agents; \u201ccost\u201d is a counted token/byte proxy, not measured LLM tokens; " +
|
| 384 |
+
"invariants are checked by in-sim assertions, NOT the paper\u2019s TLA+ model checker (no " +
|
| 385 |
+
"~2,400-state exploration); there is no LangGraph/CrewAI/AutoGen integration. It " +
|
| 386 |
+
"demonstrates WHY lazy invalidation beats full-state rebroadcast while preserving " +
|
| 387 |
+
"single-writer safety, monotonic versioning and bounded staleness on a constructed " +
|
| 388 |
+
"trace; it does NOT reproduce Token Coherence\u2019s 84\u201395% measured savings or prove the " +
|
| 389 |
+
"Token Coherence Theorem. <b>NEW AXIS:</b> this is a distributed-consistency protocol " +
|
| 390 |
+
"(\u2260 graphmem retrieval, \u2260 single-agent memory organs, \u2260 governance policy).";
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
function _tok(s) {
|
| 394 |
+
if (s === "live") return null;
|
| 395 |
+
if (s === "missing") return "NO-LIVE-DATA";
|
| 396 |
+
if (s === "degraded") return "DEGRADED";
|
| 397 |
+
if (s === "error") return "OFFLINE";
|
| 398 |
+
return "\u2026";
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
function _set(id, v) { if (_el[id]) _el[id].textContent = v; }
|
| 402 |
+
|
| 403 |
+
function _invLetter(x) {
|
| 404 |
+
if (!x || !x.status) return "\u2014";
|
| 405 |
+
return x.status === "PASS" ? "\u2713" : "\u2717";
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
function _paintOverlay() {
|
| 409 |
+
const t = _tok(S.state);
|
| 410 |
+
_set("ac-mode", t || (S.mode || "\u2014"));
|
| 411 |
+
_set("ac-naive", t || (S.naive && typeof S.naive.cost === "number" ? String(S.naive.cost) : "\u2014"));
|
| 412 |
+
_set("ac-mesi", t || (S.mesi && typeof S.mesi.cost === "number" ? String(S.mesi.cost) : "\u2014"));
|
| 413 |
+
let save = "\u2014";
|
| 414 |
+
if (S.naive && S.mesi && S.naive.cost) {
|
| 415 |
+
save = (100 * (1 - S.mesi.cost / S.naive.cost)).toFixed(1) + "%";
|
| 416 |
+
}
|
| 417 |
+
_set("ac-save", t || save);
|
| 418 |
+
let inv = "\u2014";
|
| 419 |
+
if (S.invariants) {
|
| 420 |
+
inv = _invLetter(S.invariants.single_writer) + " " +
|
| 421 |
+
_invLetter(S.invariants.monotonic_versioning) + " " +
|
| 422 |
+
_invLetter(S.invariants.bounded_staleness);
|
| 423 |
+
}
|
| 424 |
+
_set("ac-inv", t || inv);
|
| 425 |
+
// honesty label verbatim — never upgraded
|
| 426 |
+
_set("ac-label", t || (S.label || "MODELED"));
|
| 427 |
+
if (_plain) _applyPlain();
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
// =============================================================================
|
| 431 |
+
// unmount — clean up everything; must not affect other organs
|
| 432 |
+
// =============================================================================
|
| 433 |
+
export function unmount() {
|
| 434 |
+
_polls.forEach((p) => { try { p.stop(); } catch (_) {} }); _polls = [];
|
| 435 |
+
try { if (_overlay && _overlay.parentNode) _overlay.parentNode.removeChild(_overlay); } catch (_) {}
|
| 436 |
+
try {
|
| 437 |
+
if (_group && _stage) {
|
| 438 |
+
_group.traverse((o) => {
|
| 439 |
+
if (o.geometry && o.geometry.dispose) o.geometry.dispose();
|
| 440 |
+
if (o.material) {
|
| 441 |
+
const ms = Array.isArray(o.material) ? o.material : [o.material];
|
| 442 |
+
ms.forEach((m) => { if (m.dispose) m.dispose(); });
|
| 443 |
+
}
|
| 444 |
+
});
|
| 445 |
+
_stage.scene.remove(_group);
|
| 446 |
+
}
|
| 447 |
+
} catch (_) {}
|
| 448 |
+
_group = _overlay = null;
|
| 449 |
+
_cells = []; _flash = []; _links = null;
|
| 450 |
+
_el = {}; _badge = null; _plain = false; _frameReg = false;
|
| 451 |
+
_stage = _THREE = _ctx = null;
|
| 452 |
+
S.label = S.timeline = S.naive = S.mesi = S.invariants = null;
|
| 453 |
+
S.costCurve = S.inv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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: Apache-2.0
|
| 2 |
+
// © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 · Doctrine v11
|
| 3 |
+
//
|
| 4 |
+
// surfaces/catq.js — POST-TRAINING CALIBRATION TERNARY QUANT (CAT-Q) organ for
|
| 5 |
+
// the holographic frontier ring. A SUB-ORGAN UPGRADE of the `ternary` organ:
|
| 6 |
+
// same weight-precision axis {-1,0,+1}, distinct PTQ-vs-QAT mechanism. Renders
|
| 7 |
+
// a 3D weight-magnitude histogram of a frozen synthetic heavy-tailed weight
|
| 8 |
+
// vector, with the ABSMEAN hard-snap threshold and the CAT-Q LEARNED threshold
|
| 9 |
+
// drawn as gates; bars are coloured by the ternary code each rule assigns
|
| 10 |
+
// (+1 -> add proof-teal, -1 -> subtract lattice-blue, 0 -> skip grey). A HUD
|
| 11 |
+
// shows the MEASURED reconstruction / calibration-task error, absmean vs CAT-Q,
|
| 12 |
+
// from the live snapshot at /api/killinchu/v1/catq/calibrate. Honesty label
|
| 13 |
+
// "MODELED" is read VERBATIM from the JSON and displayed as-is; never upgraded.
|
| 14 |
+
//
|
| 15 |
+
// Surface export shape (mirrors ternary.js / aimc.js exactly):
|
| 16 |
+
// export default { id, title, endpoints, mount(ctx), unmount() }
|
| 17 |
+
// ctx = { stage, container, live, label, THREE, szl3d }
|
| 18 |
+
//
|
| 19 |
+
// DATA SHOWN (all from live endpoint):
|
| 20 |
+
// num_weights, num_calibration_samples, modulation_groups, softening_steps,
|
| 21 |
+
// absmean_threshold, catq_threshold_frac, ternary_counts_absmean{neg,zero,pos},
|
| 22 |
+
// ternary_counts_catq{neg,zero,pos}, recon_err_absmean, recon_err_catq,
|
| 23 |
+
// recon_err_improvement_frac, calib_task_err_absmean, calib_task_err_catq,
|
| 24 |
+
// error_vs_calibration[{n,task_err}], bits_per_weight_ternary
|
| 25 |
+
//
|
| 26 |
+
// LEADERS ADOPTED & CITED (clean-room; NOT claimed as SZL's own; VERIFIED real):
|
| 27 |
+
// CAT-Q: Cost-efficient and Accurate Ternary Quantization for LLMs
|
| 28 |
+
// Wang, Li, Kang, Fan, Yao (2026). arXiv:2606.26650
|
| 29 |
+
// https://arxiv.org/abs/2606.26650
|
| 30 |
+
//
|
| 31 |
+
// HONESTY LABEL: MODELED — toy analytic sim of the post-training calibration-
|
| 32 |
+
// ternarization MECHANISM, not CAT-Q. Seeded synthetic heavy-tailed weights,
|
| 33 |
+
// seeded toy activations, a tiny closed-form/least-squares "learnable
|
| 34 |
+
// modulation" + fixed tanh-anneal "softened ternarization"; NO real LLM, NO
|
| 35 |
+
// BitTern code, NO 512-sample calibration of a 1.7B–235B model, NO GPU-hours.
|
| 36 |
+
// Explicitly a SUB-ORGAN UPGRADE of ternary (same weight-precision axis,
|
| 37 |
+
// distinct PTQ-vs-QAT mechanism), not a new axis. Read verbatim from JSON.
|
| 38 |
+
// COLOURS: proof-teal 0x3af4c8 (+1 -> add), lattice-blue 0x5b8dee (-1 ->
|
| 39 |
+
// subtract), violet-blue 0x8a6bff (learned-threshold / calibration accent),
|
| 40 |
+
// greys (0 -> skip / degraded). Purple BANNED as UI/background.
|
| 41 |
+
// 0 RUNTIME CDN. Vendored three.js via ctx.THREE (page importmap).
|
| 42 |
+
// DOCTRINE v11: degrades gracefully (grey) on 404/error; honesty label still shown.
|
| 43 |
+
// Nothing here is in the locked-8. Λ stays Conjecture 1. Trust never 100%.
|
| 44 |
+
|
| 45 |
+
const ID = "catq";
|
| 46 |
+
const TITLE = "Post-Training Calibration Ternary Quant · CAT-Q (live)";
|
| 47 |
+
|
| 48 |
+
// Endpoint is hosted on the dedicated killinchu Space (isolated compute), reached
|
| 49 |
+
// cross-origin (killinchu returns access-control-allow-origin for the flagship).
|
| 50 |
+
const EP = "https://szlholdings-killinchu.hf.space/api/killinchu/v1/catq/calibrate?seed=42&num_weights=256&num_calibration_samples=512&mode=catq";
|
| 51 |
+
|
| 52 |
+
// data-viz hues — purple BANNED
|
| 53 |
+
const C_POS = 0x3af4c8; // proof-teal (+1 weight -> add)
|
| 54 |
+
const C_NEG = 0x5b8dee; // lattice-blue (-1 weight -> subtract)
|
| 55 |
+
const C_LEARNED = 0x8a6bff; // violet-blue (learned-threshold / calibration accent)
|
| 56 |
+
const C_ZERO = 0x5a6570; // grey (0 weight -> skip / structured sparsity)
|
| 57 |
+
const C_DIM = 0x42505d; // grey (degraded / no-live-data)
|
| 58 |
+
const C_GRID = 0x1b3a44; // floor / link colour
|
| 59 |
+
|
| 60 |
+
// histogram layout geometry
|
| 61 |
+
const N_BINS = 24; // magnitude bins per side of the histogram
|
| 62 |
+
const BIN_GAP = 0.42; // world-units between bins
|
| 63 |
+
const MAX_H = 4.0; // max bar height (world units)
|
| 64 |
+
const ROW_ABS = 0.0; // z-row for the ABSMEAN (before) histogram
|
| 65 |
+
const ROW_CATQ = 3.2; // z-row for the CAT-Q (after) histogram
|
| 66 |
+
|
| 67 |
+
let _stage = null, _THREE = null, _ctx = null, _group = null, _overlay = null;
|
| 68 |
+
let _frameReg = false, _polls = [], _el = {}, _badge = null;
|
| 69 |
+
let _plain = false;
|
| 70 |
+
|
| 71 |
+
// geometry handles
|
| 72 |
+
let _floor = null;
|
| 73 |
+
let _barsAbs = []; // Array<THREE.Mesh> — absmean (before) histogram bars
|
| 74 |
+
let _barsCatq = []; // Array<THREE.Mesh> — CAT-Q (after) histogram bars
|
| 75 |
+
let _gateAbs = null; // THREE.Mesh — absmean hard threshold gate
|
| 76 |
+
let _gateCatq = null; // THREE.Mesh — CAT-Q learned threshold gate
|
| 77 |
+
|
| 78 |
+
// live state
|
| 79 |
+
const S = {
|
| 80 |
+
label: null,
|
| 81 |
+
numWeights: null,
|
| 82 |
+
numCalib: null,
|
| 83 |
+
modGroups: null,
|
| 84 |
+
softSteps: null,
|
| 85 |
+
absmeanThresh: null, // absmean_threshold
|
| 86 |
+
catqThreshFrac: null, // catq_threshold_frac
|
| 87 |
+
absNeg: null, absZero: null, absPos: null, // ternary_counts_absmean
|
| 88 |
+
catqNeg: null, catqZero: null, catqPos: null, // ternary_counts_catq
|
| 89 |
+
reconErrAbs: null, // recon_err_absmean (MEASURED)
|
| 90 |
+
reconErrCatq: null, // recon_err_catq (MEASURED)
|
| 91 |
+
reconImprovFrac: null, // recon_err_improvement_frac
|
| 92 |
+
taskErrAbs: null, // calib_task_err_absmean (MEASURED)
|
| 93 |
+
taskErrCatq: null, // calib_task_err_catq (MEASURED)
|
| 94 |
+
bitsPerWeight: null, // bits_per_weight_ternary
|
| 95 |
+
curve: null, // error_vs_calibration [{n, task_err}]
|
| 96 |
+
state: "init",
|
| 97 |
+
};
|
| 98 |
+
|
| 99 |
+
// =============================================================================
|
| 100 |
+
// mount(ctx)
|
| 101 |
+
// =============================================================================
|
| 102 |
+
export function mount(ctx) {
|
| 103 |
+
_ctx = ctx; _stage = ctx.stage; _THREE = ctx.THREE;
|
| 104 |
+
_group = new _THREE.Group();
|
| 105 |
+
_stage.scene.add(_group);
|
| 106 |
+
_stage.camera.position.set(6, 8, 16);
|
| 107 |
+
try { if (_stage.controls && _stage.controls.target) { _stage.controls.target.set(5, 1, 1.5); _stage.controls.update(); } } catch (_) {}
|
| 108 |
+
try { _stage.setBloom(true); } catch (_) {}
|
| 109 |
+
|
| 110 |
+
_buildFloor();
|
| 111 |
+
_buildHistograms();
|
| 112 |
+
_buildGates();
|
| 113 |
+
|
| 114 |
+
if (!_frameReg) { _stage.onFrame(_onFrame); _frameReg = true; }
|
| 115 |
+
|
| 116 |
+
_badge = ctx.live.createBadge();
|
| 117 |
+
_polls.push(ctx.live.poll(EP, 5000, _onCatq, { badge: _badge, onState: (m) => { S.state = m.state; _paintOverlay(); } }));
|
| 118 |
+
|
| 119 |
+
_buildOverlay();
|
| 120 |
+
return { id: ID, started: true };
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// =============================================================================
|
| 124 |
+
// builders
|
| 125 |
+
// =============================================================================
|
| 126 |
+
function _buildFloor() {
|
| 127 |
+
const THREE = _THREE;
|
| 128 |
+
const grid = new THREE.GridHelper(40, 40, C_GRID, 0x0f2027);
|
| 129 |
+
grid.material.opacity = 0.18; grid.material.transparent = true; grid.position.y = -0.01;
|
| 130 |
+
_group.add(grid);
|
| 131 |
+
_floor = grid;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
// Two rows of magnitude-histogram bars: the "before" (absmean hard-snap) row and
|
| 135 |
+
// the "after" (CAT-Q learned-threshold + calibrated modulation) row. We toggle
|
| 136 |
+
// height / colour in-place as live data arrives (no per-poll geometry churn).
|
| 137 |
+
function _buildHistograms() {
|
| 138 |
+
const THREE = _THREE;
|
| 139 |
+
const barGeo = new THREE.BoxGeometry(0.28, 1.0, 0.28);
|
| 140 |
+
for (let b = 0; b < N_BINS; b++) {
|
| 141 |
+
const mAbs = new THREE.Mesh(
|
| 142 |
+
barGeo,
|
| 143 |
+
new THREE.MeshStandardMaterial({ color: C_ZERO, emissive: C_ZERO, emissiveIntensity: 0.2, transparent: true, opacity: 0.0 }),
|
| 144 |
+
);
|
| 145 |
+
mAbs.position.set(b * BIN_GAP, 0.5, ROW_ABS);
|
| 146 |
+
mAbs.visible = false;
|
| 147 |
+
_group.add(mAbs);
|
| 148 |
+
_barsAbs.push(mAbs);
|
| 149 |
+
|
| 150 |
+
const mCatq = new THREE.Mesh(
|
| 151 |
+
barGeo,
|
| 152 |
+
new THREE.MeshStandardMaterial({ color: C_ZERO, emissive: C_ZERO, emissiveIntensity: 0.2, transparent: true, opacity: 0.0 }),
|
| 153 |
+
);
|
| 154 |
+
mCatq.position.set(b * BIN_GAP, 0.5, ROW_CATQ);
|
| 155 |
+
mCatq.visible = false;
|
| 156 |
+
_group.add(mCatq);
|
| 157 |
+
_barsCatq.push(mCatq);
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
// Threshold "gates": thin planes marking the absmean hard threshold (before row)
|
| 162 |
+
// and the CAT-Q learned threshold (after row). Bins to the left of the gate
|
| 163 |
+
// ternarize to 0 (skip); bins to the right ternarize to ±1.
|
| 164 |
+
function _buildGates() {
|
| 165 |
+
const THREE = _THREE;
|
| 166 |
+
const gateGeo = new THREE.BoxGeometry(0.06, MAX_H, 0.9);
|
| 167 |
+
_gateAbs = new THREE.Mesh(
|
| 168 |
+
gateGeo,
|
| 169 |
+
new THREE.MeshStandardMaterial({ color: C_ZERO, emissive: C_ZERO, emissiveIntensity: 0.4, transparent: true, opacity: 0.0 }),
|
| 170 |
+
);
|
| 171 |
+
_gateAbs.position.set(0, MAX_H / 2, ROW_ABS);
|
| 172 |
+
_gateAbs.visible = false;
|
| 173 |
+
_group.add(_gateAbs);
|
| 174 |
+
|
| 175 |
+
_gateCatq = new THREE.Mesh(
|
| 176 |
+
gateGeo,
|
| 177 |
+
new THREE.MeshStandardMaterial({ color: C_LEARNED, emissive: C_LEARNED, emissiveIntensity: 0.55, transparent: true, opacity: 0.0 }),
|
| 178 |
+
);
|
| 179 |
+
_gateCatq.position.set(0, MAX_H / 2, ROW_CATQ);
|
| 180 |
+
_gateCatq.visible = false;
|
| 181 |
+
_group.add(_gateCatq);
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
// =============================================================================
|
| 185 |
+
// live data handler
|
| 186 |
+
// =============================================================================
|
| 187 |
+
function _onCatq(j) {
|
| 188 |
+
// read honesty label VERBATIM — never upgrade. handle top-level 'label' OR
|
| 189 |
+
// nested 'payload.label' to match our own module's shape.
|
| 190 |
+
const lbl = (j && j.label != null) ? j.label
|
| 191 |
+
: (j && j.payload && j.payload.label != null) ? j.payload.label
|
| 192 |
+
: "MODELED";
|
| 193 |
+
const src = (j && j.payload && typeof j.payload === "object") ? j.payload : j;
|
| 194 |
+
S.label = String(lbl).toUpperCase();
|
| 195 |
+
|
| 196 |
+
S.numWeights = typeof src.num_weights === "number" ? src.num_weights : null;
|
| 197 |
+
S.numCalib = typeof src.num_calibration_samples === "number" ? src.num_calibration_samples : null;
|
| 198 |
+
S.modGroups = typeof src.modulation_groups === "number" ? src.modulation_groups : null;
|
| 199 |
+
S.softSteps = typeof src.softening_steps === "number" ? src.softening_steps : null;
|
| 200 |
+
S.absmeanThresh = typeof src.absmean_threshold === "number" ? src.absmean_threshold : null;
|
| 201 |
+
S.catqThreshFrac = typeof src.catq_threshold_frac === "number" ? src.catq_threshold_frac : null;
|
| 202 |
+
S.reconErrAbs = typeof src.recon_err_absmean === "number" ? src.recon_err_absmean : null;
|
| 203 |
+
S.reconErrCatq = typeof src.recon_err_catq === "number" ? src.recon_err_catq : null;
|
| 204 |
+
S.reconImprovFrac = typeof src.recon_err_improvement_frac === "number" ? src.recon_err_improvement_frac : null;
|
| 205 |
+
S.taskErrAbs = typeof src.calib_task_err_absmean === "number" ? src.calib_task_err_absmean : null;
|
| 206 |
+
S.taskErrCatq = typeof src.calib_task_err_catq === "number" ? src.calib_task_err_catq : null;
|
| 207 |
+
S.bitsPerWeight = typeof src.bits_per_weight_ternary === "number" ? src.bits_per_weight_ternary : null;
|
| 208 |
+
S.curve = Array.isArray(src.error_vs_calibration) ? src.error_vs_calibration : null;
|
| 209 |
+
|
| 210 |
+
if (src.ternary_counts_absmean && typeof src.ternary_counts_absmean === "object") {
|
| 211 |
+
S.absNeg = typeof src.ternary_counts_absmean.neg === "number" ? src.ternary_counts_absmean.neg : null;
|
| 212 |
+
S.absZero = typeof src.ternary_counts_absmean.zero === "number" ? src.ternary_counts_absmean.zero : null;
|
| 213 |
+
S.absPos = typeof src.ternary_counts_absmean.pos === "number" ? src.ternary_counts_absmean.pos : null;
|
| 214 |
+
}
|
| 215 |
+
if (src.ternary_counts_catq && typeof src.ternary_counts_catq === "object") {
|
| 216 |
+
S.catqNeg = typeof src.ternary_counts_catq.neg === "number" ? src.ternary_counts_catq.neg : null;
|
| 217 |
+
S.catqZero = typeof src.ternary_counts_catq.zero === "number" ? src.ternary_counts_catq.zero : null;
|
| 218 |
+
S.catqPos = typeof src.ternary_counts_catq.pos === "number" ? src.ternary_counts_catq.pos : null;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
_updateHistograms();
|
| 222 |
+
_paintOverlay();
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
// =============================================================================
|
| 226 |
+
// geometry updater — draws the before/after magnitude histograms + gates
|
| 227 |
+
// =============================================================================
|
| 228 |
+
// Deterministic per-bin heavy-tailed magnitude profile (LCG family, mirrors the
|
| 229 |
+
// module) so the histogram shape is stable across polls and never fabricated
|
| 230 |
+
// beyond a heavy-tailed envelope: most mass near zero, a light tail out to the
|
| 231 |
+
// right (the pretrained-weight outliers). This is a VISUAL proxy for the
|
| 232 |
+
// reported distribution — the numeric metrics come only from the live JSON.
|
| 233 |
+
function _binMass(b) {
|
| 234 |
+
// heavy-tailed-ish falloff with a small deterministic ripple
|
| 235 |
+
let s = ((b + 1) * 2654435761) >>> 0;
|
| 236 |
+
s = (1664525 * s + 1013904223) >>> 0;
|
| 237 |
+
const ripple = 0.12 * ((s / 4294967295) - 0.5);
|
| 238 |
+
const x = b / (N_BINS - 1);
|
| 239 |
+
const env = Math.exp(-3.1 * x) + 0.05 * Math.exp(-0.6 * (1.0 - x)); // bulk + tail
|
| 240 |
+
return Math.max(0.02, env + ripple);
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
function _updateHistograms() {
|
| 244 |
+
const live = S.state === "live";
|
| 245 |
+
|
| 246 |
+
// gate bin positions from live thresholds (normalized to the bin axis).
|
| 247 |
+
// absmean threshold in weight-units -> map through a nominal magnitude span;
|
| 248 |
+
// CAT-Q learned threshold = catq_threshold_frac * (absmean_threshold/0.5)
|
| 249 |
+
// since absmean_threshold = 0.5*beta => beta = absmean_threshold/0.5.
|
| 250 |
+
const beta = (S.absmeanThresh != null) ? (S.absmeanThresh / 0.5) : 1.0;
|
| 251 |
+
const span = Math.max(1e-6, 3.0 * beta); // nominal |w| axis span
|
| 252 |
+
const absBin = live && S.absmeanThresh != null ? Math.min(N_BINS - 1, (S.absmeanThresh / span) * N_BINS) : 0;
|
| 253 |
+
const catqThr = (S.catqThreshFrac != null) ? S.catqThreshFrac * beta : null;
|
| 254 |
+
const catqBin = live && catqThr != null ? Math.min(N_BINS - 1, (catqThr / span) * N_BINS) : 0;
|
| 255 |
+
|
| 256 |
+
for (let b = 0; b < N_BINS; b++) {
|
| 257 |
+
const mass = _binMass(b);
|
| 258 |
+
const h = MAX_H * mass;
|
| 259 |
+
|
| 260 |
+
_updateBar(_barsAbs[b], b, h, live, absBin, false);
|
| 261 |
+
_updateBar(_barsCatq[b], b, h, live, catqBin, true);
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
_placeGate(_gateAbs, absBin, ROW_ABS, C_ZERO, live);
|
| 265 |
+
_placeGate(_gateCatq, catqBin, ROW_CATQ, C_LEARNED, live);
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
function _updateBar(mesh, b, h, live, gateBin, isCatq) {
|
| 269 |
+
if (!mesh) return;
|
| 270 |
+
if (!live) { mesh.visible = false; return; }
|
| 271 |
+
mesh.visible = true;
|
| 272 |
+
mesh.scale.y = Math.max(0.04, h);
|
| 273 |
+
mesh.position.y = mesh.scale.y * 0.5;
|
| 274 |
+
// bins beyond the (soft/hard) threshold ternarize to ±1; below -> 0 (skip).
|
| 275 |
+
let color;
|
| 276 |
+
if (b < gateBin) {
|
| 277 |
+
color = C_ZERO; // 0 -> skip (grey)
|
| 278 |
+
} else {
|
| 279 |
+
color = (b % 2 === 0) ? C_POS : C_NEG; // ±1 -> add / subtract
|
| 280 |
+
}
|
| 281 |
+
mesh.material.color.setHex(color);
|
| 282 |
+
mesh.material.emissive.setHex(color);
|
| 283 |
+
mesh.material.emissiveIntensity = (b < gateBin) ? 0.14 : (isCatq ? 0.6 : 0.42);
|
| 284 |
+
mesh.material.opacity = (b < gateBin) ? 0.32 : 0.95;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
function _placeGate(gate, bin, row, litColor, live) {
|
| 288 |
+
if (!gate) return;
|
| 289 |
+
if (!live) { gate.visible = false; return; }
|
| 290 |
+
gate.visible = true;
|
| 291 |
+
gate.position.set(bin * BIN_GAP - BIN_GAP * 0.5, MAX_H / 2, row);
|
| 292 |
+
gate.material.color.setHex(litColor);
|
| 293 |
+
gate.material.emissive.setHex(litColor);
|
| 294 |
+
gate.material.opacity = 0.5;
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
// =============================================================================
|
| 298 |
+
// per-frame animation
|
| 299 |
+
// =============================================================================
|
| 300 |
+
function _onFrame() {
|
| 301 |
+
const t = performance.now();
|
| 302 |
+
if (_group) _group.rotation.y = Math.sin(t * 0.00009) * 0.12;
|
| 303 |
+
if (_gateCatq && _gateCatq.visible) {
|
| 304 |
+
const pulse = 0.5 + 0.18 * Math.sin(t * 0.004);
|
| 305 |
+
_gateCatq.material.opacity = pulse;
|
| 306 |
+
}
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
// =============================================================================
|
| 310 |
+
// overlay
|
| 311 |
+
// =============================================================================
|
| 312 |
+
function _buildOverlay() {
|
| 313 |
+
const ctx = _ctx;
|
| 314 |
+
_overlay = document.createElement("div");
|
| 315 |
+
Object.assign(_overlay.style, {
|
| 316 |
+
position: "absolute", left: "14px", top: "14px", zIndex: "6",
|
| 317 |
+
display: "flex", flexDirection: "column", gap: "8px",
|
| 318 |
+
maxWidth: "min(94%,470px)",
|
| 319 |
+
font: "12px ui-sans-serif,system-ui,Segoe UI,Roboto,Arial",
|
| 320 |
+
color: "#eef3f6",
|
| 321 |
+
});
|
| 322 |
+
|
| 323 |
+
const h = document.createElement("div");
|
| 324 |
+
h.style.cssText = "font:600 13px ui-sans-serif,system-ui;letter-spacing:.4px";
|
| 325 |
+
h.textContent = TITLE;
|
| 326 |
+
_overlay.appendChild(h);
|
| 327 |
+
|
| 328 |
+
const sub = document.createElement("div");
|
| 329 |
+
sub.style.cssText = "color:#9fb1bf;font-size:11px;line-height:1.55";
|
| 330 |
+
sub.innerHTML =
|
| 331 |
+
'A <b>SUB-ORGAN UPGRADE of ternary</b> (same weight-precision axis {\u22121,0,+1}, distinct PTQ-vs-QAT ' +
|
| 332 |
+
'mechanism). Instead of training a ternary model from scratch, <b>CAT-Q</b> ternarizes an already-' +
|
| 333 |
+
'pretrained model <b>post-training</b> from a small calibration set. Two components: <b>learnable ' +
|
| 334 |
+
'modulation</b> (a closed-form least-squares fit reshapes the per-group scale + threshold) and ' +
|
| 335 |
+
'<b>softened ternarization</b> (a tanh-anneal transition instead of a hard snap). The two histograms ' +
|
| 336 |
+
'show the same frozen weights ternarized by the <b>absmean hard threshold</b> (before) vs the ' +
|
| 337 |
+
'<b>CAT-Q learned threshold</b> (after). HUD reports MEASURED reconstruction / calibration-task error, ' +
|
| 338 |
+
'absmean vs CAT-Q. Honesty label <b>MODELED</b>. 0 runtime CDN.';
|
| 339 |
+
_overlay.appendChild(sub);
|
| 340 |
+
|
| 341 |
+
const brow = document.createElement("div");
|
| 342 |
+
brow.style.cssText = "display:flex;gap:8px;align-items:center;flex-wrap:wrap";
|
| 343 |
+
if (_badge && _badge.el) brow.appendChild(_badge.el);
|
| 344 |
+
_overlay.appendChild(brow);
|
| 345 |
+
|
| 346 |
+
const card = document.createElement("div");
|
| 347 |
+
card.style.cssText = "background:#0a1117;border:1px solid #1d2a36;border-radius:9px;padding:9px 10px;display:flex;flex-direction:column;gap:6px";
|
| 348 |
+
|
| 349 |
+
const chead = document.createElement("div");
|
| 350 |
+
chead.style.cssText = "display:flex;align-items:center;gap:8px;flex-wrap:wrap";
|
| 351 |
+
const dot = document.createElement("span");
|
| 352 |
+
dot.style.cssText = "width:9px;height:9px;border-radius:50%;background:#3af4c8;box-shadow:0 0 7px #3af4c8";
|
| 353 |
+
const nm = document.createElement("b");
|
| 354 |
+
nm.style.cssText = "font-size:12px;color:#3af4c8;letter-spacing:.3px";
|
| 355 |
+
nm.textContent = "post-training calibration ternary quant (cat-q)";
|
| 356 |
+
chead.appendChild(dot); chead.appendChild(nm);
|
| 357 |
+
card.appendChild(chead);
|
| 358 |
+
|
| 359 |
+
const grid = document.createElement("div");
|
| 360 |
+
grid.style.cssText = "display:grid;grid-template-columns:1fr;gap:4px";
|
| 361 |
+
|
| 362 |
+
function kpiRow(id, label) {
|
| 363 |
+
const r = document.createElement("div");
|
| 364 |
+
r.style.cssText = "display:flex;justify-content:space-between;gap:10px;font-size:11px";
|
| 365 |
+
const l = document.createElement("span"); l.style.cssText = "color:#9fb1bf"; l.textContent = label;
|
| 366 |
+
const v = document.createElement("b");
|
| 367 |
+
v.id = id;
|
| 368 |
+
v.style.cssText = "font-variant-numeric:tabular-nums;color:#eef3f6;text-align:right;max-width:56%";
|
| 369 |
+
v.textContent = "\u2014";
|
| 370 |
+
_el[id] = v;
|
| 371 |
+
r.appendChild(l); r.appendChild(v); return r;
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
grid.appendChild(kpiRow("cq-weights", "frozen weights (heavy-tailed)"));
|
| 375 |
+
grid.appendChild(kpiRow("cq-calib", "calibration samples"));
|
| 376 |
+
grid.appendChild(kpiRow("cq-groups", "modulation groups (LM)"));
|
| 377 |
+
grid.appendChild(kpiRow("cq-steps", "softening steps (ST, tanh-anneal)"));
|
| 378 |
+
grid.appendChild(kpiRow("cq-absthr", "absmean hard threshold"));
|
| 379 |
+
grid.appendChild(kpiRow("cq-catqthr", "CAT-Q learned threshold frac"));
|
| 380 |
+
grid.appendChild(kpiRow("cq-absmix", "absmean mix (\u22121 / 0 / +1)"));
|
| 381 |
+
grid.appendChild(kpiRow("cq-catqmix", "CAT-Q mix (\u22121 / 0 / +1)"));
|
| 382 |
+
grid.appendChild(kpiRow("cq-reconabs", "recon err \u2014 absmean (MEASURED)"));
|
| 383 |
+
grid.appendChild(kpiRow("cq-reconcatq", "recon err \u2014 CAT-Q (MEASURED)"));
|
| 384 |
+
grid.appendChild(kpiRow("cq-reconimp", "recon err REDUCED by CAT-Q"));
|
| 385 |
+
grid.appendChild(kpiRow("cq-taskabs", "calib-task err \u2014 absmean"));
|
| 386 |
+
grid.appendChild(kpiRow("cq-taskcatq", "calib-task err \u2014 CAT-Q"));
|
| 387 |
+
grid.appendChild(kpiRow("cq-curve", "task err vs calib (first \u2192 last)"));
|
| 388 |
+
grid.appendChild(kpiRow("cq-bpw", "bits/weight (ternary) \u2014 MODELED"));
|
| 389 |
+
grid.appendChild(kpiRow("cq-label", "honesty label"));
|
| 390 |
+
card.appendChild(grid);
|
| 391 |
+
|
| 392 |
+
const fn = document.createElement("div");
|
| 393 |
+
fn.style.cssText = "font-size:9.5px;color:#6b7a86;line-height:1.5";
|
| 394 |
+
fn.textContent = "CAT-Q \u2014 Wang, Li, Kang, Fan, Yao (2026) arXiv:2606.26650. SUB-ORGAN UPGRADE of ternary (same weight-precision axis, distinct PTQ-vs-QAT mechanism). MODELED \u00b7 not claimed-as.";
|
| 395 |
+
card.appendChild(fn);
|
| 396 |
+
_overlay.appendChild(card);
|
| 397 |
+
|
| 398 |
+
const pl = document.createElement("button");
|
| 399 |
+
pl.textContent = "\u25d1 what this means";
|
| 400 |
+
pl.title = "Toggle plain-language explanation for investors & consumers.";
|
| 401 |
+
pl.style.cssText = "font:11px ui-monospace,monospace;padding:5px 11px;border-radius:7px;border:1px solid #3af4c8;background:#08140f;color:#3af4c8;cursor:pointer;width:fit-content";
|
| 402 |
+
pl.addEventListener("click", () => {
|
| 403 |
+
_plain = !_plain;
|
| 404 |
+
pl.style.background = _plain ? "#0f2a20" : "#08140f";
|
| 405 |
+
_applyPlain();
|
| 406 |
+
});
|
| 407 |
+
_overlay.appendChild(pl);
|
| 408 |
+
|
| 409 |
+
const pd = document.createElement("div");
|
| 410 |
+
pd.id = "cq-plain";
|
| 411 |
+
pd.style.cssText = "font-size:10.5px;color:#c9d6df;line-height:1.55;border:1px dashed #26333f;border-radius:7px;padding:7px 9px;display:none";
|
| 412 |
+
_el["plain"] = pd;
|
| 413 |
+
_overlay.appendChild(pd);
|
| 414 |
+
|
| 415 |
+
(ctx.container || document.body).appendChild(_overlay);
|
| 416 |
+
_paintOverlay();
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
function _applyPlain() {
|
| 420 |
+
const pd = _el["plain"];
|
| 421 |
+
if (!pd) return;
|
| 422 |
+
pd.style.display = _plain ? "block" : "none";
|
| 423 |
+
if (!_plain) return;
|
| 424 |
+
const impPct = S.reconImprovFrac != null ? (S.reconImprovFrac * 100).toFixed(1) + "%" : "loading\u2026";
|
| 425 |
+
const abs = S.reconErrAbs != null ? (S.reconErrAbs * 100).toFixed(1) + "%" : "loading\u2026";
|
| 426 |
+
const cq = S.reconErrCatq != null ? (S.reconErrCatq * 100).toFixed(1) + "%" : "loading\u2026";
|
| 427 |
+
pd.innerHTML =
|
| 428 |
+
"<b>What this means:</b> Squeezing a language model down to three-value (\u201cternary\u201d) weights " +
|
| 429 |
+
"\u2014 minus one, zero, plus one \u2014 normally means re-training it from scratch on ~100 billion words, " +
|
| 430 |
+
"which is hugely expensive. <b>CAT-Q</b> instead takes a model that is <b>already trained</b>, freezes " +
|
| 431 |
+
"it, and calibrates the ternary conversion using only a tiny sample set \u2014 no re-training. It does this " +
|
| 432 |
+
"two ways: it <b>learns a better cut-off</b> (which weights become zero) and gently <b>eases</b> weights " +
|
| 433 |
+
"toward their ternary value instead of snapping them hard. Here, on a toy frozen weight set, that lowers " +
|
| 434 |
+
"the conversion error from about <b>" + abs + "</b> (plain absmean snap) to about <b>" + cq + "</b> \u2014 an " +
|
| 435 |
+
"improvement of roughly <b>" + impPct + "</b>, with <b>no re-training</b>. This is a <b>SUB-ORGAN UPGRADE " +
|
| 436 |
+
"of the ternary organ</b>: the same three-value weight idea, but a post-training-calibration mechanism " +
|
| 437 |
+
"instead of train-from-scratch. It is <b>MODELED</b> \u2014 a deterministic toy simulation of the mechanism, " +
|
| 438 |
+
"NOT a real large model, NOT the CAT-Q authors' code, and it does NOT reproduce their published results " +
|
| 439 |
+
"versus BitNet or their ~100,000\u00d7 training-data reduction.";
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
function _tok(s) {
|
| 443 |
+
if (s === "live") return null;
|
| 444 |
+
if (s === "missing") return "NO-LIVE-DATA";
|
| 445 |
+
if (s === "degraded") return "DEGRADED";
|
| 446 |
+
if (s === "error") return "OFFLINE";
|
| 447 |
+
return "\u2026";
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
function fx(v, d) { return typeof v === "number" ? v.toFixed(d) : "\u2014"; }
|
| 451 |
+
function pct(v, d) { return typeof v === "number" ? (v * 100).toFixed(d) + "%" : "\u2014"; }
|
| 452 |
+
function _set(id, v) { if (_el[id]) _el[id].textContent = v; }
|
| 453 |
+
|
| 454 |
+
function _paintOverlay() {
|
| 455 |
+
const t = _tok(S.state);
|
| 456 |
+
_set("cq-weights", t || (S.numWeights != null ? String(S.numWeights) : "\u2014"));
|
| 457 |
+
_set("cq-calib", t || (S.numCalib != null ? String(S.numCalib) : "\u2014"));
|
| 458 |
+
_set("cq-groups", t || (S.modGroups != null ? String(S.modGroups) : "\u2014"));
|
| 459 |
+
_set("cq-steps", t || (S.softSteps != null ? String(S.softSteps) : "\u2014"));
|
| 460 |
+
_set("cq-absthr", t || fx(S.absmeanThresh, 4));
|
| 461 |
+
_set("cq-catqthr", t || fx(S.catqThreshFrac, 3));
|
| 462 |
+
_set("cq-absmix", t || ((S.absNeg != null) ? (S.absNeg + " / " + S.absZero + " / " + S.absPos) : "\u2014"));
|
| 463 |
+
_set("cq-catqmix", t || ((S.catqNeg != null) ? (S.catqNeg + " / " + S.catqZero + " / " + S.catqPos) : "\u2014"));
|
| 464 |
+
_set("cq-reconabs", t || pct(S.reconErrAbs, 2));
|
| 465 |
+
_set("cq-reconcatq", t || pct(S.reconErrCatq, 2));
|
| 466 |
+
_set("cq-reconimp", t || pct(S.reconImprovFrac, 2));
|
| 467 |
+
_set("cq-taskabs", t || pct(S.taskErrAbs, 2));
|
| 468 |
+
_set("cq-taskcatq", t || pct(S.taskErrCatq, 2));
|
| 469 |
+
let curveTxt = "\u2014";
|
| 470 |
+
if (S.curve && S.curve.length >= 2) {
|
| 471 |
+
const f = S.curve[0], l = S.curve[S.curve.length - 1];
|
| 472 |
+
if (typeof f.task_err === "number" && typeof l.task_err === "number") {
|
| 473 |
+
curveTxt = f.task_err.toFixed(2) + " \u2192 " + l.task_err.toFixed(2);
|
| 474 |
+
}
|
| 475 |
+
}
|
| 476 |
+
_set("cq-curve", t || curveTxt);
|
| 477 |
+
_set("cq-bpw", t || fx(S.bitsPerWeight, 4));
|
| 478 |
+
// honesty label verbatim — never upgraded
|
| 479 |
+
_set("cq-label", t || (S.label || "MODELED"));
|
| 480 |
+
if (_plain) _applyPlain();
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
// =============================================================================
|
| 484 |
+
// unmount — clean up everything; must not affect other organs
|
| 485 |
+
// =============================================================================
|
| 486 |
+
export function unmount() {
|
| 487 |
+
_polls.forEach((p) => { try { p.stop(); } catch (_) {} }); _polls = [];
|
| 488 |
+
try { if (_overlay && _overlay.parentNode) _overlay.parentNode.removeChild(_overlay); } catch (_) {}
|
| 489 |
+
try {
|
| 490 |
+
if (_group && _stage) {
|
| 491 |
+
_group.traverse((o) => {
|
| 492 |
+
if (o.geometry && o.geometry.dispose) o.geometry.dispose();
|
| 493 |
+
if (o.material) {
|
| 494 |
+
const ms = Array.isArray(o.material) ? o.material : [o.material];
|
| 495 |
+
ms.forEach((m) => { if (m.dispose) m.dispose(); });
|
| 496 |
+
}
|
| 497 |
+
});
|
| 498 |
+
_stage.scene.remove(_group);
|
| 499 |
+
}
|
| 500 |
+
} catch (_) {}
|
| 501 |
+
_group = _overlay = null;
|
| 502 |
+
_floor = null; _barsAbs = []; _barsCatq = []; _gateAbs = null; _gateCatq = null;
|
| 503 |
+
_el = {}; _badge = null; _plain = false; _frameReg = false;
|
| 504 |
+
_stage = _THREE = _ctx = null;
|
| 505 |
+
S.label = S.numWeights = S.numCalib = S.modGroups = S.softSteps = null;
|
| 506 |
+
S.absmeanThresh = S.catqThreshFrac = null;
|
| 507 |
+
S.absNeg = S.absZero = S.absPos = null;
|
| 508 |
+
S.catqNeg = S.catqZero = S.catqPos = null;
|
| 509 |
+
S.reconErrAbs = S.reconErrCatq = S.reconImprovFrac = null;
|
| 510 |
+
S.taskErrAbs = S.taskErrCatq = S.bitsPerWeight = S.curve = null;
|
| 511 |
+
S.state = "init";
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
export default { id: ID, title: TITLE, endpoints: [EP], mount, unmount };
|
static/3d/surfaces/rauq.js
ADDED
|
@@ -0,0 +1,501 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: Apache-2.0
|
| 2 |
+
// © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 · Doctrine v11
|
| 3 |
+
//
|
| 4 |
+
// surfaces/rauq.js — ATTENTION-PATTERN (recurrent attention-based) UNCERTAINTY organ for
|
| 5 |
+
// the holographic frontier ring. SUB-ORGAN UPGRADE of sement.
|
| 6 |
+
//
|
| 7 |
+
// Same uncertainty axis as sement (hallucination / abstain-vs-answer), DISTINCT mechanism:
|
| 8 |
+
// sement's true signal is MULTI-SAMPLE semantic entropy (resample K generations, cluster
|
| 9 |
+
// meanings); RAUQ here reads INTRINSIC ATTENTION PATTERNS in a SINGLE forward pass — no
|
| 10 |
+
// resampling. It identifies "uncertainty-aware" attention heads whose attention TO PRECEDING
|
| 11 |
+
// TOKENS systematically DROPS during incorrect generations, auto-selects them, recurrently
|
| 12 |
+
// aggregates their preceding-token attention with per-token confidence into one SEQUENCE-LEVEL
|
| 13 |
+
// uncertainty scalar, and thresholds it to flag likely-wrong generations.
|
| 14 |
+
//
|
| 15 |
+
// Driven by a live snapshot from /api/killinchu/v1/rauq/score. The organ renders, per
|
| 16 |
+
// selected head, an ATTENTION-MASS TIMELINE across the sequence: a lattice-blue polyline for a
|
| 17 |
+
// CORRECT example (preceding-token mass stays HIGH) and a violet-blue polyline for an INCORRECT
|
| 18 |
+
// example (preceding-token mass DROPS / falls on flagged spans). Two KPI columns compare the
|
| 19 |
+
// RAUQ attention-drop score against a cheap OUTPUT-ENTROPY baseline (AUROC / accuracy / F1) —
|
| 20 |
+
// the attention-drop signal separates the labeled toy set better. Honesty label "MODELED" is
|
| 21 |
+
// read VERBATIM from the JSON and displayed as-is; never upgraded.
|
| 22 |
+
//
|
| 23 |
+
// IMPORTANT — MODELED, NOT A REAL TRANSFORMER:
|
| 24 |
+
// This organ simulates the attention-pattern-uncertainty MECHANISM on synthetic toy data.
|
| 25 |
+
// The "attention matrices" are SEEDED SYNTHETIC row-stochastic toys with correct/incorrect
|
| 26 |
+
// regimes BUILT IN BY CONSTRUCTION; there is NO real transformer, NO forward pass, and NO
|
| 27 |
+
// 4-LLM / 12-task evaluation. "Head selection" separates a hand-made labeled toy set. It
|
| 28 |
+
// demonstrates WHY a drop in preceding-token attention mass in selected heads can serve as a
|
| 29 |
+
// single-pass uncertainty signal a naive output-entropy baseline misses on constructed cases;
|
| 30 |
+
// it does NOT reproduce RAUQ's QA/summarization/translation results or its <1% real-latency
|
| 31 |
+
// claim. Explicitly a SUB-ORGAN UPGRADE of sement (same uncertainty axis, distinct single-
|
| 32 |
+
// pass-attention vs multi-sample-semantic-entropy mechanism — the true sement signal is
|
| 33 |
+
// MULTI-SAMPLE), not a new axis. Stated plainly in "what this means" and echoed in the
|
| 34 |
+
// endpoint's own JSON payload (honest_note).
|
| 35 |
+
//
|
| 36 |
+
// Surface export shape (mirrors sement.js / interpretability.js exactly):
|
| 37 |
+
// export default { id, title, endpoints, mount(ctx), unmount() }
|
| 38 |
+
// ctx = { stage, container, live, label, THREE, szl3d }
|
| 39 |
+
//
|
| 40 |
+
// LEADER ADOPTED & CITED (clean-room; NOT claimed as SZL's own):
|
| 41 |
+
// Vazhentsev, Rvanova, Kuzmin, Fadeeva, Lazichny, Panchenko, Panov, Baldwin, Sachan, Nakov &
|
| 42 |
+
// Shelmanov (2025) "Uncertainty-Aware Attention Heads: Efficient Unsupervised Uncertainty
|
| 43 |
+
// Quantification for LLMs" [RAUQ]. arXiv:2505.20045. https://arxiv.org/abs/2505.20045
|
| 44 |
+
//
|
| 45 |
+
// HONESTY LABEL: MODELED (simulation of the METHOD on synthetic toy data; seeded synthetic
|
| 46 |
+
// attention matrices, regimes built in by construction, NO real transformer). Read verbatim.
|
| 47 |
+
// COLOURS: lattice-blue 0x5b8dee (correct-regime timeline / RAUQ column), violet-blue 0x8a6bff
|
| 48 |
+
// (incorrect-regime timeline — data-viz only), proof-teal 0x3af4c8 (selected-head accent /
|
| 49 |
+
// verdict), greys for dim/idle. Purple BANNED as UI/background.
|
| 50 |
+
// 0 RUNTIME CDN. Vendored three.js via page importmap (ctx.THREE).
|
| 51 |
+
// DOCTRINE v11: degrades gracefully (grey) on 404/error; honesty label still shown.
|
| 52 |
+
// This organ adds NOTHING to SZL's own locked-8 / Λ-Conjecture-1.
|
| 53 |
+
|
| 54 |
+
const ID = "rauq";
|
| 55 |
+
const TITLE = "Attention-Pattern (Recurrent Attention) Uncertainty · sub-organ of sement (live)";
|
| 56 |
+
|
| 57 |
+
// Endpoint is hosted on the dedicated killinchu Space (isolated compute), reached
|
| 58 |
+
// cross-origin (killinchu returns access-control-allow-origin for the flagship origin).
|
| 59 |
+
const EP = "https://szlholdings-killinchu.hf.space/api/killinchu/v1/rauq/score?seed=42&seq_len=8&num_heads=6&num_selected_heads=2&preceding_window=1&confidence_weight=0.4&threshold=0.5";
|
| 60 |
+
|
| 61 |
+
// data-viz hues — purple BANNED
|
| 62 |
+
const C_CORRECT = 0x5b8dee; // lattice-blue (correct-regime timeline / RAUQ column)
|
| 63 |
+
const C_WRONG = 0x8a6bff; // violet-blue (incorrect-regime timeline — data-viz only)
|
| 64 |
+
const C_ACCENT = 0x3af4c8; // proof-teal accent (selected-head rails + verdict ring)
|
| 65 |
+
const C_DIM = 0x42505d; // grey (degraded / no-live-data / idle)
|
| 66 |
+
const C_GRID = 0x1b3a44; // floor / link colour
|
| 67 |
+
|
| 68 |
+
let _stage = null, _THREE = null, _ctx = null, _group = null, _overlay = null;
|
| 69 |
+
let _frameReg = false, _polls = [], _el = {}, _badge = null;
|
| 70 |
+
let _plain = false;
|
| 71 |
+
|
| 72 |
+
// geometry handles
|
| 73 |
+
let _lines = []; // Array<THREE.Line> — timeline polylines (per selected head x regime)
|
| 74 |
+
let _nodes = []; // Array<THREE.Mesh> — per-position marker spheres
|
| 75 |
+
let _rails = []; // Array<THREE.Mesh> — one rail bar per selected head
|
| 76 |
+
let _ring = null; // verdict ring (rauq_beats_baseline)
|
| 77 |
+
let _built = false;
|
| 78 |
+
const _MAX_NODES = 256;
|
| 79 |
+
const _pulse = new Float32Array(_MAX_NODES);
|
| 80 |
+
|
| 81 |
+
// live state
|
| 82 |
+
const S = {
|
| 83 |
+
label: null,
|
| 84 |
+
seqLen: null,
|
| 85 |
+
selectedHeads: [], // Array<int>
|
| 86 |
+
threshold: null,
|
| 87 |
+
beats: null, // rauq_beats_baseline
|
| 88 |
+
// one representative correct + one incorrect example, per selected head timeline
|
| 89 |
+
headTimelines: {}, // { headId: { correct: [..], incorrect: [..] } }
|
| 90 |
+
rauq: { auroc: null, accuracy: null, precision: null, recall: null, f1: null },
|
| 91 |
+
baseline: { auroc: null, accuracy: null, precision: null, recall: null, f1: null },
|
| 92 |
+
state: "init",
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
// =============================================================================
|
| 96 |
+
// mount(ctx)
|
| 97 |
+
// =============================================================================
|
| 98 |
+
export function mount(ctx) {
|
| 99 |
+
_ctx = ctx; _stage = ctx.stage; _THREE = ctx.THREE;
|
| 100 |
+
_group = new _THREE.Group();
|
| 101 |
+
_stage.scene.add(_group);
|
| 102 |
+
_stage.camera.position.set(0, 7, 22);
|
| 103 |
+
try { if (_stage.controls && _stage.controls.target) { _stage.controls.target.set(0, 2.2, 0); _stage.controls.update(); } } catch (_) {}
|
| 104 |
+
try { _stage.setBloom(true); } catch (_) {}
|
| 105 |
+
|
| 106 |
+
_buildFloor();
|
| 107 |
+
_buildVerdict();
|
| 108 |
+
|
| 109 |
+
if (!_frameReg) { _stage.onFrame(_onFrame); _frameReg = true; }
|
| 110 |
+
|
| 111 |
+
_badge = ctx.live.createBadge();
|
| 112 |
+
_polls.push(ctx.live.poll(EP, 5000, _onScore, { badge: _badge, onState: (m) => { S.state = m.state; _paintOverlay(); _updateGeometry(); } }));
|
| 113 |
+
|
| 114 |
+
_buildOverlay();
|
| 115 |
+
return { id: ID, started: true };
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
// =============================================================================
|
| 119 |
+
// builders
|
| 120 |
+
// =============================================================================
|
| 121 |
+
function _buildFloor() {
|
| 122 |
+
const THREE = _THREE;
|
| 123 |
+
const grid = new THREE.GridHelper(44, 44, C_GRID, 0x0f2027);
|
| 124 |
+
grid.material.opacity = 0.18; grid.material.transparent = true; grid.position.y = -0.01;
|
| 125 |
+
_group.add(grid);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
function _buildVerdict() {
|
| 129 |
+
const THREE = _THREE;
|
| 130 |
+
_ring = new THREE.Mesh(
|
| 131 |
+
new THREE.TorusGeometry(1.5, 0.05, 10, 48),
|
| 132 |
+
new THREE.MeshStandardMaterial({ color: C_ACCENT, emissive: C_ACCENT, emissiveIntensity: 0.4, transparent: true, opacity: 0.5 }),
|
| 133 |
+
);
|
| 134 |
+
_ring.position.set(0, 7.6, 0);
|
| 135 |
+
_ring.rotation.x = Math.PI / 2;
|
| 136 |
+
_group.add(_ring);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
// Dispose only the timeline geometry (rebuilt whenever selected heads / data change).
|
| 140 |
+
function _clearTimelines() {
|
| 141 |
+
const drop = (o) => {
|
| 142 |
+
try {
|
| 143 |
+
if (o.geometry && o.geometry.dispose) o.geometry.dispose();
|
| 144 |
+
if (o.material) {
|
| 145 |
+
const ms = Array.isArray(o.material) ? o.material : [o.material];
|
| 146 |
+
ms.forEach((m) => { if (m.dispose) m.dispose(); });
|
| 147 |
+
}
|
| 148 |
+
if (_group) _group.remove(o);
|
| 149 |
+
} catch (_) {}
|
| 150 |
+
};
|
| 151 |
+
_lines.forEach(drop); _nodes.forEach(drop); _rails.forEach(drop);
|
| 152 |
+
_lines = []; _nodes = []; _rails = [];
|
| 153 |
+
_pulse.fill(0);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
// Build one attention-mass timeline per selected head: a CORRECT polyline (lattice-blue,
|
| 157 |
+
// preceding-mass stays high) and an INCORRECT polyline (violet-blue, preceding-mass drops).
|
| 158 |
+
function _buildTimelines() {
|
| 159 |
+
const THREE = _THREE;
|
| 160 |
+
_clearTimelines();
|
| 161 |
+
const heads = S.selectedHeads;
|
| 162 |
+
const seqLen = S.seqLen || 8;
|
| 163 |
+
if (!heads.length) return;
|
| 164 |
+
|
| 165 |
+
const laneGap = 5.0; // z-separation between head lanes
|
| 166 |
+
const x0 = -((seqLen - 1) * 1.2) / 2; // centre the timeline in x
|
| 167 |
+
const dx = 1.2; // x per token position
|
| 168 |
+
const yScale = 6.0; // world-units per unit attention mass (mass 0..1)
|
| 169 |
+
|
| 170 |
+
heads.forEach((h, li) => {
|
| 171 |
+
const z = (li - (heads.length - 1) / 2) * laneGap;
|
| 172 |
+
const tl = S.headTimelines[String(h)] || {};
|
| 173 |
+
|
| 174 |
+
// rail bar under each lane (selected-head accent)
|
| 175 |
+
const rail = new THREE.Mesh(
|
| 176 |
+
new THREE.BoxGeometry((seqLen - 1) * dx + 0.4, 0.06, 0.12),
|
| 177 |
+
new THREE.MeshStandardMaterial({ color: C_ACCENT, emissive: C_ACCENT, emissiveIntensity: 0.3, transparent: true, opacity: 0.55 }),
|
| 178 |
+
);
|
| 179 |
+
rail.position.set(0, 0.03, z);
|
| 180 |
+
rail.userData.head = h;
|
| 181 |
+
_group.add(rail); _rails.push(rail);
|
| 182 |
+
|
| 183 |
+
[["correct", C_CORRECT], ["incorrect", C_WRONG]].forEach(([regime, col]) => {
|
| 184 |
+
const series = Array.isArray(tl[regime]) ? tl[regime] : [];
|
| 185 |
+
if (!series.length) return;
|
| 186 |
+
const pts = [];
|
| 187 |
+
for (let i = 0; i < series.length; i++) {
|
| 188 |
+
const x = x0 + i * dx;
|
| 189 |
+
const y = Math.max(0.05, Math.min(series[i] * yScale, 8.5));
|
| 190 |
+
pts.push(new THREE.Vector3(x, y, z + (regime === "incorrect" ? 0.35 : -0.35)));
|
| 191 |
+
// marker node
|
| 192 |
+
const node = new THREE.Mesh(
|
| 193 |
+
new THREE.SphereGeometry(0.11, 12, 12),
|
| 194 |
+
new THREE.MeshStandardMaterial({ color: col, emissive: col, emissiveIntensity: 0.5 }),
|
| 195 |
+
);
|
| 196 |
+
node.position.copy(pts[pts.length - 1]);
|
| 197 |
+
node.userData.pi = _nodes.length % _MAX_NODES;
|
| 198 |
+
_group.add(node); _nodes.push(node);
|
| 199 |
+
}
|
| 200 |
+
const geo = new THREE.BufferGeometry().setFromPoints(pts);
|
| 201 |
+
const line = new THREE.Line(geo, new THREE.LineBasicMaterial({ color: col, transparent: true, opacity: 0.9 }));
|
| 202 |
+
line.userData.regime = regime;
|
| 203 |
+
_group.add(line); _lines.push(line);
|
| 204 |
+
});
|
| 205 |
+
});
|
| 206 |
+
_built = true;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
// =============================================================================
|
| 210 |
+
// live data handler — reads label VERBATIM (top-level 'label' OR nested 'payload.label')
|
| 211 |
+
// =============================================================================
|
| 212 |
+
function _onScore(j) {
|
| 213 |
+
const p = (j && typeof j.payload === "object" && j.payload) ? j.payload : j;
|
| 214 |
+
const rawLabel = (p && p.label != null) ? p.label : (j && j.label != null ? j.label : "MODELED");
|
| 215 |
+
S.label = String(rawLabel).toUpperCase();
|
| 216 |
+
|
| 217 |
+
S.seqLen = typeof p.seq_len === "number" ? p.seq_len : null;
|
| 218 |
+
S.threshold = typeof p.threshold === "number" ? p.threshold : null;
|
| 219 |
+
S.beats = typeof p.rauq_beats_baseline === "boolean" ? p.rauq_beats_baseline : null;
|
| 220 |
+
S.selectedHeads = Array.isArray(p.selected_heads) ? p.selected_heads.slice() : [];
|
| 221 |
+
|
| 222 |
+
// metrics
|
| 223 |
+
const rm = p.rauq_metrics || {}, bm = p.baseline_metrics || {};
|
| 224 |
+
const grab = (o, dst) => {
|
| 225 |
+
dst.auroc = typeof o.auroc === "number" ? o.auroc : null;
|
| 226 |
+
dst.accuracy = typeof o.accuracy === "number" ? o.accuracy : null;
|
| 227 |
+
dst.precision = typeof o.precision === "number" ? o.precision : null;
|
| 228 |
+
dst.recall = typeof o.recall === "number" ? o.recall : null;
|
| 229 |
+
dst.f1 = typeof o.f1 === "number" ? o.f1 : null;
|
| 230 |
+
};
|
| 231 |
+
grab(rm, S.rauq); grab(bm, S.baseline);
|
| 232 |
+
|
| 233 |
+
// Extract one representative correct + one incorrect example's per-selected-head timeline.
|
| 234 |
+
S.headTimelines = {};
|
| 235 |
+
const exs = Array.isArray(p.examples) ? p.examples : [];
|
| 236 |
+
const firstCorrect = exs.find((e) => e && e.label === "correct");
|
| 237 |
+
const firstWrong = exs.find((e) => e && e.label === "incorrect");
|
| 238 |
+
S.selectedHeads.forEach((h) => {
|
| 239 |
+
const key = String(h);
|
| 240 |
+
const tl = {};
|
| 241 |
+
if (firstCorrect && firstCorrect.selected_head_preceding_timeline && Array.isArray(firstCorrect.selected_head_preceding_timeline[key])) {
|
| 242 |
+
tl.correct = firstCorrect.selected_head_preceding_timeline[key].slice();
|
| 243 |
+
}
|
| 244 |
+
if (firstWrong && firstWrong.selected_head_preceding_timeline && Array.isArray(firstWrong.selected_head_preceding_timeline[key])) {
|
| 245 |
+
tl.incorrect = firstWrong.selected_head_preceding_timeline[key].slice();
|
| 246 |
+
}
|
| 247 |
+
S.headTimelines[key] = tl;
|
| 248 |
+
});
|
| 249 |
+
|
| 250 |
+
_buildTimelines();
|
| 251 |
+
_updateGeometry();
|
| 252 |
+
_paintOverlay();
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
// =============================================================================
|
| 256 |
+
// geometry updater — colours by live/degraded state, verdict ring
|
| 257 |
+
// =============================================================================
|
| 258 |
+
function _updateGeometry() {
|
| 259 |
+
const live = S.state === "live";
|
| 260 |
+
_lines.forEach((ln) => {
|
| 261 |
+
const col = live ? (ln.userData.regime === "incorrect" ? C_WRONG : C_CORRECT) : C_DIM;
|
| 262 |
+
ln.material.color.setHex(col);
|
| 263 |
+
ln.material.opacity = live ? 0.9 : 0.3;
|
| 264 |
+
});
|
| 265 |
+
_nodes.forEach((nd) => {
|
| 266 |
+
if (!live) { nd.material.color.setHex(C_DIM); nd.material.emissive.setHex(C_DIM); nd.material.emissiveIntensity = 0.1; }
|
| 267 |
+
});
|
| 268 |
+
_rails.forEach((rl) => {
|
| 269 |
+
const col = live ? C_ACCENT : C_DIM;
|
| 270 |
+
rl.material.color.setHex(col); rl.material.emissive.setHex(col);
|
| 271 |
+
rl.material.emissiveIntensity = live ? 0.3 : 0.1; rl.material.opacity = live ? 0.55 : 0.2;
|
| 272 |
+
});
|
| 273 |
+
if (_ring) {
|
| 274 |
+
// verdict: RAUQ beats baseline -> calm teal; else violet-blue warning
|
| 275 |
+
const beats = S.beats === true;
|
| 276 |
+
const rcol = live ? (beats ? C_ACCENT : C_WRONG) : C_DIM;
|
| 277 |
+
_ring.material.color.setHex(rcol); _ring.material.emissive.setHex(rcol);
|
| 278 |
+
_ring.material.emissiveIntensity = live ? (beats ? 0.6 : 0.85) : 0.12;
|
| 279 |
+
_ring.material.opacity = live ? 0.6 : 0.2;
|
| 280 |
+
_ring.scale.setScalar(live ? (beats ? 1.0 : 1.15) : 0.8);
|
| 281 |
+
}
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
// =============================================================================
|
| 285 |
+
// per-frame animation
|
| 286 |
+
// =============================================================================
|
| 287 |
+
function _onFrame() {
|
| 288 |
+
const t = performance.now();
|
| 289 |
+
if (_group) _group.rotation.y = Math.sin(t * 0.0001) * 0.12;
|
| 290 |
+
if (_ring) _ring.rotation.z += 0.004;
|
| 291 |
+
const live = S.state === "live";
|
| 292 |
+
_nodes.forEach((nd) => {
|
| 293 |
+
const i = nd.userData.pi;
|
| 294 |
+
if (_pulse[i] > 0) {
|
| 295 |
+
_pulse[i] -= 1;
|
| 296 |
+
const f = _pulse[i] / 60;
|
| 297 |
+
nd.material.emissiveIntensity = Math.max(nd.material.emissiveIntensity, 0.2 + 0.6 * f);
|
| 298 |
+
} else if (live) {
|
| 299 |
+
nd.material.emissiveIntensity = 0.4;
|
| 300 |
+
}
|
| 301 |
+
});
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
// =============================================================================
|
| 305 |
+
// overlay
|
| 306 |
+
// =============================================================================
|
| 307 |
+
function _buildOverlay() {
|
| 308 |
+
const ctx = _ctx;
|
| 309 |
+
_overlay = document.createElement("div");
|
| 310 |
+
Object.assign(_overlay.style, {
|
| 311 |
+
position: "absolute", left: "14px", top: "14px", zIndex: "6",
|
| 312 |
+
display: "flex", flexDirection: "column", gap: "8px",
|
| 313 |
+
maxWidth: "min(94%,500px)",
|
| 314 |
+
font: "12px ui-sans-serif,system-ui,Segoe UI,Roboto,Arial",
|
| 315 |
+
color: "#eef3f6",
|
| 316 |
+
});
|
| 317 |
+
|
| 318 |
+
const h = document.createElement("div");
|
| 319 |
+
h.style.cssText = "font:600 13px ui-sans-serif,system-ui;letter-spacing:.4px";
|
| 320 |
+
h.textContent = TITLE;
|
| 321 |
+
_overlay.appendChild(h);
|
| 322 |
+
|
| 323 |
+
const sub = document.createElement("div");
|
| 324 |
+
sub.style.cssText = "color:#9fb1bf;font-size:11px;line-height:1.55";
|
| 325 |
+
sub.innerHTML =
|
| 326 |
+
'In a <b>single forward pass</b> we read a model\u2019s <b>attention patterns</b>: certain ' +
|
| 327 |
+
'<b>uncertainty-aware heads</b> keep high attention on the <b>immediately-preceding token</b> ' +
|
| 328 |
+
'when a generation is <b>correct</b>, but that mass <b>drops</b> when it is <b>incorrect</b>. ' +
|
| 329 |
+
'We <b>auto-select</b> those heads by how well they separate a labeled set, <b>recurrently ' +
|
| 330 |
+
'aggregate</b> their preceding-token attention with a confidence proxy into one ' +
|
| 331 |
+
'<b>sequence-level uncertainty score</b>, and <b>flag</b> likely-wrong generations \u2014 beating ' +
|
| 332 |
+
'a cheap <b>output-entropy</b> baseline. Sub-organ upgrade of <b>sement</b> (same uncertainty ' +
|
| 333 |
+
'axis; sement\u2019s true signal is <b>multi-sample</b> semantic entropy, this is ' +
|
| 334 |
+
'<b>single-pass attention</b>). Honesty label <b>MODELED</b> \u2014 a simulation of the method on ' +
|
| 335 |
+
'synthetic toy data, <b>not</b> a real transformer. 0 runtime CDN.';
|
| 336 |
+
_overlay.appendChild(sub);
|
| 337 |
+
|
| 338 |
+
const brow = document.createElement("div");
|
| 339 |
+
brow.style.cssText = "display:flex;gap:8px;align-items:center;flex-wrap:wrap";
|
| 340 |
+
if (_badge && _badge.el) brow.appendChild(_badge.el);
|
| 341 |
+
_overlay.appendChild(brow);
|
| 342 |
+
|
| 343 |
+
const card = document.createElement("div");
|
| 344 |
+
card.style.cssText = "background:#0a1117;border:1px solid #1d2a36;border-radius:9px;padding:9px 10px;display:flex;flex-direction:column;gap:6px";
|
| 345 |
+
|
| 346 |
+
const chead = document.createElement("div");
|
| 347 |
+
chead.style.cssText = "display:flex;align-items:center;gap:8px;flex-wrap:wrap";
|
| 348 |
+
const dot = document.createElement("span");
|
| 349 |
+
dot.style.cssText = "width:9px;height:9px;border-radius:50%;background:#5b8dee;box-shadow:0 0 7px #5b8dee";
|
| 350 |
+
const nm = document.createElement("b");
|
| 351 |
+
nm.style.cssText = "font-size:12px;color:#5b8dee;letter-spacing:.3px";
|
| 352 |
+
nm.textContent = "rauq \u00b7 attention-pattern uncertainty";
|
| 353 |
+
chead.appendChild(dot); chead.appendChild(nm);
|
| 354 |
+
card.appendChild(chead);
|
| 355 |
+
|
| 356 |
+
const grid = document.createElement("div");
|
| 357 |
+
grid.style.cssText = "display:grid;grid-template-columns:1fr;gap:4px";
|
| 358 |
+
|
| 359 |
+
function kpiRow(id, label) {
|
| 360 |
+
const r = document.createElement("div");
|
| 361 |
+
r.style.cssText = "display:flex;justify-content:space-between;gap:10px;font-size:11px";
|
| 362 |
+
const l = document.createElement("span"); l.style.cssText = "color:#9fb1bf"; l.textContent = label;
|
| 363 |
+
const v = document.createElement("b");
|
| 364 |
+
v.id = id;
|
| 365 |
+
v.style.cssText = "font-variant-numeric:tabular-nums;color:#eef3f6;text-align:right;max-width:62%";
|
| 366 |
+
v.textContent = "\u2014";
|
| 367 |
+
_el[id] = v;
|
| 368 |
+
r.appendChild(l); r.appendChild(v); return r;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
grid.appendChild(kpiRow("rq-sel", "auto-selected heads"));
|
| 372 |
+
grid.appendChild(kpiRow("rq-thr", "RAUQ flag threshold"));
|
| 373 |
+
grid.appendChild(kpiRow("rq-ra", "RAUQ \u00b7 AUROC / accuracy"));
|
| 374 |
+
grid.appendChild(kpiRow("rq-rf", "RAUQ \u00b7 precision / recall / F1"));
|
| 375 |
+
grid.appendChild(kpiRow("rq-ba", "baseline \u00b7 AUROC / accuracy"));
|
| 376 |
+
grid.appendChild(kpiRow("rq-bf", "baseline \u00b7 precision / recall / F1"));
|
| 377 |
+
grid.appendChild(kpiRow("rq-beats", "attention-drop beats output-entropy"));
|
| 378 |
+
grid.appendChild(kpiRow("rq-label", "honesty label"));
|
| 379 |
+
card.appendChild(grid);
|
| 380 |
+
|
| 381 |
+
const fn = document.createElement("div");
|
| 382 |
+
fn.style.cssText = "font-size:9.5px;color:#6b7a86;line-height:1.5";
|
| 383 |
+
fn.textContent = "Vazhentsev, Rvanova, Kuzmin, Fadeeva, Lazichny, Panchenko, Panov, Baldwin, " +
|
| 384 |
+
"Sachan, Nakov & Shelmanov, arXiv:2505.20045 (2025) \u00b7 MODELED \u00b7 seeded synthetic attention " +
|
| 385 |
+
"matrices, regimes built in by construction, no real transformer \u00b7 sub-organ upgrade of " +
|
| 386 |
+
"sement (true sement signal is multi-sample) \u00b7 not claimed-as.";
|
| 387 |
+
card.appendChild(fn);
|
| 388 |
+
_overlay.appendChild(card);
|
| 389 |
+
|
| 390 |
+
const pl = document.createElement("button");
|
| 391 |
+
pl.textContent = "\u25d1 what this means";
|
| 392 |
+
pl.title = "Toggle plain-language explanation for investors & consumers.";
|
| 393 |
+
pl.style.cssText = "font:11px ui-monospace,monospace;padding:5px 11px;border-radius:7px;border:1px solid #3af4c8;background:#08140f;color:#3af4c8;cursor:pointer;width:fit-content";
|
| 394 |
+
pl.addEventListener("click", () => {
|
| 395 |
+
_plain = !_plain;
|
| 396 |
+
pl.style.background = _plain ? "#0f2a20" : "#08140f";
|
| 397 |
+
_applyPlain();
|
| 398 |
+
});
|
| 399 |
+
_overlay.appendChild(pl);
|
| 400 |
+
|
| 401 |
+
const pd = document.createElement("div");
|
| 402 |
+
pd.id = "rauq-plain";
|
| 403 |
+
pd.style.cssText = "font-size:10.5px;color:#c9d6df;line-height:1.55;border:1px dashed #26333f;border-radius:7px;padding:7px 9px;display:none";
|
| 404 |
+
_el["plain"] = pd;
|
| 405 |
+
_overlay.appendChild(pd);
|
| 406 |
+
|
| 407 |
+
(ctx.container || document.body).appendChild(_overlay);
|
| 408 |
+
_paintOverlay();
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
function _applyPlain() {
|
| 412 |
+
const pd = _el["plain"];
|
| 413 |
+
if (!pd) return;
|
| 414 |
+
pd.style.display = _plain ? "block" : "none";
|
| 415 |
+
if (!_plain) return;
|
| 416 |
+
const sel = S.selectedHeads.length ? S.selectedHeads.join(", ") : "loading\u2026";
|
| 417 |
+
const rAuroc = S.rauq.auroc != null ? S.rauq.auroc.toFixed(3) : "loading\u2026";
|
| 418 |
+
const rAcc = S.rauq.accuracy != null ? S.rauq.accuracy.toFixed(3) : "loading\u2026";
|
| 419 |
+
const bAuroc = S.baseline.auroc != null ? S.baseline.auroc.toFixed(3) : "loading\u2026";
|
| 420 |
+
const bAcc = S.baseline.accuracy != null ? S.baseline.accuracy.toFixed(3) : "loading\u2026";
|
| 421 |
+
pd.innerHTML =
|
| 422 |
+
"<b>What this means:</b> A transformer pays <b>attention</b> to earlier words as it writes. " +
|
| 423 |
+
"In some heads, when the model is on solid ground it keeps a strong link to the <b>word it just " +
|
| 424 |
+
"wrote</b>; when it starts to <b>make things up</b>, that link <b>weakens</b>. We find the heads " +
|
| 425 |
+
"where this pattern is clearest (here heads <b>" + sel + "</b>), watch how their preceding-word " +
|
| 426 |
+
"attention rises and falls across the sentence, and roll it into a single <b>uncertainty score</b> " +
|
| 427 |
+
"\u2014 all in <b>one pass</b>, no re-asking the model. On our labeled toy set that attention-drop " +
|
| 428 |
+
"score tells correct from incorrect almost perfectly (AUROC \u2248 <b>" + rAuroc + "</b>, accuracy " +
|
| 429 |
+
"\u2248 <b>" + rAcc + "</b>), while a naive <b>output-entropy</b> baseline is much weaker " +
|
| 430 |
+
"(AUROC \u2248 <b>" + bAuroc + "</b>, accuracy \u2248 <b>" + bAcc + "</b>). The blue timeline holds " +
|
| 431 |
+
"high; the violet timeline collapses \u2014 that collapse is the signal." +
|
| 432 |
+
"<br><br><b>Important honesty note:</b> this is a <b>MODELED</b> toy analytic simulation of the " +
|
| 433 |
+
"attention-pattern-uncertainty <b>mechanism</b>, <b>not RAUQ</b> and <b>not a real transformer</b>. " +
|
| 434 |
+
"The \u201cattention matrices\u201d are <b>seeded synthetic</b> row-stochastic toys with the " +
|
| 435 |
+
"correct/incorrect regimes <b>built in by construction</b>; there is <b>no forward pass</b> and " +
|
| 436 |
+
"<b>no 4-LLM / 12-task evaluation</b>, and \u201chead selection\u201d separates a <b>hand-made " +
|
| 437 |
+
"labeled toy set</b>. It shows <b>why</b> a drop in preceding-token attention can be a single-pass " +
|
| 438 |
+
"uncertainty signal that output-entropy misses, but it does <b>not</b> reproduce RAUQ\u2019s " +
|
| 439 |
+
"QA/summarization/translation results or its <b><1% latency</b> claim. It is explicitly a " +
|
| 440 |
+
"<b>sub-organ upgrade of sement</b> \u2014 same uncertainty axis, distinct <b>single-pass-attention</b> " +
|
| 441 |
+
"vs <b>multi-sample semantic-entropy</b> mechanism (the true sement signal is <b>multi-sample</b>) " +
|
| 442 |
+
"\u2014 not a new axis (Vazhentsev et al., arXiv:2505.20045, 2025).";
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
function _tok(s) {
|
| 446 |
+
if (s === "live") return null;
|
| 447 |
+
if (s === "missing") return "NO-LIVE-DATA";
|
| 448 |
+
if (s === "degraded") return "DEGRADED";
|
| 449 |
+
if (s === "error") return "OFFLINE";
|
| 450 |
+
return "\u2026";
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
function fx(v, d) { return typeof v === "number" ? v.toFixed(d) : "\u2014"; }
|
| 454 |
+
function _set(id, v) { if (_el[id]) _el[id].textContent = v; }
|
| 455 |
+
|
| 456 |
+
function _paintOverlay() {
|
| 457 |
+
const t = _tok(S.state);
|
| 458 |
+
_set("rq-sel", t || (S.selectedHeads.length ? S.selectedHeads.join(", ") : "\u2014"));
|
| 459 |
+
_set("rq-thr", t || fx(S.threshold, 3));
|
| 460 |
+
_set("rq-ra", t || (S.rauq.auroc != null && S.rauq.accuracy != null ? fx(S.rauq.auroc, 3) + " / " + fx(S.rauq.accuracy, 3) : "\u2014"));
|
| 461 |
+
_set("rq-rf", t || (S.rauq.precision != null ? fx(S.rauq.precision, 3) + " / " + fx(S.rauq.recall, 3) + " / " + fx(S.rauq.f1, 3) : "\u2014"));
|
| 462 |
+
_set("rq-ba", t || (S.baseline.auroc != null && S.baseline.accuracy != null ? fx(S.baseline.auroc, 3) + " / " + fx(S.baseline.accuracy, 3) : "\u2014"));
|
| 463 |
+
_set("rq-bf", t || (S.baseline.precision != null ? fx(S.baseline.precision, 3) + " / " + fx(S.baseline.recall, 3) + " / " + fx(S.baseline.f1, 3) : "\u2014"));
|
| 464 |
+
_set("rq-beats", t || (S.beats == null ? "\u2014" : (S.beats ? "YES \u2014 attention-drop separates better" : "no")));
|
| 465 |
+
// honesty label verbatim — never upgraded
|
| 466 |
+
_set("rq-label", t || (S.label || "MODELED"));
|
| 467 |
+
if (_plain) _applyPlain();
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
// =============================================================================
|
| 471 |
+
// unmount — clean up everything; must not affect other organs
|
| 472 |
+
// =============================================================================
|
| 473 |
+
export function unmount() {
|
| 474 |
+
_polls.forEach((p) => { try { p.stop(); } catch (_) {} }); _polls = [];
|
| 475 |
+
try { if (_overlay && _overlay.parentNode) _overlay.parentNode.removeChild(_overlay); } catch (_) {}
|
| 476 |
+
try {
|
| 477 |
+
if (_group && _stage) {
|
| 478 |
+
_group.traverse((o) => {
|
| 479 |
+
if (o.geometry && o.geometry.dispose) o.geometry.dispose();
|
| 480 |
+
if (o.material) {
|
| 481 |
+
const ms = Array.isArray(o.material) ? o.material : [o.material];
|
| 482 |
+
ms.forEach((m) => { if (m.dispose) m.dispose(); });
|
| 483 |
+
}
|
| 484 |
+
});
|
| 485 |
+
_stage.scene.remove(_group);
|
| 486 |
+
}
|
| 487 |
+
} catch (_) {}
|
| 488 |
+
_group = _overlay = null;
|
| 489 |
+
_lines = []; _nodes = []; _rails = []; _ring = null;
|
| 490 |
+
_built = false;
|
| 491 |
+
_el = {}; _badge = null; _plain = false; _frameReg = false;
|
| 492 |
+
_stage = _THREE = _ctx = null;
|
| 493 |
+
S.label = S.seqLen = S.threshold = S.beats = null;
|
| 494 |
+
S.selectedHeads = []; S.headTimelines = {};
|
| 495 |
+
S.rauq = { auroc: null, accuracy: null, precision: null, recall: null, f1: null };
|
| 496 |
+
S.baseline = { auroc: null, accuracy: null, precision: null, recall: null, f1: null };
|
| 497 |
+
S.state = "init";
|
| 498 |
+
_pulse.fill(0);
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
export default { id: ID, title: TITLE, end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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: Apache-2.0
|
| 2 |
+
// © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 · Doctrine v11
|
| 3 |
+
//
|
| 4 |
+
// surfaces/slidesparse.js — STRUCTURED-SPARSE LAYOUT PACKING organ for the
|
| 5 |
+
// holographic frontier ring (SlideSparse (2N-2):2N sliding-window decomposition
|
| 6 |
+
// + activation lifting, Furu Wei group-style). Renders one 2N-wide structured-
|
| 7 |
+
// sparse weight block as a row of cells, then lifts it into N-1 OVERLAPPING
|
| 8 |
+
// 4-wide 2:4 windows stacked above it — each window 2:4-compliant (<=2 nonzeros
|
| 9 |
+
// per 4) — visually showing that the N-1 windows recompose the block EXACTLY
|
| 10 |
+
// (lossless). A throughput-proxy bar trio compares dense (lattice-blue), strict-
|
| 11 |
+
// 2:4 (grey/over-pruned) and slidesparse (proof-teal) effective-MAC speedups
|
| 12 |
+
// against the N/(N-1) ceiling read live from /api/killinchu/v1/slidesparse/pack.
|
| 13 |
+
// Honesty label "MODELED" is read VERBATIM from the JSON and displayed as-is; it
|
| 14 |
+
// is never upgraded.
|
| 15 |
+
//
|
| 16 |
+
// Surface export shape (mirrors ternary.js / aimc.js exactly):
|
| 17 |
+
// export default { id, title, endpoints, mount(ctx), unmount() }
|
| 18 |
+
// ctx = { stage, container, live, label, THREE, szl3d }
|
| 19 |
+
//
|
| 20 |
+
// DATA SHOWN (all from live endpoint):
|
| 21 |
+
// N, block_width, windows_per_block, sparsity_pattern, prune_fraction,
|
| 22 |
+
// matrix_rows, matrix_cols, blocks_total, mode, reconstruction_error, lossless,
|
| 23 |
+
// slidesparse_recon_error, strict_2to4_recon_error, dense_macs,
|
| 24 |
+
// strict_2to4_macs, slidesparse_macs, speedup_dense, speedup_strict_2to4,
|
| 25 |
+
// speedup_slidesparse, throughput_ceiling, ceiling_gap,
|
| 26 |
+
// activation_lifting_perm[], sample_window_masks[]
|
| 27 |
+
//
|
| 28 |
+
// LEADERS ADOPTED & CITED (clean-room; NOT claimed as SZL's own; VERIFY real):
|
| 29 |
+
// SlideSparse: Fast and Flexible (2N-2):2N Structured Sparsity (mechanism
|
| 30 |
+
// simulated here):
|
| 31 |
+
// Shao, Hao, Song, Xia, Zhang, Huang, Wu, Xu, Xu, Dong, Chi, Zou, Wei
|
| 32 |
+
// (Furu Wei group) arXiv:2603.05232 https://arxiv.org/abs/2603.05232
|
| 33 |
+
//
|
| 34 |
+
// HONESTY LABELS: MODELED (deterministic reproduction of the SlideSparse sliding-
|
| 35 |
+
// window-decomposition + activation-lifting PACKING mechanism on a toy synthetic
|
| 36 |
+
// matrix; NO GPU, NO Sparse Tensor Core, NO vLLM, NO CUDA; 'throughput' is a
|
| 37 |
+
// counted MAC proxy, 'accuracy' a reconstruction-error proxy; NEVER-CLAIMED-AS a
|
| 38 |
+
// real tensor-core run or SlideSparse's 1.33x Qwen2.5-7B result). Read verbatim
|
| 39 |
+
// from JSON; never upgraded here. NEW AXIS: structured-sparse layout/packing —
|
| 40 |
+
// orthogonal to ternary bit-precision + aimc analog compute.
|
| 41 |
+
// COLOURS: proof-teal 0x3af4c8 (slidesparse path / kept nonzero / HUD accent),
|
| 42 |
+
// lattice-blue 0x5b8dee (dense baseline / block cells), violet-blue 0x8a6bff
|
| 43 |
+
// (window frame / activation-lifting accent), greys (pruned zeros / strict-2:4
|
| 44 |
+
// over-prune / degraded state). Purple BANNED as UI/background.
|
| 45 |
+
// 0 RUNTIME CDN. Vendored three.js via ctx.THREE (page importmap).
|
| 46 |
+
// DOCTRINE v11: degrades gracefully (grey) on 404/error; honesty label still shown.
|
| 47 |
+
// Nothing here is in the locked-8. Λ stays Conjecture 1. Trust never 100%.
|
| 48 |
+
|
| 49 |
+
const ID = "slidesparse";
|
| 50 |
+
const TITLE = "Structured-Sparse Layout Packing · SlideSparse (2N-2):2N (live)";
|
| 51 |
+
|
| 52 |
+
// Endpoint is hosted on the dedicated killinchu Space (isolated compute), reached
|
| 53 |
+
// cross-origin (killinchu returns access-control-allow-origin for the flagship).
|
| 54 |
+
// This keeps the slidesparse organ's rebuilds/faults isolated from the flagship.
|
| 55 |
+
const EP = "https://szlholdings-killinchu.hf.space/api/killinchu/v1/slidesparse/pack?seed=42&N=4&mode=slidesparse";
|
| 56 |
+
|
| 57 |
+
// data-viz hues — purple BANNED
|
| 58 |
+
const C_SLIDE = 0x3af4c8; // proof-teal (slidesparse path / kept nonzero)
|
| 59 |
+
const C_DENSE = 0x5b8dee; // lattice-blue (dense baseline / block cell)
|
| 60 |
+
const C_WINDOW = 0x8a6bff; // violet-blue (window frame / activation-lifting)
|
| 61 |
+
const C_PRUNE = 0x5a6570; // grey (pruned zero / dropped weight)
|
| 62 |
+
const C_STRICT = 0x6b7a86; // grey (strict-2:4 over-pruned baseline)
|
| 63 |
+
const C_DIM = 0x42505d; // grey (degraded / no-live-data)
|
| 64 |
+
const C_GRID = 0x1b3a44; // floor / link colour
|
| 65 |
+
|
| 66 |
+
// layout geometry
|
| 67 |
+
const MAX_BLOCK = 32; // cap on block cells rendered (perf): 2N <= MAX_BLOCK
|
| 68 |
+
const MAX_WINDOWS = 15; // cap on windows rendered (perf): N-1 <= MAX_WINDOWS
|
| 69 |
+
const CELL_GAP = 0.6; // world-units between block cells along X
|
| 70 |
+
const WIN_Y_GAP = 0.62; // vertical spacing between stacked windows
|
| 71 |
+
const BLOCK_Y = 0.4; // resting height of the source block row
|
| 72 |
+
const MAX_BAR_H = 4.2; // world-units — throughput bar height at ceiling
|
| 73 |
+
const MIN_BAR_H = 0.04; // floor height so a bar never fully vanishes
|
| 74 |
+
const BAR_GAP = 1.1; // spacing between the three throughput bars
|
| 75 |
+
|
| 76 |
+
let _stage = null, _THREE = null, _ctx = null, _group = null, _overlay = null;
|
| 77 |
+
let _frameReg = false, _polls = [], _el = {}, _badge = null;
|
| 78 |
+
let _plain = false;
|
| 79 |
+
|
| 80 |
+
// geometry handles
|
| 81 |
+
let _floor = null;
|
| 82 |
+
let _blockCell = []; // Array<THREE.Mesh> — the 2N source-block cells
|
| 83 |
+
let _winCell = []; // Array<Array<THREE.Mesh>> — window x 4 cells
|
| 84 |
+
let _winFrame = []; // Array<THREE.LineSegments> — window frames
|
| 85 |
+
let _barDense = null; // THREE.Mesh — dense speedup bar
|
| 86 |
+
let _barStrict = null; // THREE.Mesh — strict-2:4 speedup bar
|
| 87 |
+
let _barSlide = null; // THREE.Mesh — slidesparse speedup bar
|
| 88 |
+
let _ceilLine = null; // THREE.Line — N/(N-1) ceiling marker
|
| 89 |
+
let _liftMark = null; // THREE.Mesh — activation-lifting pulse marker
|
| 90 |
+
|
| 91 |
+
// live state
|
| 92 |
+
const S = {
|
| 93 |
+
label: null,
|
| 94 |
+
N: null,
|
| 95 |
+
blockWidth: null, // block_width (2N)
|
| 96 |
+
winsPerBlock: null, // windows_per_block (N-1)
|
| 97 |
+
pattern: null, // sparsity_pattern e.g. "6:8"
|
| 98 |
+
pruneFrac: null, // prune_fraction
|
| 99 |
+
rows: null, // matrix_rows
|
| 100 |
+
cols: null, // matrix_cols
|
| 101 |
+
blocksTotal: null, // blocks_total
|
| 102 |
+
mode: null, // mode
|
| 103 |
+
reconErr: null, // reconstruction_error (for mode)
|
| 104 |
+
lossless: null, // lossless
|
| 105 |
+
slideRecon: null, // slidesparse_recon_error
|
| 106 |
+
strictRecon: null, // strict_2to4_recon_error
|
| 107 |
+
denseMacs: null, // dense_macs
|
| 108 |
+
strictMacs: null, // strict_2to4_macs
|
| 109 |
+
slideMacs: null, // slidesparse_macs
|
| 110 |
+
spDense: null, // speedup_dense
|
| 111 |
+
spStrict: null, // speedup_strict_2to4
|
| 112 |
+
spSlide: null, // speedup_slidesparse
|
| 113 |
+
ceiling: null, // throughput_ceiling N/(N-1)
|
| 114 |
+
ceilingGap: null, // ceiling_gap
|
| 115 |
+
liftPerm: null, // activation_lifting_perm[]
|
| 116 |
+
winMasks: null, // sample_window_masks[]
|
| 117 |
+
state: "init",
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
+
// =============================================================================
|
| 121 |
+
// mount(ctx)
|
| 122 |
+
// =============================================================================
|
| 123 |
+
export function mount(ctx) {
|
| 124 |
+
_ctx = ctx; _stage = ctx.stage; _THREE = ctx.THREE;
|
| 125 |
+
_group = new _THREE.Group();
|
| 126 |
+
_stage.scene.add(_group);
|
| 127 |
+
_stage.camera.position.set(4, 7, 16);
|
| 128 |
+
try { if (_stage.controls && _stage.controls.target) { _stage.controls.target.set(3, 2, 0); _stage.controls.update(); } } catch (_) {}
|
| 129 |
+
try { _stage.setBloom(true); } catch (_) {}
|
| 130 |
+
|
| 131 |
+
_buildFloor();
|
| 132 |
+
_buildBlock();
|
| 133 |
+
_buildWindows();
|
| 134 |
+
_buildBars();
|
| 135 |
+
_buildLiftMarker();
|
| 136 |
+
|
| 137 |
+
if (!_frameReg) { _stage.onFrame(_onFrame); _frameReg = true; }
|
| 138 |
+
|
| 139 |
+
_badge = ctx.live.createBadge();
|
| 140 |
+
_polls.push(ctx.live.poll(EP, 5000, _onSlide, { badge: _badge, onState: (m) => { S.state = m.state; _paintOverlay(); } }));
|
| 141 |
+
|
| 142 |
+
_buildOverlay();
|
| 143 |
+
return { id: ID, started: true };
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
// =============================================================================
|
| 147 |
+
// builders
|
| 148 |
+
// =============================================================================
|
| 149 |
+
function _buildFloor() {
|
| 150 |
+
const THREE = _THREE;
|
| 151 |
+
const grid = new THREE.GridHelper(40, 40, C_GRID, 0x0f2027);
|
| 152 |
+
grid.material.opacity = 0.18; grid.material.transparent = true; grid.position.y = -0.01;
|
| 153 |
+
_group.add(grid);
|
| 154 |
+
_floor = grid;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
// The 2N-wide structured-sparse source block: a row of cells along X. Kept
|
| 158 |
+
// nonzeros glow lattice-blue; the 2 dropped (pruned) entries fade to grey and
|
| 159 |
+
// sink. Coloured in-place from the live window masks (no per-poll churn).
|
| 160 |
+
function _buildBlock() {
|
| 161 |
+
const THREE = _THREE;
|
| 162 |
+
const cellGeo = new THREE.BoxGeometry(0.34, 0.34, 0.34);
|
| 163 |
+
for (let i = 0; i < MAX_BLOCK; i++) {
|
| 164 |
+
const mesh = new THREE.Mesh(
|
| 165 |
+
cellGeo,
|
| 166 |
+
new THREE.MeshStandardMaterial({ color: C_PRUNE, emissive: C_PRUNE, emissiveIntensity: 0.15, transparent: true, opacity: 0.0 }),
|
| 167 |
+
);
|
| 168 |
+
mesh.position.set(i * CELL_GAP, BLOCK_Y, 0);
|
| 169 |
+
mesh.visible = false;
|
| 170 |
+
_group.add(mesh);
|
| 171 |
+
_blockCell.push(mesh);
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
// N-1 overlapping 4-wide 2:4 windows, stacked upward above the source block.
|
| 176 |
+
// Each window is a violet-blue wireframe frame around its 4 cells; kept nonzeros
|
| 177 |
+
// in a window glow proof-teal, empty slots stay grey. Positioned at the window's
|
| 178 |
+
// column offset so it visually overlays the exact columns it recomposes.
|
| 179 |
+
function _buildWindows() {
|
| 180 |
+
const THREE = _THREE;
|
| 181 |
+
const cellGeo = new THREE.BoxGeometry(0.28, 0.28, 0.28);
|
| 182 |
+
for (let w = 0; w < MAX_WINDOWS; w++) {
|
| 183 |
+
const row = [];
|
| 184 |
+
for (let k = 0; k < 4; k++) {
|
| 185 |
+
const mesh = new THREE.Mesh(
|
| 186 |
+
cellGeo,
|
| 187 |
+
new THREE.MeshStandardMaterial({ color: C_PRUNE, emissive: C_PRUNE, emissiveIntensity: 0.12, transparent: true, opacity: 0.0 }),
|
| 188 |
+
);
|
| 189 |
+
mesh.visible = false;
|
| 190 |
+
_group.add(mesh);
|
| 191 |
+
row.push(mesh);
|
| 192 |
+
}
|
| 193 |
+
_winCell.push(row);
|
| 194 |
+
|
| 195 |
+
// window frame (violet-blue wireframe box spanning the 4-wide window)
|
| 196 |
+
const frameGeo = new THREE.BoxGeometry(4 * CELL_GAP, 0.5, 0.5);
|
| 197 |
+
const edges = new THREE.EdgesGeometry(frameGeo);
|
| 198 |
+
const frame = new THREE.LineSegments(
|
| 199 |
+
edges,
|
| 200 |
+
new THREE.LineBasicMaterial({ color: C_WINDOW, transparent: true, opacity: 0.0 }),
|
| 201 |
+
);
|
| 202 |
+
frame.visible = false;
|
| 203 |
+
_group.add(frame);
|
| 204 |
+
_winFrame.push(frame);
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
// Three throughput-proxy bars (dense / strict-2:4 / slidesparse effective-MAC
|
| 209 |
+
// speedup) plus a horizontal N/(N-1) ceiling marker line the slidesparse bar
|
| 210 |
+
// should reach but never exceed.
|
| 211 |
+
function _buildBars() {
|
| 212 |
+
const THREE = _THREE;
|
| 213 |
+
const barGeo = new THREE.BoxGeometry(0.5, 1, 0.5);
|
| 214 |
+
barGeo.translate(0, 0.5, 0); // base at y=0; scaling Y grows upward
|
| 215 |
+
|
| 216 |
+
function mkBar(color, emis) {
|
| 217 |
+
const m = new THREE.Mesh(
|
| 218 |
+
barGeo,
|
| 219 |
+
new THREE.MeshStandardMaterial({ color, emissive: color, emissiveIntensity: emis, transparent: true, opacity: 0.9 }),
|
| 220 |
+
);
|
| 221 |
+
m.scale.set(1, MIN_BAR_H, 1);
|
| 222 |
+
m.visible = false;
|
| 223 |
+
_group.add(m);
|
| 224 |
+
return m;
|
| 225 |
+
}
|
| 226 |
+
const baseX = -3.2, baseZ = -3.0;
|
| 227 |
+
_barDense = mkBar(C_DENSE, 0.3); _barDense.position.set(baseX, 0, baseZ);
|
| 228 |
+
_barStrict = mkBar(C_STRICT, 0.25); _barStrict.position.set(baseX + BAR_GAP, 0, baseZ);
|
| 229 |
+
_barSlide = mkBar(C_SLIDE, 0.45); _barSlide.position.set(baseX + 2 * BAR_GAP, 0, baseZ);
|
| 230 |
+
|
| 231 |
+
const pts = [
|
| 232 |
+
new THREE.Vector3(baseX - 0.5, MIN_BAR_H, baseZ),
|
| 233 |
+
new THREE.Vector3(baseX + 2 * BAR_GAP + 0.5, MIN_BAR_H, baseZ),
|
| 234 |
+
];
|
| 235 |
+
const geo = new THREE.BufferGeometry().setFromPoints(pts);
|
| 236 |
+
_ceilLine = new THREE.Line(geo, new THREE.LineBasicMaterial({ color: C_WINDOW, transparent: true, opacity: 0.6 }));
|
| 237 |
+
_group.add(_ceilLine);
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
function _buildLiftMarker() {
|
| 241 |
+
const THREE = _THREE;
|
| 242 |
+
_liftMark = new THREE.Mesh(
|
| 243 |
+
new THREE.IcosahedronGeometry(0.3, 1),
|
| 244 |
+
new THREE.MeshStandardMaterial({ color: C_WINDOW, emissive: C_WINDOW, emissiveIntensity: 0.5, wireframe: true, transparent: true, opacity: 0.85 }),
|
| 245 |
+
);
|
| 246 |
+
_liftMark.position.set(-1.2, 1.4, 2.2);
|
| 247 |
+
_group.add(_liftMark);
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
// =============================================================================
|
| 251 |
+
// live data handler
|
| 252 |
+
// =============================================================================
|
| 253 |
+
function _onSlide(j) {
|
| 254 |
+
// read honesty label VERBATIM — never upgrade. handle top-level 'label' OR
|
| 255 |
+
// nested 'payload.label' to match our own module's shape.
|
| 256 |
+
const lbl = (j && j.label != null) ? j.label
|
| 257 |
+
: (j && j.payload && j.payload.label != null) ? j.payload.label
|
| 258 |
+
: "MODELED";
|
| 259 |
+
const src = (j && j.payload && typeof j.payload === "object") ? j.payload : j;
|
| 260 |
+
|
| 261 |
+
S.label = String(lbl).toUpperCase();
|
| 262 |
+
S.N = typeof src.N === "number" ? src.N : null;
|
| 263 |
+
S.blockWidth = typeof src.block_width === "number" ? src.block_width : null;
|
| 264 |
+
S.winsPerBlock = typeof src.windows_per_block === "number" ? src.windows_per_block : null;
|
| 265 |
+
S.pattern = typeof src.sparsity_pattern === "string" ? src.sparsity_pattern : null;
|
| 266 |
+
S.pruneFrac = typeof src.prune_fraction === "number" ? src.prune_fraction : null;
|
| 267 |
+
S.rows = typeof src.matrix_rows === "number" ? src.matrix_rows : null;
|
| 268 |
+
S.cols = typeof src.matrix_cols === "number" ? src.matrix_cols : null;
|
| 269 |
+
S.blocksTotal = typeof src.blocks_total === "number" ? src.blocks_total : null;
|
| 270 |
+
S.mode = typeof src.mode === "string" ? src.mode : null;
|
| 271 |
+
S.reconErr = typeof src.reconstruction_error === "number" ? src.reconstruction_error : null;
|
| 272 |
+
S.lossless = typeof src.lossless === "boolean" ? src.lossless : null;
|
| 273 |
+
S.slideRecon = typeof src.slidesparse_recon_error === "number" ? src.slidesparse_recon_error : null;
|
| 274 |
+
S.strictRecon = typeof src.strict_2to4_recon_error === "number" ? src.strict_2to4_recon_error : null;
|
| 275 |
+
S.denseMacs = typeof src.dense_macs === "number" ? src.dense_macs : null;
|
| 276 |
+
S.strictMacs = typeof src.strict_2to4_macs === "number" ? src.strict_2to4_macs : null;
|
| 277 |
+
S.slideMacs = typeof src.slidesparse_macs === "number" ? src.slidesparse_macs : null;
|
| 278 |
+
S.spDense = typeof src.speedup_dense === "number" ? src.speedup_dense : null;
|
| 279 |
+
S.spStrict = typeof src.speedup_strict_2to4 === "number" ? src.speedup_strict_2to4 : null;
|
| 280 |
+
S.spSlide = typeof src.speedup_slidesparse === "number" ? src.speedup_slidesparse : null;
|
| 281 |
+
S.ceiling = typeof src.throughput_ceiling === "number" ? src.throughput_ceiling : null;
|
| 282 |
+
S.ceilingGap = typeof src.ceiling_gap === "number" ? src.ceiling_gap : null;
|
| 283 |
+
S.liftPerm = Array.isArray(src.activation_lifting_perm) ? src.activation_lifting_perm : null;
|
| 284 |
+
S.winMasks = Array.isArray(src.sample_window_masks) ? src.sample_window_masks : null;
|
| 285 |
+
|
| 286 |
+
_updateBlock();
|
| 287 |
+
_updateWindows();
|
| 288 |
+
_updateBars();
|
| 289 |
+
_paintOverlay();
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
// =============================================================================
|
| 293 |
+
// geometry updaters
|
| 294 |
+
// =============================================================================
|
| 295 |
+
// Which block columns are kept (nonzero)? Derive from the live window masks:
|
| 296 |
+
// every column that appears (mask=1) in some window is a kept nonzero; the rest
|
| 297 |
+
// are the pruned/dropped entries. Client never invents structure it cannot see.
|
| 298 |
+
function _keptColumns() {
|
| 299 |
+
const kept = {};
|
| 300 |
+
if (!S.winMasks) return kept;
|
| 301 |
+
for (const win of S.winMasks) {
|
| 302 |
+
if (!win || !Array.isArray(win.mask)) continue;
|
| 303 |
+
const off = typeof win.offset === "number" ? win.offset : 0;
|
| 304 |
+
for (let k = 0; k < 4; k++) {
|
| 305 |
+
if (win.mask[k]) kept[off + k] = true;
|
| 306 |
+
}
|
| 307 |
+
}
|
| 308 |
+
return kept;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
function _updateBlock() {
|
| 312 |
+
const live = S.state === "live";
|
| 313 |
+
const width = live && S.blockWidth ? Math.min(S.blockWidth, MAX_BLOCK) : 0;
|
| 314 |
+
const kept = _keptColumns();
|
| 315 |
+
for (let i = 0; i < MAX_BLOCK; i++) {
|
| 316 |
+
const mesh = _blockCell[i];
|
| 317 |
+
if (!live || i >= width) { mesh.visible = false; continue; }
|
| 318 |
+
mesh.visible = true;
|
| 319 |
+
const isKept = kept[i] === true;
|
| 320 |
+
const color = isKept ? C_DENSE : C_PRUNE; // kept -> lattice-blue; dropped -> grey
|
| 321 |
+
mesh.material.color.setHex(color);
|
| 322 |
+
mesh.material.emissive.setHex(color);
|
| 323 |
+
mesh.material.emissiveIntensity = isKept ? 0.5 : 0.12;
|
| 324 |
+
mesh.material.opacity = isKept ? 0.95 : 0.3;
|
| 325 |
+
mesh.position.y = isKept ? BLOCK_Y : BLOCK_Y - 0.3; // dropped entries sink
|
| 326 |
+
}
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
function _updateWindows() {
|
| 330 |
+
const live = S.state === "live";
|
| 331 |
+
const masks = live && S.winMasks ? S.winMasks : [];
|
| 332 |
+
for (let w = 0; w < MAX_WINDOWS; w++) {
|
| 333 |
+
const has = live && w < masks.length;
|
| 334 |
+
const row = _winCell[w];
|
| 335 |
+
const frame = _winFrame[w];
|
| 336 |
+
if (!has) {
|
| 337 |
+
for (let k = 0; k < 4; k++) row[k].visible = false;
|
| 338 |
+
frame.visible = false;
|
| 339 |
+
continue;
|
| 340 |
+
}
|
| 341 |
+
const win = masks[w];
|
| 342 |
+
const off = typeof win.offset === "number" ? win.offset : 0;
|
| 343 |
+
const yLevel = BLOCK_Y + (w + 1) * WIN_Y_GAP + 0.6;
|
| 344 |
+
for (let k = 0; k < 4; k++) {
|
| 345 |
+
const mesh = row[k];
|
| 346 |
+
mesh.visible = true;
|
| 347 |
+
const on = win.mask && win.mask[k];
|
| 348 |
+
const color = on ? C_SLIDE : C_PRUNE; // kept nonzero -> proof-teal; empty -> grey
|
| 349 |
+
mesh.material.color.setHex(color);
|
| 350 |
+
mesh.material.emissive.setHex(color);
|
| 351 |
+
mesh.material.emissiveIntensity = on ? 0.55 : 0.1;
|
| 352 |
+
mesh.material.opacity = on ? 0.95 : 0.2;
|
| 353 |
+
mesh.position.set((off + k) * CELL_GAP, yLevel, 0);
|
| 354 |
+
}
|
| 355 |
+
frame.visible = true;
|
| 356 |
+
frame.material.opacity = 0.45;
|
| 357 |
+
frame.position.set((off + 1.5) * CELL_GAP, yLevel, 0);
|
| 358 |
+
}
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
function _updateBars() {
|
| 362 |
+
const live = S.state === "live";
|
| 363 |
+
const ceiling = live && typeof S.ceiling === "number" && S.ceiling > 0 ? S.ceiling : 1.0;
|
| 364 |
+
// scale so the N/(N-1) ceiling sits at MAX_BAR_H; dense (1.0) is the reference.
|
| 365 |
+
const scaleFor = (v) => {
|
| 366 |
+
if (typeof v !== "number") return MIN_BAR_H;
|
| 367 |
+
return Math.max(MIN_BAR_H, (v / ceiling) * MAX_BAR_H);
|
| 368 |
+
};
|
| 369 |
+
|
| 370 |
+
const showBar = (bar, v, colorLive) => {
|
| 371 |
+
bar.visible = live;
|
| 372 |
+
if (!live) return;
|
| 373 |
+
bar.scale.y = scaleFor(v);
|
| 374 |
+
const c = live ? colorLive : C_DIM;
|
| 375 |
+
bar.material.color.setHex(c);
|
| 376 |
+
bar.material.emissive.setHex(c);
|
| 377 |
+
};
|
| 378 |
+
showBar(_barDense, S.spDense, C_DENSE);
|
| 379 |
+
showBar(_barStrict, S.spStrict, C_STRICT);
|
| 380 |
+
showBar(_barSlide, S.spSlide, C_SLIDE);
|
| 381 |
+
|
| 382 |
+
if (_ceilLine) {
|
| 383 |
+
// ceiling marker sits at MAX_BAR_H (the N/(N-1) line)
|
| 384 |
+
_ceilLine.position.y = live ? MAX_BAR_H : MIN_BAR_H;
|
| 385 |
+
_ceilLine.material.opacity = live ? 0.6 : 0.12;
|
| 386 |
+
_ceilLine.material.color.setHex(live ? C_WINDOW : C_DIM);
|
| 387 |
+
}
|
| 388 |
+
if (_liftMark) {
|
| 389 |
+
const c = live ? C_WINDOW : C_DIM;
|
| 390 |
+
_liftMark.material.color.setHex(c);
|
| 391 |
+
_liftMark.material.emissive.setHex(c);
|
| 392 |
+
_liftMark.material.opacity = live ? 0.85 : 0.3;
|
| 393 |
+
}
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
// =============================================================================
|
| 397 |
+
// per-frame animation
|
| 398 |
+
// =============================================================================
|
| 399 |
+
function _onFrame() {
|
| 400 |
+
const t = performance.now();
|
| 401 |
+
if (_group) _group.rotation.y = Math.sin(t * 0.00008) * 0.12;
|
| 402 |
+
if (_liftMark) {
|
| 403 |
+
_liftMark.rotation.y += 0.024;
|
| 404 |
+
_liftMark.rotation.x += 0.011;
|
| 405 |
+
const pulse = 1.0 + 0.15 * Math.sin(t * 0.004);
|
| 406 |
+
_liftMark.scale.setScalar(pulse);
|
| 407 |
+
}
|
| 408 |
+
// gentle upward shimmer on the window cells to suggest the lift/decomposition
|
| 409 |
+
for (let w = 0; w < _winCell.length; w++) {
|
| 410 |
+
const row = _winCell[w];
|
| 411 |
+
for (let k = 0; k < 4; k++) {
|
| 412 |
+
const m = row[k];
|
| 413 |
+
if (m.visible) m.material.emissiveIntensity = 0.2 + 0.2 * (0.5 + 0.5 * Math.sin(t * 0.003 + (w * 4 + k) * 0.5));
|
| 414 |
+
}
|
| 415 |
+
}
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
// =============================================================================
|
| 419 |
+
// overlay
|
| 420 |
+
// =============================================================================
|
| 421 |
+
function _buildOverlay() {
|
| 422 |
+
const ctx = _ctx;
|
| 423 |
+
_overlay = document.createElement("div");
|
| 424 |
+
Object.assign(_overlay.style, {
|
| 425 |
+
position: "absolute", left: "14px", top: "14px", zIndex: "6",
|
| 426 |
+
display: "flex", flexDirection: "column", gap: "8px",
|
| 427 |
+
maxWidth: "min(94%,470px)",
|
| 428 |
+
font: "12px ui-sans-serif,system-ui,Segoe UI,Roboto,Arial",
|
| 429 |
+
color: "#eef3f6",
|
| 430 |
+
});
|
| 431 |
+
|
| 432 |
+
const h = document.createElement("div");
|
| 433 |
+
h.style.cssText = "font:600 13px ui-sans-serif,system-ui;letter-spacing:.4px";
|
| 434 |
+
h.textContent = TITLE;
|
| 435 |
+
_overlay.appendChild(h);
|
| 436 |
+
|
| 437 |
+
const sub = document.createElement("div");
|
| 438 |
+
sub.style.cssText = "color:#9fb1bf;font-size:11px;line-height:1.55";
|
| 439 |
+
sub.innerHTML =
|
| 440 |
+
'NVIDIA Sparse Tensor Cores accelerate ONLY the rigid <b>2:4</b> pattern (50% prune) \u2014 often ' +
|
| 441 |
+
'too harsh for accuracy. Milder <b>(2N-2):2N</b> patterns (e.g. <b>6:8</b>, 25% prune) keep ' +
|
| 442 |
+
'accuracy but get no hardware support. SlideSparse is a pure <b>data-layout / packing</b> ' +
|
| 443 |
+
'transform: a <b>sliding-window decomposition</b> splits each (2N-2):2N block into <b>N-1 ' +
|
| 444 |
+
'overlapping 4-wide 2:4 windows</b> that recompose the block <b>EXACTLY</b> (lossless), so mild ' +
|
| 445 |
+
'sparsity runs on existing 2:4 cores; <b>activation lifting</b> fuses the matching activation ' +
|
| 446 |
+
'rearrangement. Honesty label <b>MODELED</b> \u2014 a toy counted-MAC proxy, NOT a GPU/tensor-core ' +
|
| 447 |
+
'run. 0 runtime CDN.';
|
| 448 |
+
_overlay.appendChild(sub);
|
| 449 |
+
|
| 450 |
+
const brow = document.createElement("div");
|
| 451 |
+
brow.style.cssText = "display:flex;gap:8px;align-items:center;flex-wrap:wrap";
|
| 452 |
+
if (_badge && _badge.el) brow.appendChild(_badge.el);
|
| 453 |
+
_overlay.appendChild(brow);
|
| 454 |
+
|
| 455 |
+
const card = document.createElement("div");
|
| 456 |
+
card.style.cssText = "background:#0a1117;border:1px solid #1d2a36;border-radius:9px;padding:9px 10px;display:flex;flex-direction:column;gap:6px";
|
| 457 |
+
|
| 458 |
+
const chead = document.createElement("div");
|
| 459 |
+
chead.style.cssText = "display:flex;align-items:center;gap:8px;flex-wrap:wrap";
|
| 460 |
+
const dot = document.createElement("span");
|
| 461 |
+
dot.style.cssText = "width:9px;height:9px;border-radius:50%;background:#3af4c8;box-shadow:0 0 7px #3af4c8";
|
| 462 |
+
const nm = document.createElement("b");
|
| 463 |
+
nm.style.cssText = "font-size:12px;color:#3af4c8;letter-spacing:.3px";
|
| 464 |
+
nm.textContent = "structured-sparse layout packing";
|
| 465 |
+
chead.appendChild(dot); chead.appendChild(nm);
|
| 466 |
+
card.appendChild(chead);
|
| 467 |
+
|
| 468 |
+
const grid = document.createElement("div");
|
| 469 |
+
grid.style.cssText = "display:grid;grid-template-columns:1fr;gap:4px";
|
| 470 |
+
|
| 471 |
+
function kpiRow(id, label) {
|
| 472 |
+
const r = document.createElement("div");
|
| 473 |
+
r.style.cssText = "display:flex;justify-content:space-between;gap:10px;font-size:11px";
|
| 474 |
+
const l = document.createElement("span"); l.style.cssText = "color:#9fb1bf"; l.textContent = label;
|
| 475 |
+
const v = document.createElement("b");
|
| 476 |
+
v.id = id;
|
| 477 |
+
v.style.cssText = "font-variant-numeric:tabular-nums;color:#eef3f6;text-align:right;max-width:56%";
|
| 478 |
+
v.textContent = "\u2014";
|
| 479 |
+
_el[id] = v;
|
| 480 |
+
r.appendChild(l); r.appendChild(v); return r;
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
grid.appendChild(kpiRow("ss-pattern", "sparsity pattern (2N-2):2N"));
|
| 484 |
+
grid.appendChild(kpiRow("ss-block", "block width (2N)"));
|
| 485 |
+
grid.appendChild(kpiRow("ss-wins", "windows / block (N-1)"));
|
| 486 |
+
grid.appendChild(kpiRow("ss-prune", "prune fraction"));
|
| 487 |
+
grid.appendChild(kpiRow("ss-blocks", "blocks packed"));
|
| 488 |
+
grid.appendChild(kpiRow("ss-slrecon", "RECON \u2014 slidesparse error (EXACT)"));
|
| 489 |
+
grid.appendChild(kpiRow("ss-strecon", "RECON \u2014 strict-2:4 error (baseline)"));
|
| 490 |
+
grid.appendChild(kpiRow("ss-lossless", "lossless reconstruction"));
|
| 491 |
+
grid.appendChild(kpiRow("ss-spstrict", "THROUGHPUT \u2014 strict-2:4 speedup"));
|
| 492 |
+
grid.appendChild(kpiRow("ss-spslide", "THROUGHPUT \u2014 slidesparse speedup"));
|
| 493 |
+
grid.appendChild(kpiRow("ss-ceiling", "ceiling N/(N-1) \u2014 MODELED proxy"));
|
| 494 |
+
grid.appendChild(kpiRow("ss-gap", "gap to ceiling"));
|
| 495 |
+
grid.appendChild(kpiRow("ss-label", "honesty label"));
|
| 496 |
+
card.appendChild(grid);
|
| 497 |
+
|
| 498 |
+
const fn = document.createElement("div");
|
| 499 |
+
fn.style.cssText = "font-size:9.5px;color:#6b7a86;line-height:1.5";
|
| 500 |
+
fn.textContent = "SlideSparse: Fast and Flexible (2N-2):2N Structured Sparsity \u2014 Shao, Hao, Song, Xia, Zhang, Huang, Wu, Xu, Xu, Dong, Chi, Zou, Wei (Furu Wei group) arXiv:2603.05232. MODELED \u00b7 not claimed-as \u00b7 counted-MAC proxy, not a GPU/tensor-core run.";
|
| 501 |
+
card.appendChild(fn);
|
| 502 |
+
_overlay.appendChild(card);
|
| 503 |
+
|
| 504 |
+
const pl = document.createElement("button");
|
| 505 |
+
pl.textContent = "\u25d1 what this means";
|
| 506 |
+
pl.title = "Toggle plain-language explanation for investors & consumers.";
|
| 507 |
+
pl.style.cssText = "font:11px ui-monospace,monospace;padding:5px 11px;border-radius:7px;border:1px solid #3af4c8;background:#08140f;color:#3af4c8;cursor:pointer;width:fit-content";
|
| 508 |
+
pl.addEventListener("click", () => {
|
| 509 |
+
_plain = !_plain;
|
| 510 |
+
pl.style.background = _plain ? "#0f2a20" : "#08140f";
|
| 511 |
+
_applyPlain();
|
| 512 |
+
});
|
| 513 |
+
_overlay.appendChild(pl);
|
| 514 |
+
|
| 515 |
+
const pd = document.createElement("div");
|
| 516 |
+
pd.id = "ss-plain";
|
| 517 |
+
pd.style.cssText = "font-size:10.5px;color:#c9d6df;line-height:1.55;border:1px dashed #26333f;border-radius:7px;padding:7px 9px;display:none";
|
| 518 |
+
_el["plain"] = pd;
|
| 519 |
+
_overlay.appendChild(pd);
|
| 520 |
+
|
| 521 |
+
(ctx.container || document.body).appendChild(_overlay);
|
| 522 |
+
_paintOverlay();
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
function _applyPlain() {
|
| 526 |
+
const pd = _el["plain"];
|
| 527 |
+
if (!pd) return;
|
| 528 |
+
pd.style.display = _plain ? "block" : "none";
|
| 529 |
+
if (!_plain) return;
|
| 530 |
+
const pat = S.pattern != null ? S.pattern : "loading\u2026";
|
| 531 |
+
const wins = S.winsPerBlock != null ? String(S.winsPerBlock) : "loading\u2026";
|
| 532 |
+
const spd = S.spSlide != null ? S.spSlide.toFixed(2) + "\u00d7" : "loading\u2026";
|
| 533 |
+
const ceil = S.ceiling != null ? S.ceiling.toFixed(2) + "\u00d7" : "loading\u2026";
|
| 534 |
+
const strErr = S.strictRecon != null ? S.strictRecon.toFixed(3) : "loading\u2026";
|
| 535 |
+
pd.innerHTML =
|
| 536 |
+
"<b>What this means:</b> Modern AI chips have a special fast path that only works if you delete " +
|
| 537 |
+
"exactly half of the numbers in a very rigid on/off pattern (\u201c2:4\u201d). Deleting half is often too " +
|
| 538 |
+
"aggressive and hurts the model, so people use gentler patterns like <b>" + pat + "</b> (deleting " +
|
| 539 |
+
"only a quarter) \u2014 but then the fast path won\u2019t take them, and the chip falls back to the slow " +
|
| 540 |
+
"route. <b>SlideSparse</b> is a clever re-packing trick: it slices each gentle-sparsity block into " +
|
| 541 |
+
"<b>" + wins + "</b> small overlapping windows that each DO obey the rigid 2:4 rule, and those windows " +
|
| 542 |
+
"add back up to the original block <b>with zero error</b> \u2014 so you keep the accuracy of gentle " +
|
| 543 |
+
"pruning AND regain the hardware fast path. Here the fast path reaches about <b>" + spd + "</b> speed " +
|
| 544 |
+
"(its theoretical ceiling is <b>" + ceil + "</b>), while forcing the rigid 2:4 pattern instead would " +
|
| 545 |
+
"corrupt the weights (reconstruction error \u2248 <b>" + strErr + "</b>). <b>Important honesty note:</b> " +
|
| 546 |
+
"this is a <b>MODELED</b> toy on a small synthetic matrix running on an ordinary CPU \u2014 there is " +
|
| 547 |
+
"<b>NO GPU, NO Sparse Tensor Core, NO CUDA, NO vLLM</b>; \u201cspeed\u201d here is a counted " +
|
| 548 |
+
"multiply-accumulate proxy, not a hardware measurement. It does NOT reproduce SlideSparse\u2019s " +
|
| 549 |
+
"reported 1.33\u00d7 speedup on Qwen2.5-7B or its real GPU results. This is a <b>new axis</b> \u2014 " +
|
| 550 |
+
"structured-sparse layout/packing \u2014 separate from the ternary bit-precision and analog in-memory " +
|
| 551 |
+
"compute organs.";
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
function _tok(s) {
|
| 555 |
+
if (s === "live") return null;
|
| 556 |
+
if (s === "missing") return "NO-LIVE-DATA";
|
| 557 |
+
if (s === "degraded") return "DEGRADED";
|
| 558 |
+
if (s === "error") return "OFFLINE";
|
| 559 |
+
return "\u2026";
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
function fx(v, d) { return typeof v === "number" ? v.toFixed(d) : "\u2014"; }
|
| 563 |
+
function _set(id, v) { if (_el[id]) _el[id].textContent = v; }
|
| 564 |
+
|
| 565 |
+
function _paintOverlay() {
|
| 566 |
+
const t = _tok(S.state);
|
| 567 |
+
_set("ss-pattern", t || (S.pattern != null ? S.pattern : "\u2014"));
|
| 568 |
+
_set("ss-block", t || (S.blockWidth != null ? String(S.blockWidth) : "\u2014"));
|
| 569 |
+
_set("ss-wins", t || (S.winsPerBlock != null ? String(S.winsPerBlock) : "\u2014"));
|
| 570 |
+
_set("ss-prune", t || (S.pruneFrac != null ? (S.pruneFrac * 100).toFixed(1) + "%" : "\u2014"));
|
| 571 |
+
_set("ss-blocks", t || (S.blocksTotal != null ? S.blocksTotal.toLocaleString() : "\u2014"));
|
| 572 |
+
_set("ss-slrecon", t || (S.slideRecon != null ? S.slideRecon.toFixed(6) : "\u2014"));
|
| 573 |
+
_set("ss-strecon", t || fx(S.strictRecon, 6));
|
| 574 |
+
_set("ss-lossless", t || (S.lossless != null ? (S.lossless ? "YES (zero error)" : "no") : "\u2014"));
|
| 575 |
+
_set("ss-spstrict", t || (S.spStrict != null ? S.spStrict.toFixed(3) + "\u00d7" : "\u2014"));
|
| 576 |
+
_set("ss-spslide", t || (S.spSlide != null ? S.spSlide.toFixed(3) + "\u00d7" : "\u2014"));
|
| 577 |
+
_set("ss-ceiling", t || (S.ceiling != null ? S.ceiling.toFixed(3) + "\u00d7" : "\u2014"));
|
| 578 |
+
_set("ss-gap", t || (S.ceilingGap != null ? S.ceilingGap.toFixed(6) : "\u2014"));
|
| 579 |
+
// honesty label verbatim — never upgraded
|
| 580 |
+
_set("ss-label", t || (S.label || "MODELED"));
|
| 581 |
+
if (_plain) _applyPlain();
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
// =============================================================================
|
| 585 |
+
// unmount — clean up everything; must not affect other organs
|
| 586 |
+
// =============================================================================
|
| 587 |
+
export function unmount() {
|
| 588 |
+
_polls.forEach((p) => { try { p.stop(); } catch (_) {} }); _polls = [];
|
| 589 |
+
try { if (_overlay && _overlay.parentNode) _overlay.parentNode.removeChild(_overlay); } catch (_) {}
|
| 590 |
+
try {
|
| 591 |
+
if (_group && _stage) {
|
| 592 |
+
_group.traverse((o) => {
|
| 593 |
+
if (o.geometry && o.geometry.dispose) o.geometry.dispose();
|
| 594 |
+
if (o.material) {
|
| 595 |
+
const ms = Array.isArray(o.material) ? o.material : [o.material];
|
| 596 |
+
ms.forEach((m) => { if (m.dispose) m.dispose(); });
|
| 597 |
+
}
|
| 598 |
+
});
|
| 599 |
+
_stage.scene.remove(_group);
|
| 600 |
+
}
|
| 601 |
+
} catch (_) {}
|
| 602 |
+
_group = _overlay = null;
|
| 603 |
+
_floor = null; _blockCell = []; _winCell = []; _winFrame = [];
|
| 604 |
+
_barDense = _barStrict = _barSlide = _ceilLine = _liftMark = null;
|
| 605 |
+
_el = {}; _badge = null; _plain = false; _frameReg = false;
|
| 606 |
+
_stage = _THREE = _ctx = null;
|
| 607 |
+
S.label = S.N = S.blockWidth = S.winsPerBlock = S.pattern = S.pruneFrac = null;
|
| 608 |
+
S.rows = S.cols = S.blocksTotal = S.mode = null;
|
| 609 |
+
S.reconErr = S.lossless = S.slideRecon = S.strictRecon = null;
|
| 610 |
+
S.denseMacs = S.strictMacs = S.slideMacs = null;
|
| 611 |
+
S.spDense = S.spStrict = S.spSlide = S.ceiling = S.ceilingGap = null;
|
| 612 |
+
S.liftPerm = S.winMasks = null;
|
| 613 |
+
S.state = "init";
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
export default { id: ID, title: TITLE, endpoints: [EP], mount, unmount };
|