@openfluke/welvet 0.3.0 → 0.75.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,283 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Loom Core | Browser AI Engine</title>
8
+ <style>
9
+ :root {
10
+ --bg: #0a0a0c;
11
+ --panel: rgba(255, 255, 255, 0.03);
12
+ --accent: #00f2ff;
13
+ --accent-glow: rgba(0, 242, 255, 0.3);
14
+ --text: #e0e0e6;
15
+ --dim: #888891;
16
+ --border: rgba(255, 255, 255, 0.1);
17
+ }
18
+
19
+ body {
20
+ background-color: var(--bg);
21
+ color: var(--text);
22
+ font-family: 'Inter', -apple-system, system-ui, sans-serif;
23
+ margin: 0;
24
+ display: flex;
25
+ height: 100vh;
26
+ overflow: hidden;
27
+ }
28
+
29
+ /* Sidebar Navigation */
30
+ nav {
31
+ width: 280px;
32
+ border-right: 1px solid var(--border);
33
+ padding: 40px 20px;
34
+ display: flex;
35
+ flex-direction: column;
36
+ gap: 12px;
37
+ }
38
+
39
+ .logo {
40
+ font-size: 20px;
41
+ font-weight: 800;
42
+ letter-spacing: -1px;
43
+ color: var(--accent);
44
+ margin-bottom: 40px;
45
+ display: flex;
46
+ align-items: center;
47
+ gap: 10px;
48
+ }
49
+
50
+ .nav-btn {
51
+ padding: 12px 16px;
52
+ border-radius: 8px;
53
+ cursor: pointer;
54
+ transition: 0.2s;
55
+ font-size: 14px;
56
+ color: var(--dim);
57
+ border: 1px solid transparent;
58
+ }
59
+
60
+ .nav-btn:hover {
61
+ background: var(--panel);
62
+ color: white;
63
+ }
64
+
65
+ .nav-btn.active {
66
+ background: var(--accent-glow);
67
+ color: var(--accent);
68
+ border-color: var(--border);
69
+ }
70
+
71
+ /* Main Content Area */
72
+ main {
73
+ flex: 1;
74
+ padding: 40px;
75
+ overflow-y: auto;
76
+ position: relative;
77
+ }
78
+
79
+ .card {
80
+ background: var(--panel);
81
+ border: 1px solid var(--border);
82
+ border-radius: 12px;
83
+ padding: 24px;
84
+ margin-bottom: 24px;
85
+ backdrop-filter: blur(10px);
86
+ }
87
+
88
+ h2 {
89
+ font-size: 18px;
90
+ margin-top: 0;
91
+ color: white;
92
+ }
93
+
94
+ p {
95
+ font-size: 14px;
96
+ color: var(--dim);
97
+ line-height: 1.6;
98
+ }
99
+
100
+ .status-badge {
101
+ display: inline-flex;
102
+ align-items: center;
103
+ gap: 6px;
104
+ padding: 4px 10px;
105
+ border-radius: 100px;
106
+ font-size: 11px;
107
+ text-transform: uppercase;
108
+ font-weight: 700;
109
+ background: rgba(255, 255, 255, 0.05);
110
+ }
111
+
112
+ .status-badge.ready {
113
+ color: #00ff88;
114
+ background: rgba(0, 255, 136, 0.1);
115
+ }
116
+
117
+ .terminal {
118
+ background: #000;
119
+ border-radius: 8px;
120
+ padding: 16px;
121
+ font-family: 'JetBrains Mono', monospace;
122
+ font-size: 12px;
123
+ color: #00ff88;
124
+ height: 200px;
125
+ overflow-y: auto;
126
+ border: 1px solid #111;
127
+ }
128
+
129
+ button.primary {
130
+ background: var(--accent);
131
+ color: black;
132
+ border: none;
133
+ padding: 12px 24px;
134
+ border-radius: 6px;
135
+ font-weight: 600;
136
+ cursor: pointer;
137
+ transition: 0.2s;
138
+ }
139
+
140
+ button.primary:hover {
141
+ box-shadow: 0 0 20px var(--accent-glow);
142
+ transform: translateY(-1px);
143
+ }
144
+
145
+ .grid {
146
+ display: grid;
147
+ grid-template-columns: repeat(2, 1fr);
148
+ gap: 20px;
149
+ }
150
+ </style>
151
+ </head>
152
+
153
+ <body>
154
+
155
+ <nav>
156
+ <div class="logo">
157
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3">
158
+ <path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" />
159
+ </svg>
160
+ LOOM CORE
161
+ </div>
162
+ <div class="nav-btn active">Dashboard</div>
163
+ <div class="nav-btn">Engine Audit</div>
164
+ <div class="nav-btn">DNA Lab</div>
165
+ <div class="nav-btn">Weights Management</div>
166
+ </nav>
167
+
168
+ <main>
169
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 32px;">
170
+ <div>
171
+ <h1 style="margin:0; font-size: 24px;">System Overview</h1>
172
+ <div class="status-badge ready" id="hw-status">Initializing...</div>
173
+ </div>
174
+ <button class="primary" onclick="runDemo()">Execute Full Forward Pass</button>
175
+ </div>
176
+
177
+ <div class="grid">
178
+ <div class="card">
179
+ <h2>Network Intelligence</h2>
180
+ <p>Constructing polymorphic networks directly from JSON definitions with strict DType enforcement.</p>
181
+ <div class="terminal" id="net-log">Waiting for engine...</div>
182
+ </div>
183
+ <div class="card">
184
+ <h2>Transformer Prefill</h2>
185
+ <p>Simulating 4096-seq/768-dim Transformer prefill using WebGPU resident context.</p>
186
+ <div class="terminal" id="gpu-log">GPU Idle</div>
187
+ </div>
188
+ </div>
189
+
190
+ <div class="card">
191
+ <h2>DNA Comparison (Crossover Analytics)</h2>
192
+ <div id="dna-chart" style="height: 100px; display: flex; align-items: flex-end; gap: 4px;">
193
+ <!-- Bars will go here -->
194
+ </div>
195
+ <p style="margin-top: 15px;">Genetic distance between Network Alpha and Network Beta: <span id="dna-dist"
196
+ style="color:var(--accent)">0.00%</span></p>
197
+ </div>
198
+ </main>
199
+
200
+ <script src="wasm_exec.js"></script>
201
+ <script>
202
+ const go = new Go();
203
+ let engine;
204
+
205
+ // 1. Loading and Initializing the Engine
206
+ WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then(async (result) => {
207
+ go.run(result.instance);
208
+
209
+ log("net-log", "LOOM v0.75-STABLE WASM Runtime Loaded.");
210
+
211
+ // Setup WebGPU
212
+ try {
213
+ const status = await window.setupWebGPU();
214
+ document.getElementById('hw-status').innerText = "WGPU ACCELERATION: ACTIVE";
215
+ log("gpu-log", "WebGPU Context initialized successfully.");
216
+ } catch (e) {
217
+ document.getElementById('hw-status').style.color = "#ff4444";
218
+ document.getElementById('hw-status').innerText = "WGPU ERROR: CPU FALLBACK";
219
+ }
220
+
221
+ initDemo();
222
+ });
223
+
224
+ function log(id, msg) {
225
+ const el = document.getElementById(id);
226
+ const time = new Date().toLocaleTimeString();
227
+ el.innerHTML += `<div><span style="color:#555">[${time}]</span> ${msg}</div>`;
228
+ el.scrollTop = el.scrollHeight;
229
+ }
230
+
231
+ async function initDemo() {
232
+ // Build a Network from JSON (Strict Functional Parity Check)
233
+ const config = {
234
+ depth: 1, rows: 1, cols: 1, layers_per_cell: 4,
235
+ layers: [
236
+ { type: "Embedding", input_height: 32000, output_height: 768 },
237
+ { type: "RMSNorm", input_height: 768 },
238
+ { type: "MultiHeadAttention", d_model: 768, num_heads: 12, seq_length: 512 },
239
+ { type: "Dense", input_height: 768, output_height: 32000, activation: "Softmax" }
240
+ ]
241
+ };
242
+
243
+ const net = window.BuildNetworkFromJSON(JSON.stringify(config));
244
+ log("net-log", "Network Alpha built successfully.");
245
+
246
+ // Extract DNA and compare
247
+ const dnaA = window.ExtractDNA(net._id);
248
+ const netAlt = window.BuildNetworkFromJSON(JSON.stringify(config));
249
+ const dnaB = window.ExtractDNA(netAlt._id);
250
+
251
+ const comparisonJSON = window.compareLoomDNA(dnaA, dnaB);
252
+ const comparison = JSON.parse(comparisonJSON);
253
+ const score = (comparison.OverallOverlap || 0) * 100;
254
+
255
+ document.getElementById('dna-dist').innerText = score.toFixed(2) + "%";
256
+ log("net-log", `DNA Hash Alpha: ${dnaA.substring(0, 32)}...`);
257
+ }
258
+
259
+ function runDemo() {
260
+ log("gpu-log", "Beginning Full Pass on WGPU context...");
261
+
262
+ requestAnimationFrame(() => {
263
+ setTimeout(() => {
264
+ const input = new Float32Array(768).map(() => Math.random());
265
+
266
+ const config = JSON.stringify({
267
+ layers: [{ type: "Dense", input_height: 768, output_height: 768, activation: "ReLU" }]
268
+ });
269
+ const net = window.BuildNetworkFromJSON(config);
270
+
271
+ const start = performance.now();
272
+ const result = net.sequentialForward(input);
273
+ const end = performance.now();
274
+
275
+ log("gpu-log", `Inference complete in ${(end - start).toFixed(2)}ms.`);
276
+ log("gpu-log", `Result Shape: [1, ${result.data.length}]`);
277
+ }, 100);
278
+ });
279
+ }
280
+ </script>
281
+ </body>
282
+
283
+ </html>
package/dist/index.d.ts CHANGED
@@ -1,69 +1,190 @@
1
1
  /**
2
- * @openfluke/welvet - Isomorphic WASM Wrapper
2
+ * @openfluke/welvet — M-POLY-VTD AI Engine
3
3
  *
4
- * Direct wrapper around Loom WASM that mirrors main.go exports exactly.
5
- * Provides the same API in both Node.js and browser environments.
4
+ * Isomorphic TypeScript wrapper for the Loom v0.75.0 WASM module.
5
+ * Supports Node.js and browser environments.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { init, createNetwork, DType } from "@openfluke/welvet";
10
+ *
11
+ * await init();
12
+ *
13
+ * const net = createNetwork({
14
+ * layers: [
15
+ * { type: "dense", input_height: 4, output_height: 8 },
16
+ * { type: "dense", input_height: 8, output_height: 2 },
17
+ * ]
18
+ * });
19
+ *
20
+ * const output = net.sequentialForward(new Float32Array([1, 0, 0, 1]));
21
+ * console.log(output); // Float32Array [...]
22
+ * ```
6
23
  */
