@openfluke/welvet 0.1.3 → 0.1.4

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,211 +1,105 @@
1
1
  /**
2
- * LOOM Network instance returned by NewNetwork()
3
- * All Network methods are dynamically exposed via reflection
2
+ * Type definitions for LOOM WASM API
4
3
  */
5
- export interface LoomNetwork {
6
- ForwardCPU(inputJSON: string): string;
7
- ForwardGPU?(inputJSON: string): string;
8
- BackwardCPU(gradOutputJSON: string): string;
9
- BackwardGPU?(gradOutputJSON: string): string;
10
- UpdateWeights(learningRateJSON: string): string;
11
- Train(batchesAndConfigJSON: string): string;
12
- SetLayer(configJSON: string): string;
13
- InitGPU?(argsJSON: string): string;
14
- ReleaseGPU?(): string;
15
- SaveModelToString(modelIDJSON: string): string;
16
- SaveModel?(pathAndIDJSON: string): string;
17
- GetMethods(): string;
18
- ListMethods(): string;
19
- GetMethodSignature(methodNameJSON: string): string;
20
- HasMethod(methodName: string): boolean;
21
- [key: string]: any;
4
+ export interface LayerConfig {
5
+ type: string;
6
+ input_size?: number;
7
+ output_size?: number;
8
+ hidden_size?: number;
9
+ seq_length?: number;
10
+ activation?: string;
11
+ combine_mode?: string;
12
+ grid_output_rows?: number;
13
+ grid_output_cols?: number;
14
+ grid_output_layers?: number;
15
+ grid_positions?: GridPosition[];
16
+ branches?: LayerConfig[];
22
17
  }
23
- /**
24
- * Global WASM functions exposed by LOOM
25
- */
26
- export interface LoomAPI {
27
- /**
28
- * Create a new neural network
29
- * @param inputSize - Size of input layer
30
- * @param gridRows - Number of grid rows
31
- * @param gridCols - Number of grid columns
32
- * @param layersPerCell - Number of layers per grid cell
33
- * @returns LoomNetwork instance with all methods
34
- */
35
- NewNetwork: (inputSize: number, gridRows: number, gridCols: number, layersPerCell: number) => LoomNetwork;
36
- /**
37
- * Load a model from JSON string
38
- * @param modelJSON - JSON string of the model
39
- * @param modelID - Model identifier
40
- * @returns LoomNetwork instance
41
- */
42
- LoadModelFromString: (modelJSON: string, modelID: string) => LoomNetwork;
43
- /**
44
- * Call any layer initialization function from the registry
45
- * @param functionName - Name of the layer init function (e.g., "InitDenseLayer")
46
- * @param paramsJSON - JSON string of parameters array
47
- * @returns JSON string of layer configuration
48
- */
49
- CallLayerInit: (functionName: string, paramsJSON: string) => string;
50
- /**
51
- * Initialize a dense (fully-connected) layer configuration
52
- * @param inputSize - Input dimension
53
- * @param outputSize - Output dimension
54
- * @param activation - Activation type (0=ReLU, 1=Sigmoid, 2=Tanh, 3=Linear)
55
- * @returns JSON string of layer configuration
56
- */
57
- InitDenseLayer: (inputSize: number, outputSize: number, activation: number) => string;
58
- /**
59
- * Initialize a multi-head attention layer configuration
60
- * @param dModel - Model dimension
61
- * @param numHeads - Number of attention heads
62
- * @param seqLength - Sequence length
63
- * @param activation - Activation type
64
- * @returns JSON string of layer configuration
65
- */
66
- InitMultiHeadAttentionLayer: (dModel: number, numHeads: number, seqLength: number, activation: number) => string;
67
- /**
68
- * Initialize a 2D convolutional layer configuration
69
- * @param inputHeight - Input height
70
- * @param inputWidth - Input width
71
- * @param inputChannels - Number of input channels
72
- * @param kernelSize - Kernel size
73
- * @param stride - Stride
74
- * @param padding - Padding
75
- * @param filters - Number of filters
76
- * @param activation - Activation type
77
- * @returns JSON string of layer configuration
78
- */
79
- InitConv2DLayer: (inputHeight: number, inputWidth: number, inputChannels: number, kernelSize: number, stride: number, padding: number, filters: number, activation: number) => string;
80
- /**
81
- * Initialize an RNN layer configuration
82
- * @param inputSize - Input size
83
- * @param hiddenSize - Hidden size
84
- * @param batchSize - Batch size
85
- * @param seqLength - Sequence length
86
- * @returns JSON string of layer configuration
87
- */
88
- InitRNNLayer: (inputSize: number, hiddenSize: number, batchSize: number, seqLength: number) => string;
89
- /**
90
- * Initialize an LSTM layer configuration
91
- * @param inputSize - Input size
92
- * @param hiddenSize - Hidden size
93
- * @param batchSize - Batch size
94
- * @param seqLength - Sequence length
95
- * @returns JSON string of layer configuration
96
- */
97
- InitLSTMLayer: (inputSize: number, hiddenSize: number, batchSize: number, seqLength: number) => string;
18
+ export interface NetworkConfig {
19
+ batch_size: number;
20
+ grid_rows?: number;
21
+ grid_cols?: number;
22
+ layers_per_cell?: number;
23
+ layers: LayerConfig[];
98
24
  }
99
- export interface InitOptions {
100
- /** Override where the WASM is read from. Useful in exotic deploys (Capacitor, CDN). */
101
- wasmUrl?: string | URL;
102
- /** Set false to skip injecting wasm_exec.js (e.g., if you already included it). Default: true */
103
- injectGoRuntime?: boolean;
25
+ export interface GridPosition {
26
+ branch_index: number;
27
+ target_row: number;
28
+ target_col: number;
29
+ target_layer: number;
104
30
  }
105
- /**
106
- * Activation function types
107
- */
108
- export declare enum ActivationType {
109
- ReLU = 0,
110
- Sigmoid = 1,
111
- Tanh = 2,
112
- Softplus = 3,
113
- LeakyReLU = 4,
114
- Linear = 5
31
+ export interface TrainingBatch {
32
+ Input: number[];
33
+ Target: number[];
115
34
  }
116
- /**
117
- * Result from tokenizer loading
118
- */
119
- export interface TokenizerLoadResult {
120
- success: boolean;
121
- vocab_size?: number;
122
- message?: string;
123
- error?: string;
35
+ export interface TrainingConfig {
36
+ Epochs: number;
37
+ LearningRate: number;
38
+ LossType?: string;
39
+ Verbose?: boolean;
40
+ UseGPU?: boolean;
41
+ PrintEveryBatch?: number;
42
+ GradientClip?: number;
124
43
  }
125
- /**
126
- * Result from transformer model loading
127
- */
128
- export interface TransformerLoadResult {
129
- success: boolean;
130
- num_layers?: number;
131
- hidden_size?: number;
132
- vocab_size?: number;
133
- message?: string;
134
- error?: string;
135
- }
136
- /**
137
- * Result from text encoding
138
- */
139
- export interface EncodeResult {
140
- success: boolean;
141
- ids?: number[];
142
- error?: string;
143
- }
144
- /**
145
- * Result from token decoding
146
- */
147
- export interface DecodeResult {
148
- success: boolean;
149
- text?: string;
150
- error?: string;
151
- }
152
- /**
153
- * Result from text generation
154
- */
155
- export interface GenerateResult {
156
- success: boolean;
157
- generated_text?: string;
158
- error?: string;
44
+ export interface TrainingResult {
45
+ final_loss: number;
46
+ duration_ms: number;
47
+ epochs_completed: number;
159
48
  }
160
49
  /**
161
- * Result from next token generation
50
+ * Network interface with all available methods
51
+ * All methods take a JSON string of parameters (JSON array)
52
+ * and return a JSON string of results (JSON array)
162
53
  */
163
- export interface NextTokenResult {
164
- success: boolean;
165
- token?: number;
166
- is_eos?: boolean;
167
- error?: string;
54
+ export interface Network {
55
+ ForwardCPU(inputsJSON: string): string;
56
+ ForwardGPU(inputsJSON: string): string;
57
+ BackwardCPU(gradientsJSON: string): string;
58
+ BackwardGPU(gradientsJSON: string): string;
59
+ UpdateWeights(paramsJSON: string): string;
60
+ Train(paramsJSON: string): string;
61
+ ZeroGradients(paramsJSON: string): string;
62
+ ResetGradients(paramsJSON: string): string;
63
+ SaveModelToString(paramsJSON: string): string;
64
+ SerializeModel(paramsJSON: string): string;
65
+ GetWeights(paramsJSON: string): string;
66
+ SetWeights(paramsJSON: string): string;
67
+ GetBiases(paramsJSON: string): string;
68
+ SetBiases(paramsJSON: string): string;
69
+ GetLayer(paramsJSON: string): string;
70
+ SetLayer(paramsJSON: string): string;
71
+ GetActivation(paramsJSON: string): string;
72
+ SetActivation(paramsJSON: string): string;
73
+ GetLayerType(paramsJSON: string): string;
74
+ GetLayerSizes(paramsJSON: string): string;
75
+ GetBatchSize(paramsJSON: string): string;
76
+ SetBatchSize(paramsJSON: string): string;
77
+ GetGridDimensions(paramsJSON: string): string;
78
+ GetLayersPerCell(paramsJSON: string): string;
79
+ TotalLayers(paramsJSON: string): string;
80
+ GetNetworkInfo(paramsJSON: string): string;
81
+ GetTotalParameters(paramsJSON: string): string;
82
+ GetMemoryUsage(paramsJSON: string): string;
83
+ ValidateArchitecture(paramsJSON: string): string;
84
+ GetLastOutput(paramsJSON: string): string;
85
+ GetLastGradients(paramsJSON: string): string;
86
+ Activations(paramsJSON: string): string;
87
+ KernelGradients(paramsJSON: string): string;
88
+ BiasGradients(paramsJSON: string): string;
89
+ Clone(paramsJSON: string): string;
90
+ InitializeWeights(paramsJSON: string): string;
91
+ InitGPU(paramsJSON: string): string;
92
+ ReleaseGPU(paramsJSON: string): string;
93
+ GetMethods(paramsJSON: string): string;
94
+ GetMethodsJSON(paramsJSON: string): string;
95
+ ListMethods(paramsJSON: string): string;
96
+ HasMethod(paramsJSON: string): string;
97
+ GetMethodSignature(paramsJSON: string): string;
168
98
  }
169
99
  /**
170
- * Transformer API for LLM inference
100
+ * Global WASM functions exposed by main.go
101
+ * Only createLoomNetwork is exposed - use network.SaveModelToString() for saving
171
102
  */
172
- export interface TransformerAPI {
173
- /**
174
- * Load tokenizer from JSON bytes
175
- * @param tokenizerData - Uint8Array of tokenizer.json file
176
- */
177
- loadTokenizer(tokenizerData: Uint8Array): Promise<TokenizerLoadResult>;
178
- /**
179
- * Load transformer model from config and weights bytes
180
- * @param configData - Uint8Array of config.json file
181
- * @param weightsData - Uint8Array of model.safetensors file
182
- */
183
- loadModel(configData: Uint8Array, weightsData: Uint8Array): Promise<TransformerLoadResult>;
184
- /**
185
- * Encode text to token IDs
186
- * @param text - Input text to encode
187
- * @param addSpecialTokens - Whether to add special tokens (default: true)
188
- */
189
- encode(text: string, addSpecialTokens?: boolean): Promise<EncodeResult>;
190
- /**
191
- * Decode token IDs to text
192
- * @param tokenIds - Array of token IDs
193
- * @param skipSpecialTokens - Whether to skip special tokens (default: true)
194
- */
195
- decode(tokenIds: number[], skipSpecialTokens?: boolean): Promise<DecodeResult>;
196
- /**
197
- * Generate text from prompt (blocking, all tokens at once)
198
- * @param prompt - Input prompt
199
- * @param maxTokens - Maximum tokens to generate (default: 50)
200
- * @param temperature - Sampling temperature (default: 0.7)
201
- */
202
- generate(prompt: string, maxTokens?: number, temperature?: number): Promise<GenerateResult>;
203
- /**
204
- * Generate text token-by-token (streaming)
205
- * @param prompt - Input prompt
206
- * @param maxTokens - Maximum tokens to generate (default: 50)
207
- * @param temperature - Sampling temperature (default: 0.7)
208
- * @yields Token text strings
209
- */
210
- generateStream(prompt: string, maxTokens?: number, temperature?: number): AsyncGenerator<string, void, unknown>;
103
+ declare global {
104
+ function createLoomNetwork(jsonConfig: string): Network;
211
105
  }
package/dist/types.js CHANGED
@@ -1,12 +1,4 @@
1
1
  /**
2
- * Activation function types
2
+ * Type definitions for LOOM WASM API
3
3
  */
4
- export var ActivationType;
5
- (function (ActivationType) {
6
- ActivationType[ActivationType["ReLU"] = 0] = "ReLU";
7
- ActivationType[ActivationType["Sigmoid"] = 1] = "Sigmoid";
8
- ActivationType[ActivationType["Tanh"] = 2] = "Tanh";
9
- ActivationType[ActivationType["Softplus"] = 3] = "Softplus";
10
- ActivationType[ActivationType["LeakyReLU"] = 4] = "LeakyReLU";
11
- ActivationType[ActivationType["Linear"] = 5] = "Linear";
12
- })(ActivationType || (ActivationType = {}));
4
+ export {};