@openfluke/welvet 0.2.0 → 0.74.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.
package/dist/types.d.ts CHANGED
@@ -1,200 +1,299 @@
1
1
  /**
2
- * Type definitions for LOOM WASM API
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.
3
6
  */
4
- export interface LayerConfig {
5
- type: string;
6
- input_size?: number;
7
- output_size?: number;
8
- hidden_size?: number;
9
- activation?: string;
10
- combine_mode?: string;
11
- grid_output_rows?: number;
12
- grid_output_cols?: number;
13
- grid_output_layers?: number;
14
- grid_positions?: GridPosition[];
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;
15
67
  input_height?: number;
16
- output_height?: number;
17
68
  input_width?: number;
69
+ input_depth?: number;
70
+ output_height?: number;
71
+ output_width?: number;
72
+ output_depth?: number;
18
73
  input_channels?: number;
19
- output_channels?: number;
74
+ filters?: number;
20
75
  kernel_size?: number;
21
76
  stride?: number;
22
77
  padding?: number;
23
- filters?: number;
24
- d_model?: number;
25
78
  num_heads?: number;
79
+ num_kv_heads?: number;
80
+ d_model?: number;
26
81
  seq_length?: number;
27
- norm_size?: number;
28
82
  vocab_size?: number;
29
83
  embedding_dim?: number;
30
- epsilon?: number;
31
- softmax_variant?: string;
32
- temperature?: number;
33
- residual?: boolean;
34
- filter_gate?: LayerConfig;
35
- filter_temperature?: number;
36
- branches?: LayerConfig[];
84
+ z?: number;
85
+ y?: number;
86
+ x?: number;
87
+ l?: number;
88
+ tile_size?: number;
37
89
  }
38
90
  export interface NetworkConfig {
39
- batch_size: number;
40
- grid_rows?: number;
41
- grid_cols?: number;
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 */
42
98
  layers_per_cell?: number;
43
- layers: LayerConfig[];
44
- }
45
- export interface GridPosition {
46
- branch_index: number;
47
- target_row: number;
48
- target_col: number;
49
- target_layer: number;
99
+ /** Layer definitions (flat list, laid out z→y→x→l) */
100
+ layers: LayerSpec[];
50
101
  }
51
102
  export interface TrainingBatch {
52
- Input: number[];
53
- Target: number[];
54
- }
55
- export interface TrainingConfig {
56
- Epochs: number;
57
- LearningRate: number;
58
- LossType?: string;
59
- Verbose?: boolean;
60
- UseGPU?: boolean;
61
- PrintEveryBatch?: number;
62
- GradientClip?: number;
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[];
63
109
  }
64
110
  export interface TrainingResult {
65
111
  final_loss: number;
66
112
  duration_ms: number;
67
113
  epochs_completed: number;
114
+ loss_history?: number[];
68
115
  }