7
- import { Network, GraftResult, KMeansResult, CorrelationResult, EnsembleMatch, AdaptationTracker } from "./types.js";
24
+ import type { Network, NEATPopulation, SystolicState, TargetPropState, TrainingBatch, TrainingResult, DNACompareResult, Transformer } from "./types.js";
8
25
  import { loadLoomWASMBrowser } from "./loader.browser.js";
9
26
  export * from "./types.js";
10
27
  export { loadLoomWASMBrowser };
11
- export declare function loadLoomWASM(): Promise<void>;
12
28
  /**
13
- * Initialize WASM
14
- * Auto-detects environment (Browser vs Node.js)
29
+ * Initialize the welvet WASM module.
30
+ * Auto-detects Node.js vs browser environment.
31
+ *
32
+ * @param wasmUrl Optional custom URL for browser WASM loading (default: /dist/main.wasm)
15
33
  */
16
34
  export declare function init(wasmUrl?: string): Promise<void>;
17
35
  /**
18
- * Initialize WASM for Browser environment
36
+ * Initialize explicitly for browser environments.
37
+ * @param wasmUrl Optional custom URL for WASM binary
19
38
  */
20
39
  export declare function initBrowser(wasmUrl?: string): Promise<void>;
21
40
  /**
22
- * Create a network from JSON config
23
- * Wrapper around the global createLoomNetwork function exposed by WASM
41
+ * Build a VolumetricNetwork from a JSON configuration object or string.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * const net = createNetwork({
46
+ * layers: [
47
+ * { type: "dense", input_height: 784, output_height: 256 },
48
+ * { type: "dense", input_height: 256, output_height: 10, activation: "silu" },
49
+ * ]
50
+ * });
51
+ * ```
24
52
  */
