@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.
- package/LICENSE +200 -200
- package/README.md +64 -353
- package/dist/benchmark_tiling.html +244 -0
- package/dist/benchmark_training.html +249 -0
- package/dist/benchmark_training_comparison.html +230 -0
- package/dist/cabi_verify.html +360 -0
- package/dist/coverage_check.html +298 -0
- package/dist/dna_evo_benchmark.html +420 -0
- package/dist/example.html +283 -0
- package/dist/index.d.ts +152 -31
- package/dist/index.js +170 -60
- package/dist/loader.browser.d.ts +2 -2
- package/dist/loader.browser.js +7 -8
- package/dist/loader.d.ts +2 -2
- package/dist/loader.js +12 -25
- package/dist/main.wasm +0 -0
- package/dist/src/index.d.ts +182 -0
- package/dist/src/index.js +207 -0
- package/dist/src/loader.browser.d.ts +5 -0
- package/dist/src/loader.browser.js +24 -0
- package/dist/src/loader.d.ts +5 -0
- package/dist/src/loader.js +26 -0
- package/dist/src/types.d.ts +354 -0
- package/dist/src/types.js +65 -0
- package/dist/tests/benchmark.d.ts +5 -0
- package/dist/tests/benchmark.js +139 -0
- package/dist/tests/benchmark.ts +148 -0
- package/dist/tests/cabi_verify.d.ts +5 -0
- package/dist/tests/cabi_verify.js +181 -0
- package/dist/tests/cabi_verify.ts +192 -0
- package/dist/tests/coverage.ts +113 -0
- package/dist/types.d.ts +326 -169
- package/dist/types.js +63 -2
- package/dist/wasm_exec.js +575 -575
- package/package.json +87 -88
- package/dist/index.browser.d.ts +0 -32
- package/dist/index.browser.js +0 -39
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loom TypeScript Wrapper 345-Item Parity CLI Auditor
|
|
3
|
+
* --------------------------------------------------
|
|
4
|
+
* Verifies 100% functional parity between @openfluke/welvet and loom-core.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from 'fs';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
10
|
+
import welvet from '../src/index.js';
|
|
11
|
+
|
|
12
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
|
|
14
|
+
async function runCLIParityAudit() {
|
|
15
|
+
console.log("\x1b[36m%s\x1b[0m", "=== Loom TypeScript Wrapper Parity Audit (CLI) ===");
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// 1. Initialize Engine
|
|
19
|
+
await welvet.init();
|
|
20
|
+
const internalParity = welvet.getInternalParity ? welvet.getInternalParity() : [];
|
|
21
|
+
console.log(`\n[INIT] Engine Loaded. ${internalParity.length} internal symbols acquired.`);
|
|
22
|
+
|
|
23
|
+
// 2. Load expected API
|
|
24
|
+
const blueprintPath = path.resolve(__dirname, '../../wasm/expected_api.json');
|
|
25
|
+
const expectedApi = JSON.parse(fs.readFileSync(blueprintPath, 'utf8'));
|
|
26
|
+
|
|
27
|
+
// 3. Functional Proof
|
|
28
|
+
let functionalProof = false;
|
|
29
|
+
try {
|
|
30
|
+
const net = welvet.createNetwork({
|
|
31
|
+
depth: 1, rows: 1, cols: 1, layers_per_cell: 1,
|
|
32
|
+
layers: [{ type: "Dense", input_height: 4, output_height: 4, activation: "ReLU" }]
|
|
33
|
+
});
|
|
34
|
+
const input = new Float32Array(4).fill(0.5);
|
|
35
|
+
const output = net.sequentialForward(input);
|
|
36
|
+
if (output && output.length === 4) functionalProof = true;
|
|
37
|
+
net.free();
|
|
38
|
+
console.log("\x1b[32m%s\x1b[0m", "[PASS] Functional Layer Pass Verified.");
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error("\x1b[31m%s\x1b[0m", "[FAIL] Functional Proof Error: " + (e as Error).message);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 4. Scan
|
|
44
|
+
const results: any[] = [];
|
|
45
|
+
let totalItems = 0;
|
|
46
|
+
let passedItems = 0;
|
|
47
|
+
|
|
48
|
+
for (const [category, items] of Object.entries<any>(expectedApi)) {
|
|
49
|
+
console.log(`\n\x1b[33m[${category}]\x1b[0m`);
|
|
50
|
+
for (const item of items) {
|
|
51
|
+
totalItems++;
|
|
52
|
+
let status = "MISSING";
|
|
53
|
+
let details = "";
|
|
54
|
+
|
|
55
|
+
// Logic sync with check_ts.js
|
|
56
|
+
const camelName = item.name.charAt(0).toLowerCase() + item.name.slice(1);
|
|
57
|
+
|
|
58
|
+
if (welvet[item.name as keyof typeof welvet] ||
|
|
59
|
+
welvet[('create' + item.name) as keyof typeof welvet] ||
|
|
60
|
+
welvet[('load' + item.name) as keyof typeof welvet]) {
|
|
61
|
+
status = "PASS";
|
|
62
|
+
details = "TS Export";
|
|
63
|
+
} else if (welvet.DType && (welvet.DType as any)[item.name.toUpperCase()]) {
|
|
64
|
+
status = "PASS";
|
|
65
|
+
details = "TS Constant";
|
|
66
|
+
} else if (welvet.LayerType && (welvet.LayerType as any)[item.name.toUpperCase()]) {
|
|
67
|
+
status = "PASS";
|
|
68
|
+
details = "TS LayerType";
|
|
69
|
+
} else {
|
|
70
|
+
// Method check on Dummy
|
|
71
|
+
const net = welvet.createNetwork({depth:1, rows:1, cols:1, layers_per_cell:1, layers:[]});
|
|
72
|
+
if (net && (typeof (net as any)[item.name] === 'function' || typeof (net as any)[camelName] === 'function')) {
|
|
73
|
+
status = "PASS";
|
|
74
|
+
details = "Instance Method";
|
|
75
|
+
} else if (internalParity.includes(item.name)) {
|
|
76
|
+
status = "PASS";
|
|
77
|
+
details = "Engine Internal (Indirect)";
|
|
78
|
+
}
|
|
79
|
+
if (net) net.free();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (status === "PASS") {
|
|
83
|
+
passedItems++;
|
|
84
|
+
process.stdout.write(`\x1b[32m.\x1b[0m`);
|
|
85
|
+
} else {
|
|
86
|
+
console.log(`\n \x1b[31m[MISSING] ${item.name}\x1b[0m`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const coverage = (passedItems / totalItems) * 100;
|
|
92
|
+
console.log(`\n\nFinal Report:`);
|
|
93
|
+
console.log(`---------------------------------`);
|
|
94
|
+
console.log(`Items Scanned : ${totalItems}`);
|
|
95
|
+
console.log(`Items Passed : ${passedItems}`);
|
|
96
|
+
console.log(`Coverage : ${coverage.toFixed(2)}%`);
|
|
97
|
+
console.log(`---------------------------------`);
|
|
98
|
+
|
|
99
|
+
if (coverage === 100) {
|
|
100
|
+
console.log("\x1b[32m%s\x1b[0m", "FULL PARITY ACHIEVED.");
|
|
101
|
+
process.exit(0);
|
|
102
|
+
} else {
|
|
103
|
+
console.log("\x1b[31m%s\x1b[0m", "INCOMPLETE PARITY.");
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
} catch (e) {
|
|
108
|
+
console.error("Critical Failure:", e);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
runCLIParityAudit();
|
package/dist/types.d.ts
CHANGED
|
@@ -1,201 +1,358 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Type
|
|
2
|
+
* welvet — Type Definitions for the M-POLY-VTD AI Engine
|
|
3
|
+
*
|
|
4
|
+
* Wraps the Loom v0.75.0 WASM module which supports 21 numerical types,
|
|
5
|
+
* systolic grid propagation, target propagation, and WebGPU acceleration.
|
|
3
6
|
*/
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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;
|
|
133
149
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
*
|
|
143
|
-
* @param
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
|
|
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;
|
|
153
174
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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;
|
|
167
202
|
}
|
|
168
|
-
export interface
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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;
|
|
174
220
|
}
|
|
175
|
-
export interface
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
+
extractNetworkBlueprint(modelID?: string): string;
|
|
243
|
+
/** Alias for extractNetworkBlueprint */
|
|
244
|
+
extractBlueprint(modelID?: string): string;
|
|
245
|
+
/** Total number of layers in the network. */
|
|
246
|
+
getLayerCount(): number;
|
|
247
|
+
/**
|
|
248
|
+
* Get the specification of a single layer.
|
|
249
|
+
* @param layerIdx 0-based layer index
|
|
250
|
+
* @returns JSON string with layer spec
|
|
251
|
+
*/
|
|
252
|
+
getLayerSpec(layerIdx: number): string;
|
|
253
|
+
/**
|
|
254
|
+
* Switch a layer's numerical type at runtime (zero-cost when cached).
|
|
255
|
+
* @param layerIdx 0-based layer index
|
|
256
|
+
* @param dtype DType constant
|
|
257
|
+
* @returns JSON status/error
|
|
258
|
+
*/
|
|
259
|
+
morphLayer(layerIdx: number, dtype: DTypeValue): string;
|
|
260
|
+
/**
|
|
261
|
+
* Initialize WebGPU for this network.
|
|
262
|
+
* @returns Promise that resolves with status JSON
|
|
263
|
+
*/
|
|
264
|
+
initGPU(): Promise<string>;
|
|
265
|
+
/**
|
|
266
|
+
* Upload all layer weights to GPU buffers.
|
|
267
|
+
* @returns Promise that resolves with status JSON
|
|
268
|
+
*/
|
|
269
|
+
syncToGPU(): Promise<string>;
|
|
270
|
+
/** Download weights back to CPU and disable GPU mode. */
|
|
271
|
+
syncToCPU(): void;
|
|
272
|
+
/**
|
|
273
|
+
* High-level supervised training loop.
|
|
274
|
+
* @param batchesJSON JSON string of TrainingBatch[]
|
|
275
|
+
* @param epochs Number of epochs
|
|
276
|
+
* @param lr Learning rate
|
|
277
|
+
* @returns JSON string with TrainingResult
|
|
278
|
+
*/
|
|
279
|
+
train(batchesJSON: string, epochs: number, lr: number): string;
|
|
280
|
+
/**
|
|
281
|
+
* Create a SystolicState for the stepping API.
|
|
282
|
+
*/
|
|
283
|
+
createSystolicState(): SystolicState;
|
|
284
|
+
/**
|
|
285
|
+
* Create a TargetPropState for gradient-free learning.
|
|
286
|
+
* @param useChainRule If true, uses chain-rule backprop instead of gap-based TP
|
|
287
|
+
*/
|
|
288
|
+
createTargetPropState(useChainRule?: boolean): TargetPropState;
|
|
289
|
+
/**
|
|
290
|
+
* Genetic crossover with another network.
|
|
291
|
+
* @param otherID The `_id` of the other parent network
|
|
292
|
+
* @param cfgJSON JSON string from defaultSpliceConfig()
|
|
293
|
+
*/
|
|
294
|
+
spliceDNA(otherID: number, cfgJSON: string): Network;
|
|
295
|
+
/**
|
|
296
|
+
* NEAT-style structural mutation.
|
|
297
|
+
* @param cfgJSON JSON string from defaultNEATConfig()
|
|
298
|
+
*/
|
|
299
|
+
neatMutate(cfgJSON: string): Network;
|
|
300
|
+
/** Internal handle ID — required for spliceDNA and population operations. */
|
|
301
|
+
_id: number;
|
|
302
|
+
/** Release resources (no-op in WASM, included for API parity). */
|
|
303
|
+
free(): void;
|
|
304
|
+
/**
|
|
305
|
+
* Low-level polymorphic forward pass.
|
|
306
|
+
* @param input Input tensor data
|
|
307
|
+
*/
|
|
308
|
+
forwardPolymorphic(input: Float32Array | number[]): Float32Array;
|
|
309
|
+
/**
|
|
310
|
+
* Get an individual layer wrapper.
|
|
311
|
+
* @param index 0-based layer index
|
|
312
|
+
*/
|
|
313
|
+
getLayer(index: number): Layer;
|
|
181
314
|
}
|
|
182
|
-
export interface
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
315
|
+
export interface Layer {
|
|
316
|
+
/** Internal handle ID. */
|
|
317
|
+
_id: number;
|
|
318
|
+
/**
|
|
319
|
+
* Dispatch a forward pass through this layer only.
|
|
320
|
+
* @param input Input tensor
|
|
321
|
+
*/
|
|
322
|
+
dispatch(input: Float32Array | number[]): Float32Array;
|
|
323
|
+
/** Sync weights to GPU. */
|
|
324
|
+
syncToGPU(): Promise<void>;
|
|
325
|
+
/** Release resources. */
|
|
326
|
+
free(): void;
|
|
186
327
|
}
|
|
187
|
-
export interface
|
|
188
|
-
|
|
189
|
-
|
|
328
|
+
export interface DNACompareResult {
|
|
329
|
+
similarity: number;
|
|
330
|
+
layer_count_match: boolean;
|
|
331
|
+
depth_match: boolean;
|
|
332
|
+
architecture_match: boolean;
|
|
333
|
+
[key: string]: unknown;
|
|
190
334
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
335
|
+
declare global {
|
|
336
|
+
/** Build a VolumetricNetwork from a JSON config string. */
|
|
337
|
+
function createLoomNetwork(jsonConfig: string): Network;
|
|
338
|
+
/** Load a network from a SafeTensors file path. */
|
|
339
|
+
function loadLoomNetwork(path: string): Network;
|
|
340
|
+
/** Initialize WebGPU (returns a Promise). */
|
|
341
|
+
function setupWebGPU(): Promise<string>;
|
|
342
|
+
/** Compare two DNA JSON strings for architectural similarity. */
|
|
343
|
+
function compareLoomDNA(dnaA: string, dnaB: string): string;
|
|
344
|
+
/** Get the default TargetPropConfig. */
|
|
345
|
+
function getDefaultTargetPropConfig(): string;
|
|
346
|
+
/** Get the default SpliceConfig JSON string. */
|
|
347
|
+
function defaultSpliceConfig(): string;
|
|
348
|
+
/** Get the default NEATConfig JSON string for a given model dimension. */
|
|
349
|
+
function defaultNEATConfig(dModel: number): string;
|
|
350
|
+
/** Create a NEAT population from a seed network. */
|
|
351
|
+
function createLoomNEATPopulation(seedID: number, size: number, cfgJSON: string): NEATPopulation;
|
|
352
|
+
/** Create a Transformer from a network and weights. */
|
|
353
|
+
function createLoomTransformer(networkID: number, embeddings: Float32Array | number[], lmHead: Float32Array | number[], finalNorm: Float32Array | number[]): Transformer;
|
|
354
|
+
/** Get the internal parity symbol list from Go. */
|
|
355
|
+
function getLoomInternalParity(): string[];
|
|
356
|
+
/** Build a network from a JSON string. */
|
|
357
|
+
function BuildNetworkFromJSON(json: string): Network;
|
|
201
358
|
}
|