69
- /**
70
- * Network interface with all available methods
71
- * All methods take a JSON string of parameters (JSON array)
72
- * and return a JSON string of results (JSON array)
73
- */
74
- export interface Network {
75
- ForwardCPU(inputsJSON: string): string;
76
- ForwardGPU(inputsJSON: string): string;
77
- BackwardCPU(gradientsJSON: string): string;
78
- BackwardGPU(gradientsJSON: string): string;
79
- UpdateWeights(paramsJSON: string): string;
80
- Train(paramsJSON: string): string;
81
- ZeroGradients(paramsJSON: string): string;
82
- ResetGradients(paramsJSON: string): string;
83
- SaveModelToString(paramsJSON: string): string;
84
- SerializeModel(paramsJSON: string): string;
85
- GetWeights(paramsJSON: string): string;
86
- SetWeights(paramsJSON: string): string;
87
- GetBiases(paramsJSON: string): string;
88
- SetBiases(paramsJSON: string): string;
89
- GetLayer(paramsJSON: string): string;
90
- SetLayer(paramsJSON: string): string;
91
- GetActivation(paramsJSON: string): string;
92
- SetActivation(paramsJSON: string): string;
93
- GetLayerType(paramsJSON: string): string;
94
- GetLayerSizes(paramsJSON: string): string;
95
- GetBatchSize(paramsJSON: string): string;
96
- SetBatchSize(paramsJSON: string): string;
97
- GetGridDimensions(paramsJSON: string): string;
98
- GetLayersPerCell(paramsJSON: string): string;
99
- TotalLayers(paramsJSON: string): string;
100
- GetNetworkInfo(paramsJSON: string): string;
101
- GetTotalParameters(paramsJSON: string): string;
102
- GetMemoryUsage(paramsJSON: string): string;
103
- ValidateArchitecture(paramsJSON: string): string;
104
- GetLastOutput(paramsJSON: string): string;
105
- GetLastGradients(paramsJSON: string): string;
106
- Activations(paramsJSON: string): string;
107
- KernelGradients(paramsJSON: string): string;
108
- BiasGradients(paramsJSON: string): string;
109
- Clone(paramsJSON: string): string;
110
- InitializeWeights(paramsJSON: string): string;
111
- InitGPU(paramsJSON: string): string;
112
- ReleaseGPU(paramsJSON: string): string;
113
- GetMethods(paramsJSON: string): string;
114
- GetMethodsJSON(paramsJSON: string): string;
115
- ListMethods(paramsJSON: string): string;
116
- HasMethod(paramsJSON: string): string;
117
- GetMethodSignature(paramsJSON: string): string;
118
- ApplyGradients(paramsJSON: string): string;
119
- ApplyGradientsAdamW(paramsJSON: string): string;
120
- ApplyGradientsRMSprop(paramsJSON: string): string;
121
- ApplyGradientsSGDMomentum(paramsJSON: string): string;
122
- createStepState(inputSize: number): StepState;
123
- createTweenState(useChainRule?: boolean): TweenState;
124
- }
125
- /**
126
- * StepState interface for stepping execution
127
- */
128
- export interface StepState {
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
+ */
129
121
  setInput(data: Float32Array | number[]): void;
130
- stepForward(): number;
131
- getOutput(): Float32Array;
132
- stepBackward(gradients: Float32Array | number[]): Float32Array;
133
- }
134
- /**
135
- * TweenState interface for neural tweening execution
136
- */
137
- export interface TweenState {
138
- /**
139
- * Perform a tween training step
140
- * @param input - Input data
141
- * @param targetClass - Target class index
142
- * @param outputSize - Size of output layer
143
- * @param learningRate - Learning rate for this step
144
- * @returns Loss value
145
- */
146
- TweenStep(input: Float32Array | number[], targetClass: number, outputSize: number, learningRate: number): number;
147
- /** Enable/disable chain rule mode */
148
- setChainRule(enabled: boolean): void;
149
- /** Get current chain rule setting */
150
- getChainRule(): boolean;
151
- /** Get number of tween steps performed */
152
- getTweenSteps(): number;
153
- }
154
- /**
155
- * Global WASM functions exposed by main.go
156
- * Only createLoomNetwork is exposed - use network.SaveModelToString() for saving
157
- */
158
- declare global {
159
- function createLoomNetwork(jsonConfig: string): Network;
160
- function createAdaptationTracker(windowMs: number, totalMs: number): AdaptationTracker;
161
- function createNetworkForGraft(jsonConfig: string): number;
162
- function graftNetworks(idsJSON: string, combineMode: string): string;
163
- function kmeansCluster(dataJSON: string, k: number, iter: number): string;
164
- function computeCorrelation(matrixAJSON: string, matrixBJSON: string): string;
165
- function findComplementaryMatches(modelsJSON: string, minCoverage: number): string;
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;
166
149
  }
167
- export interface EnsembleMatch {
168
- ModelA: string;
169
- ModelB: string;
170
- Coverage: number;
171
- Overlap: number;
172
- WeightedAcc?: number;
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;
173
174
  }
