Spaces:
Running
Running
feat(frontier): specdecode+flowmatch+dllm surfaces+tabs (organs on killinchu)
Browse filesSurfaces 19-21. Poll killinchu cross-origin. MODELED. Nothing in locked-8; Lambda stays Conjecture 1.
- static/3d/holographic.html +3 -0
- static/3d/surfaces/dllm.js +453 -0
- static/3d/surfaces/flowmatch.js +448 -0
- static/3d/surfaces/specdecode.js +433 -0
static/3d/holographic.html
CHANGED
|
@@ -77,6 +77,9 @@ const SURFACES = [
|
|
| 77 |
{ id: "testtime", title: "Test-Time Compute", mod: "/static/3d/surfaces/testtime.js" },
|
| 78 |
{ id: "ssm", title: "State-Space (Mamba-3)", mod: "/static/3d/surfaces/ssm.js" },
|
| 79 |
{ id: "genie", title: "Genie World-Model", mod: "/static/3d/surfaces/genie.js" },
|
|
|
|
|
|
|
|
|
|
| 80 |
{ id: "energy", title: "Energy", mod: "/static/3d/surfaces/energy.js" },
|
| 81 |
{ id: "fabric", title: "Fabric", mod: "/static/3d/surfaces/fabric.js" },
|
| 82 |
{ id: "pnt", title: "PNT", mod: "/static/3d/surfaces/pnt.js" },
|
|
|
|
| 77 |
{ id: "testtime", title: "Test-Time Compute", mod: "/static/3d/surfaces/testtime.js" },
|
| 78 |
{ id: "ssm", title: "State-Space (Mamba-3)", mod: "/static/3d/surfaces/ssm.js" },
|
| 79 |
{ id: "genie", title: "Genie World-Model", mod: "/static/3d/surfaces/genie.js" },
|
| 80 |
+
{ id: "specdecode", title: "Speculative Decoding", mod: "/static/3d/surfaces/specdecode.js" },
|
| 81 |
+
{ id: "flowmatch", title: "Flow Matching", mod: "/static/3d/surfaces/flowmatch.js" },
|
| 82 |
+
{ id: "dllm", title: "Diffusion LLM", mod: "/static/3d/surfaces/dllm.js" },
|
| 83 |
{ id: "energy", title: "Energy", mod: "/static/3d/surfaces/energy.js" },
|
| 84 |
{ id: "fabric", title: "Fabric", mod: "/static/3d/surfaces/fabric.js" },
|
| 85 |
{ id: "pnt", title: "PNT", mod: "/static/3d/surfaces/pnt.js" },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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/dllm.js — DIFFUSION-LLM PARALLEL DENOISING organ for the holographic
|
| 5 |
+
// frontier ring (Mercury/LLaDA-style masked-diffusion decoding, MODELED).
|
| 6 |
+
//
|
| 7 |
+
// Renders the token sequence as a 3D row/grid lattice driven by a live closed-
|
| 8 |
+
// form snapshot from /api/killinchu/v1/dllm/denoise:
|
| 9 |
+
// - ALL `length` positions start MASKED (grey cubes).
|
| 10 |
+
// - Across `steps` denoising rounds, a highest-confidence-first schedule
|
| 11 |
+
// unmasks a batch of NEW positions EACH round, in parallel (not left-to-
|
| 12 |
+
// right) -- they light up lattice-blue -> violet-blue as rounds advance.
|
| 13 |
+
// - A HUD shows parallelism_factor (= length/steps, tokens decided per
|
| 14 |
+
// round) and the tokens_per_round schedule, contrasted against the
|
| 15 |
+
// autoregressive baseline of 1.0 token/step.
|
| 16 |
+
// Honesty label "MODELED" is read VERBATIM from the JSON and displayed as-is;
|
| 17 |
+
// it is never upgraded.
|
| 18 |
+
//
|
| 19 |
+
// Surface export shape (mirrors testtime.js / interpretability.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 |
+
// length, steps, parallelism_factor, tokens_per_round[], cumulative_unmasked[],
|
| 25 |
+
// confidence_trajectory[], final_sequence[] (synthetic token ids)
|
| 26 |
+
//
|
| 27 |
+
// LEADERS ADOPTED & CITED (clean-room; NOT claimed as SZL's own):
|
| 28 |
+
// LLaDA (masked diffusion LLM): Nie et al. 2025, arXiv:2502.09992
|
| 29 |
+
// https://arxiv.org/abs/2502.09992 · https://github.com/ML-GSAI/LLaDA
|
| 30 |
+
// Mercury (Inception Labs, commercial-scale diffusion LLM): arXiv:2506.17298
|
| 31 |
+
// https://arxiv.org/abs/2506.17298
|
| 32 |
+
// D3PM (discrete-state denoising diffusion foundation): Austin et al. 2021,
|
| 33 |
+
// arXiv:2107.03006 https://arxiv.org/abs/2107.03006
|
| 34 |
+
//
|
| 35 |
+
// HONESTY LABELS: MODELED (clean-room deterministic simulation of the masked-
|
| 36 |
+
// diffusion parallel-decoding SCHEDULE; NOT a trained diffusion LLM; NEVER-
|
| 37 |
+
// CLAIMED-AS Mercury/LLaDA). Read verbatim from JSON; never upgraded here.
|
| 38 |
+
// COLOURS: lattice-blue 0x5b8dee (unmasked tokens), violet-blue 0x8a6bff
|
| 39 |
+
// (recently-unmasked / active-round highlight), proof-teal 0x3af4c8 (HUD
|
| 40 |
+
// accent), greys (masked / degraded). Purple BANNED as UI/background.
|
| 41 |
+
// 0 RUNTIME CDN. Vendored three.js r170 via 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 = "dllm";
|
| 46 |
+
const TITLE = "Diffusion-LLM Parallel Denoising (live)";
|
| 47 |
+
|
| 48 |
+
// Endpoint is hosted on the dedicated killinchu Space (isolated compute), reached
|
| 49 |
+
// cross-origin (killinchu returns access-control-allow-origin: https://a-11-oy.com).
|
| 50 |
+
// This keeps the dLLM organ's rebuilds/faults isolated from the flagship.
|
| 51 |
+
const EP = "https://szlholdings-killinchu.hf.space/api/killinchu/v1/dllm/denoise?seed=42&steps=8&length=64";
|
| 52 |
+
|
| 53 |
+
// data-viz hues — purple BANNED
|
| 54 |
+
const C_MASKED = 0x3a4149; // grey — still-masked token (pre-denoise)
|
| 55 |
+
const C_UNMASK = 0x5b8dee; // lattice-blue — committed/unmasked token
|
| 56 |
+
const C_RECENT = 0x8a6bff; // violet-blue — unmasked THIS round (active highlight)
|
| 57 |
+
const C_DIM = 0x42505d; // grey (degraded / no-live-data)
|
| 58 |
+
const C_ACCENT = 0x3af4c8; // proof-teal accent (HUD / round marker)
|
| 59 |
+
const C_GRID = 0x1b3a44; // floor / link colour
|
| 60 |
+
|
| 61 |
+
// grid layout geometry
|
| 62 |
+
const CELL = 0.42; // world-units per token cell
|
| 63 |
+
const GAP = 0.10; // world-units gap between cells
|
| 64 |
+
const MAX_COLS = 16; // wrap the row into a grid after this many columns
|
| 65 |
+
|
| 66 |
+
let _stage = null, _THREE = null, _ctx = null, _group = null, _overlay = null;
|
| 67 |
+
let _frameReg = false, _polls = [], _el = {}, _badge = null;
|
| 68 |
+
let _plain = false;
|
| 69 |
+
|
| 70 |
+
// geometry handles
|
| 71 |
+
let _cells = []; // Array<THREE.Mesh> — one per token position
|
| 72 |
+
let _floor = null;
|
| 73 |
+
let _roundMarker = null; // THREE.Mesh — pulsing "current round" indicator
|
| 74 |
+
|
| 75 |
+
// round-by-round playback state (client-side animation over the live schedule)
|
| 76 |
+
let _playTimer = null;
|
| 77 |
+
let _playRound = 0;
|
| 78 |
+
|
| 79 |
+
// live state
|
| 80 |
+
const S = {
|
| 81 |
+
label: null,
|
| 82 |
+
length: null,
|
| 83 |
+
steps: null,
|
| 84 |
+
parallelism: null,
|
| 85 |
+
tokensPerRound: null, // tokens_per_round[]
|
| 86 |
+
cumulative: null, // cumulative_unmasked[]
|
| 87 |
+
confidence: null, // confidence_trajectory[]
|
| 88 |
+
finalSeq: null, // final_sequence[]
|
| 89 |
+
state: "init",
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
// =============================================================================
|
| 93 |
+
// mount(ctx)
|
| 94 |
+
// =============================================================================
|
| 95 |
+
export function mount(ctx) {
|
| 96 |
+
_ctx = ctx; _stage = ctx.stage; _THREE = ctx.THREE;
|
| 97 |
+
_group = new _THREE.Group();
|
| 98 |
+
_stage.scene.add(_group);
|
| 99 |
+
_stage.camera.position.set(3, 6, 14);
|
| 100 |
+
try { if (_stage.controls && _stage.controls.target) { _stage.controls.target.set(3, 0, 0); _stage.controls.update(); } } catch (_) {}
|
| 101 |
+
try { _stage.setBloom(true); } catch (_) {}
|
| 102 |
+
|
| 103 |
+
_buildFloor();
|
| 104 |
+
_buildRoundMarker();
|
| 105 |
+
|
| 106 |
+
if (!_frameReg) { _stage.onFrame(_onFrame); _frameReg = true; }
|
| 107 |
+
|
| 108 |
+
_badge = ctx.live.createBadge();
|
| 109 |
+
_polls.push(ctx.live.poll(EP, 5000, _onDenoise, { badge: _badge, onState: (m) => { S.state = m.state; _paintOverlay(); } }));
|
| 110 |
+
|
| 111 |
+
_buildOverlay();
|
| 112 |
+
return { id: ID, started: true };
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
// =============================================================================
|
| 116 |
+
// builders
|
| 117 |
+
// =============================================================================
|
| 118 |
+
function _buildFloor() {
|
| 119 |
+
const THREE = _THREE;
|
| 120 |
+
const grid = new THREE.GridHelper(40, 40, C_GRID, 0x0f2027);
|
| 121 |
+
grid.material.opacity = 0.18; grid.material.transparent = true; grid.position.y = -0.4;
|
| 122 |
+
_group.add(grid);
|
| 123 |
+
_floor = grid;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
function _buildRoundMarker() {
|
| 127 |
+
const THREE = _THREE;
|
| 128 |
+
_roundMarker = new THREE.Mesh(
|
| 129 |
+
new THREE.IcosahedronGeometry(0.20, 1),
|
| 130 |
+
new THREE.MeshStandardMaterial({ color: C_ACCENT, emissive: C_ACCENT, emissiveIntensity: 0.5, wireframe: true, transparent: true, opacity: 0.85 }),
|
| 131 |
+
);
|
| 132 |
+
_roundMarker.position.set(0, 1.4, 0);
|
| 133 |
+
_group.add(_roundMarker);
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
// Build (or rebuild) the token lattice once `length` is known from live data.
|
| 137 |
+
function _ensureCells(length) {
|
| 138 |
+
if (_cells.length === length) return;
|
| 139 |
+
// dispose old cells first
|
| 140 |
+
_cells.forEach((m) => {
|
| 141 |
+
_group.remove(m);
|
| 142 |
+
if (m.geometry && m.geometry.dispose) m.geometry.dispose();
|
| 143 |
+
if (m.material && m.material.dispose) m.material.dispose();
|
| 144 |
+
});
|
| 145 |
+
_cells = [];
|
| 146 |
+
|
| 147 |
+
const THREE = _THREE;
|
| 148 |
+
const geo = new THREE.BoxGeometry(CELL, CELL, CELL);
|
| 149 |
+
const cols = Math.min(MAX_COLS, Math.max(1, length));
|
| 150 |
+
for (let i = 0; i < length; i++) {
|
| 151 |
+
const col = i % cols;
|
| 152 |
+
const row = Math.floor(i / cols);
|
| 153 |
+
const mat = new THREE.MeshStandardMaterial({ color: C_MASKED, emissive: C_MASKED, emissiveIntensity: 0.15, transparent: true, opacity: 0.85 });
|
| 154 |
+
const m = new THREE.Mesh(geo, mat);
|
| 155 |
+
m.position.set(col * (CELL + GAP), -row * (CELL + GAP), 0);
|
| 156 |
+
_group.add(m);
|
| 157 |
+
_cells.push(m);
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
// =============================================================================
|
| 162 |
+
// live data handler
|
| 163 |
+
// =============================================================================
|
| 164 |
+
function _onDenoise(j) {
|
| 165 |
+
// read honesty label VERBATIM — never upgrade
|
| 166 |
+
S.label = (j.label || "MODELED").toUpperCase();
|
| 167 |
+
S.length = typeof j.length === "number" ? j.length : null;
|
| 168 |
+
S.steps = typeof j.steps === "number" ? j.steps : null;
|
| 169 |
+
S.parallelism = typeof j.parallelism_factor === "number" ? j.parallelism_factor : null;
|
| 170 |
+
S.tokensPerRound = Array.isArray(j.tokens_per_round) ? j.tokens_per_round : null;
|
| 171 |
+
S.cumulative = Array.isArray(j.cumulative_unmasked) ? j.cumulative_unmasked : null;
|
| 172 |
+
S.confidence = Array.isArray(j.confidence_trajectory) ? j.confidence_trajectory : null;
|
| 173 |
+
S.finalSeq = Array.isArray(j.final_sequence) ? j.final_sequence : null;
|
| 174 |
+
|
| 175 |
+
if (S.length) _ensureCells(S.length);
|
| 176 |
+
_restartPlayback();
|
| 177 |
+
_paintOverlay();
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
// =============================================================================
|
| 181 |
+
// round-by-round playback — animates the parallel unmask schedule so the
|
| 182 |
+
// viewer can SEE positions light up in batches per round, not left-to-right.
|
| 183 |
+
// =============================================================================
|
| 184 |
+
function _restartPlayback() {
|
| 185 |
+
if (_playTimer) { clearInterval(_playTimer); _playTimer = null; }
|
| 186 |
+
_playRound = 0;
|
| 187 |
+
if (!(S.state === "live" && S.length && S.steps && S.tokensPerRound)) {
|
| 188 |
+
_paintMasked();
|
| 189 |
+
return;
|
| 190 |
+
}
|
| 191 |
+
// Deterministic-looking reveal order: fixed shuffled index list derived from
|
| 192 |
+
// the cell count (client-side only, purely for visual ordering — the
|
| 193 |
+
// authoritative parallel-unmask COUNTS per round come from the live endpoint).
|
| 194 |
+
const order = _shuffledIndices(S.length);
|
| 195 |
+
let cursor = 0;
|
| 196 |
+
_paintMasked();
|
| 197 |
+
|
| 198 |
+
_playTimer = setInterval(() => {
|
| 199 |
+
if (_playRound >= S.tokensPerRound.length) {
|
| 200 |
+
clearInterval(_playTimer); _playTimer = null;
|
| 201 |
+
return;
|
| 202 |
+
}
|
| 203 |
+
const n = S.tokensPerRound[_playRound] || 0;
|
| 204 |
+
for (let k = 0; k < n && cursor < order.length; k++, cursor++) {
|
| 205 |
+
_lightCell(order[cursor], true);
|
| 206 |
+
}
|
| 207 |
+
// dim the "recent" highlight from the previous round back to steady unmasked-blue
|
| 208 |
+
_settleColors();
|
| 209 |
+
_playRound += 1;
|
| 210 |
+
_updateRoundMarker();
|
| 211 |
+
}, 650);
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
function _shuffledIndices(n) {
|
| 215 |
+
// simple deterministic-seeded shuffle (Mulberry32-style) purely for display order
|
| 216 |
+
let seed = (n * 2654435761) >>> 0;
|
| 217 |
+
function rnd() {
|
| 218 |
+
seed = (seed + 0x6D2B79F5) >>> 0;
|
| 219 |
+
let t = seed;
|
| 220 |
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
| 221 |
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
| 222 |
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
| 223 |
+
}
|
| 224 |
+
const idx = Array.from({ length: n }, (_, i) => i);
|
| 225 |
+
for (let i = n - 1; i > 0; i--) {
|
| 226 |
+
const j = Math.floor(rnd() * (i + 1));
|
| 227 |
+
[idx[i], idx[j]] = [idx[j], idx[i]];
|
| 228 |
+
}
|
| 229 |
+
return idx;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
function _paintMasked() {
|
| 233 |
+
_cells.forEach((m) => {
|
| 234 |
+
m.material.color.setHex(C_MASKED);
|
| 235 |
+
m.material.emissive.setHex(C_MASKED);
|
| 236 |
+
m.material.emissiveIntensity = 0.15;
|
| 237 |
+
m.material.opacity = 0.85;
|
| 238 |
+
});
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
function _lightCell(i, recent) {
|
| 242 |
+
const m = _cells[i];
|
| 243 |
+
if (!m) return;
|
| 244 |
+
const c = recent ? C_RECENT : C_UNMASK;
|
| 245 |
+
m.material.color.setHex(c);
|
| 246 |
+
m.material.emissive.setHex(c);
|
| 247 |
+
m.material.emissiveIntensity = recent ? 0.7 : 0.35;
|
| 248 |
+
m.material.opacity = 1.0;
|
| 249 |
+
m._recentTick = 3; // frames-ish counter handled in _onFrame settle pass
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
function _settleColors() {
|
| 253 |
+
// cells lit "recent" (violet-blue) on the previous tick fade to steady
|
| 254 |
+
// lattice-blue on this tick, so only the CURRENT round's batch glows bright.
|
| 255 |
+
_cells.forEach((m) => {
|
| 256 |
+
if (m.material.color.getHex() === C_RECENT) {
|
| 257 |
+
m.material.color.setHex(C_UNMASK);
|
| 258 |
+
m.material.emissive.setHex(C_UNMASK);
|
| 259 |
+
m.material.emissiveIntensity = 0.35;
|
| 260 |
+
}
|
| 261 |
+
});
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
function _updateRoundMarker() {
|
| 265 |
+
if (!_roundMarker || !_cells.length) return;
|
| 266 |
+
const cols = Math.min(MAX_COLS, Math.max(1, S.length || 1));
|
| 267 |
+
const x = ((cols - 1) * (CELL + GAP)) / 2;
|
| 268 |
+
_roundMarker.position.set(x, 1.4, 0);
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
// =============================================================================
|
| 272 |
+
// per-frame animation
|
| 273 |
+
// =============================================================================
|
| 274 |
+
function _onFrame() {
|
| 275 |
+
const t = performance.now();
|
| 276 |
+
if (_group) _group.rotation.y = Math.sin(t * 0.00008) * 0.12;
|
| 277 |
+
if (_roundMarker) {
|
| 278 |
+
_roundMarker.rotation.y += 0.02;
|
| 279 |
+
_roundMarker.rotation.x += 0.01;
|
| 280 |
+
const pulse = 1.0 + 0.15 * Math.sin(t * 0.004);
|
| 281 |
+
_roundMarker.scale.setScalar(pulse);
|
| 282 |
+
}
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
// =============================================================================
|
| 286 |
+
// overlay
|
| 287 |
+
// =============================================================================
|
| 288 |
+
function _buildOverlay() {
|
| 289 |
+
const ctx = _ctx;
|
| 290 |
+
_overlay = document.createElement("div");
|
| 291 |
+
Object.assign(_overlay.style, {
|
| 292 |
+
position: "absolute", left: "14px", top: "14px", zIndex: "6",
|
| 293 |
+
display: "flex", flexDirection: "column", gap: "8px",
|
| 294 |
+
maxWidth: "min(94%,440px)",
|
| 295 |
+
font: "12px ui-sans-serif,system-ui,Segoe UI,Roboto,Arial",
|
| 296 |
+
color: "#eef3f6",
|
| 297 |
+
});
|
| 298 |
+
|
| 299 |
+
const h = document.createElement("div");
|
| 300 |
+
h.style.cssText = "font:600 13px ui-sans-serif,system-ui;letter-spacing:.4px";
|
| 301 |
+
h.textContent = TITLE;
|
| 302 |
+
_overlay.appendChild(h);
|
| 303 |
+
|
| 304 |
+
const sub = document.createElement("div");
|
| 305 |
+
sub.style.cssText = "color:#9fb1bf;font-size:11px;line-height:1.55";
|
| 306 |
+
sub.innerHTML =
|
| 307 |
+
'Diffusion LLMs (<b>Mercury</b>/<b>LLaDA</b>-style) start from a <b>fully-masked</b> sequence ' +
|
| 308 |
+
'and unmask ALL positions in <b>parallel</b> across denoising rounds \u2014 not left-to-right like ' +
|
| 309 |
+
'autoregressive decoding. Honesty label <b>MODELED</b> (clean-room simulation of the decoding ' +
|
| 310 |
+
'SCHEDULE; NOT a trained diffusion LLM). 0 runtime CDN.';
|
| 311 |
+
_overlay.appendChild(sub);
|
| 312 |
+
|
| 313 |
+
const brow = document.createElement("div");
|
| 314 |
+
brow.style.cssText = "display:flex;gap:8px;align-items:center;flex-wrap:wrap";
|
| 315 |
+
if (_badge && _badge.el) brow.appendChild(_badge.el);
|
| 316 |
+
_overlay.appendChild(brow);
|
| 317 |
+
|
| 318 |
+
const card = document.createElement("div");
|
| 319 |
+
card.style.cssText = "background:#0a1117;border:1px solid #1d2a36;border-radius:9px;padding:9px 10px;display:flex;flex-direction:column;gap:6px";
|
| 320 |
+
|
| 321 |
+
const chead = document.createElement("div");
|
| 322 |
+
chead.style.cssText = "display:flex;align-items:center;gap:8px;flex-wrap:wrap";
|
| 323 |
+
const dot = document.createElement("span");
|
| 324 |
+
dot.style.cssText = "width:9px;height:9px;border-radius:50%;background:#5b8dee;box-shadow:0 0 7px #5b8dee";
|
| 325 |
+
const nm = document.createElement("b");
|
| 326 |
+
nm.style.cssText = "font-size:12px;color:#5b8dee;letter-spacing:.3px";
|
| 327 |
+
nm.textContent = "dllm-parallel-denoise";
|
| 328 |
+
chead.appendChild(dot); chead.appendChild(nm);
|
| 329 |
+
card.appendChild(chead);
|
| 330 |
+
|
| 331 |
+
const grid = document.createElement("div");
|
| 332 |
+
grid.style.cssText = "display:grid;grid-template-columns:1fr;gap:4px";
|
| 333 |
+
|
| 334 |
+
function kpiRow(id, label) {
|
| 335 |
+
const r = document.createElement("div");
|
| 336 |
+
r.style.cssText = "display:flex;justify-content:space-between;gap:10px;font-size:11px";
|
| 337 |
+
const l = document.createElement("span"); l.style.cssText = "color:#9fb1bf"; l.textContent = label;
|
| 338 |
+
const v = document.createElement("b");
|
| 339 |
+
v.id = id;
|
| 340 |
+
v.style.cssText = "font-variant-numeric:tabular-nums;color:#eef3f6;text-align:right;max-width:58%";
|
| 341 |
+
v.textContent = "\u2014";
|
| 342 |
+
_el[id] = v;
|
| 343 |
+
r.appendChild(l); r.appendChild(v); return r;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
grid.appendChild(kpiRow("dl-length", "sequence length"));
|
| 347 |
+
grid.appendChild(kpiRow("dl-steps", "denoising rounds (steps)"));
|
| 348 |
+
grid.appendChild(kpiRow("dl-parallel", "parallelism factor \u2014 MODELED"));
|
| 349 |
+
grid.appendChild(kpiRow("dl-ar", "vs autoregressive (1.0 tok/step)"));
|
| 350 |
+
grid.appendChild(kpiRow("dl-tpr", "tokens/round schedule"));
|
| 351 |
+
grid.appendChild(kpiRow("dl-conf", "confidence trajectory (last)"));
|
| 352 |
+
grid.appendChild(kpiRow("dl-label", "honesty label"));
|
| 353 |
+
card.appendChild(grid);
|
| 354 |
+
|
| 355 |
+
const fn = document.createElement("div");
|
| 356 |
+
fn.style.cssText = "font-size:9.5px;color:#6b7a86;line-height:1.5";
|
| 357 |
+
fn.textContent = "LLaDA \u2014 Nie et al. arXiv:2502.09992 (github.com/ML-GSAI/LLaDA) \u00b7 Mercury (Inception Labs) arXiv:2506.17298 \u00b7 D3PM \u2014 Austin et al. arXiv:2107.03006. MODELED \u00b7 not claimed-as.";
|
| 358 |
+
card.appendChild(fn);
|
| 359 |
+
_overlay.appendChild(card);
|
| 360 |
+
|
| 361 |
+
const pl = document.createElement("button");
|
| 362 |
+
pl.textContent = "\u25d1 what this means";
|
| 363 |
+
pl.title = "Toggle plain-language explanation for investors & consumers.";
|
| 364 |
+
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";
|
| 365 |
+
pl.addEventListener("click", () => {
|
| 366 |
+
_plain = !_plain;
|
| 367 |
+
pl.style.background = _plain ? "#0f2a20" : "#08140f";
|
| 368 |
+
_applyPlain();
|
| 369 |
+
});
|
| 370 |
+
_overlay.appendChild(pl);
|
| 371 |
+
|
| 372 |
+
const pd = document.createElement("div");
|
| 373 |
+
pd.id = "dl-plain";
|
| 374 |
+
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";
|
| 375 |
+
_el["plain"] = pd;
|
| 376 |
+
_overlay.appendChild(pd);
|
| 377 |
+
|
| 378 |
+
(ctx.container || document.body).appendChild(_overlay);
|
| 379 |
+
_paintOverlay();
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
function _applyPlain() {
|
| 383 |
+
const pd = _el["plain"];
|
| 384 |
+
if (!pd) return;
|
| 385 |
+
pd.style.display = _plain ? "block" : "none";
|
| 386 |
+
if (!_plain) return;
|
| 387 |
+
const len = S.length != null ? String(S.length) : "loading\u2026";
|
| 388 |
+
const steps = S.steps != null ? String(S.steps) : "loading\u2026";
|
| 389 |
+
const par = S.parallelism != null ? S.parallelism.toFixed(2) : "loading\u2026";
|
| 390 |
+
pd.innerHTML =
|
| 391 |
+
"<b>What this means:</b> A normal (autoregressive) AI writes one word at a time, so a " +
|
| 392 |
+
len + "-token answer takes " + len + " sequential steps. A <b>diffusion LLM</b> instead starts " +
|
| 393 |
+
"with a completely blank/masked answer and fills in <b>many words at once</b>, refining the " +
|
| 394 |
+
"whole thing over just " + steps + " rounds. That is a <b>" + par + "x parallelism factor</b> \u2014 " +
|
| 395 |
+
"roughly " + par + " tokens decided per round versus 1 token per step for old-style decoding. " +
|
| 396 |
+
"This view is a <b>MODELED</b> clean-room simulation of that decoding SCHEDULE, not a real " +
|
| 397 |
+
"trained diffusion model \u2014 and it is NEVER claimed to be Mercury or LLaDA themselves.";
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
function _tok(s) {
|
| 401 |
+
if (s === "live") return null;
|
| 402 |
+
if (s === "missing") return "NO-LIVE-DATA";
|
| 403 |
+
if (s === "degraded") return "DEGRADED";
|
| 404 |
+
if (s === "error") return "OFFLINE";
|
| 405 |
+
return "\u2026";
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
function fx(v, d) { return typeof v === "number" ? v.toFixed(d) : "\u2014"; }
|
| 409 |
+
function _set(id, v) { if (_el[id]) _el[id].textContent = v; }
|
| 410 |
+
|
| 411 |
+
function _paintOverlay() {
|
| 412 |
+
const t = _tok(S.state);
|
| 413 |
+
_set("dl-length", t || (S.length != null ? String(S.length) : "\u2014"));
|
| 414 |
+
_set("dl-steps", t || (S.steps != null ? String(S.steps) : "\u2014"));
|
| 415 |
+
_set("dl-parallel", t || (S.parallelism != null ? fx(S.parallelism, 3) + "x" : "\u2014"));
|
| 416 |
+
_set("dl-ar", t || (S.parallelism != null ? fx(S.parallelism, 2) + "x faster (tokens/round vs 1.0 tok/step)" : "\u2014"));
|
| 417 |
+
_set("dl-tpr", t || (S.tokensPerRound ? S.tokensPerRound.join(",") : "\u2014"));
|
| 418 |
+
_set("dl-conf", t || (S.confidence && S.confidence.length ? fx(S.confidence[S.confidence.length - 1], 3) : "\u2014"));
|
| 419 |
+
// honesty label verbatim — never upgraded
|
| 420 |
+
_set("dl-label", t || (S.label || "MODELED"));
|
| 421 |
+
if (_plain) _applyPlain();
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
// =============================================================================
|
| 425 |
+
// unmount — clean up everything; must not affect other organs
|
| 426 |
+
// =============================================================================
|
| 427 |
+
export function unmount() {
|
| 428 |
+
_polls.forEach((p) => { try { p.stop(); } catch (_) {} }); _polls = [];
|
| 429 |
+
if (_playTimer) { try { clearInterval(_playTimer); } catch (_) {} _playTimer = null; }
|
| 430 |
+
try { if (_overlay && _overlay.parentNode) _overlay.parentNode.removeChild(_overlay); } catch (_) {}
|
| 431 |
+
try {
|
| 432 |
+
if (_group && _stage) {
|
| 433 |
+
_group.traverse((o) => {
|
| 434 |
+
if (o.geometry && o.geometry.dispose) o.geometry.dispose();
|
| 435 |
+
if (o.material) {
|
| 436 |
+
const ms = Array.isArray(o.material) ? o.material : [o.material];
|
| 437 |
+
ms.forEach((m) => { if (m.dispose) m.dispose(); });
|
| 438 |
+
}
|
| 439 |
+
});
|
| 440 |
+
_stage.scene.remove(_group);
|
| 441 |
+
}
|
| 442 |
+
} catch (_) {}
|
| 443 |
+
_group = _overlay = null;
|
| 444 |
+
_cells = []; _floor = null; _roundMarker = null;
|
| 445 |
+
_el = {}; _badge = null; _plain = false; _frameReg = false;
|
| 446 |
+
_playRound = 0;
|
| 447 |
+
_stage = _THREE = _ctx = null;
|
| 448 |
+
S.label = S.length = S.steps = S.parallelism = null;
|
| 449 |
+
S.tokensPerRound = S.cumulative = S.confidence = S.finalSeq = null;
|
| 450 |
+
S.state = "init";
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
export default { id: ID, title: TITLE, endpoints: [EP], mount, unmount };
|
static/3d/surfaces/flowmatch.js
ADDED
|
@@ -0,0 +1,448 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 · Doctrine v11
|
| 3 |
+
//
|
| 4 |
+
// surfaces/flowmatch.js — RECTIFIED-FLOW / FLOW-MATCHING ODE-SAMPLER organ for the
|
| 5 |
+
// holographic frontier ring. Renders the ODE trajectory of a rectified-flow sampler:
|
| 6 |
+
// dx/dt = v(x,t) = x1 - x0 (a constant straight-line velocity field), integrated with
|
| 7 |
+
// explicit-Euler steps from a noise point x0 ~ N(0,I) to a target point x1.
|
| 8 |
+
//
|
| 9 |
+
// Renders a 3D flow path driven by a live closed-form snapshot from
|
| 10 |
+
// /api/killinchu/v1/flowmatch/sample:
|
| 11 |
+
// 1. A noise-cloud marker at x0 (start of the flow).
|
| 12 |
+
// 2. The Euler-integrated trajectory as a growing line from x0 toward x1 — for the
|
| 13 |
+
// rectified (straight-line) case this path IS a straight line.
|
| 14 |
+
// 3. A target marker at x1 (end of the flow).
|
| 15 |
+
// A HUD shows final_error DROPPING as steps increase (few-step vs many-step comparison)
|
| 16 |
+
// plus straightness_score and steps_to_converge — the rectified-flow win: few steps
|
| 17 |
+
// already converge. Honesty label "MODELED" is read VERBATIM from the JSON and
|
| 18 |
+
// displayed as-is; it is never upgraded.
|
| 19 |
+
//
|
| 20 |
+
// Surface export shape (mirrors testtime.js / interpretability.js exactly):
|
| 21 |
+
// export default { id, title, endpoints, mount(ctx), unmount() }
|
| 22 |
+
// ctx = { stage, container, live, label, THREE, szl3d }
|
| 23 |
+
//
|
| 24 |
+
// DATA SHOWN (all from live endpoint):
|
| 25 |
+
// dims, steps, x0, x1, trajectory[], final_error, straightness_score,
|
| 26 |
+
// steps_to_converge, few_vs_many{few_steps,few_step_error,many_steps,many_step_error}
|
| 27 |
+
//
|
| 28 |
+
// LEADERS ADOPTED & CITED (clean-room; NOT claimed as SZL's own):
|
| 29 |
+
// Flow Matching for Generative Modeling: Lipman et al. 2022, arXiv:2210.02747
|
| 30 |
+
// https://arxiv.org/abs/2210.02747
|
| 31 |
+
// Rectified Flow ("Flow Straight and Fast"): Liu et al. 2022, arXiv:2209.03003
|
| 32 |
+
// https://arxiv.org/abs/2209.03003
|
| 33 |
+
// FLUX (production rectified-flow model, Black Forest Labs — cited only, NEVER
|
| 34 |
+
// claimed as SZL's own): https://github.com/black-forest-labs/flux
|
| 35 |
+
//
|
| 36 |
+
// HONESTY LABELS: MODELED (deterministic analytic rectified-flow ODE integration on a
|
| 37 |
+
// toy noise->target case; NOT a trained flow/diffusion model; NEVER-CLAIMED-AS FLUX
|
| 38 |
+
// or Stable Diffusion 3). Read verbatim from JSON; never upgraded here.
|
| 39 |
+
// COLOURS: lattice-blue 0x5b8dee (trajectory path), violet-blue 0x8a6bff (noise/target
|
| 40 |
+
// markers — data-viz only), proof-teal 0x3af4c8 (HUD accent / convergence marker).
|
| 41 |
+
// Purple BANNED as UI/background.
|
| 42 |
+
// 0 RUNTIME CDN. Vendored three.js r170 via page importmap.
|
| 43 |
+
// DOCTRINE v11: degrades gracefully (grey) on 404/error; honesty label still shown.
|
| 44 |
+
// Nothing here is in the locked-8. Λ stays Conjecture 1. Trust never 100%.
|
| 45 |
+
|
| 46 |
+
const ID = "flowmatch";
|
| 47 |
+
const TITLE = "Rectified Flow · Flow-Matching ODE Sampler (live)";
|
| 48 |
+
|
| 49 |
+
// Endpoint is hosted on the dedicated killinchu Space (isolated compute), reached
|
| 50 |
+
// cross-origin (killinchu returns access-control-allow-origin: https://a-11-oy.com).
|
| 51 |
+
// This keeps the flow-matching organ's rebuilds/faults isolated from the flagship.
|
| 52 |
+
const EP = "https://szlholdings-killinchu.hf.space/api/killinchu/v1/flowmatch/sample?seed=42&steps=8&dims=3";
|
| 53 |
+
|
| 54 |
+
// data-viz hues — purple BANNED
|
| 55 |
+
const C_PATH = 0x5b8dee; // lattice-blue (ODE trajectory path)
|
| 56 |
+
const C_MARKERS = 0x8a6bff; // violet-blue (x0 noise / x1 target markers — data-viz only)
|
| 57 |
+
const C_DIM = 0x42505d; // grey (degraded / no-live-data)
|
| 58 |
+
const C_ACCENT = 0x3af4c8; // proof-teal accent (HUD / convergence marker)
|
| 59 |
+
const C_GRID = 0x1b3a44; // floor / link colour
|
| 60 |
+
|
| 61 |
+
// path layout geometry
|
| 62 |
+
const PATH_SCALE = 1.6; // world-units per unit of raw x/y/z coordinate
|
| 63 |
+
|
| 64 |
+
let _stage = null, _THREE = null, _ctx = null, _group = null, _overlay = null;
|
| 65 |
+
let _frameReg = false, _polls = [], _el = {}, _badge = null;
|
| 66 |
+
let _plain = false;
|
| 67 |
+
|
| 68 |
+
// geometry handles
|
| 69 |
+
let _pathLine = null; // THREE.Line — Euler-integrated trajectory
|
| 70 |
+
let _pathDots = []; // Array<THREE.Mesh> — markers along the trajectory
|
| 71 |
+
let _x0Marker = null; // THREE.Mesh — noise-cloud start marker
|
| 72 |
+
let _x1Marker = null; // THREE.Mesh — target end marker
|
| 73 |
+
let _converge = null; // THREE.Mesh — pulsing "converged" HUD marker
|
| 74 |
+
let _floor = null;
|
| 75 |
+
|
| 76 |
+
// live state
|
| 77 |
+
const S = {
|
| 78 |
+
label: null,
|
| 79 |
+
dims: null,
|
| 80 |
+
steps: null,
|
| 81 |
+
x0: null,
|
| 82 |
+
x1: null,
|
| 83 |
+
trajectory: null, // [{t, x}, ...]
|
| 84 |
+
finalError: null,
|
| 85 |
+
straightness: null,
|
| 86 |
+
stepsToConverge: null,
|
| 87 |
+
fewSteps: null,
|
| 88 |
+
fewError: null,
|
| 89 |
+
manySteps: null,
|
| 90 |
+
manyError: null,
|
| 91 |
+
state: "init",
|
| 92 |
+
};
|
| 93 |
+
|
| 94 |
+
// =============================================================================
|
| 95 |
+
// mount(ctx)
|
| 96 |
+
// =============================================================================
|
| 97 |
+
export function mount(ctx) {
|
| 98 |
+
_ctx = ctx; _stage = ctx.stage; _THREE = ctx.THREE;
|
| 99 |
+
_group = new _THREE.Group();
|
| 100 |
+
_stage.scene.add(_group);
|
| 101 |
+
_stage.camera.position.set(2, 6, 16);
|
| 102 |
+
try { if (_stage.controls && _stage.controls.target) { _stage.controls.target.set(2, 2, 0); _stage.controls.update(); } } catch (_) {}
|
| 103 |
+
try { _stage.setBloom(true); } catch (_) {}
|
| 104 |
+
|
| 105 |
+
_buildFloor();
|
| 106 |
+
_buildPath();
|
| 107 |
+
_buildMarkers();
|
| 108 |
+
|
| 109 |
+
if (!_frameReg) { _stage.onFrame(_onFrame); _frameReg = true; }
|
| 110 |
+
|
| 111 |
+
_badge = ctx.live.createBadge();
|
| 112 |
+
_polls.push(ctx.live.poll(EP, 5000, _onSample, { badge: _badge, onState: (m) => { S.state = m.state; _paintOverlay(); } }));
|
| 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(40, 40, C_GRID, 0x0f2027);
|
| 124 |
+
grid.material.opacity = 0.18; grid.material.transparent = true; grid.position.y = -0.01;
|
| 125 |
+
_group.add(grid);
|
| 126 |
+
_floor = grid;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
// Pre-allocate the trajectory line geometry with a fixed max point-count; update
|
| 130 |
+
// point positions in-place as live data arrives (no per-poll geometry churn).
|
| 131 |
+
const _MAX_PTS = 130; // covers up to 128-step many-step trajectories
|
| 132 |
+
|
| 133 |
+
function _buildPath() {
|
| 134 |
+
const THREE = _THREE;
|
| 135 |
+
const pts = new Array(_MAX_PTS).fill(0).map(() => new THREE.Vector3(0, 0, 0));
|
| 136 |
+
const geo = new THREE.BufferGeometry().setFromPoints(pts);
|
| 137 |
+
const mat = new THREE.LineBasicMaterial({ color: C_PATH, transparent: true, opacity: 0.85, linewidth: 2 });
|
| 138 |
+
_pathLine = new THREE.Line(geo, mat);
|
| 139 |
+
_group.add(_pathLine);
|
| 140 |
+
|
| 141 |
+
const dotGeo = new THREE.SphereGeometry(0.07, 10, 8);
|
| 142 |
+
for (let i = 0; i < _MAX_PTS; i++) {
|
| 143 |
+
const m = new THREE.Mesh(dotGeo, new THREE.MeshStandardMaterial({ color: C_PATH, emissive: C_PATH, emissiveIntensity: 0.3 }));
|
| 144 |
+
m.visible = false;
|
| 145 |
+
_group.add(m);
|
| 146 |
+
_pathDots.push(m);
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
function _buildMarkers() {
|
| 151 |
+
const THREE = _THREE;
|
| 152 |
+
// noise-cloud start marker (x0) — wireframe icosahedron, violet-blue
|
| 153 |
+
_x0Marker = new THREE.Mesh(
|
| 154 |
+
new THREE.IcosahedronGeometry(0.28, 1),
|
| 155 |
+
new THREE.MeshStandardMaterial({ color: C_MARKERS, emissive: C_MARKERS, emissiveIntensity: 0.4, wireframe: true, transparent: true, opacity: 0.85 }),
|
| 156 |
+
);
|
| 157 |
+
_group.add(_x0Marker);
|
| 158 |
+
|
| 159 |
+
// target end marker (x1) — solid octahedron, violet-blue
|
| 160 |
+
_x1Marker = new THREE.Mesh(
|
| 161 |
+
new THREE.OctahedronGeometry(0.30, 0),
|
| 162 |
+
new THREE.MeshStandardMaterial({ color: C_MARKERS, emissive: C_MARKERS, emissiveIntensity: 0.5, transparent: true, opacity: 0.9 }),
|
| 163 |
+
);
|
| 164 |
+
_group.add(_x1Marker);
|
| 165 |
+
|
| 166 |
+
// convergence pulse marker — proof-teal, sits at the ODE's final point
|
| 167 |
+
_converge = new THREE.Mesh(
|
| 168 |
+
new THREE.IcosahedronGeometry(0.16, 1),
|
| 169 |
+
new THREE.MeshStandardMaterial({ color: C_ACCENT, emissive: C_ACCENT, emissiveIntensity: 0.6, wireframe: true, transparent: true, opacity: 0.9 }),
|
| 170 |
+
);
|
| 171 |
+
_group.add(_converge);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
// =============================================================================
|
| 175 |
+
// live data handler
|
| 176 |
+
// =============================================================================
|
| 177 |
+
function _onSample(j) {
|
| 178 |
+
// read honesty label VERBATIM — never upgrade
|
| 179 |
+
S.label = (j.label || "MODELED").toUpperCase();
|
| 180 |
+
S.dims = typeof j.dims === "number" ? j.dims : null;
|
| 181 |
+
S.steps = typeof j.steps === "number" ? j.steps : null;
|
| 182 |
+
S.x0 = Array.isArray(j.x0) ? j.x0 : null;
|
| 183 |
+
S.x1 = Array.isArray(j.x1) ? j.x1 : null;
|
| 184 |
+
S.trajectory = Array.isArray(j.trajectory) ? j.trajectory : null;
|
| 185 |
+
S.finalError = typeof j.final_error === "number" ? j.final_error : null;
|
| 186 |
+
S.straightness = typeof j.straightness_score === "number" ? j.straightness_score : null;
|
| 187 |
+
S.stepsToConverge = typeof j.steps_to_converge === "number" ? j.steps_to_converge : null;
|
| 188 |
+
|
| 189 |
+
const fvm = j.few_vs_many || {};
|
| 190 |
+
S.fewSteps = typeof fvm.few_steps === "number" ? fvm.few_steps : null;
|
| 191 |
+
S.fewError = typeof fvm.few_step_error === "number" ? fvm.few_step_error : null;
|
| 192 |
+
S.manySteps = typeof fvm.many_steps === "number" ? fvm.many_steps : null;
|
| 193 |
+
S.manyError = typeof fvm.many_step_error === "number" ? fvm.many_step_error : null;
|
| 194 |
+
|
| 195 |
+
_updatePath();
|
| 196 |
+
_paintOverlay();
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
// =============================================================================
|
| 200 |
+
// geometry updater — drives the trajectory path + markers from live data
|
| 201 |
+
// =============================================================================
|
| 202 |
+
function _proj(vec) {
|
| 203 |
+
// Project a small dims-length vector (2..8 dims) down to 3D world coords by
|
| 204 |
+
// taking the first 3 components (pad with 0 if fewer). Pure display mapping —
|
| 205 |
+
// does not alter any reported numeric values.
|
| 206 |
+
const x = (vec[0] || 0) * PATH_SCALE;
|
| 207 |
+
const y = (vec[1] || 0) * PATH_SCALE;
|
| 208 |
+
const z = (vec[2] || 0) * PATH_SCALE;
|
| 209 |
+
return [x, y, z];
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
function _updatePath() {
|
| 213 |
+
const live = S.state === "live";
|
| 214 |
+
|
| 215 |
+
if (live && S.trajectory && S.trajectory.length) {
|
| 216 |
+
const pos = _pathLine.geometry.attributes.position;
|
| 217 |
+
const n = Math.min(_MAX_PTS, S.trajectory.length);
|
| 218 |
+
for (let i = 0; i < _MAX_PTS; i++) {
|
| 219 |
+
const row = S.trajectory[Math.min(i, n - 1)];
|
| 220 |
+
const [x, y, z] = _proj(row.x || []);
|
| 221 |
+
pos.setXYZ(i, x, y, z);
|
| 222 |
+
if (i < n) {
|
| 223 |
+
_pathDots[i].position.set(x, y, z);
|
| 224 |
+
_pathDots[i].visible = true;
|
| 225 |
+
} else {
|
| 226 |
+
_pathDots[i].visible = false;
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
+
pos.needsUpdate = true;
|
| 230 |
+
_pathLine.geometry.computeBoundingSphere();
|
| 231 |
+
_pathLine.material.color.setHex(C_PATH);
|
| 232 |
+
_pathLine.material.opacity = 0.85;
|
| 233 |
+
|
| 234 |
+
// x0 / x1 markers
|
| 235 |
+
if (S.x0) { const [x, y, z] = _proj(S.x0); _x0Marker.position.set(x, y, z); }
|
| 236 |
+
if (S.x1) { const [x, y, z] = _proj(S.x1); _x1Marker.position.set(x, y, z); }
|
| 237 |
+
_x0Marker.material.color.setHex(C_MARKERS); _x0Marker.material.emissive.setHex(C_MARKERS); _x0Marker.material.opacity = 0.85;
|
| 238 |
+
_x1Marker.material.color.setHex(C_MARKERS); _x1Marker.material.emissive.setHex(C_MARKERS); _x1Marker.material.opacity = 0.9;
|
| 239 |
+
|
| 240 |
+
// convergence marker sits at the ODE's final integrated point
|
| 241 |
+
const lastRow = S.trajectory[S.trajectory.length - 1];
|
| 242 |
+
if (lastRow && lastRow.x) {
|
| 243 |
+
const [x, y, z] = _proj(lastRow.x);
|
| 244 |
+
_converge.position.set(x, y, z);
|
| 245 |
+
}
|
| 246 |
+
_converge.material.color.setHex(C_ACCENT);
|
| 247 |
+
_converge.material.emissive.setHex(C_ACCENT);
|
| 248 |
+
_converge.material.opacity = 0.9;
|
| 249 |
+
} else {
|
| 250 |
+
_pathDots.forEach((d) => { d.visible = false; });
|
| 251 |
+
_pathLine.material.color.setHex(C_DIM);
|
| 252 |
+
_pathLine.material.opacity = 0.25;
|
| 253 |
+
_x0Marker.material.color.setHex(C_DIM); _x0Marker.material.emissive.setHex(C_DIM); _x0Marker.material.opacity = 0.3;
|
| 254 |
+
_x1Marker.material.color.setHex(C_DIM); _x1Marker.material.emissive.setHex(C_DIM); _x1Marker.material.opacity = 0.3;
|
| 255 |
+
_converge.material.color.setHex(C_DIM); _converge.material.emissive.setHex(C_DIM); _converge.material.opacity = 0.3;
|
| 256 |
+
}
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
// =============================================================================
|
| 260 |
+
// per-frame animation
|
| 261 |
+
// =============================================================================
|
| 262 |
+
function _onFrame() {
|
| 263 |
+
const t = performance.now();
|
| 264 |
+
if (_group) _group.rotation.y = Math.sin(t * 0.00010) * 0.15;
|
| 265 |
+
if (_converge) {
|
| 266 |
+
_converge.rotation.y += 0.02;
|
| 267 |
+
_converge.rotation.x += 0.01;
|
| 268 |
+
const pulse = 1.0 + 0.15 * Math.sin(t * 0.004);
|
| 269 |
+
_converge.scale.setScalar(pulse);
|
| 270 |
+
}
|
| 271 |
+
if (_x1Marker) { _x1Marker.rotation.y += 0.01; }
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
// =============================================================================
|
| 275 |
+
// overlay
|
| 276 |
+
// =============================================================================
|
| 277 |
+
function _buildOverlay() {
|
| 278 |
+
const ctx = _ctx;
|
| 279 |
+
_overlay = document.createElement("div");
|
| 280 |
+
Object.assign(_overlay.style, {
|
| 281 |
+
position: "absolute", left: "14px", top: "14px", zIndex: "6",
|
| 282 |
+
display: "flex", flexDirection: "column", gap: "8px",
|
| 283 |
+
maxWidth: "min(94%,440px)",
|
| 284 |
+
font: "12px ui-sans-serif,system-ui,Segoe UI,Roboto,Arial",
|
| 285 |
+
color: "#eef3f6",
|
| 286 |
+
});
|
| 287 |
+
|
| 288 |
+
const h = document.createElement("div");
|
| 289 |
+
h.style.cssText = "font:600 13px ui-sans-serif,system-ui;letter-spacing:.4px";
|
| 290 |
+
h.textContent = TITLE;
|
| 291 |
+
_overlay.appendChild(h);
|
| 292 |
+
|
| 293 |
+
const sub = document.createElement("div");
|
| 294 |
+
sub.style.cssText = "color:#9fb1bf;font-size:11px;line-height:1.55";
|
| 295 |
+
sub.innerHTML =
|
| 296 |
+
'A <b>rectified-flow ODE sampler</b>: integrate dx/dt = v(x,t) = x1 \u2212 x0 (a ' +
|
| 297 |
+
'<b>straight-line velocity field</b>) from noise x0 to a target x1 with Euler steps. ' +
|
| 298 |
+
'Honesty label <b>MODELED</b> (analytic toy case; NOT a trained flow/diffusion model; ' +
|
| 299 |
+
'never claimed as FLUX or SD3). 0 runtime CDN.';
|
| 300 |
+
_overlay.appendChild(sub);
|
| 301 |
+
|
| 302 |
+
const brow = document.createElement("div");
|
| 303 |
+
brow.style.cssText = "display:flex;gap:8px;align-items:center;flex-wrap:wrap";
|
| 304 |
+
if (_badge && _badge.el) brow.appendChild(_badge.el);
|
| 305 |
+
_overlay.appendChild(brow);
|
| 306 |
+
|
| 307 |
+
const card = document.createElement("div");
|
| 308 |
+
card.style.cssText = "background:#0a1117;border:1px solid #1d2a36;border-radius:9px;padding:9px 10px;display:flex;flex-direction:column;gap:6px";
|
| 309 |
+
|
| 310 |
+
const chead = document.createElement("div");
|
| 311 |
+
chead.style.cssText = "display:flex;align-items:center;gap:8px;flex-wrap:wrap";
|
| 312 |
+
const dot = document.createElement("span");
|
| 313 |
+
dot.style.cssText = "width:9px;height:9px;border-radius:50%;background:#5b8dee;box-shadow:0 0 7px #5b8dee";
|
| 314 |
+
const nm = document.createElement("b");
|
| 315 |
+
nm.style.cssText = "font-size:12px;color:#5b8dee;letter-spacing:.3px";
|
| 316 |
+
nm.textContent = "flow-matching";
|
| 317 |
+
chead.appendChild(dot); chead.appendChild(nm);
|
| 318 |
+
card.appendChild(chead);
|
| 319 |
+
|
| 320 |
+
const grid = document.createElement("div");
|
| 321 |
+
grid.style.cssText = "display:grid;grid-template-columns:1fr;gap:4px";
|
| 322 |
+
|
| 323 |
+
function kpiRow(id, label) {
|
| 324 |
+
const r = document.createElement("div");
|
| 325 |
+
r.style.cssText = "display:flex;justify-content:space-between;gap:10px;font-size:11px";
|
| 326 |
+
const l = document.createElement("span"); l.style.cssText = "color:#9fb1bf"; l.textContent = label;
|
| 327 |
+
const v = document.createElement("b");
|
| 328 |
+
v.id = id;
|
| 329 |
+
v.style.cssText = "font-variant-numeric:tabular-nums;color:#eef3f6;text-align:right;max-width:58%";
|
| 330 |
+
v.textContent = "\u2014";
|
| 331 |
+
_el[id] = v;
|
| 332 |
+
r.appendChild(l); r.appendChild(v); return r;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
grid.appendChild(kpiRow("fm-dims", "dims"));
|
| 336 |
+
grid.appendChild(kpiRow("fm-steps", "steps (Euler)"));
|
| 337 |
+
grid.appendChild(kpiRow("fm-err", "final_error \u2014 MODELED"));
|
| 338 |
+
grid.appendChild(kpiRow("fm-straight","straightness_score"));
|
| 339 |
+
grid.appendChild(kpiRow("fm-conv", "steps_to_converge"));
|
| 340 |
+
grid.appendChild(kpiRow("fm-few", "few-step error"));
|
| 341 |
+
grid.appendChild(kpiRow("fm-many", "many-step error"));
|
| 342 |
+
grid.appendChild(kpiRow("fm-label", "honesty label"));
|
| 343 |
+
card.appendChild(grid);
|
| 344 |
+
|
| 345 |
+
const fn = document.createElement("div");
|
| 346 |
+
fn.style.cssText = "font-size:9.5px;color:#6b7a86;line-height:1.5";
|
| 347 |
+
fn.textContent = "Lipman et al. arXiv:2210.02747 (Flow Matching) \u00b7 Liu et al. arXiv:2209.03003 (Rectified Flow) \u00b7 FLUX github.com/black-forest-labs/flux (cited only). MODELED \u00b7 not claimed-as.";
|
| 348 |
+
card.appendChild(fn);
|
| 349 |
+
_overlay.appendChild(card);
|
| 350 |
+
|
| 351 |
+
const pl = document.createElement("button");
|
| 352 |
+
pl.textContent = "\u25d1 what this means";
|
| 353 |
+
pl.title = "Toggle plain-language explanation for investors & consumers.";
|
| 354 |
+
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";
|
| 355 |
+
pl.addEventListener("click", () => {
|
| 356 |
+
_plain = !_plain;
|
| 357 |
+
pl.style.background = _plain ? "#0f2a20" : "#08140f";
|
| 358 |
+
_applyPlain();
|
| 359 |
+
});
|
| 360 |
+
_overlay.appendChild(pl);
|
| 361 |
+
|
| 362 |
+
const pd = document.createElement("div");
|
| 363 |
+
pd.id = "fm-plain";
|
| 364 |
+
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";
|
| 365 |
+
_el["plain"] = pd;
|
| 366 |
+
_overlay.appendChild(pd);
|
| 367 |
+
|
| 368 |
+
(ctx.container || document.body).appendChild(_overlay);
|
| 369 |
+
_paintOverlay();
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
function _applyPlain() {
|
| 373 |
+
const pd = _el["plain"];
|
| 374 |
+
if (!pd) return;
|
| 375 |
+
pd.style.display = _plain ? "block" : "none";
|
| 376 |
+
if (!_plain) return;
|
| 377 |
+
const steps = S.steps != null ? String(S.steps) : "loading\u2026";
|
| 378 |
+
const few = S.fewSteps != null ? String(S.fewSteps) : "1";
|
| 379 |
+
const many = S.manySteps != null ? String(S.manySteps) : "128";
|
| 380 |
+
const str = S.straightness != null ? (S.straightness * 100).toFixed(2) + "%" : "loading\u2026";
|
| 381 |
+
pd.innerHTML =
|
| 382 |
+
"<b>What this means:</b> Older generative-AI samplers (like standard diffusion) need " +
|
| 383 |
+
"<i>many small steps</i> to trace a curved path from random noise to a real output. " +
|
| 384 |
+
"<b>Rectified flow</b> instead learns (or here, defines) a <b>straight-line path</b> " +
|
| 385 |
+
"from noise to the target, so a model can take just <b>" + few + " step</b> and land " +
|
| 386 |
+
"almost exactly on target \u2014 versus needing <b>" + many + " steps</b> the old way, " +
|
| 387 |
+
"with barely any extra benefit. The path here is <b>" + str + " straight</b>. This is " +
|
| 388 |
+
"the same core idea behind fast production image generators like FLUX. This view is a " +
|
| 389 |
+
"<b>MODELED</b> analytic toy case (not a trained model, not FLUX itself), used at " +
|
| 390 |
+
"steps=" + steps + " to show the effect live.";
|
| 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 fx(v, d) { return typeof v === "number" ? v.toFixed(d) : "\u2014"; }
|
| 402 |
+
function pct(v, d) { return typeof v === "number" ? (v * 100).toFixed(d) + "%" : "\u2014"; }
|
| 403 |
+
function sci(v, d) { return typeof v === "number" ? v.toExponential(d) : "\u2014"; }
|
| 404 |
+
function _set(id, v) { if (_el[id]) _el[id].textContent = v; }
|
| 405 |
+
|
| 406 |
+
function _paintOverlay() {
|
| 407 |
+
const t = _tok(S.state);
|
| 408 |
+
_set("fm-dims", t || (S.dims != null ? String(S.dims) : "\u2014"));
|
| 409 |
+
_set("fm-steps", t || (S.steps != null ? String(S.steps) : "\u2014"));
|
| 410 |
+
_set("fm-err", t || sci(S.finalError, 3));
|
| 411 |
+
_set("fm-straight", t || pct(S.straightness, 2));
|
| 412 |
+
_set("fm-conv", t || (S.stepsToConverge != null ? String(S.stepsToConverge) : "\u2014"));
|
| 413 |
+
_set("fm-few", t || (S.fewSteps != null ? `${sci(S.fewError, 2)} (n=${S.fewSteps})` : "\u2014"));
|
| 414 |
+
_set("fm-many", t || (S.manySteps != null ? `${sci(S.manyError, 2)} (n=${S.manySteps})` : "\u2014"));
|
| 415 |
+
// honesty label verbatim — never upgraded
|
| 416 |
+
_set("fm-label", t || (S.label || "MODELED"));
|
| 417 |
+
if (_plain) _applyPlain();
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
// =============================================================================
|
| 421 |
+
// unmount — clean up everything; must not affect other organs
|
| 422 |
+
// =============================================================================
|
| 423 |
+
export function unmount() {
|
| 424 |
+
_polls.forEach((p) => { try { p.stop(); } catch (_) {} }); _polls = [];
|
| 425 |
+
try { if (_overlay && _overlay.parentNode) _overlay.parentNode.removeChild(_overlay); } catch (_) {}
|
| 426 |
+
try {
|
| 427 |
+
if (_group && _stage) {
|
| 428 |
+
_group.traverse((o) => {
|
| 429 |
+
if (o.geometry && o.geometry.dispose) o.geometry.dispose();
|
| 430 |
+
if (o.material) {
|
| 431 |
+
const ms = Array.isArray(o.material) ? o.material : [o.material];
|
| 432 |
+
ms.forEach((m) => { if (m.dispose) m.dispose(); });
|
| 433 |
+
}
|
| 434 |
+
});
|
| 435 |
+
_stage.scene.remove(_group);
|
| 436 |
+
}
|
| 437 |
+
} catch (_) {}
|
| 438 |
+
_group = _overlay = null;
|
| 439 |
+
_pathLine = null; _pathDots = []; _x0Marker = null; _x1Marker = null; _converge = null; _floor = null;
|
| 440 |
+
_el = {}; _badge = null; _plain = false; _frameReg = false;
|
| 441 |
+
_stage = _THREE = _ctx = null;
|
| 442 |
+
S.label = S.dims = S.steps = S.x0 = S.x1 = S.trajectory = null;
|
| 443 |
+
S.finalError = S.straightness = S.stepsToConverge = null;
|
| 444 |
+
S.fewSteps = S.fewError = S.manySteps = S.manyError = null;
|
| 445 |
+
S.state = "init";
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
export default { id: ID, title: TITLE, endpoints: [EP], mount, unmount };
|
static/3d/surfaces/specdecode.js
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
|
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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/specdecode.js — SELF-SPECULATIVE MULTI-TOKEN DECODING organ for the
|
| 5 |
+
// holographic frontier ring (Medusa/EAGLE-style draft-then-verify). Renders the
|
| 6 |
+
// draft model proposing `draft_len` candidate tokens per step as a 3D token-tree
|
| 7 |
+
// / pipeline, then colors each proposed token ACCEPTED (proof-teal) or REJECTED
|
| 8 |
+
// (grey) per the live snapshot from /api/killinchu/v1/specdecode/simulate. A HUD
|
| 9 |
+
// shows acceptance_rate + speedup_factor. Honesty label "MODELED" is read
|
| 10 |
+
// VERBATIM from the JSON and displayed as-is; it is never upgraded.
|
| 11 |
+
//
|
| 12 |
+
// Surface export shape (mirrors testtime.js / interpretability.js exactly):
|
| 13 |
+
// export default { id, title, endpoints, mount(ctx), unmount() }
|
| 14 |
+
// ctx = { stage, container, live, label, THREE, szl3d }
|
| 15 |
+
//
|
| 16 |
+
// DATA SHOWN (all from live endpoint):
|
| 17 |
+
// draft_len, trials, acceptance_rate, mean_accept_len, mean_tokens_per_step,
|
| 18 |
+
// speedup_factor, per_step_accept_lengths[], lossless
|
| 19 |
+
//
|
| 20 |
+
// LEADERS ADOPTED & CITED (clean-room; NOT claimed as SZL's own):
|
| 21 |
+
// Speculative Decoding (accept/reject arithmetic simulated here):
|
| 22 |
+
// Leviathan, Kalman & Matias 2023, arXiv:2211.17192
|
| 23 |
+
// https://arxiv.org/abs/2211.17192
|
| 24 |
+
// Medusa (multiple decoding heads, tree verification — reference only):
|
| 25 |
+
// Cai et al. 2024, github.com/FasterDecoding/Medusa
|
| 26 |
+
// https://github.com/FasterDecoding/Medusa
|
| 27 |
+
// EAGLE (feature-level extrapolation drafting — reference only):
|
| 28 |
+
// Li et al. 2024, arXiv:2401.15077
|
| 29 |
+
// https://arxiv.org/abs/2401.15077
|
| 30 |
+
//
|
| 31 |
+
// HONESTY LABELS: MODELED (deterministic re-implementation of the accept/reject
|
| 32 |
+
// arithmetic; NOT Medusa/EAGLE; NEVER-CLAIMED-AS a production drafter). Read
|
| 33 |
+
// verbatim from JSON; never upgraded here.
|
| 34 |
+
// COLOURS: lattice-blue 0x5b8dee (draft tokens / pipeline), proof-teal 0x3af4c8
|
| 35 |
+
// (accepted tokens / HUD accent), greys (rejected tokens / degraded state).
|
| 36 |
+
// Purple BANNED as UI/background.
|
| 37 |
+
// 0 RUNTIME CDN. Vendored three.js r170 via page importmap.
|
| 38 |
+
// DOCTRINE v11: degrades gracefully (grey) on 404/error; honesty label still shown.
|
| 39 |
+
// Nothing here is in the locked-8. Λ stays Conjecture 1. Trust never 100%.
|
| 40 |
+
|
| 41 |
+
const ID = "specdecode";
|
| 42 |
+
const TITLE = "Self-Speculative Decoding · Draft-then-Verify (live)";
|
| 43 |
+
|
| 44 |
+
// Endpoint is hosted on the dedicated killinchu Space (isolated compute), reached
|
| 45 |
+
// cross-origin (killinchu returns access-control-allow-origin: https://a-11-oy.com).
|
| 46 |
+
// This keeps the spec-decode organ's rebuilds/faults isolated from the flagship.
|
| 47 |
+
const EP = "https://szlholdings-killinchu.hf.space/api/killinchu/v1/specdecode/simulate?seed=42&draft_len=6&trials=256";
|
| 48 |
+
|
| 49 |
+
// data-viz hues — purple BANNED
|
| 50 |
+
const C_DRAFT = 0x5b8dee; // lattice-blue (draft-proposed token / pipeline spine)
|
| 51 |
+
const C_ACCEPT = 0x3af4c8; // proof-teal (accepted token / HUD accent)
|
| 52 |
+
const C_REJECT = 0x5a6570; // grey (rejected token)
|
| 53 |
+
const C_DIM = 0x42505d; // grey (degraded / no-live-data)
|
| 54 |
+
const C_GRID = 0x1b3a44; // floor / link colour
|
| 55 |
+
|
| 56 |
+
// token-tree pipeline layout geometry
|
| 57 |
+
const STEP_LEN = 2.1; // world-units between steps along X (pipeline axis)
|
| 58 |
+
const TOKEN_GAP = 0.85; // world-units between tokens within a step (Y, draft depth)
|
| 59 |
+
const MAX_STEPS = 10; // number of recent steps rendered along the pipeline
|
| 60 |
+
const MAX_TOKENS = 12; // cap on draft_len rendered per step (perf)
|
| 61 |
+
|
| 62 |
+
let _stage = null, _THREE = null, _ctx = null, _group = null, _overlay = null;
|
| 63 |
+
let _frameReg = false, _polls = [], _el = {}, _badge = null;
|
| 64 |
+
let _plain = false;
|
| 65 |
+
|
| 66 |
+
// geometry handles
|
| 67 |
+
let _floor = null;
|
| 68 |
+
let _spine = null; // THREE.Line — pipeline spine (draft -> verify axis)
|
| 69 |
+
let _tokenMesh = []; // Array<Array<THREE.Mesh>> — [step][tokenIdx]
|
| 70 |
+
let _stepLinks = []; // Array<THREE.Line> — link from spine to each step's tokens
|
| 71 |
+
let _marker = null; // THREE.Mesh — HUD "current step" pulsing marker
|
| 72 |
+
|
| 73 |
+
// live state
|
| 74 |
+
const S = {
|
| 75 |
+
label: null,
|
| 76 |
+
draftLen: null, // draft_len
|
| 77 |
+
trials: null, // trials
|
| 78 |
+
acceptRate: null, // acceptance_rate
|
| 79 |
+
meanAccept: null, // mean_accept_len
|
| 80 |
+
meanTokens: null, // mean_tokens_per_step
|
| 81 |
+
speedup: null, // speedup_factor
|
| 82 |
+
stepLengths: null, // per_step_accept_lengths[]
|
| 83 |
+
lossless: null, // lossless (bool)
|
| 84 |
+
state: "init",
|
| 85 |
+
};
|
| 86 |
+
|
| 87 |
+
// =============================================================================
|
| 88 |
+
// mount(ctx)
|
| 89 |
+
// =============================================================================
|
| 90 |
+
export function mount(ctx) {
|
| 91 |
+
_ctx = ctx; _stage = ctx.stage; _THREE = ctx.THREE;
|
| 92 |
+
_group = new _THREE.Group();
|
| 93 |
+
_stage.scene.add(_group);
|
| 94 |
+
_stage.camera.position.set(4, 7, 18);
|
| 95 |
+
try { if (_stage.controls && _stage.controls.target) { _stage.controls.target.set(6, 2, 0); _stage.controls.update(); } } catch (_) {}
|
| 96 |
+
try { _stage.setBloom(true); } catch (_) {}
|
| 97 |
+
|
| 98 |
+
_buildFloor();
|
| 99 |
+
_buildPipeline();
|
| 100 |
+
_buildMarker();
|
| 101 |
+
|
| 102 |
+
if (!_frameReg) { _stage.onFrame(_onFrame); _frameReg = true; }
|
| 103 |
+
|
| 104 |
+
_badge = ctx.live.createBadge();
|
| 105 |
+
_polls.push(ctx.live.poll(EP, 5000, _onSpecdecode, { badge: _badge, onState: (m) => { S.state = m.state; _paintOverlay(); } }));
|
| 106 |
+
|
| 107 |
+
_buildOverlay();
|
| 108 |
+
return { id: ID, started: true };
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
// =============================================================================
|
| 112 |
+
// builders
|
| 113 |
+
// =============================================================================
|
| 114 |
+
function _buildFloor() {
|
| 115 |
+
const THREE = _THREE;
|
| 116 |
+
const grid = new THREE.GridHelper(40, 40, C_GRID, 0x0f2027);
|
| 117 |
+
grid.material.opacity = 0.18; grid.material.transparent = true; grid.position.y = -0.01;
|
| 118 |
+
_group.add(grid);
|
| 119 |
+
_floor = grid;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
// Pre-allocate a fixed grid of token meshes: MAX_STEPS steps x MAX_TOKENS tokens
|
| 123 |
+
// per step. We toggle visibility / color / position in-place as live data
|
| 124 |
+
// arrives (no per-poll geometry churn).
|
| 125 |
+
function _buildPipeline() {
|
| 126 |
+
const THREE = _THREE;
|
| 127 |
+
|
| 128 |
+
// pipeline spine: a straight line along X marking the draft->verify axis
|
| 129 |
+
{
|
| 130 |
+
const pts = [new THREE.Vector3(0, 0, 0), new THREE.Vector3(STEP_LEN * (MAX_STEPS - 1) + 1, 0, 0)];
|
| 131 |
+
const geo = new THREE.BufferGeometry().setFromPoints(pts);
|
| 132 |
+
const mat = new THREE.LineBasicMaterial({ color: C_DRAFT, transparent: true, opacity: 0.45 });
|
| 133 |
+
_spine = new THREE.Line(geo, mat);
|
| 134 |
+
_group.add(_spine);
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
const tokenGeo = new THREE.OctahedronGeometry(0.20, 0);
|
| 138 |
+
for (let s = 0; s < MAX_STEPS; s++) {
|
| 139 |
+
const stepTokens = [];
|
| 140 |
+
const x = s * STEP_LEN;
|
| 141 |
+
for (let t = 0; t < MAX_TOKENS; t++) {
|
| 142 |
+
const y = 0.4 + t * TOKEN_GAP;
|
| 143 |
+
const mesh = new THREE.Mesh(
|
| 144 |
+
tokenGeo,
|
| 145 |
+
new THREE.MeshStandardMaterial({ color: C_DRAFT, emissive: C_DRAFT, emissiveIntensity: 0.25, transparent: true, opacity: 0.0 }),
|
| 146 |
+
);
|
| 147 |
+
mesh.position.set(x, y, 0);
|
| 148 |
+
mesh.visible = false;
|
| 149 |
+
_group.add(mesh);
|
| 150 |
+
stepTokens.push(mesh);
|
| 151 |
+
}
|
| 152 |
+
_tokenMesh.push(stepTokens);
|
| 153 |
+
|
| 154 |
+
// vertical link line from spine up to the step's token column
|
| 155 |
+
const linkGeo = new THREE.BufferGeometry().setFromPoints([
|
| 156 |
+
new THREE.Vector3(x, 0, 0), new THREE.Vector3(x, 0.4 + (MAX_TOKENS - 1) * TOKEN_GAP, 0),
|
| 157 |
+
]);
|
| 158 |
+
const linkMat = new THREE.LineBasicMaterial({ color: C_GRID, transparent: true, opacity: 0.25 });
|
| 159 |
+
const link = new THREE.Line(linkGeo, linkMat);
|
| 160 |
+
link.visible = false;
|
| 161 |
+
_group.add(link);
|
| 162 |
+
_stepLinks.push(link);
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
function _buildMarker() {
|
| 167 |
+
const THREE = _THREE;
|
| 168 |
+
_marker = new THREE.Mesh(
|
| 169 |
+
new THREE.IcosahedronGeometry(0.26, 1),
|
| 170 |
+
new THREE.MeshStandardMaterial({ color: C_ACCEPT, emissive: C_ACCEPT, emissiveIntensity: 0.5, wireframe: true, transparent: true, opacity: 0.85 }),
|
| 171 |
+
);
|
| 172 |
+
_marker.position.set(0, -0.6, 0);
|
| 173 |
+
_group.add(_marker);
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
// =============================================================================
|
| 177 |
+
// live data handler
|
| 178 |
+
// =============================================================================
|
| 179 |
+
function _onSpecdecode(j) {
|
| 180 |
+
// read honesty label VERBATIM — never upgrade
|
| 181 |
+
S.label = (j.label || "MODELED").toUpperCase();
|
| 182 |
+
S.draftLen = typeof j.draft_len === "number" ? j.draft_len : null;
|
| 183 |
+
S.trials = typeof j.trials === "number" ? j.trials : null;
|
| 184 |
+
S.acceptRate = typeof j.acceptance_rate === "number" ? j.acceptance_rate : null;
|
| 185 |
+
S.meanAccept = typeof j.mean_accept_len === "number" ? j.mean_accept_len : null;
|
| 186 |
+
S.meanTokens = typeof j.mean_tokens_per_step === "number" ? j.mean_tokens_per_step : null;
|
| 187 |
+
S.speedup = typeof j.speedup_factor === "number" ? j.speedup_factor : null;
|
| 188 |
+
S.stepLengths = Array.isArray(j.per_step_accept_lengths) ? j.per_step_accept_lengths : null;
|
| 189 |
+
S.lossless = typeof j.lossless === "boolean" ? j.lossless : null;
|
| 190 |
+
|
| 191 |
+
_updatePipeline();
|
| 192 |
+
_paintOverlay();
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
// =============================================================================
|
| 196 |
+
// geometry updater — drives the token-tree / pipeline from live data
|
| 197 |
+
// =============================================================================
|
| 198 |
+
function _updatePipeline() {
|
| 199 |
+
const live = S.state === "live";
|
| 200 |
+
const draftLen = live && S.draftLen ? Math.min(S.draftLen, MAX_TOKENS) : 0;
|
| 201 |
+
const steps = live && S.stepLengths && S.stepLengths.length
|
| 202 |
+
? S.stepLengths.slice(0, MAX_STEPS)
|
| 203 |
+
: [];
|
| 204 |
+
|
| 205 |
+
for (let s = 0; s < MAX_STEPS; s++) {
|
| 206 |
+
const acceptedLen = s < steps.length ? steps[s] : -1;
|
| 207 |
+
const showStep = live && s < steps.length && draftLen > 0;
|
| 208 |
+
_stepLinks[s].visible = showStep;
|
| 209 |
+
|
| 210 |
+
for (let t = 0; t < MAX_TOKENS; t++) {
|
| 211 |
+
const mesh = _tokenMesh[s][t];
|
| 212 |
+
if (!showStep || t >= draftLen) {
|
| 213 |
+
mesh.visible = false;
|
| 214 |
+
continue;
|
| 215 |
+
}
|
| 216 |
+
mesh.visible = true;
|
| 217 |
+
const accepted = t < acceptedLen;
|
| 218 |
+
const color = accepted ? C_ACCEPT : C_REJECT;
|
| 219 |
+
mesh.material.color.setHex(color);
|
| 220 |
+
mesh.material.emissive.setHex(color);
|
| 221 |
+
mesh.material.emissiveIntensity = accepted ? 0.55 : 0.12;
|
| 222 |
+
mesh.material.opacity = accepted ? 0.95 : 0.35;
|
| 223 |
+
// rejected tokens (and everything after the first rejection) sit slightly
|
| 224 |
+
// recessed in Z to visually read as "pruned" from the accepted path.
|
| 225 |
+
mesh.position.z = accepted ? 0 : -0.35;
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
// spine + marker degrade to grey when not live
|
| 230 |
+
_spine.material.color.setHex(live ? C_DRAFT : C_DIM);
|
| 231 |
+
_spine.material.opacity = live ? 0.45 : 0.15;
|
| 232 |
+
|
| 233 |
+
if (_marker) {
|
| 234 |
+
if (live && S.speedup != null) {
|
| 235 |
+
_marker.material.color.setHex(C_ACCEPT);
|
| 236 |
+
_marker.material.emissive.setHex(C_ACCEPT);
|
| 237 |
+
_marker.material.opacity = 0.85;
|
| 238 |
+
// marker rides along X proportional to speedup_factor (visual "throughput" cue)
|
| 239 |
+
const x = Math.min(STEP_LEN * (MAX_STEPS - 1), (S.speedup || 1) * STEP_LEN * 0.9);
|
| 240 |
+
_marker.position.set(x, -0.6, 0);
|
| 241 |
+
} else {
|
| 242 |
+
_marker.material.color.setHex(C_DIM);
|
| 243 |
+
_marker.material.emissive.setHex(C_DIM);
|
| 244 |
+
_marker.material.opacity = 0.3;
|
| 245 |
+
}
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
// =============================================================================
|
| 250 |
+
// per-frame animation
|
| 251 |
+
// =============================================================================
|
| 252 |
+
function _onFrame() {
|
| 253 |
+
const t = performance.now();
|
| 254 |
+
if (_group) _group.rotation.y = Math.sin(t * 0.00009) * 0.12;
|
| 255 |
+
if (_marker) {
|
| 256 |
+
_marker.rotation.y += 0.025;
|
| 257 |
+
_marker.rotation.x += 0.012;
|
| 258 |
+
const pulse = 1.0 + 0.15 * Math.sin(t * 0.004);
|
| 259 |
+
_marker.scale.setScalar(pulse);
|
| 260 |
+
}
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
// =============================================================================
|
| 264 |
+
// overlay
|
| 265 |
+
// =============================================================================
|
| 266 |
+
function _buildOverlay() {
|
| 267 |
+
const ctx = _ctx;
|
| 268 |
+
_overlay = document.createElement("div");
|
| 269 |
+
Object.assign(_overlay.style, {
|
| 270 |
+
position: "absolute", left: "14px", top: "14px", zIndex: "6",
|
| 271 |
+
display: "flex", flexDirection: "column", gap: "8px",
|
| 272 |
+
maxWidth: "min(94%,440px)",
|
| 273 |
+
font: "12px ui-sans-serif,system-ui,Segoe UI,Roboto,Arial",
|
| 274 |
+
color: "#eef3f6",
|
| 275 |
+
});
|
| 276 |
+
|
| 277 |
+
const h = document.createElement("div");
|
| 278 |
+
h.style.cssText = "font:600 13px ui-sans-serif,system-ui;letter-spacing:.4px";
|
| 279 |
+
h.textContent = TITLE;
|
| 280 |
+
_overlay.appendChild(h);
|
| 281 |
+
|
| 282 |
+
const sub = document.createElement("div");
|
| 283 |
+
sub.style.cssText = "color:#9fb1bf;font-size:11px;line-height:1.55";
|
| 284 |
+
sub.innerHTML =
|
| 285 |
+
'A small <b>draft</b> model proposes several tokens per step; the <b>target</b> model ' +
|
| 286 |
+
'verifies them all in one parallel pass, accepting via rejection sampling ' +
|
| 287 |
+
'(accept if p<sub>draft</sub> \u2264 p<sub>target</sub>, else w.p. p<sub>target</sub>/p<sub>draft</sub>). ' +
|
| 288 |
+
'Output distribution is <b>lossless</b> \u2014 identical to plain autoregressive decoding, just faster. ' +
|
| 289 |
+
'Honesty label <b>MODELED</b> (deterministic accept/reject simulation; NOT Medusa/EAGLE). 0 runtime CDN.';
|
| 290 |
+
_overlay.appendChild(sub);
|
| 291 |
+
|
| 292 |
+
const brow = document.createElement("div");
|
| 293 |
+
brow.style.cssText = "display:flex;gap:8px;align-items:center;flex-wrap:wrap";
|
| 294 |
+
if (_badge && _badge.el) brow.appendChild(_badge.el);
|
| 295 |
+
_overlay.appendChild(brow);
|
| 296 |
+
|
| 297 |
+
const card = document.createElement("div");
|
| 298 |
+
card.style.cssText = "background:#0a1117;border:1px solid #1d2a36;border-radius:9px;padding:9px 10px;display:flex;flex-direction:column;gap:6px";
|
| 299 |
+
|
| 300 |
+
const chead = document.createElement("div");
|
| 301 |
+
chead.style.cssText = "display:flex;align-items:center;gap:8px;flex-wrap:wrap";
|
| 302 |
+
const dot = document.createElement("span");
|
| 303 |
+
dot.style.cssText = "width:9px;height:9px;border-radius:50%;background:#3af4c8;box-shadow:0 0 7px #3af4c8";
|
| 304 |
+
const nm = document.createElement("b");
|
| 305 |
+
nm.style.cssText = "font-size:12px;color:#3af4c8;letter-spacing:.3px";
|
| 306 |
+
nm.textContent = "self-speculative decoding";
|
| 307 |
+
chead.appendChild(dot); chead.appendChild(nm);
|
| 308 |
+
card.appendChild(chead);
|
| 309 |
+
|
| 310 |
+
const grid = document.createElement("div");
|
| 311 |
+
grid.style.cssText = "display:grid;grid-template-columns:1fr;gap:4px";
|
| 312 |
+
|
| 313 |
+
function kpiRow(id, label) {
|
| 314 |
+
const r = document.createElement("div");
|
| 315 |
+
r.style.cssText = "display:flex;justify-content:space-between;gap:10px;font-size:11px";
|
| 316 |
+
const l = document.createElement("span"); l.style.cssText = "color:#9fb1bf"; l.textContent = label;
|
| 317 |
+
const v = document.createElement("b");
|
| 318 |
+
v.id = id;
|
| 319 |
+
v.style.cssText = "font-variant-numeric:tabular-nums;color:#eef3f6;text-align:right;max-width:58%";
|
| 320 |
+
v.textContent = "\u2014";
|
| 321 |
+
_el[id] = v;
|
| 322 |
+
r.appendChild(l); r.appendChild(v); return r;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
grid.appendChild(kpiRow("sd-draftlen", "draft_len (\u03b3 proposed/step)"));
|
| 326 |
+
grid.appendChild(kpiRow("sd-trials", "trials simulated"));
|
| 327 |
+
grid.appendChild(kpiRow("sd-accrate", "acceptance_rate \u2014 MODELED"));
|
| 328 |
+
grid.appendChild(kpiRow("sd-meanacc", "mean accepted tokens/step"));
|
| 329 |
+
grid.appendChild(kpiRow("sd-speedup", "speedup_factor \u2014 MODELED"));
|
| 330 |
+
grid.appendChild(kpiRow("sd-lossless", "lossless?"));
|
| 331 |
+
grid.appendChild(kpiRow("sd-label", "honesty label"));
|
| 332 |
+
card.appendChild(grid);
|
| 333 |
+
|
| 334 |
+
const fn = document.createElement("div");
|
| 335 |
+
fn.style.cssText = "font-size:9.5px;color:#6b7a86;line-height:1.5";
|
| 336 |
+
fn.textContent = "Leviathan et al. arXiv:2211.17192 (speculative decoding) \u00b7 Medusa github.com/FasterDecoding/Medusa \u00b7 EAGLE arXiv:2401.15077. MODELED \u00b7 not claimed-as.";
|
| 337 |
+
card.appendChild(fn);
|
| 338 |
+
_overlay.appendChild(card);
|
| 339 |
+
|
| 340 |
+
const pl = document.createElement("button");
|
| 341 |
+
pl.textContent = "\u25d1 what this means";
|
| 342 |
+
pl.title = "Toggle plain-language explanation for investors & consumers.";
|
| 343 |
+
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";
|
| 344 |
+
pl.addEventListener("click", () => {
|
| 345 |
+
_plain = !_plain;
|
| 346 |
+
pl.style.background = _plain ? "#0f2a20" : "#08140f";
|
| 347 |
+
_applyPlain();
|
| 348 |
+
});
|
| 349 |
+
_overlay.appendChild(pl);
|
| 350 |
+
|
| 351 |
+
const pd = document.createElement("div");
|
| 352 |
+
pd.id = "sd-plain";
|
| 353 |
+
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";
|
| 354 |
+
_el["plain"] = pd;
|
| 355 |
+
_overlay.appendChild(pd);
|
| 356 |
+
|
| 357 |
+
(ctx.container || document.body).appendChild(_overlay);
|
| 358 |
+
_paintOverlay();
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
function _applyPlain() {
|
| 362 |
+
const pd = _el["plain"];
|
| 363 |
+
if (!pd) return;
|
| 364 |
+
pd.style.display = _plain ? "block" : "none";
|
| 365 |
+
if (!_plain) return;
|
| 366 |
+
const g = S.draftLen != null ? String(S.draftLen) : "loading\u2026";
|
| 367 |
+
const accPct = S.acceptRate != null ? (S.acceptRate * 100).toFixed(1) + "%" : "loading\u2026";
|
| 368 |
+
const speedup = S.speedup != null ? S.speedup.toFixed(2) + "\u00d7" : "loading\u2026";
|
| 369 |
+
pd.innerHTML =
|
| 370 |
+
"<b>What this means:</b> Instead of generating one word at a time, a small, cheap " +
|
| 371 |
+
"\u201cdraft\u201d model quickly guesses <b>" + g + " words ahead</b>. The big \u201ctarget\u201d " +
|
| 372 |
+
"model then checks all of those guesses <i>at once</i> and keeps every guess it agrees with " +
|
| 373 |
+
"(here, about <b>" + accPct + "</b> of guesses survive). Because checking a whole batch of " +
|
| 374 |
+
"guesses costs about the same as generating one word normally, this yields roughly a <b>" +
|
| 375 |
+
speedup + " speedup</b> in tokens produced per expensive model pass \u2014 with " +
|
| 376 |
+
"<i>zero change</i> to what the model actually outputs (mathematically lossless, per " +
|
| 377 |
+
"Leviathan et al. 2023). Plain: same answer, produced faster. This view is a <b>MODELED</b> " +
|
| 378 |
+
"closed-form simulation of the accept/reject math, not a run of Medusa or EAGLE.";
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
function _tok(s) {
|
| 382 |
+
if (s === "live") return null;
|
| 383 |
+
if (s === "missing") return "NO-LIVE-DATA";
|
| 384 |
+
if (s === "degraded") return "DEGRADED";
|
| 385 |
+
if (s === "error") return "OFFLINE";
|
| 386 |
+
return "\u2026";
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
function fx(v, d) { return typeof v === "number" ? v.toFixed(d) : "\u2014"; }
|
| 390 |
+
function pct(v, d) { return typeof v === "number" ? (v * 100).toFixed(d) + "%" : "\u2014"; }
|
| 391 |
+
function _set(id, v) { if (_el[id]) _el[id].textContent = v; }
|
| 392 |
+
|
| 393 |
+
function _paintOverlay() {
|
| 394 |
+
const t = _tok(S.state);
|
| 395 |
+
_set("sd-draftlen", t || (S.draftLen != null ? String(S.draftLen) : "\u2014"));
|
| 396 |
+
_set("sd-trials", t || (S.trials != null ? String(S.trials) : "\u2014"));
|
| 397 |
+
_set("sd-accrate", t || pct(S.acceptRate, 2));
|
| 398 |
+
_set("sd-meanacc", t || fx(S.meanAccept, 3));
|
| 399 |
+
_set("sd-speedup", t || (S.speedup != null ? S.speedup.toFixed(3) + "\u00d7" : "\u2014"));
|
| 400 |
+
_set("sd-lossless", t || (S.lossless === true ? "yes (rejection-sampling identity)" : S.lossless === false ? "no" : "\u2014"));
|
| 401 |
+
// honesty label verbatim — never upgraded
|
| 402 |
+
_set("sd-label", t || (S.label || "MODELED"));
|
| 403 |
+
if (_plain) _applyPlain();
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
// =============================================================================
|
| 407 |
+
// unmount — clean up everything; must not affect other organs
|
| 408 |
+
// =============================================================================
|
| 409 |
+
export function unmount() {
|
| 410 |
+
_polls.forEach((p) => { try { p.stop(); } catch (_) {} }); _polls = [];
|
| 411 |
+
try { if (_overlay && _overlay.parentNode) _overlay.parentNode.removeChild(_overlay); } catch (_) {}
|
| 412 |
+
try {
|
| 413 |
+
if (_group && _stage) {
|
| 414 |
+
_group.traverse((o) => {
|
| 415 |
+
if (o.geometry && o.geometry.dispose) o.geometry.dispose();
|
| 416 |
+
if (o.material) {
|
| 417 |
+
const ms = Array.isArray(o.material) ? o.material : [o.material];
|
| 418 |
+
ms.forEach((m) => { if (m.dispose) m.dispose(); });
|
| 419 |
+
}
|
| 420 |
+
});
|
| 421 |
+
_stage.scene.remove(_group);
|
| 422 |
+
}
|
| 423 |
+
} catch (_) {}
|
| 424 |
+
_group = _overlay = null;
|
| 425 |
+
_floor = null; _spine = null; _tokenMesh = []; _stepLinks = []; _marker = null;
|
| 426 |
+
_el = {}; _badge = null; _plain = false; _frameReg = false;
|
| 427 |
+
_stage = _THREE = _ctx = null;
|
| 428 |
+
S.label = S.draftLen = S.trials = S.acceptRate = null;
|
| 429 |
+
S.meanAccept = S.meanTokens = S.speedup = S.stepLengths = S.lossless = null;
|
| 430 |
+
S.state = "init";
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
export default { id: ID, title: TITLE, endpoints: [EP], mount, unmount };
|