@openfluke/welvet 0.1.7 β 0.2.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 +0 -0
- package/README.md +222 -251
- package/dist/index.browser.d.ts +0 -0
- package/dist/index.browser.js +0 -0
- package/dist/index.d.ts +31 -1
- package/dist/index.js +56 -1
- package/dist/loader.browser.d.ts +0 -0
- package/dist/loader.browser.js +0 -0
- package/dist/loader.d.ts +0 -0
- package/dist/loader.js +0 -0
- package/dist/main.wasm +0 -0
- package/dist/types.d.ts +49 -1
- package/dist/types.js +0 -0
- package/dist/wasm_exec.js +0 -0
- package/package.json +32 -4
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -1,18 +1,54 @@
|
|
|
1
|
-
# @openfluke/welvet
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
# @openfluke/welvet - LOOM TypeScript/WASM Bindings
|
|
2
|
+
|
|
3
|
+
**Wrapper for Embedding Loom Via External (WASM) Toolchain**
|
|
4
|
+
|
|
5
|
+
High-performance neural network library with **full training in browser/Node.js** via WebAssembly. Zero external dependenciesβjust import and go.
|
|
6
|
+
|
|
7
|
+
## Framework Comparison
|
|
8
|
+
|
|
9
|
+
| Feature Category | Feature | **Loom/welvet** | **TensorFlow.js** | **Brain.js** | **ONNX.js** | **Candle (WASM)** |
|
|
10
|
+
| :--- | :--- | :---: | :---: | :---: | :---: | :---: |
|
|
11
|
+
| **Core** | **Runtime** | WASM (Pure Go) | JS + WebGL | Pure JS | WASM | WASM (Rust) |
|
|
12
|
+
| | **Runtime Dependency** | **None** | Heavy | Light | Light | None |
|
|
13
|
+
| **Loading** | **Safetensors** | β
**Native** | β | β | β | β
|
|
|
14
|
+
| | **Structure Inference** | β
**Auto-Detect** | β | β | β | β |
|
|
15
|
+
| **Training** | **Browser Training** | β
**Full** | β
(Slow) | β
| β | β
|
|
|
16
|
+
| | **Neural Tweening** | β
**Hybrid Engine** | β | β | β | β |
|
|
17
|
+
| | **LR Schedulers** | β
**7 Types** | β
| β οΈ | β | β
|
|
|
18
|
+
| **Layer Support** | **Dense (MLP)** | β
| β
| β
| β
| β
|
|
|
19
|
+
| | **Conv1D/2D** | β
**Native** | β
| β | β
| β
|
|
|
20
|
+
| | **RNN / LSTM** | β
**Full Gate** | β
| β
| β
| β
|
|
|
21
|
+
| | **Transformer (MHA)** | β
(Explicit) | β
| β | β
| β
|
|
|
22
|
+
| | **Parallel / MoE** | β
**Structure** | β (Manual) | β | β | β |
|
|
23
|
+
| | **Sequential Layers** | β
**Native** | β οΈ | β οΈ | β | β οΈ |
|
|
24
|
+
| **Advanced** | **Step-Based Forward** | β
**Unique** | β | β | β | β |
|
|
25
|
+
| | **Stitch Layers** | β
**Native** | β | β | β | β |
|
|
26
|
+
| | **K-Means / Stats** | β
**Parallel** | β | β | β | β |
|
|
27
|
+
| | **Cross-Lang ABI** | β
**Universal** | β | β | β | β οΈ |
|
|
28
|
+
| **Streaming** | **LLM Streaming** | β
| β
| β | β | β
|
|
|
29
|
+
| | **Pure Go Tokenizer** | β
| β | β | β | β |
|
|
30
|
+
|
|
31
|
+
For detailed comparison, see [`docs/loom_assessment_comparison.md`](../docs/loom_assessment_comparison.md).
|
|
32
|
+
|
|
33
|
+
## π Cross-Ecosystem Compatibility
|
|
34
|
+
|
|
35
|
+
Models trained in TypeScript can be loaded instantly in Python, C#, Go, or other WASM environments. **Bit-for-bit identical results** across all platforms.
|
|
36
|
+
|
|
37
|
+
| Platform | Package | Install |
|
|
38
|
+
|:---------|:--------|:--------|
|
|
39
|
+
| **TypeScript/Node** | [NPM](https://www.npmjs.com/package/@openfluke/welvet) | `npm install @openfluke/welvet` |
|
|
40
|
+
| **Python** | [PyPI](https://pypi.org/project/welvet/) | `pip install welvet` |
|
|
41
|
+
| **C#/.NET** | [NuGet](https://www.nuget.org/packages/Welvet) | `dotnet add package Welvet` |
|
|
42
|
+
| **Go** | [GitHub](https://github.com/openfluke/loom) | `go get github.com/openfluke/loom` |
|
|
43
|
+
|
|
44
|
+
### Key Strengths
|
|
45
|
+
|
|
46
|
+
- **True Embeddability**: Single WASM binary. Works in Node.js and browsers with the same API.
|
|
47
|
+
- **Hybrid Gradient/Geometric Engine**: "Neural Tweening" combines geometric gap-closing with backpropagation-guided momentum.
|
|
48
|
+
- **Structural Parallelism**: Native support for Inception, ResNeXt, Siamese, and MoE architectures via `LayerParallel`.
|
|
49
|
+
- **Native Mixed-Precision**: Generic tensor backend supports `int8`, `uint16`, and `float32`.
|
|
50
|
+
- **Complete Evaluation Suite**: Deviation metrics, training milestones, and adaptation tracking.
|
|
51
|
+
- **Network Telemetry**: Runtime introspection with `GetMethodsJSON()` and `ExtractNetworkBlueprint()`.
|
|
16
52
|
|
|
17
53
|
## Installation
|
|
18
54
|
|
|
@@ -20,18 +56,19 @@ Isomorphic TypeScript/JavaScript wrapper for the LOOM WebAssembly neural network
|
|
|
20
56
|
npm install @openfluke/welvet
|
|
21
57
|
```
|
|
22
58
|
|
|
59
|
+
**Using Bun:**
|
|
60
|
+
```bash
|
|
61
|
+
bun add @openfluke/welvet
|
|
62
|
+
```
|
|
63
|
+
|
|
23
64
|
## Quick Start
|
|
24
65
|
|
|
25
|
-
### π
|
|
66
|
+
### π Simple API (Recommended)
|
|
26
67
|
|
|
27
|
-
The simple API provides streamlined functions with
|
|
68
|
+
The simple API provides streamlined functions with **cross-platform consistency**:
|
|
28
69
|
|
|
29
70
|
```typescript
|
|
30
|
-
import {
|
|
31
|
-
init,
|
|
32
|
-
createNetworkFromJSON,
|
|
33
|
-
loadLoomNetwork,
|
|
34
|
-
} from "@openfluke/welvet";
|
|
71
|
+
import { init, createNetworkFromJSON, loadLoomNetwork } from "@openfluke/welvet";
|
|
35
72
|
|
|
36
73
|
// Initialize LOOM WASM
|
|
37
74
|
await init();
|
|
@@ -47,33 +84,17 @@ const config = {
|
|
|
47
84
|
{
|
|
48
85
|
type: "parallel",
|
|
49
86
|
combine_mode: "grid_scatter",
|
|
50
|
-
grid_output_rows: 3,
|
|
51
|
-
grid_output_cols: 1,
|
|
52
|
-
grid_output_layers: 1,
|
|
87
|
+
grid_output_rows: 3, grid_output_cols: 1, grid_output_layers: 1,
|
|
53
88
|
grid_positions: [
|
|
54
89
|
{ branch_index: 0, target_row: 0, target_col: 0, target_layer: 0 },
|
|
55
90
|
{ branch_index: 1, target_row: 1, target_col: 0, target_layer: 0 },
|
|
56
91
|
{ branch_index: 2, target_row: 2, target_col: 0, target_layer: 0 },
|
|
57
92
|
],
|
|
58
93
|
branches: [
|
|
59
|
-
{
|
|
60
|
-
type: "
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
{
|
|
64
|
-
type: "dense",
|
|
65
|
-
input_size: 16,
|
|
66
|
-
output_size: 8,
|
|
67
|
-
activation: "relu",
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
type: "dense",
|
|
71
|
-
input_size: 16,
|
|
72
|
-
output_size: 8,
|
|
73
|
-
activation: "gelu",
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
},
|
|
94
|
+
{ type: "parallel", combine_mode: "add", branches: [
|
|
95
|
+
{ type: "dense", input_size: 16, output_size: 8, activation: "relu" },
|
|
96
|
+
{ type: "dense", input_size: 16, output_size: 8, activation: "gelu" },
|
|
97
|
+
]},
|
|
77
98
|
{ type: "lstm", input_size: 16, hidden_size: 8, seq_length: 1 },
|
|
78
99
|
{ type: "rnn", input_size: 16, hidden_size: 8, seq_length: 1 },
|
|
79
100
|
],
|
|
@@ -88,86 +109,55 @@ const network = createNetworkFromJSON(JSON.stringify(config));
|
|
|
88
109
|
const batches = [
|
|
89
110
|
{ Input: [0.2, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8], Target: [1.0, 0.0] },
|
|
90
111
|
{ Input: [0.9, 0.9, 0.9, 0.9, 0.1, 0.1, 0.1, 0.1], Target: [0.0, 1.0] },
|
|
91
|
-
{ Input: [0.7, 0.7, 0.7, 0.7, 0.3, 0.3, 0.3, 0.3], Target: [0.0, 1.0] },
|
|
92
|
-
{ Input: [0.3, 0.3, 0.3, 0.3, 0.7, 0.7, 0.7, 0.7], Target: [1.0, 0.0] },
|
|
93
112
|
];
|
|
94
113
|
|
|
95
114
|
const trainingConfig = {
|
|
96
115
|
Epochs: 800,
|
|
97
116
|
LearningRate: 0.15,
|
|
98
|
-
UseGPU: false,
|
|
99
|
-
PrintEveryBatch: 0,
|
|
100
|
-
GradientClip: 1.0,
|
|
101
117
|
LossType: "mse",
|
|
102
|
-
|
|
118
|
+
GradientClip: 1.0,
|
|
103
119
|
};
|
|
104
120
|
|
|
105
|
-
|
|
106
|
-
console.log("Training complete!");
|
|
121
|
+
network.Train(JSON.stringify([batches, trainingConfig]));
|
|
107
122
|
|
|
108
123
|
// Forward pass
|
|
109
|
-
const [output] = network.ForwardCPU(
|
|
110
|
-
|
|
111
|
-
);
|
|
112
|
-
console.log("Output:", JSON.parse(output)); // [0.950, 0.050]
|
|
113
|
-
|
|
114
|
-
// Evaluate network
|
|
115
|
-
const inputs = batches.map((b) => b.Input);
|
|
116
|
-
const expected = [0, 1, 1, 0];
|
|
117
|
-
const [metrics] = network.EvaluateNetwork(JSON.stringify([inputs, expected]));
|
|
118
|
-
const metricsData = JSON.parse(metrics);
|
|
119
|
-
console.log(
|
|
120
|
-
`Quality: ${metricsData.score}/100, Deviation: ${metricsData.avg_deviation}%`
|
|
121
|
-
);
|
|
124
|
+
const [output] = network.ForwardCPU(JSON.stringify([[0.2, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8]]));
|
|
125
|
+
console.log("Output:", JSON.parse(output)); // [0.95, 0.05]
|
|
122
126
|
|
|
123
127
|
// Save/Load
|
|
124
128
|
const [modelJSON] = network.SaveModelToString(JSON.stringify(["my_model"]));
|
|
125
|
-
console.log(`Model saved (${modelJSON.length} bytes)`);
|
|
126
|
-
|
|
127
|
-
// Load model
|
|
128
129
|
const loadedNetwork = loadLoomNetwork(modelJSON, "my_model");
|
|
129
|
-
const [output2] = loadedNetwork.ForwardCPU(
|
|
130
|
-
JSON.stringify([[0.2, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8]])
|
|
131
|
-
);
|
|
132
|
-
// output2 === output (bit-for-bit identical!)
|
|
133
130
|
```
|
|
134
131
|
|
|
135
132
|
**Simple API Functions:**
|
|
136
133
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
**Cross-Platform Results:**
|
|
147
|
-
|
|
148
|
-
- β
Same training: 99.5% improvement, 100/100 quality score
|
|
149
|
-
- β
Same save/load: 0.00 difference in predictions
|
|
150
|
-
- β
Same evaluation: Identical deviation metrics
|
|
151
|
-
- β
Same behavior as Python, C#, C, and WASM
|
|
152
|
-
|
|
153
|
-
See `example/grid-scatter.ts` for a complete working example.
|
|
134
|
+
| Function | Description |
|
|
135
|
+
|:---------|:------------|
|
|
136
|
+
| `createNetworkFromJSON(config)` | Create network from JSON |
|
|
137
|
+
| `loadLoomNetwork(json, id)` | Load saved model |
|
|
138
|
+
| `network.ForwardCPU(input)` | Forward pass |
|
|
139
|
+
| `network.BackwardCPU(gradients)` | Backward pass |
|
|
140
|
+
| `network.Train(params)` | Train network |
|
|
141
|
+
| `network.SaveModelToString(id)` | Save to JSON string |
|
|
142
|
+
| `network.EvaluateNetwork(params)` | Evaluate with metrics |
|
|
154
143
|
|
|
155
144
|
### β‘ Stepping API - Fine-Grained Execution Control
|
|
156
145
|
|
|
157
|
-
|
|
146
|
+
Execute networks one step at a time for online learning:
|
|
158
147
|
|
|
159
148
|
```typescript
|
|
160
149
|
import { init, createNetwork, StepState } from "@openfluke/welvet";
|
|
161
150
|
|
|
162
151
|
await init();
|
|
163
152
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
153
|
+
const network = createNetwork({
|
|
154
|
+
batch_size: 1,
|
|
155
|
+
layers: [
|
|
156
|
+
{ type: "dense", input_height: 4, output_height: 8, activation: "relu" },
|
|
157
|
+
{ type: "lstm", input_size: 8, hidden_size: 12, seq_length: 1 },
|
|
158
|
+
{ type: "dense", input_height: 12, output_height: 3, activation: "softmax" }
|
|
159
|
+
]
|
|
160
|
+
});
|
|
171
161
|
|
|
172
162
|
// Initialize stepping state
|
|
173
163
|
const state: StepState = network.createStepState(4);
|
|
@@ -178,12 +168,8 @@ for (let step = 0; step < 100000; step++) {
|
|
|
178
168
|
state.stepForward();
|
|
179
169
|
const output = state.getOutput();
|
|
180
170
|
|
|
181
|
-
// Calculate gradients
|
|
182
|
-
const gradients = new Float32Array(output.length);
|
|
183
|
-
for (let i = 0; i < output.length; i++)
|
|
184
|
-
gradients[i] = output[i] - target[i];
|
|
185
|
-
|
|
186
171
|
// Backward pass
|
|
172
|
+
const gradients = output.map((o, i) => o - target[i]);
|
|
187
173
|
state.stepBackward(gradients);
|
|
188
174
|
|
|
189
175
|
// Update weights immediately
|
|
@@ -191,19 +177,9 @@ for (let step = 0; step < 100000; step++) {
|
|
|
191
177
|
}
|
|
192
178
|
```
|
|
193
179
|
|
|
194
|
-
**Stepping API:**
|
|
195
|
-
- `network.createStepState(inputSize)` - Initialize stepping state
|
|
196
|
-
- `state.setInput(data)` - Set input for current step
|
|
197
|
-
- `state.stepForward()` - Execute forward pass
|
|
198
|
-
- `state.getOutput()` - Get output from last layer
|
|
199
|
-
- `state.stepBackward(gradients)` - Execute backward pass
|
|
200
|
-
- `network.ApplyGradients(paramsJSON)` - Update network weights
|
|
201
|
-
|
|
202
|
-
See `example/step_train_v3.ts` for a complete example achieving 100% accuracy.
|
|
203
|
-
|
|
204
180
|
### π§ Neural Tweening API - Gradient-Free Learning
|
|
205
181
|
|
|
206
|
-
|
|
182
|
+
Direct weight adjustment without backpropagation:
|
|
207
183
|
|
|
208
184
|
```typescript
|
|
209
185
|
import { init, createNetwork, TweenState } from "@openfluke/welvet";
|
|
@@ -217,212 +193,207 @@ const tweenState: TweenState = network.createTweenState(true); // useChainRule=t
|
|
|
217
193
|
|
|
218
194
|
// Training loop - direct weight updates
|
|
219
195
|
for (let step = 0; step < 10000; step++) {
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
196
|
+
const loss = tweenState.TweenStep(
|
|
197
|
+
new Float32Array([0.1, 0.2, 0.3, 0.4]),
|
|
198
|
+
1, // targetClass
|
|
199
|
+
4, // outputSize
|
|
200
|
+
0.02 // learningRate
|
|
201
|
+
);
|
|
225
202
|
}
|
|
226
203
|
```
|
|
227
204
|
|
|
228
|
-
|
|
229
|
-
- `network.createTweenState(useChainRule)` - Initialize tween state
|
|
230
|
-
- `tweenState.TweenStep(input, targetClass, outputSize, lr)` - Train step
|
|
231
|
-
- `tweenState.setChainRule(enabled)` - Toggle chain rule
|
|
232
|
-
- `tweenState.getChainRule()` - Get chain rule status
|
|
233
|
-
- `tweenState.getTweenSteps()` - Get total steps performed
|
|
205
|
+
### π Adaptation Benchmark
|
|
234
206
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
**NEW:** Run the full Test 18 Multi-Architecture Adaptation Benchmark:
|
|
207
|
+
Run the full multi-architecture adaptation benchmark:
|
|
238
208
|
|
|
239
209
|
```bash
|
|
240
210
|
cd example
|
|
241
211
|
bun run test18_adaptation.ts
|
|
242
212
|
```
|
|
243
213
|
|
|
244
|
-
Tests 5 architectures Γ 3 depths Γ 5 training modes (75 tests total):
|
|
214
|
+
Tests **5 architectures Γ 3 depths Γ 5 training modes** (75 tests total):
|
|
245
215
|
- **Architectures:** Dense, Conv2D, RNN, LSTM, Attention
|
|
246
216
|
- **Depths:** 3, 5, 9 layers
|
|
247
217
|
- **Modes:** NormalBP, StepBP, Tween, TweenChain, StepTweenChain
|
|
248
218
|
|
|
249
|
-
|
|
219
|
+
## Complete Test Suite
|
|
250
220
|
|
|
251
|
-
|
|
221
|
+
The `universal_test.ts` example demonstrates all framework capabilities:
|
|
252
222
|
|
|
223
|
+
```bash
|
|
224
|
+
cd example
|
|
225
|
+
bun run universal_test.ts
|
|
253
226
|
```
|
|
254
227
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
228
|
+
**Test Coverage:**
|
|
229
|
+
- β
12 Layer Types Γ 6 Data Types (72 tests)
|
|
230
|
+
- β
Network Grafting
|
|
231
|
+
- β
K-Means Clustering & Correlation Analysis
|
|
232
|
+
- β
Optimizers (SGD, AdamW, RMSprop)
|
|
233
|
+
- β
Ensemble Features
|
|
234
|
+
- β
Observer Pattern (Adaptation Tracking)
|
|
235
|
+
- β
Introspection API
|
|
236
|
+
- β
Step & Tween API
|
|
237
|
+
- β
Advanced Layers (Embedding, Residual)
|
|
258
238
|
|
|
259
|
-
|
|
239
|
+
See [`example/universal_test.ts`](./example/universal_test.ts) for the complete test implementation.
|
|
260
240
|
|
|
261
|
-
|
|
241
|
+
## Layer Types
|
|
262
242
|
|
|
263
|
-
|
|
243
|
+
| Layer | Type String | Description |
|
|
244
|
+
|:------|:------------|:------------|
|
|
245
|
+
| Dense | `dense` | Fully connected layer |
|
|
246
|
+
| LSTM | `lstm` | Long Short-Term Memory |
|
|
247
|
+
| RNN | `rnn` | Recurrent Neural Network |
|
|
248
|
+
| GRU | `gru` | Gated Recurrent Unit |
|
|
249
|
+
| Conv2D | `conv2d` | 2D Convolution |
|
|
250
|
+
| Conv1D | `conv1d` | 1D Convolution |
|
|
251
|
+
| Multi-Head Attention | `multi_head_attention` | Transformer attention |
|
|
252
|
+
| LayerNorm | `layer_norm` | Layer normalization |
|
|
253
|
+
| RMSNorm | `rms_norm` | RMS normalization |
|
|
254
|
+
| SwiGLU | `swiglu` | SwiGLU activation layer |
|
|
255
|
+
| Softmax | `softmax` | Softmax classification |
|
|
256
|
+
| Embedding | `embedding` | Token embedding |
|
|
257
|
+
| Parallel | `parallel` | Branching with combine modes |
|
|
258
|
+
| Sequential | `sequential` | Grouped sub-layers |
|
|
259
|
+
|
|
260
|
+
**Parallel Combine Modes:** `add`, `concat`, `multiply`, `average`, `grid_scatter`, `filter`
|
|
264
261
|
|
|
265
|
-
|
|
262
|
+
## Activation Functions
|
|
266
263
|
|
|
267
|
-
|
|
264
|
+
`relu`, `sigmoid`, `tanh`, `softmax`, `gelu`, `swish`, `mish`, `leaky_relu`, `elu`, `selu`, `linear`
|
|
268
265
|
|
|
269
|
-
|
|
266
|
+
## API Reference
|
|
270
267
|
|
|
271
|
-
|
|
268
|
+
### Initialization
|
|
272
269
|
|
|
273
|
-
|
|
270
|
+
```typescript
|
|
271
|
+
import { init, initBrowser, createNetwork, createNetworkFromJSON } from "@openfluke/welvet";
|
|
274
272
|
|
|
275
|
-
|
|
273
|
+
// Node.js
|
|
274
|
+
await init();
|
|
276
275
|
|
|
277
|
-
|
|
276
|
+
// Browser
|
|
277
|
+
await initBrowser();
|
|
278
|
+
```
|
|
278
279
|
|
|
279
|
-
|
|
280
|
-
- Return a JSON string of an array of results
|
|
280
|
+
### Network Methods
|
|
281
281
|
|
|
282
|
-
|
|
282
|
+
All Network methods follow the WASM calling convention:
|
|
283
|
+
- **Input:** JSON string of an array of parameters
|
|
284
|
+
- **Return:** JSON string of an array of results
|
|
283
285
|
|
|
284
286
|
```typescript
|
|
285
287
|
// Method with no parameters
|
|
286
288
|
const info = network.GetNetworkInfo(JSON.stringify([]));
|
|
287
|
-
const parsed = JSON.parse(info)[0];
|
|
288
289
|
|
|
289
290
|
// Method with parameters
|
|
290
291
|
const result = network.Train(JSON.stringify([batches, config]));
|
|
291
|
-
const data = JSON.parse(result)[0];
|
|
292
292
|
|
|
293
|
-
// Save model
|
|
293
|
+
// Save model
|
|
294
294
|
const saved = network.SaveModelToString(JSON.stringify(["my-model"]));
|
|
295
|
-
const json = JSON.parse(saved)[0];
|
|
296
|
-
````
|
|
297
|
-
|
|
298
|
-
#### Available Network Methods
|
|
299
|
-
|
|
300
|
-
- `ForwardCPU(paramsJSON)` - CPU forward pass: `[inputs]`
|
|
301
|
-
- `ForwardGPU(paramsJSON)` - GPU forward pass: `[inputs]`
|
|
302
|
-
- `BackwardCPU(paramsJSON)` - CPU backward pass: `[gradients]`
|
|
303
|
-
- `BackwardGPU(paramsJSON)` - GPU backward pass: `[gradients]`
|
|
304
|
-
- `UpdateWeights(paramsJSON)` - Update weights: `[learningRate]`
|
|
305
|
-
- `Train(paramsJSON)` - Train network: `[batches, config]`
|
|
306
|
-
- `SaveModelToString(paramsJSON)` - Save model: `["modelID"]`
|
|
307
|
-
- `GetWeights(paramsJSON)` - Get layer weights: `[row, col, layer]`
|
|
308
|
-
- `SetWeights(paramsJSON)` - Set layer weights: `[row, col, layer, weights]`
|
|
309
|
-
- `GetBiases(paramsJSON)` - Get layer biases: `[row, col, layer]`
|
|
310
|
-
- `SetBiases(paramsJSON)` - Set layer biases: `[row, col, layer, biases]`
|
|
311
|
-
- `GetActivation(paramsJSON)` - Get activation: `[row, col, layer]`
|
|
312
|
-
- `GetLayerType(paramsJSON)` - Get layer type: `[row, col, layer]`
|
|
313
|
-
- `GetLayerSizes(paramsJSON)` - Get layer sizes: `[row, col, layer]`
|
|
314
|
-
- `GetBatchSize(paramsJSON)` - Get batch size: `[]`
|
|
315
|
-
- `GetGridDimensions(paramsJSON)` - Get grid dimensions: `[]`
|
|
316
|
-
- `GetNetworkInfo(paramsJSON)` - Get network info: `[]`
|
|
317
|
-
- `GetTotalParameters(paramsJSON)` - Get parameter count: `[]`
|
|
318
|
-
- `InitializeWeights(paramsJSON)` - Initialize weights: `[]` or `[method]`
|
|
319
|
-
- `Clone(paramsJSON)` - Clone network: `[]`
|
|
320
|
-
- And 10+ more methods...
|
|
321
|
-
- `GetLastOutput(): string` - Get last forward pass output
|
|
322
|
-
|
|
323
|
-
### Types
|
|
324
|
-
|
|
325
|
-
#### `NetworkConfig`
|
|
326
|
-
|
|
327
|
-
```typescript
|
|
328
|
-
interface NetworkConfig {
|
|
329
|
-
batch_size: number;
|
|
330
|
-
grid_rows?: number; // Required for grid networks (use 1 for sequential)
|
|
331
|
-
grid_cols?: number; // Required for grid networks (use 1 for sequential)
|
|
332
|
-
layers_per_cell?: number; // Required for grid networks
|
|
333
|
-
layers: LayerConfig[];
|
|
334
|
-
}
|
|
335
295
|
```
|
|
336
296
|
|
|
337
|
-
|
|
297
|
+
**Available Methods:**
|
|
298
|
+
|
|
299
|
+
| Method | Parameters | Description |
|
|
300
|
+
|:-------|:-----------|:------------|
|
|
301
|
+
| `ForwardCPU` | `[inputs]` | CPU forward pass |
|
|
302
|
+
| `ForwardGPU` | `[inputs]` | GPU forward pass |
|
|
303
|
+
| `BackwardCPU` | `[gradients]` | CPU backward pass |
|
|
304
|
+
| `Train` | `[batches, config]` | Train network |
|
|
305
|
+
| `SaveModelToString` | `["modelID"]` | Save to JSON |
|
|
306
|
+
| `GetWeights` | `[row, col, layer]` | Get layer weights |
|
|
307
|
+
| `SetWeights` | `[row, col, layer, weights]` | Set layer weights |
|
|
308
|
+
| `GetBiases` | `[row, col, layer]` | Get layer biases |
|
|
309
|
+
| `SetBiases` | `[row, col, layer, biases]` | Set layer biases |
|
|
310
|
+
| `GetNetworkInfo` | `[]` | Get network info |
|
|
311
|
+
| `GetTotalParameters` | `[]` | Get parameter count |
|
|
312
|
+
| `Clone` | `[]` | Clone network |
|
|
313
|
+
| `TotalLayers` | `[]` | Get total layer count |
|
|
314
|
+
|
|
315
|
+
### Statistical Tools
|
|
338
316
|
|
|
339
317
|
```typescript
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
branches?: LayerConfig[];
|
|
353
|
-
}
|
|
318
|
+
import welvet from "@openfluke/welvet";
|
|
319
|
+
|
|
320
|
+
// K-Means Clustering
|
|
321
|
+
const data = [[1, 1], [1.1, 1.1], [5, 5], [5.1, 5.1]];
|
|
322
|
+
const result = welvet.kmeans(data, 2, 100);
|
|
323
|
+
console.log(`Centroids: ${result.centroids}`);
|
|
324
|
+
console.log(`Silhouette Score: ${result.silhouette_score}`);
|
|
325
|
+
|
|
326
|
+
// Correlation Matrix
|
|
327
|
+
const matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
|
|
328
|
+
const corr = welvet.correlation(matrix);
|
|
329
|
+
console.log(`Pearson: ${corr.pearson}`);
|
|
354
330
|
```
|
|
355
331
|
|
|
356
|
-
|
|
332
|
+
### Network Grafting
|
|
357
333
|
|
|
358
|
-
|
|
359
|
-
interface TrainingBatch {
|
|
360
|
-
Input: number[];
|
|
361
|
-
Target: number[];
|
|
362
|
-
}
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
#### `TrainingConfig`
|
|
334
|
+
Combine multiple trained networks:
|
|
366
335
|
|
|
367
336
|
```typescript
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
UseGPU?: boolean;
|
|
374
|
-
PrintEveryBatch?: number;
|
|
375
|
-
GradientClip?: number;
|
|
376
|
-
}
|
|
337
|
+
const h1 = welvet.createKHandle(config);
|
|
338
|
+
const h2 = welvet.createKHandle(config);
|
|
339
|
+
|
|
340
|
+
const result = welvet.graft([h1, h2], "concat");
|
|
341
|
+
console.log(`Grafted: ${result.num_branches} branches`);
|
|
377
342
|
```
|
|
378
343
|
|
|
379
344
|
## Examples
|
|
380
345
|
|
|
381
|
-
### Grid Scatter Multi-Agent
|
|
382
|
-
|
|
383
346
|
```bash
|
|
384
347
|
cd example
|
|
385
|
-
bun install
|
|
386
|
-
bun run grid-scatter.ts
|
|
387
|
-
```
|
|
388
348
|
|
|
389
|
-
|
|
349
|
+
# Grid Scatter Multi-Agent
|
|
350
|
+
bun run grid-scatter.ts
|
|
390
351
|
|
|
391
|
-
|
|
352
|
+
# Stepping Training (LSTM)
|
|
392
353
|
bun run step_train_v3.ts
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
### Adaptation Benchmark (75 tests)
|
|
396
354
|
|
|
397
|
-
|
|
355
|
+
# Adaptation Benchmark (75 tests)
|
|
398
356
|
bun run test18_adaptation.ts
|
|
357
|
+
|
|
358
|
+
# Full Test Suite (77 tests)
|
|
359
|
+
bun run universal_test.ts
|
|
399
360
|
```
|
|
400
361
|
|
|
401
|
-
|
|
362
|
+
## TypeScript Types
|
|
402
363
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
- `concat` - Concatenation
|
|
413
|
-
- `multiply` - Element-wise multiplication
|
|
414
|
-
- `grid_scatter` - Multi-agent grid routing
|
|
364
|
+
```typescript
|
|
365
|
+
interface NetworkConfig {
|
|
366
|
+
batch_size: number;
|
|
367
|
+
grid_rows?: number;
|
|
368
|
+
grid_cols?: number;
|
|
369
|
+
layers_per_cell?: number;
|
|
370
|
+
layers: LayerConfig[];
|
|
371
|
+
dtype?: "float32" | "float64" | "int32" | "int16" | "int8" | "uint8";
|
|
372
|
+
}
|
|
415
373
|
|
|
416
|
-
|
|
374
|
+
interface TrainingConfig {
|
|
375
|
+
Epochs: number;
|
|
376
|
+
LearningRate: number;
|
|
377
|
+
LossType?: string;
|
|
378
|
+
Verbose?: boolean;
|
|
379
|
+
UseGPU?: boolean;
|
|
380
|
+
GradientClip?: number;
|
|
381
|
+
}
|
|
417
382
|
|
|
418
|
-
|
|
383
|
+
interface TrainingBatch {
|
|
384
|
+
Input: number[];
|
|
385
|
+
Target: number[];
|
|
386
|
+
}
|
|
387
|
+
```
|
|
419
388
|
|
|
420
389
|
## License
|
|
421
390
|
|
|
422
|
-
|
|
391
|
+
Apache-2.0
|
|
423
392
|
|
|
424
393
|
## Links
|
|
425
394
|
|
|
426
|
-
- [
|
|
427
|
-
- [
|
|
428
|
-
- [
|
|
395
|
+
- **GitHub**: [github.com/openfluke/loom](https://github.com/openfluke/loom)
|
|
396
|
+
- **NPM**: [@openfluke/welvet](https://www.npmjs.com/package/@openfluke/welvet)
|
|
397
|
+
- **PyPI**: [welvet](https://pypi.org/project/welvet/)
|
|
398
|
+
- **NuGet**: [Welvet](https://www.nuget.org/packages/Welvet)
|
|
399
|
+
- **Documentation**: [`docs/loom_assessment_comparison.md`](../docs/loom_assessment_comparison.md)
|
package/dist/index.browser.d.ts
CHANGED
|
File without changes
|
package/dist/index.browser.js
CHANGED
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Direct wrapper around Loom WASM that mirrors main.go exports exactly.
|
|
5
5
|
* Provides the same API in both Node.js and browser environments.
|
|
6
6
|
*/
|
|
7
|
-
import { Network } from "./types.js";
|
|
7
|
+
import { Network, GraftResult, KMeansResult, CorrelationResult, EnsembleMatch, AdaptationTracker } from "./types.js";
|
|
8
8
|
import { loadLoomWASM } from "./loader.js";
|
|
9
9
|
import { loadLoomWASMBrowser } from "./loader.browser.js";
|
|
10
10
|
export * from "./types.js";
|
|
@@ -22,6 +22,30 @@ export declare function initBrowser(): Promise<void>;
|
|
|
22
22
|
* Wrapper around the global createLoomNetwork function exposed by WASM
|
|
23
23
|
*/
|
|
24
24
|
export declare function createNetwork(config: object | string): Network;
|
|
25
|
+
/**
|
|
26
|
+
* Create a network handle for grafting
|
|
27
|
+
*/
|
|
28
|
+
export declare function createKHandle(config: object | string): number;
|
|
29
|
+
/**
|
|
30
|
+
* Graft multiple networks together
|
|
31
|
+
*/
|
|
32
|
+
export declare function graft(ids: number[], combineMode: string): GraftResult;
|
|
33
|
+
/**
|
|
34
|
+
* Perform K-Means Clustering
|
|
35
|
+
*/
|
|
36
|
+
export declare function kmeans(data: number[][], k: number, iter: number): KMeansResult;
|
|
37
|
+
/**
|
|
38
|
+
* Compute Correlation Matrix
|
|
39
|
+
*/
|
|
40
|
+
export declare function correlation(matrixA: number[][], matrixB?: number[][]): CorrelationResult;
|
|
41
|
+
/**
|
|
42
|
+
* Find Complementary Ensemble Matches
|
|
43
|
+
*/
|
|
44
|
+
export declare function ensemble(models: object[], minCoverage: number): EnsembleMatch[];
|
|
45
|
+
/**
|
|
46
|
+
* Create Adaptation Tracker
|
|
47
|
+
*/
|
|
48
|
+
export declare function tracker(windowMs: number, totalMs: number): AdaptationTracker;
|
|
25
49
|
/**
|
|
26
50
|
* Default export with all functions
|
|
27
51
|
*/
|
|
@@ -29,5 +53,11 @@ declare const _default: {
|
|
|
29
53
|
init: typeof init;
|
|
30
54
|
initBrowser: typeof initBrowser;
|
|
31
55
|
createNetwork: typeof createNetwork;
|
|
56
|
+
createKHandle: typeof createKHandle;
|
|
57
|
+
graft: typeof graft;
|
|
58
|
+
kmeans: typeof kmeans;
|
|
59
|
+
correlation: typeof correlation;
|
|
60
|
+
ensemble: typeof ensemble;
|
|
61
|
+
tracker: typeof tracker;
|
|
32
62
|
};
|
|
33
63
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -30,11 +30,66 @@ export function createNetwork(config) {
|
|
|
30
30
|
: JSON.stringify(config);
|
|
31
31
|
return createLoomNetwork(jsonConfig);
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a network handle for grafting
|
|
35
|
+
*/
|
|
36
|
+
export function createKHandle(config) {
|
|
37
|
+
const jsonConfig = typeof config === "string" ? config : JSON.stringify(config);
|
|
38
|
+
return createNetworkForGraft(jsonConfig);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Graft multiple networks together
|
|
42
|
+
*/
|
|
43
|
+
export function graft(ids, combineMode) {
|
|
44
|
+
const idsJSON = JSON.stringify(ids);
|
|
45
|
+
const resJSON = graftNetworks(idsJSON, combineMode);
|
|
46
|
+
return JSON.parse(resJSON);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Perform K-Means Clustering
|
|
50
|
+
*/
|
|
51
|
+
export function kmeans(data, k, iter) {
|
|
52
|
+
const resJSON = kmeansCluster(JSON.stringify(data), k, iter);
|
|
53
|
+
return JSON.parse(resJSON);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Compute Correlation Matrix
|
|
57
|
+
*/
|
|
58
|
+
export function correlation(matrixA, matrixB) {
|
|
59
|
+
const jsonA = JSON.stringify(matrixA);
|
|
60
|
+
const jsonB = matrixB ? JSON.stringify(matrixB) : "null"; // Use "null" string for nil
|
|
61
|
+
const resJSON = computeCorrelation(jsonA, jsonB);
|
|
62
|
+
const raw = JSON.parse(resJSON);
|
|
63
|
+
// Transform to match interface
|
|
64
|
+
return {
|
|
65
|
+
pearson: raw.correlation?.matrix || raw.Correlation?.Matrix || raw.matrix || [],
|
|
66
|
+
spearman: raw.spearman?.matrix || raw.Spearman?.Matrix || []
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Find Complementary Ensemble Matches
|
|
71
|
+
*/
|
|
72
|
+
export function ensemble(models, minCoverage) {
|
|
73
|
+
const resJSON = findComplementaryMatches(JSON.stringify(models), minCoverage);
|
|
74
|
+
return JSON.parse(resJSON);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Create Adaptation Tracker
|
|
78
|
+
*/
|
|
79
|
+
export function tracker(windowMs, totalMs) {
|
|
80
|
+
return createAdaptationTracker(windowMs, totalMs);
|
|
81
|
+
}
|
|
33
82
|
/**
|
|
34
83
|
* Default export with all functions
|
|
35
84
|
*/
|
|
36
85
|
export default {
|
|
37
86
|
init,
|
|
38
87
|
initBrowser,
|
|
39
|
-
createNetwork
|
|
88
|
+
createNetwork,
|
|
89
|
+
createKHandle,
|
|
90
|
+
graft,
|
|
91
|
+
kmeans,
|
|
92
|
+
correlation,
|
|
93
|
+
ensemble,
|
|
94
|
+
tracker
|
|
40
95
|
};
|
package/dist/loader.browser.d.ts
CHANGED
|
File without changes
|
package/dist/loader.browser.js
CHANGED
|
File without changes
|
package/dist/loader.d.ts
CHANGED
|
File without changes
|
package/dist/loader.js
CHANGED
|
File without changes
|
package/dist/main.wasm
ADDED
|
Binary file
|
package/dist/types.d.ts
CHANGED
|
@@ -6,13 +6,33 @@ export interface LayerConfig {
|
|
|
6
6
|
input_size?: number;
|
|
7
7
|
output_size?: number;
|
|
8
8
|
hidden_size?: number;
|
|
9
|
-
seq_length?: number;
|
|
10
9
|
activation?: string;
|
|
11
10
|
combine_mode?: string;
|
|
12
11
|
grid_output_rows?: number;
|
|
13
12
|
grid_output_cols?: number;
|
|
14
13
|
grid_output_layers?: number;
|
|
15
14
|
grid_positions?: GridPosition[];
|
|
15
|
+
input_height?: number;
|
|
16
|
+
output_height?: number;
|
|
17
|
+
input_width?: number;
|
|
18
|
+
input_channels?: number;
|
|
19
|
+
output_channels?: number;
|
|
20
|
+
kernel_size?: number;
|
|
21
|
+
stride?: number;
|
|
22
|
+
padding?: number;
|
|
23
|
+
filters?: number;
|
|
24
|
+
d_model?: number;
|
|
25
|
+
num_heads?: number;
|
|
26
|
+
seq_length?: number;
|
|
27
|
+
norm_size?: number;
|
|
28
|
+
vocab_size?: number;
|
|
29
|
+
embedding_dim?: number;
|
|
30
|
+
epsilon?: number;
|
|
31
|
+
softmax_variant?: string;
|
|
32
|
+
temperature?: number;
|
|
33
|
+
residual?: boolean;
|
|
34
|
+
filter_gate?: LayerConfig;
|
|
35
|
+
filter_temperature?: number;
|
|
16
36
|
branches?: LayerConfig[];
|
|
17
37
|
}
|
|
18
38
|
export interface NetworkConfig {
|
|
@@ -138,6 +158,34 @@ export interface TweenState {
|
|
|
138
158
|
declare global {
|
|
139
159
|
function createLoomNetwork(jsonConfig: string): Network;
|
|
140
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;
|
|
166
|
+
}
|
|
167
|
+
export interface EnsembleMatch {
|
|
168
|
+
ModelA: string;
|
|
169
|
+
ModelB: string;
|
|
170
|
+
Coverage: number;
|
|
171
|
+
Overlap: number;
|
|
172
|
+
WeightedAcc?: number;
|
|
173
|
+
}
|
|
174
|
+
export interface GraftResult {
|
|
175
|
+
success: boolean;
|
|
176
|
+
type: string;
|
|
177
|
+
num_branches: number;
|
|
178
|
+
combine_mode: string;
|
|
179
|
+
error?: string;
|
|
180
|
+
}
|
|
181
|
+
export interface KMeansResult {
|
|
182
|
+
centroids: number[][];
|
|
183
|
+
assignment: number[];
|
|
184
|
+
silhouette_score: number;
|
|
185
|
+
}
|
|
186
|
+
export interface CorrelationResult {
|
|
187
|
+
pearson: number[][];
|
|
188
|
+
spearman: number[][];
|
|
141
189
|
}
|
|
142
190
|
/**
|
|
143
191
|
* AdaptationTracker interface for tracking accuracy during task changes
|
package/dist/types.js
CHANGED
|
File without changes
|
package/dist/wasm_exec.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfluke/welvet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "TypeScript/JavaScript bindings for LOOM neural network framework with WebAssembly support - GPU-accelerated machine learning in the browser",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,13 +22,41 @@
|
|
|
22
22
|
"gpu",
|
|
23
23
|
"typescript",
|
|
24
24
|
"javascript",
|
|
25
|
-
"go",
|
|
26
|
-
"golang",
|
|
27
25
|
"ml",
|
|
28
26
|
"ai",
|
|
29
27
|
"training",
|
|
30
28
|
"inference",
|
|
31
|
-
"browser"
|
|
29
|
+
"browser",
|
|
30
|
+
"nodejs",
|
|
31
|
+
"isomorphic",
|
|
32
|
+
"transformer",
|
|
33
|
+
"lstm",
|
|
34
|
+
"rnn",
|
|
35
|
+
"gru",
|
|
36
|
+
"attention",
|
|
37
|
+
"multi-head-attention",
|
|
38
|
+
"conv2d",
|
|
39
|
+
"conv1d",
|
|
40
|
+
"convolution",
|
|
41
|
+
"embedding",
|
|
42
|
+
"layer-norm",
|
|
43
|
+
"rms-norm",
|
|
44
|
+
"swiglu",
|
|
45
|
+
"moe",
|
|
46
|
+
"mixture-of-experts",
|
|
47
|
+
"tweening",
|
|
48
|
+
"gradient-free",
|
|
49
|
+
"safetensors",
|
|
50
|
+
"cross-platform",
|
|
51
|
+
"clustering",
|
|
52
|
+
"kmeans",
|
|
53
|
+
"k-means",
|
|
54
|
+
"correlation",
|
|
55
|
+
"statistics",
|
|
56
|
+
"streaming",
|
|
57
|
+
"llm",
|
|
58
|
+
"tokenizer",
|
|
59
|
+
"bpe"
|
|
32
60
|
],
|
|
33
61
|
"license": "Apache-2.0",
|
|
34
62
|
"repository": {
|