174
- export interface GraftResult {
175
- success: boolean;
176
- type: string;
177
- num_branches: number;
178
- combine_mode: string;
179
- error?: string;
175
+ export interface NEATPopulation {
176
+ /** Internal handle ID. */
177
+ _id: number;
178
+ /** Number of networks in the population. */
179
+ size: number;
180
+ /** Get a network wrapper by index. */
181
+ getNetwork(index: number): Network;
182
+ /** Run one generation given pre-computed fitnesses (length must equal size). */
183
+ evolveWithFitnesses(fitnesses: number[]): void;
184
+ /** Return the best-performing network wrapper. */
185
+ best(): Network;
186
+ /** Return the best fitness score. */
187
+ bestFitness(): number;
188
+ /** Human-readable generation summary. */
189
+ summary(generation: number): string;
190
+ /** Release resources. */
191
+ free(): void;
180
192
  }
181
- export interface KMeansResult {
182
- centroids: number[][];
183
- assignment: number[];
184
- silhouette_score: number;
193
+ export interface Network {
194
+ /**
195
+ * Full sequential forward pass through the network.
196
+ * @param input Float32Array or number[] of inputs
197
+ * @returns Output as Float32Array
198
+ */
199
+ sequentialForward(input: Float32Array | number[]): Float32Array;
200
+ /**
201
+ * Returns a JSON string with network shape info.
202
+ * {depth, rows, cols, layers_per_cell, total_layers, use_gpu, default_dtype}
203
+ */
204
+ getInfo(): string;
205
+ /**
206
+ * Extract the network's DNA fingerprint as a JSON string.
207
+ * Use compareLoomDNA() to compare two fingerprints.
208
+ */
209
+ extractDNA(): string;
210
+ /**
211
+ * Extract the network's full blueprint as a JSON string.
212
+ * @param modelID Optional model identifier
213
+ */
214
+ extractBlueprint(modelID?: string): string;
215
+ /** Total number of layers in the network. */
216
+ getLayerCount(): number;
217
+ /**
218
+ * Get the specification of a single layer.
219
+ * @param layerIdx 0-based layer index
220
+ * @returns JSON string with layer spec
221
+ */
222
+ getLayerSpec(layerIdx: number): string;
223
+ /**
224
+ * Switch a layer's numerical type at runtime (zero-cost when cached).
225
+ * @param layerIdx 0-based layer index
226
+ * @param dtype DType constant
227
+ * @returns JSON status/error
228
+ */
229
+ morphLayer(layerIdx: number, dtype: DTypeValue): string;
230
+ /**
231
+ * Initialize WebGPU for this network.
232
+ * @returns Promise that resolves with status JSON
233
+ */
234
+ initGPU(): Promise<string>;
235
+ /**
236
+ * Upload all layer weights to GPU buffers.
237
+ * @returns Promise that resolves with status JSON
238
+ */
239
+ syncToGPU(): Promise<string>;
240
+ /** Download weights back to CPU and disable GPU mode. */
241
+ syncToCPU(): void;
242
+ /**
243
+ * High-level supervised training loop.
244
+ * @param batchesJSON JSON string of TrainingBatch[]
245
+ * @param epochs Number of epochs
246
+ * @param lr Learning rate
247
+ * @returns JSON string with TrainingResult
248
+ */
249
+ train(batchesJSON: string, epochs: number, lr: number): string;
250
+ /**
251
+ * Create a SystolicState for the stepping API.
252
+ */
253
+ createSystolicState(): SystolicState;
254
+ /**
255
+ * Create a TargetPropState for gradient-free learning.
256
+ * @param useChainRule If true, uses chain-rule backprop instead of gap-based TP
257
+ */
258
+ createTargetPropState(useChainRule?: boolean): TargetPropState;
259
+ /**
260
+ * Genetic crossover with another network.
261
+ * @param otherID The `_id` of the other parent network
262
+ * @param cfgJSON JSON string from defaultSpliceConfig()
263
+ */
264
+ spliceDNA(otherID: number, cfgJSON: string): Network;
265
+ /**
266
+ * NEAT-style structural mutation.
267
+ * @param cfgJSON JSON string from defaultNEATConfig()
268
+ */
269
+ neatMutate(cfgJSON: string): Network;
270
+ /** Internal handle ID — required for spliceDNA and population operations. */
271
+ _id: number;
272
+ /** Release resources (no-op in WASM, included for API parity). */
273
+ free(): void;
185
274
  }
186
- export interface CorrelationResult {
187
- pearson: number[][];
188
- spearman: number[][];
275
+ export interface DNACompareResult {
276
+ similarity: number;
277
+ layer_count_match: boolean;
278
+ depth_match: boolean;
279
+ architecture_match: boolean;
280
+ [key: string]: unknown;
189
281
  }
190
- /**
191
- * AdaptationTracker interface for tracking accuracy during task changes
192
- */
193
- export interface AdaptationTracker {
194
- setModelInfo(modelName: string, modeName: string): void;
195
- scheduleTaskChange(atOffsetMs: number, taskID: number, taskName: string): void;
196
- start(initialTask: string, initialTaskID: number): void;
197
- recordOutput(isCorrect: boolean): void;
198
- getCurrentTask(): number;
199
- finalize(): string;
282
+ declare global {
283
+ /** Build a VolumetricNetwork from a JSON config string. */
284
+ function createLoomNetwork(jsonConfig: string): Network;
285
+ /** Load a network from a SafeTensors file path. */
286
+ function loadLoomNetwork(path: string): Network;
287
+ /** Initialize WebGPU (returns a Promise). */
288
+ function setupWebGPU(): Promise<string>;
289
+ /** Compare two DNA JSON strings for architectural similarity. */
290
+ function compareLoomDNA(dnaA: string, dnaB: string): string;
291
+ /** Get the default TargetPropConfig. */
292
+ function getDefaultTargetPropConfig(): string;
293
+ /** Get the default SpliceConfig JSON string. */
294
+ function defaultSpliceConfig(): string;
295
+ /** Get the default NEATConfig JSON string for a given model dimension. */
296
+ function defaultNEATConfig(dModel: number): string;
297
+ /** Create a NEAT population from a seed network. */
298
+ function createLoomNEATPopulation(seedID: number, size: number, cfgJSON: string): NEATPopulation;
200
299
  }
package/dist/types.js CHANGED
@@ -1,4 +1,65 @@
1
1
  /**
2
- * Type definitions for LOOM WASM API
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.
3
6
  */
4
- export {};
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
+ };