@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,207 @@
1
+ /**
2
+ * @openfluke/welvet — M-POLY-VTD AI Engine
3
+ *
4
+ * Isomorphic TypeScript wrapper for the Loom v0.73.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
+ * ```
23
+ */
24
+ import { DType, LayerType, Activation } from "./types.js";
25
+ import { loadLoomWASMBrowser } from "./loader.browser.js";
26
+ // Re-export all types and constants
27
+ export * from "./types.js";
28
+ export { loadLoomWASMBrowser };
29
+ // ──────────────────────────────────────────────────────────────────────────────
30
+ // Initialization
31
+ // ──────────────────────────────────────────────────────────────────────────────
32
+ /**
33
+ * Initialize the welvet WASM module.
34
+ * Auto-detects Node.js vs browser environment.
35
+ *
36
+ * @param wasmUrl Optional custom URL for browser WASM loading (default: /dist/main.wasm)
37
+ */
38
+ export async function init(wasmUrl) {
39
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
40
+ return loadLoomWASMBrowser(wasmUrl);
41
+ }
42
+ const mod = await import("./loader.js");
43
+ return mod.loadLoomWASM();
44
+ }
45
+ /**
46
+ * Initialize explicitly for browser environments.
47
+ * @param wasmUrl Optional custom URL for WASM binary
48
+ */
49
+ export async function initBrowser(wasmUrl) {
50
+ return loadLoomWASMBrowser(wasmUrl);
51
+ }
52
+ // ──────────────────────────────────────────────────────────────────────────────
53
+ // Network Lifecycle
54
+ // ──────────────────────────────────────────────────────────────────────────────
55
+ /**
56
+ * Build a VolumetricNetwork from a JSON configuration object or string.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const net = createNetwork({
61
+ * layers: [
62
+ * { type: "dense", input_height: 784, output_height: 256 },
63
+ * { type: "dense", input_height: 256, output_height: 10, activation: "silu" },
64
+ * ]
65
+ * });
66
+ * ```
67
+ */
68
+ export function createNetwork(config) {
69
+ const jsonConfig = typeof config === "string" ? config : JSON.stringify(config);
70
+ return createLoomNetwork(jsonConfig);
71
+ }
72
+ /**
73
+ * Load a pre-trained network from a SafeTensors file path.
74
+ * (Node.js only — requires file system access)
75
+ *
76
+ * @param path Absolute or relative path to a .safetensors file
77
+ */
78
+ export function loadNetwork(path) {
79
+ return loadLoomNetwork(path);
80
+ }
81
+ // ──────────────────────────────────────────────────────────────────────────────
82
+ // WebGPU
83
+ // ──────────────────────────────────────────────────────────────────────────────
84
+ /**
85
+ * Initialize WebGPU (browser only).
86
+ * Sets window.webgpuAdapter, window.webgpuDevice, window.webgpuQueue.
87
+ */
88
+ export async function setupWebGPU() {
89
+ // @ts-ignore — setupWebGPU is injected by the WASM module
90
+ return setupWebGPU();
91
+ }
92
+ // ──────────────────────────────────────────────────────────────────────────────
93
+ // DNA / Introspection
94
+ // ──────────────────────────────────────────────────────────────────────────────
95
+ /**
96
+ * Compare the architectural DNA of two networks.
97
+ *
98
+ * @param dnaA JSON string from network.extractDNA()
99
+ * @param dnaB JSON string from network.extractDNA()
100
+ * @returns DNACompareResult
101
+ */
102
+ export function compareDNA(dnaA, dnaB) {
103
+ return JSON.parse(compareLoomDNA(dnaA, dnaB));
104
+ }
105
+ /**
106
+ * Get the default TargetPropConfig.
107
+ */
108
+ export function defaultTargetPropConfig() {
109
+ return JSON.parse(getDefaultTargetPropConfig());
110
+ }
111
+ /**
112
+ * Get the internal parity symbol list from Go.
113
+ * Used for audits and verification.
114
+ */
115
+ export function getInternalParity() {
116
+ if (typeof getLoomInternalParity === "function") {
117
+ return getLoomInternalParity();
118
+ }
119
+ return [];
120
+ }
121
+ // ──────────────────────────────────────────────────────────────────────────────
122
+ // Training Helpers
123
+ // ──────────────────────────────────────────────────────────────────────────────
124
+ /**
125
+ * Convenience wrapper for network.train() that handles JSON serialization.
126
+ *
127
+ * @param network The network to train
128
+ * @param batches Array of {input, target} training pairs
129
+ * @param epochs Number of training epochs
130
+ * @param lr Learning rate
131
+ */
132
+ export function trainNetwork(network, batches, epochs, lr) {
133
+ const serialized = batches.map((b) => {
134
+ const inp = b.input instanceof Float32Array ? b.input : new Float32Array(b.input);
135
+ const tgt = b.target instanceof Float32Array ? b.target : new Float32Array(b.target);
136
+ const inShape = b.inputShape ?? [1, inp.length];
137
+ const tgtShape = b.targetShape ?? [1, tgt.length];
138
+ return {
139
+ input: { shape: inShape, data: Array.from(inp) },
140
+ target: { shape: tgtShape, data: Array.from(tgt) },
141
+ };
142
+ });
143
+ return JSON.parse(network.train(JSON.stringify(serialized), epochs, lr));
144
+ }
145
+ // ──────────────────────────────────────────────────────────────────────────────
146
+ // Evolution / DNA
147
+ // ──────────────────────────────────────────────────────────────────────────────
148
+ /** Get the default SpliceConfig as a plain object. */
149
+ export function getSpliceConfig() {
150
+ return JSON.parse(globalThis["defaultSpliceConfig"]());
151
+ }
152
+ /** Get the default NEATConfig as a plain object. */
153
+ export function getNEATConfig(dModel) {
154
+ return JSON.parse(globalThis["defaultNEATConfig"](dModel));
155
+ }
156
+ /**
157
+ * Create a NEAT population from a seed network.
158
+ * @param network Seed network (its _id is used)
159
+ * @param size Population size
160
+ * @param cfg NEATConfig object or JSON string (defaults to getNEATConfig(64))
161
+ */
162
+ export function createNEATPopulation(network, size, cfg) {
163
+ const cfgJSON = cfg
164
+ ? (typeof cfg === "string" ? cfg : JSON.stringify(cfg))
165
+ : globalThis["defaultNEATConfig"](64);
166
+ return globalThis["createLoomNEATPopulation"](network._id, size, cfgJSON);
167
+ }
168
+ /**
169
+ * Create a Transformer wrapper.
170
+ * @param network Network to use as the base
171
+ * @param embeddings Float32Array of embedding weights
172
+ * @param lmHead Float32Array of LM head weights
173
+ * @param finalNorm Float32Array of final norm weights
174
+ */
175
+ export function createTransformer(network, embeddings, lmHead, finalNorm) {
176
+ return createLoomTransformer(network._id, embeddings, lmHead, finalNorm);
177
+ }
178
+ /**
179
+ * Save a network to a SafeTensors byte array.
180
+ */
181
+ export function saveNetwork(network) {
182
+ // @ts-ignore
183
+ return network.saveSafetensors();
184
+ }
185
+ // ──────────────────────────────────────────────────────────────────────────────
186
+ // Default export
187
+ // ──────────────────────────────────────────────────────────────────────────────
188
+ export default {
189
+ init,
190
+ initBrowser,
191
+ createNetwork,
192
+ loadNetwork,
193
+ saveNetwork,
194
+ setupWebGPU,
195
+ compareDNA,
196
+ defaultTargetPropConfig,
197
+ getInternalParity,
198
+ trainNetwork,
199
+ getSpliceConfig,
200
+ getNEATConfig,
201
+ createNEATPopulation,
202
+ createTransformer,
203
+ // Re-export constants for convenience
204
+ DType,
205
+ LayerType,
206
+ Activation,
207
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * welvet WASM Browser Loader
3
+ * Loads the Go runtime and WASM module in a browser environment.
4
+ */
5
+ export declare function loadLoomWASMBrowser(wasmUrl?: string): Promise<void>;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * welvet WASM Browser Loader
3
+ * Loads the Go runtime and WASM module in a browser environment.
4
+ */
5
+ export async function loadLoomWASMBrowser(wasmUrl) {
6
+ // Inject wasm_exec.js if the Go runtime is not yet available
7
+ if (typeof globalThis["Go"] === "undefined") {
8
+ const script = document.createElement("script");
9
+ script.src = "/dist/wasm_exec.js";
10
+ await new Promise((resolve, reject) => {
11
+ script.onload = () => resolve();
12
+ script.onerror = () => reject(new Error("Failed to load wasm_exec.js"));
13
+ document.head.appendChild(script);
14
+ });
15
+ }
16
+ const response = await fetch(wasmUrl ?? "/dist/main.wasm");
17
+ const wasmBuffer = await response.arrayBuffer();
18
+ // @ts-ignore — Go is injected by wasm_exec.js
19
+ const go = new Go();
20
+ const { instance } = await WebAssembly.instantiate(wasmBuffer, go.importObject);
21
+ go.run(instance);
22
+ // Allow Go goroutines to settle
23
+ await new Promise((resolve) => setTimeout(resolve, 100));
24
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * welvet WASM Loader — Node.js
3
+ * Loads and initializes the welvet WebAssembly module.
4
+ */
5
+ export declare function loadLoomWASM(): Promise<void>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * welvet WASM Loader — Node.js
3
+ * Loads and initializes the welvet WebAssembly module.
4
+ */
5
+ export async function loadLoomWASM() {
6
+ const fs = await import("fs");
7
+ const url = await import("url");
8
+ const path = await import("path");
9
+ const __filename = url.fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+ // Resolve root: dist/ in production, or one level up from src/
12
+ const root = __dirname.endsWith("dist")
13
+ ? __dirname
14
+ : path.join(__dirname, "..", "dist");
15
+ // Bootstrap Go runtime
16
+ const wasmExecCode = fs.readFileSync(path.join(root, "wasm_exec.js"), "utf-8");
17
+ eval(wasmExecCode);
18
+ // Load and instantiate the WASM module
19
+ const wasmBuffer = fs.readFileSync(path.join(root, "main.wasm"));
20
+ // @ts-ignore — Go is injected by wasm_exec.js
21
+ const go = new Go();
22
+ const { instance } = await WebAssembly.instantiate(wasmBuffer, go.importObject);
23
+ go.run(instance);
24
+ // Allow Go goroutines to settle
25
+ await new Promise((resolve) => setTimeout(resolve, 100));
26
+ }
@@ -0,0 +1,354 @@
1
+ /**
2
+ * welvet — Type Definitions for the M-POLY-VTD AI Engine
3
+ *
4
+ * Wraps the Loom v0.73.0 WASM module which supports 21 numerical types,
5
+ * systolic grid propagation, target propagation, and WebGPU acceleration.
6
+ */
7
+ export declare const DType: {
8
+ readonly FLOAT64: 0;
9
+ readonly FLOAT32: 1;
10
+ readonly FLOAT16: 2;
11
+ readonly BFLOAT16: 3;
12
+ readonly FP8_E4M3: 4;
13
+ readonly FP8_E5M2: 5;
14
+ readonly INT64: 6;
15
+ readonly INT32: 7;
16
+ readonly INT16: 8;
17
+ readonly INT8: 9;
18
+ readonly UINT64: 10;
19
+ readonly UINT32: 11;
20
+ readonly UINT16: 12;
21
+ readonly UINT8: 13;
22
+ readonly INT4: 14;
23
+ readonly UINT4: 15;
24
+ readonly FP4: 16;
25
+ readonly INT2: 17;
26
+ readonly UINT2: 18;
27
+ readonly TERNARY: 19;
28
+ readonly BINARY: 20;
29
+ };
30
+ export type DTypeValue = typeof DType[keyof typeof DType];
31
+ export declare const LayerType: {
32
+ readonly DENSE: 0;
33
+ readonly RMS_NORM: 1;
34
+ readonly LAYER_NORM: 2;
35
+ readonly MHA: 3;
36
+ readonly SOFTMAX: 4;
37
+ readonly SWIGLU: 5;
38
+ readonly EMBEDDING: 6;
39
+ readonly RESIDUAL: 7;
40
+ readonly KMEANS: 8;
41
+ readonly RNN: 9;
42
+ readonly LSTM: 10;
43
+ readonly CNN1: 11;
44
+ readonly CNN2: 12;
45
+ readonly CNN3: 13;
46
+ readonly CONV_TRANSPOSED_1D: 14;
47
+ readonly CONV_TRANSPOSED_2D: 15;
48
+ readonly CONV_TRANSPOSED_3D: 16;
49
+ };
50
+ export type LayerTypeValue = typeof LayerType[keyof typeof LayerType];
51
+ export declare const Activation: {
52
+ readonly RELU: 0;
53
+ readonly SILU: 1;
54
+ readonly GELU: 2;
55
+ readonly TANH: 3;
56
+ readonly SIGMOID: 4;
57
+ readonly LINEAR: 5;
58
+ };
59
+ export type ActivationValue = typeof Activation[keyof typeof Activation];
60
+ export interface LayerSpec {
61
+ /** Layer type (use LayerType constants) */
62
+ type: string | number;
63
+ /** Numerical precision (use DType constants, default: FLOAT32) */
64
+ dtype?: number;
65
+ /** Activation function (use Activation constants) */
66
+ activation?: string | number;
67
+ input_height?: number;
68
+ input_width?: number;
69
+ input_depth?: number;
70
+ output_height?: number;
71
+ output_width?: number;
72
+ output_depth?: number;
73
+ input_channels?: number;
74
+ filters?: number;
75
+ kernel_size?: number;
76
+ stride?: number;
77
+ padding?: number;
78
+ num_heads?: number;
79
+ num_kv_heads?: number;
80
+ d_model?: number;
81
+ seq_length?: number;
82
+ vocab_size?: number;
83
+ embedding_dim?: number;
84
+ z?: number;
85
+ y?: number;
86
+ x?: number;
87
+ l?: number;
88
+ tile_size?: number;
89
+ }
90
+ export interface NetworkConfig {
91
+ /** Grid depth (number of z-planes). Default: 1 */
92
+ depth?: number;
93
+ /** Grid rows (y-dimension). Default: 1 */
94
+ rows?: number;
95
+ /** Grid columns (x-dimension). Default: 1 */
96
+ cols?: number;
97
+ /** Layers per cell. Default: number of layers */
98
+ layers_per_cell?: number;
99
+ /** Layer definitions (flat list, laid out z→y→x→l) */
100
+ layers: LayerSpec[];
101
+ }
102
+ export interface TrainingBatch {
103
+ input: number[] | Float32Array;
104
+ target: number[] | Float32Array;
105
+ /** Optional batch shape for input, e.g. [batchSize, features]. Defaults to [1, length]. */
106
+ inputShape?: number[];
107
+ /** Optional batch shape for target, e.g. [batchSize, outputs]. Defaults to [1, length]. */
108
+ targetShape?: number[];
109
+ }
110
+ export interface TrainingResult {
111
+ final_loss: number;
112
+ duration_ms: number;
113
+ epochs_completed: number;
114
+ loss_history?: number[];
115
+ }
116
+ export interface SystolicState {
117
+ /**
118
+ * Inject input into the first layer of the grid.
119
+ * @param data Float32Array or number[] of input values
120
+ */
121
+ setInput(data: Float32Array | number[]): void;
122
+ /**
123
+ * Advance the systolic grid by one clock cycle.
124
+ * @param captureHistory Whether to store history for backpropagation
125
+ * @returns Duration of the step in milliseconds
126
+ */
127
+ step(captureHistory?: boolean): number;
128
+ /**
129
+ * Read the output of a layer (default: last active layer).
130
+ * @param layerIdx Optional layer index (0-based)
131
+ */
132
+ getOutput(layerIdx?: number): Float32Array;
133
+ /**
134
+ * Backpropagate gradients through the stored history.
135
+ * @param gradients Output gradient (Float32Array or number[])
136
+ * @returns Input gradient as Float32Array
137
+ */
138
+ backward(gradients: Float32Array | number[]): Float32Array;
139
+ /**
140
+ * Apply target propagation (gradient-free alternative to backward).
141
+ * @param target Global target tensor
142
+ * @param lr Learning rate
143
+ */
144
+ applyTargetProp(target: Float32Array | number[], lr: number): void;
145
+ /** Total number of systolic steps executed. */
146
+ stepCount(): number;
147
+ /** Release resources (no-op in WASM, included for API parity). */
148
+ free(): void;
149
+ }
150
+ export interface TargetPropState {
151
+ /**
152
+ * Forward pass through all layers, storing local targets.
153
+ * @param input Input data
154
+ * @returns Output as Float32Array
155
+ */
156
+ forward(input: Float32Array | number[]): Float32Array;
157
+ /**
158
+ * Backward pass using target propagation (gap-based, no chain rule).
159
+ * @param target Desired output
160
+ */
161
+ backward(target: Float32Array | number[]): void;
162
+ /**
163
+ * Backward pass using the chain rule (standard backprop via TP state).
164
+ * @param target Desired output
165
+ */
166
+ backwardChainRule(target: Float32Array | number[]): void;
167
+ /**
168
+ * Apply accumulated gap gradients to all layer weights.
169
+ * @param lr Learning rate
170
+ */
171
+ applyGaps(lr?: number): void;
172
+ /** Release resources (no-op in WASM). */
173
+ free(): void;
174
+ }
175
+ export interface Transformer {
176
+ /** Internal handle ID. */
177
+ _id: number;
178
+ /**
179
+ * Run a full prefill/inference pass.
180
+ * @param tokens Array of token IDs
181
+ * @returns Predicted logit tensor as Float32Array
182
+ */
183
+ forwardFull(tokens: number[] | Uint32Array): Float32Array;
184
+ /**
185
+ * Run inference using WebGPU acceleration.
186
+ * @param tokens Array of token IDs
187
+ * @returns Predicted logit tensor as Float32Array
188
+ */
189
+ forwardTokenIDsWGPU(tokens: number[] | Uint32Array): Promise<Float32Array>;
190
+ /**
191
+ * High-level prefill on GPU.
192
+ * @param tokens Array of token IDs
193
+ */
194
+ forwardWGPU(tokens: number[] | Uint32Array): Promise<void>;
195
+ /**
196
+ * Convert tokens to a tensor representation using the embedding layer.
197
+ * @param tokens Array of token IDs
198
+ */
199
+ tokensToTensor(tokens: number[] | Uint32Array): Float32Array;
200
+ /** Release resources. */
201
+ free(): void;
202
+ }
203
+ export interface NEATPopulation {
204
+ /** Internal handle ID. */
205
+ _id: number;
206
+ /** Number of networks in the population. */
207
+ size: number;
208
+ /** Get a network wrapper by index. */
209
+ getNetwork(index: number): Network;
210
+ /** Run one generation given pre-computed fitnesses (length must equal size). */
211
+ evolveWithFitnesses(fitnesses: number[]): void;
212
+ /** Return the best-performing network wrapper. */
213
+ best(): Network;
214
+ /** Return the best fitness score. */
215
+ bestFitness(): number;
216
+ /** Human-readable generation summary. */
217
+ summary(generation: number): string;
218
+ /** Release resources. */
219
+ free(): void;
220
+ }
221
+ export interface Network {
222
+ /**
223
+ * Full sequential forward pass through the network.
224
+ * @param input Float32Array or number[] of inputs
225
+ * @returns Output as Float32Array
226
+ */
227
+ sequentialForward(input: Float32Array | number[]): Float32Array;
228
+ /**
229
+ * Returns a JSON string with network shape info.
230
+ * {depth, rows, cols, layers_per_cell, total_layers, use_gpu, default_dtype}
231
+ */
232
+ getInfo(): string;
233
+ /**
234
+ * Extract the network's DNA fingerprint as a JSON string.
235
+ * Use compareLoomDNA() to compare two fingerprints.
236
+ */
237
+ extractDNA(): string;
238
+ /**
239
+ * Extract the network's full blueprint as a JSON string.
240
+ * @param modelID Optional model identifier
241
+ */
242
+ extractBlueprint(modelID?: string): string;
243
+ /** Total number of layers in the network. */
244
+ getLayerCount(): number;
245
+ /**
246
+ * Get the specification of a single layer.
247
+ * @param layerIdx 0-based layer index
248
+ * @returns JSON string with layer spec
249
+ */
250
+ getLayerSpec(layerIdx: number): string;
251
+ /**
252
+ * Switch a layer's numerical type at runtime (zero-cost when cached).
253
+ * @param layerIdx 0-based layer index
254
+ * @param dtype DType constant
255
+ * @returns JSON status/error
256
+ */
257
+ morphLayer(layerIdx: number, dtype: DTypeValue): string;
258
+ /**
259
+ * Initialize WebGPU for this network.
260
+ * @returns Promise that resolves with status JSON
261
+ */
262
+ initGPU(): Promise<string>;
263
+ /**
264
+ * Upload all layer weights to GPU buffers.
265
+ * @returns Promise that resolves with status JSON
266
+ */
267
+ syncToGPU(): Promise<string>;
268
+ /** Download weights back to CPU and disable GPU mode. */
269
+ syncToCPU(): void;
270
+ /**
271
+ * High-level supervised training loop.
272
+ * @param batchesJSON JSON string of TrainingBatch[]
273
+ * @param epochs Number of epochs
274
+ * @param lr Learning rate
275
+ * @returns JSON string with TrainingResult
276
+ */
277
+ train(batchesJSON: string, epochs: number, lr: number): string;
278
+ /**
279
+ * Create a SystolicState for the stepping API.
280
+ */
281
+ createSystolicState(): SystolicState;
282
+ /**
283
+ * Create a TargetPropState for gradient-free learning.
284
+ * @param useChainRule If true, uses chain-rule backprop instead of gap-based TP
285
+ */
286
+ createTargetPropState(useChainRule?: boolean): TargetPropState;
287
+ /**
288
+ * Genetic crossover with another network.
289
+ * @param otherID The `_id` of the other parent network
290
+ * @param cfgJSON JSON string from defaultSpliceConfig()
291
+ */
292
+ spliceDNA(otherID: number, cfgJSON: string): Network;
293
+ /**
294
+ * NEAT-style structural mutation.
295
+ * @param cfgJSON JSON string from defaultNEATConfig()
296
+ */
297
+ neatMutate(cfgJSON: string): Network;
298
+ /** Internal handle ID — required for spliceDNA and population operations. */
299
+ _id: number;
300
+ /** Release resources (no-op in WASM, included for API parity). */
301
+ free(): void;
302
+ /**
303
+ * Low-level polymorphic forward pass.
304
+ * @param input Input tensor data
305
+ */
306
+ forwardPolymorphic(input: Float32Array | number[]): Float32Array;
307
+ /**
308
+ * Get an individual layer wrapper.
309
+ * @param index 0-based layer index
310
+ */
311
+ getLayer(index: number): Layer;
312
+ }
313
+ export interface Layer {
314
+ /** Internal handle ID. */
315
+ _id: number;
316
+ /**
317
+ * Dispatch a forward pass through this layer only.
318
+ * @param input Input tensor
319
+ */
320
+ dispatch(input: Float32Array | number[]): Float32Array;
321
+ /** Sync weights to GPU. */
322
+ syncToGPU(): Promise<void>;
323
+ /** Release resources. */
324
+ free(): void;
325
+ }
326
+ export interface DNACompareResult {
327
+ similarity: number;
328
+ layer_count_match: boolean;
329
+ depth_match: boolean;
330
+ architecture_match: boolean;
331
+ [key: string]: unknown;
332
+ }
333
+ declare global {
334
+ /** Build a VolumetricNetwork from a JSON config string. */
335
+ function createLoomNetwork(jsonConfig: string): Network;
336
+ /** Load a network from a SafeTensors file path. */
337
+ function loadLoomNetwork(path: string): Network;
338
+ /** Initialize WebGPU (returns a Promise). */
339
+ function setupWebGPU(): Promise<string>;
340
+ /** Compare two DNA JSON strings for architectural similarity. */
341
+ function compareLoomDNA(dnaA: string, dnaB: string): string;
342
+ /** Get the default TargetPropConfig. */
343
+ function getDefaultTargetPropConfig(): string;
344
+ /** Get the default SpliceConfig JSON string. */
345
+ function defaultSpliceConfig(): string;
346
+ /** Get the default NEATConfig JSON string for a given model dimension. */
347
+ function defaultNEATConfig(dModel: number): string;
348
+ /** Create a NEAT population from a seed network. */
349
+ function createLoomNEATPopulation(seedID: number, size: number, cfgJSON: string): NEATPopulation;
350
+ /** Create a Transformer from a network and weights. */
351
+ function createLoomTransformer(networkID: number, embeddings: Float32Array | number[], lmHead: Float32Array | number[], finalNorm: Float32Array | number[]): Transformer;
352
+ /** Get the internal parity symbol list from Go. */
353
+ function getLoomInternalParity(): string[];
354
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * welvet — Type Definitions for the M-POLY-VTD AI Engine
3
+ *
4
+ * Wraps the Loom v0.73.0 WASM module which supports 21 numerical types,
5
+ * systolic grid propagation, target propagation, and WebGPU acceleration.
6
+ */
7
+ // ──────────────────────────────────────────────────────────────────────────────
8
+ // Numerical Type Constants (matches poly.DType)
9
+ // ──────────────────────────────────────────────────────────────────────────────
10
+ export const DType = {
11
+ FLOAT64: 0,
12
+ FLOAT32: 1,
13
+ FLOAT16: 2,
14
+ BFLOAT16: 3,
15
+ FP8_E4M3: 4,
16
+ FP8_E5M2: 5,
17
+ INT64: 6,
18
+ INT32: 7,
19
+ INT16: 8,
20
+ INT8: 9,
21
+ UINT64: 10,
22
+ UINT32: 11,
23
+ UINT16: 12,
24
+ UINT8: 13,
25
+ INT4: 14,
26
+ UINT4: 15,
27
+ FP4: 16,
28
+ INT2: 17,
29
+ UINT2: 18,
30
+ TERNARY: 19,
31
+ BINARY: 20,
32
+ };
33
+ // ──────────────────────────────────────────────────────────────────────────────
34
+ // Layer Type Constants (matches poly.LayerType)
35
+ // ──────────────────────────────────────────────────────────────────────────────
36
+ export const LayerType = {
37
+ DENSE: 0,
38
+ RMS_NORM: 1,
39
+ LAYER_NORM: 2,
40
+ MHA: 3,
41
+ SOFTMAX: 4,
42
+ SWIGLU: 5,
43
+ EMBEDDING: 6,
44
+ RESIDUAL: 7,
45
+ KMEANS: 8,
46
+ RNN: 9,
47
+ LSTM: 10,
48
+ CNN1: 11,
49
+ CNN2: 12,
50
+ CNN3: 13,
51
+ CONV_TRANSPOSED_1D: 14,
52
+ CONV_TRANSPOSED_2D: 15,
53
+ CONV_TRANSPOSED_3D: 16,
54
+ };
55
+ // ──────────────────────────────────────────────────────────────────────────────
56
+ // Activation Type Constants (matches poly.ActivationType)
57
+ // ──────────────────────────────────────────────────────────────────────────────
58
+ export const Activation = {
59
+ RELU: 0,
60
+ SILU: 1,
61
+ GELU: 2,
62
+ TANH: 3,
63
+ SIGMOID: 4,
64
+ LINEAR: 5,
65
+ };