25
53
  export declare function createNetwork(config: object | string): Network;
26
54
  /**
27
- * Load a network from JSON string and ID
55
+ * Build a network from a JSON string.
28
56
  */
29
- export declare function loadNetwork(jsonString: string, modelID: string): Network;
57
+ export declare function buildNetworkFromJSON(json: string): Network;
58
+ /** Alias for buildNetworkFromJSON to match engine symbol */
59
+ export declare const BuildNetworkFromJSON: typeof buildNetworkFromJSON;
30
60
  /**
31
- * Create a network handle for grafting
61
+ * Load a pre-trained network from a SafeTensors file path.
32
62
  */
33
- export declare function createKHandle(config: object | string): number;
63
+ export declare function loadNetwork(path: string): Network;
34
64
  /**
35
- * Graft multiple networks together
65
+ * Initialize WebGPU (browser only).
66
+ * Sets window.webgpuAdapter, window.webgpuDevice, window.webgpuQueue.
36
67
  */
37
- export declare function graft(ids: number[], combineMode: string): GraftResult;
68
+ export declare function setupWebGPU(): Promise<string>;
38
69
  /**
39
- * Perform K-Means Clustering
70
+ * Compare the architectural DNA of two networks.
71
+ *
72
+ * @param dnaA JSON string from network.extractDNA()
73
+ * @param dnaB JSON string from network.extractDNA()
74
+ * @returns DNACompareResult
75
+ */
76
+ export declare function compareDNA(dnaA: string, dnaB: string): DNACompareResult;
77
+ /**
78
+ * Get the default TargetPropConfig.
40
79
  */
41
- export declare function kmeans(data: number[][], k: number, iter: number): KMeansResult;
80
+ export declare function defaultTargetPropConfig(): object;
42
81
  /**
43
- * Compute Correlation Matrix
82
+ * Get the internal parity symbol list from Go.
83
+ * Used for audits and verification.
84
+ */
85
+ export declare function getInternalParity(): string[];
86
+ /** Global accessor for extractNetworkBlueprint (engine parity) */
87
+ export declare function ExtractNetworkBlueprint(network: Network, modelID?: string): string;
88
+ /**
89
+ * Convenience wrapper for network.train() that handles JSON serialization.
90
+ *
91
+ * @param network The network to train
92
+ * @param batches Array of {input, target} training pairs
93
+ * @param epochs Number of training epochs
94
+ * @param lr Learning rate
44
95
  */
45
- export declare function correlation(matrixA: number[][], matrixB?: number[][]): CorrelationResult;
96
+ export declare function trainNetwork(network: Network, batches: TrainingBatch[], epochs: number, lr: number): TrainingResult;
97
+ /** Get the default SpliceConfig as a plain object. */
98
+ export declare function getSpliceConfig(): object;
99
+ /** Get the default NEATConfig as a plain object. */
100
+ export declare function getNEATConfig(dModel: number): object;
46
101
  /**
47
- * Find Complementary Ensemble Matches
102
+ * Create a NEAT population from a seed network.
103
+ * @param network Seed network (its _id is used)
104
+ * @param size Population size
105
+ * @param cfg NEATConfig object or JSON string (defaults to getNEATConfig(64))
48
106
  */
49
- export declare function ensemble(models: object[], minCoverage: number): EnsembleMatch[];
107
+ export declare function createNEATPopulation(network: Network, size: number, cfg?: object | string): NEATPopulation;
50
108
  /**
51
- * Create Adaptation Tracker
109
+ * Create a Transformer wrapper.
110
+ * @param network Network to use as the base
111
+ * @param embeddings Float32Array of embedding weights
112
+ * @param lmHead Float32Array of LM head weights
113
+ * @param finalNorm Float32Array of final norm weights
52
114
  */
53
- export declare function tracker(windowMs: number, totalMs: number): AdaptationTracker;
115
+ export declare function createTransformer(network: Network, embeddings: Float32Array | number[], lmHead: Float32Array | number[], finalNorm: Float32Array | number[]): Transformer;
54
116
  /**
55
- * Default export with all functions
117
+ * Save a network to a SafeTensors byte array.
56
118
  */
119
+ export declare function saveNetwork(network: Network): Uint8Array;
57
120
  declare const _default: {
58
121
  init: typeof init;
59
122
  initBrowser: typeof initBrowser;
60
123
  createNetwork: typeof createNetwork;
124
+ buildNetworkFromJSON: typeof buildNetworkFromJSON;
61
125
  loadNetwork: typeof loadNetwork;
62
- createKHandle: typeof createKHandle;
63
- graft: typeof graft;
64
- kmeans: typeof kmeans;
65
- correlation: typeof correlation;
66
- ensemble: typeof ensemble;
67
- tracker: typeof tracker;
126
+ saveNetwork: typeof saveNetwork;
127
+ setupWebGPU: typeof setupWebGPU;
128
+ compareDNA: typeof compareDNA;
129
+ defaultTargetPropConfig: typeof defaultTargetPropConfig;
130
+ getInternalParity: typeof getInternalParity;
131
+ trainNetwork: typeof trainNetwork;
132
+ getSpliceConfig: typeof getSpliceConfig;
133
+ getNEATConfig: typeof getNEATConfig;
134
+ createNEATPopulation: typeof createNEATPopulation;
135
+ createTransformer: typeof createTransformer;
136
+ BuildNetworkFromJSON: typeof buildNetworkFromJSON;
137
+ ExtractNetworkBlueprint: typeof ExtractNetworkBlueprint;
138
+ DType: {
139
+ readonly FLOAT64: 0;
140
+ readonly FLOAT32: 1;
141
+ readonly FLOAT16: 2;
142
+ readonly BFLOAT16: 3;
143
+ readonly FP8_E4M3: 4;
144
+ readonly FP8_E5M2: 5;
145
+ readonly INT64: 6;
146
+ readonly INT32: 7;
147
+ readonly INT16: 8;
148
+ readonly INT8: 9;
149
+ readonly UINT64: 10;
150
+ readonly UINT32: 11;
151
+ readonly UINT16: 12;
152
+ readonly UINT8: 13;
153
+ readonly INT4: 14;
154
+ readonly UINT4: 15;
155
+ readonly FP4: 16;
156
+ readonly INT2: 17;
157
+ readonly UINT2: 18;
158
+ readonly TERNARY: 19;
159
+ readonly BINARY: 20;
160
+ };
161
+ LayerType: {
162
+ readonly DENSE: 0;
163
+ readonly RMS_NORM: 1;
164
+ readonly LAYER_NORM: 2;
165
+ readonly MHA: 3;
166
+ readonly SOFTMAX: 4;
167
+ readonly SWIGLU: 5;
168
+ readonly EMBEDDING: 6;
169
+ readonly RESIDUAL: 7;
170
+ readonly KMEANS: 8;
171
+ readonly RNN: 9;
172
+ readonly LSTM: 10;
173
+ readonly CNN1: 11;
174
+ readonly CNN2: 12;
175
+ readonly CNN3: 13;
176
+ readonly CONV_TRANSPOSED_1D: 14;
177
+ readonly CONV_TRANSPOSED_2D: 15;
178
+ readonly CONV_TRANSPOSED_3D: 16;
179
+ };
180
+ Activation: {
181
+ readonly RELU: 0;
182
+ readonly SILU: 1;
183
+ readonly GELU: 2;
184
+ readonly TANH: 3;
185
+ readonly SIGMOID: 4;
186
+ readonly LINEAR: 5;
187
+ };
68
188
  };
69
189
  export default _default;
190
+ export type { Network, NEATPopulation, SystolicState, TargetPropState, TrainingBatch, TrainingResult, DNACompareResult };