rvlite 0.2.1
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/README.md +270 -0
- package/bin/cli.js +1685 -0
- package/dist/wasm/README.md +216 -0
- package/dist/wasm/attention/LICENSE +21 -0
- package/dist/wasm/attention/README.md +193 -0
- package/dist/wasm/attention/package.json +17 -0
- package/dist/wasm/attention/ruvector_attention_wasm.d.ts +334 -0
- package/dist/wasm/attention/ruvector_attention_wasm.js +1470 -0
- package/dist/wasm/attention/ruvector_attention_wasm_bg.wasm +0 -0
- package/dist/wasm/attention/ruvector_attention_wasm_bg.wasm.d.ts +71 -0
- package/dist/wasm/package.json +24 -0
- package/dist/wasm/rvlite.d.ts +276 -0
- package/dist/wasm/rvlite.js +1504 -0
- package/dist/wasm/rvlite_bg.wasm +0 -0
- package/dist/wasm/rvlite_bg.wasm.d.ts +56 -0
- package/dist/wasm/sona/LICENSE-APACHE +103 -0
- package/dist/wasm/sona/LICENSE-MIT +21 -0
- package/dist/wasm/sona/README.md +1513 -0
- package/dist/wasm/sona/package.json +36 -0
- package/dist/wasm/sona/ruvector_sona.d.ts +513 -0
- package/dist/wasm/sona/ruvector_sona.js +1286 -0
- package/dist/wasm/sona/ruvector_sona_bg.wasm +0 -0
- package/dist/wasm/sona/ruvector_sona_bg.wasm.d.ts +53 -0
- package/dist/wasm/sona/sona.d.ts +281 -0
- package/dist/wasm/sona/sona.js +685 -0
- package/dist/wasm/sona/sona_bg.wasm +0 -0
- package/dist/wasm/sona/sona_bg.wasm.d.ts +26 -0
- package/package.json +81 -0
|
@@ -0,0 +1,1470 @@
|
|
|
1
|
+
|
|
2
|
+
let imports = {};
|
|
3
|
+
imports['__wbindgen_placeholder__'] = module.exports;
|
|
4
|
+
|
|
5
|
+
let cachedUint8ArrayMemory0 = null;
|
|
6
|
+
|
|
7
|
+
function getUint8ArrayMemory0() {
|
|
8
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
9
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
10
|
+
}
|
|
11
|
+
return cachedUint8ArrayMemory0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
15
|
+
|
|
16
|
+
cachedTextDecoder.decode();
|
|
17
|
+
|
|
18
|
+
function decodeText(ptr, len) {
|
|
19
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getStringFromWasm0(ptr, len) {
|
|
23
|
+
ptr = ptr >>> 0;
|
|
24
|
+
return decodeText(ptr, len);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let heap = new Array(128).fill(undefined);
|
|
28
|
+
|
|
29
|
+
heap.push(undefined, null, true, false);
|
|
30
|
+
|
|
31
|
+
let heap_next = heap.length;
|
|
32
|
+
|
|
33
|
+
function addHeapObject(obj) {
|
|
34
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
35
|
+
const idx = heap_next;
|
|
36
|
+
heap_next = heap[idx];
|
|
37
|
+
|
|
38
|
+
heap[idx] = obj;
|
|
39
|
+
return idx;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getObject(idx) { return heap[idx]; }
|
|
43
|
+
|
|
44
|
+
let WASM_VECTOR_LEN = 0;
|
|
45
|
+
|
|
46
|
+
const cachedTextEncoder = new TextEncoder();
|
|
47
|
+
|
|
48
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
49
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
50
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
51
|
+
view.set(buf);
|
|
52
|
+
return {
|
|
53
|
+
read: arg.length,
|
|
54
|
+
written: buf.length
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
60
|
+
|
|
61
|
+
if (realloc === undefined) {
|
|
62
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
63
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
64
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
65
|
+
WASM_VECTOR_LEN = buf.length;
|
|
66
|
+
return ptr;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let len = arg.length;
|
|
70
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
71
|
+
|
|
72
|
+
const mem = getUint8ArrayMemory0();
|
|
73
|
+
|
|
74
|
+
let offset = 0;
|
|
75
|
+
|
|
76
|
+
for (; offset < len; offset++) {
|
|
77
|
+
const code = arg.charCodeAt(offset);
|
|
78
|
+
if (code > 0x7F) break;
|
|
79
|
+
mem[ptr + offset] = code;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (offset !== len) {
|
|
83
|
+
if (offset !== 0) {
|
|
84
|
+
arg = arg.slice(offset);
|
|
85
|
+
}
|
|
86
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
87
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
88
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
89
|
+
|
|
90
|
+
offset += ret.written;
|
|
91
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
WASM_VECTOR_LEN = offset;
|
|
95
|
+
return ptr;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let cachedDataViewMemory0 = null;
|
|
99
|
+
|
|
100
|
+
function getDataViewMemory0() {
|
|
101
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
102
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
103
|
+
}
|
|
104
|
+
return cachedDataViewMemory0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function isLikeNone(x) {
|
|
108
|
+
return x === undefined || x === null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
112
|
+
ptr = ptr >>> 0;
|
|
113
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function debugString(val) {
|
|
117
|
+
// primitive types
|
|
118
|
+
const type = typeof val;
|
|
119
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
120
|
+
return `${val}`;
|
|
121
|
+
}
|
|
122
|
+
if (type == 'string') {
|
|
123
|
+
return `"${val}"`;
|
|
124
|
+
}
|
|
125
|
+
if (type == 'symbol') {
|
|
126
|
+
const description = val.description;
|
|
127
|
+
if (description == null) {
|
|
128
|
+
return 'Symbol';
|
|
129
|
+
} else {
|
|
130
|
+
return `Symbol(${description})`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (type == 'function') {
|
|
134
|
+
const name = val.name;
|
|
135
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
136
|
+
return `Function(${name})`;
|
|
137
|
+
} else {
|
|
138
|
+
return 'Function';
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// objects
|
|
142
|
+
if (Array.isArray(val)) {
|
|
143
|
+
const length = val.length;
|
|
144
|
+
let debug = '[';
|
|
145
|
+
if (length > 0) {
|
|
146
|
+
debug += debugString(val[0]);
|
|
147
|
+
}
|
|
148
|
+
for(let i = 1; i < length; i++) {
|
|
149
|
+
debug += ', ' + debugString(val[i]);
|
|
150
|
+
}
|
|
151
|
+
debug += ']';
|
|
152
|
+
return debug;
|
|
153
|
+
}
|
|
154
|
+
// Test for built-in
|
|
155
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
156
|
+
let className;
|
|
157
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
158
|
+
className = builtInMatches[1];
|
|
159
|
+
} else {
|
|
160
|
+
// Failed to match the standard '[object ClassName]'
|
|
161
|
+
return toString.call(val);
|
|
162
|
+
}
|
|
163
|
+
if (className == 'Object') {
|
|
164
|
+
// we're a user defined class or Object
|
|
165
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
166
|
+
// easier than looping through ownProperties of `val`.
|
|
167
|
+
try {
|
|
168
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
169
|
+
} catch (_) {
|
|
170
|
+
return 'Object';
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// errors
|
|
174
|
+
if (val instanceof Error) {
|
|
175
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
176
|
+
}
|
|
177
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
178
|
+
return className;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function handleError(f, args) {
|
|
182
|
+
try {
|
|
183
|
+
return f.apply(this, args);
|
|
184
|
+
} catch (e) {
|
|
185
|
+
wasm.__wbindgen_export3(addHeapObject(e));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function dropObject(idx) {
|
|
190
|
+
if (idx < 132) return;
|
|
191
|
+
heap[idx] = heap_next;
|
|
192
|
+
heap_next = idx;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function takeObject(idx) {
|
|
196
|
+
const ret = getObject(idx);
|
|
197
|
+
dropObject(idx);
|
|
198
|
+
return ret;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Get information about available attention mechanisms
|
|
202
|
+
* @returns {any}
|
|
203
|
+
*/
|
|
204
|
+
exports.available_mechanisms = function() {
|
|
205
|
+
const ret = wasm.available_mechanisms();
|
|
206
|
+
return takeObject(ret);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Initialize the WASM module with panic hook
|
|
211
|
+
*/
|
|
212
|
+
exports.init = function() {
|
|
213
|
+
wasm.init();
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Get the version of the ruvector-attention-wasm crate
|
|
218
|
+
* @returns {string}
|
|
219
|
+
*/
|
|
220
|
+
exports.version = function() {
|
|
221
|
+
let deferred1_0;
|
|
222
|
+
let deferred1_1;
|
|
223
|
+
try {
|
|
224
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
225
|
+
wasm.version(retptr);
|
|
226
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
227
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
228
|
+
deferred1_0 = r0;
|
|
229
|
+
deferred1_1 = r1;
|
|
230
|
+
return getStringFromWasm0(r0, r1);
|
|
231
|
+
} finally {
|
|
232
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
233
|
+
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
let cachedFloat32ArrayMemory0 = null;
|
|
238
|
+
|
|
239
|
+
function getFloat32ArrayMemory0() {
|
|
240
|
+
if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
|
|
241
|
+
cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
|
|
242
|
+
}
|
|
243
|
+
return cachedFloat32ArrayMemory0;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function passArrayF32ToWasm0(arg, malloc) {
|
|
247
|
+
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
248
|
+
getFloat32ArrayMemory0().set(arg, ptr / 4);
|
|
249
|
+
WASM_VECTOR_LEN = arg.length;
|
|
250
|
+
return ptr;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Compute attention weights from scores
|
|
254
|
+
* @param {Float32Array} scores
|
|
255
|
+
* @param {number | null} [temperature]
|
|
256
|
+
*/
|
|
257
|
+
exports.attention_weights = function(scores, temperature) {
|
|
258
|
+
var ptr0 = passArrayF32ToWasm0(scores, wasm.__wbindgen_export);
|
|
259
|
+
var len0 = WASM_VECTOR_LEN;
|
|
260
|
+
wasm.attention_weights(ptr0, len0, addHeapObject(scores), isLikeNone(temperature) ? 0x100000001 : Math.fround(temperature));
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
function getArrayF32FromWasm0(ptr, len) {
|
|
264
|
+
ptr = ptr >>> 0;
|
|
265
|
+
return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Batch normalize vectors
|
|
269
|
+
* @param {any} vectors
|
|
270
|
+
* @param {number | null} [epsilon]
|
|
271
|
+
* @returns {Float32Array}
|
|
272
|
+
*/
|
|
273
|
+
exports.batch_normalize = function(vectors, epsilon) {
|
|
274
|
+
try {
|
|
275
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
276
|
+
wasm.batch_normalize(retptr, addHeapObject(vectors), isLikeNone(epsilon) ? 0x100000001 : Math.fround(epsilon));
|
|
277
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
278
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
279
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
280
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
281
|
+
if (r3) {
|
|
282
|
+
throw takeObject(r2);
|
|
283
|
+
}
|
|
284
|
+
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
|
285
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
286
|
+
return v1;
|
|
287
|
+
} finally {
|
|
288
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Log an error to the browser console
|
|
294
|
+
* @param {string} message
|
|
295
|
+
*/
|
|
296
|
+
exports.log_error = function(message) {
|
|
297
|
+
const ptr0 = passStringToWasm0(message, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
298
|
+
const len0 = WASM_VECTOR_LEN;
|
|
299
|
+
wasm.log_error(ptr0, len0);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Normalize a vector to unit length
|
|
304
|
+
* @param {Float32Array} vec
|
|
305
|
+
*/
|
|
306
|
+
exports.normalize = function(vec) {
|
|
307
|
+
try {
|
|
308
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
309
|
+
var ptr0 = passArrayF32ToWasm0(vec, wasm.__wbindgen_export);
|
|
310
|
+
var len0 = WASM_VECTOR_LEN;
|
|
311
|
+
wasm.normalize(retptr, ptr0, len0, addHeapObject(vec));
|
|
312
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
313
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
314
|
+
if (r1) {
|
|
315
|
+
throw takeObject(r0);
|
|
316
|
+
}
|
|
317
|
+
} finally {
|
|
318
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Log a message to the browser console
|
|
324
|
+
* @param {string} message
|
|
325
|
+
*/
|
|
326
|
+
exports.log = function(message) {
|
|
327
|
+
const ptr0 = passStringToWasm0(message, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
328
|
+
const len0 = WASM_VECTOR_LEN;
|
|
329
|
+
wasm.log(ptr0, len0);
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Compute L2 norm of a vector
|
|
334
|
+
* @param {Float32Array} vec
|
|
335
|
+
* @returns {number}
|
|
336
|
+
*/
|
|
337
|
+
exports.l2_norm = function(vec) {
|
|
338
|
+
const ptr0 = passArrayF32ToWasm0(vec, wasm.__wbindgen_export);
|
|
339
|
+
const len0 = WASM_VECTOR_LEN;
|
|
340
|
+
const ret = wasm.l2_norm(ptr0, len0);
|
|
341
|
+
return ret;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Compute pairwise distances between vectors
|
|
346
|
+
* @param {any} vectors
|
|
347
|
+
* @returns {Float32Array}
|
|
348
|
+
*/
|
|
349
|
+
exports.pairwise_distances = function(vectors) {
|
|
350
|
+
try {
|
|
351
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
352
|
+
wasm.pairwise_distances(retptr, addHeapObject(vectors));
|
|
353
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
354
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
355
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
356
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
357
|
+
if (r3) {
|
|
358
|
+
throw takeObject(r2);
|
|
359
|
+
}
|
|
360
|
+
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
|
361
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
362
|
+
return v1;
|
|
363
|
+
} finally {
|
|
364
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Compute cosine similarity between two vectors
|
|
370
|
+
* @param {Float32Array} a
|
|
371
|
+
* @param {Float32Array} b
|
|
372
|
+
* @returns {number}
|
|
373
|
+
*/
|
|
374
|
+
exports.cosine_similarity = function(a, b) {
|
|
375
|
+
try {
|
|
376
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
377
|
+
const ptr0 = passArrayF32ToWasm0(a, wasm.__wbindgen_export);
|
|
378
|
+
const len0 = WASM_VECTOR_LEN;
|
|
379
|
+
const ptr1 = passArrayF32ToWasm0(b, wasm.__wbindgen_export);
|
|
380
|
+
const len1 = WASM_VECTOR_LEN;
|
|
381
|
+
wasm.cosine_similarity(retptr, ptr0, len0, ptr1, len1);
|
|
382
|
+
var r0 = getDataViewMemory0().getFloat32(retptr + 4 * 0, true);
|
|
383
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
384
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
385
|
+
if (r2) {
|
|
386
|
+
throw takeObject(r1);
|
|
387
|
+
}
|
|
388
|
+
return r0;
|
|
389
|
+
} finally {
|
|
390
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Generate random orthogonal matrix (for initialization)
|
|
396
|
+
* @param {number} dim
|
|
397
|
+
* @returns {Float32Array}
|
|
398
|
+
*/
|
|
399
|
+
exports.random_orthogonal_matrix = function(dim) {
|
|
400
|
+
try {
|
|
401
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
402
|
+
wasm.random_orthogonal_matrix(retptr, dim);
|
|
403
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
404
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
405
|
+
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
|
406
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
407
|
+
return v1;
|
|
408
|
+
} finally {
|
|
409
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Compute softmax of a vector
|
|
415
|
+
* @param {Float32Array} vec
|
|
416
|
+
*/
|
|
417
|
+
exports.softmax = function(vec) {
|
|
418
|
+
var ptr0 = passArrayF32ToWasm0(vec, wasm.__wbindgen_export);
|
|
419
|
+
var len0 = WASM_VECTOR_LEN;
|
|
420
|
+
wasm.softmax(ptr0, len0, addHeapObject(vec));
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Compute scaled dot-product attention
|
|
425
|
+
*
|
|
426
|
+
* # Arguments
|
|
427
|
+
* * `query` - Query vector as Float32Array
|
|
428
|
+
* * `keys` - Array of key vectors
|
|
429
|
+
* * `values` - Array of value vectors
|
|
430
|
+
* * `scale` - Optional scaling factor (defaults to 1/sqrt(dim))
|
|
431
|
+
* @param {Float32Array} query
|
|
432
|
+
* @param {any} keys
|
|
433
|
+
* @param {any} values
|
|
434
|
+
* @param {number | null} [scale]
|
|
435
|
+
* @returns {Float32Array}
|
|
436
|
+
*/
|
|
437
|
+
exports.scaled_dot_attention = function(query, keys, values, scale) {
|
|
438
|
+
try {
|
|
439
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
440
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
441
|
+
const len0 = WASM_VECTOR_LEN;
|
|
442
|
+
wasm.scaled_dot_attention(retptr, ptr0, len0, addHeapObject(keys), addHeapObject(values), isLikeNone(scale) ? 0x100000001 : Math.fround(scale));
|
|
443
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
444
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
445
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
446
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
447
|
+
if (r3) {
|
|
448
|
+
throw takeObject(r2);
|
|
449
|
+
}
|
|
450
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
451
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
452
|
+
return v2;
|
|
453
|
+
} finally {
|
|
454
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
const WasmAdamFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
459
|
+
? { register: () => {}, unregister: () => {} }
|
|
460
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmadam_free(ptr >>> 0, 1));
|
|
461
|
+
/**
|
|
462
|
+
* Adam optimizer
|
|
463
|
+
*/
|
|
464
|
+
class WasmAdam {
|
|
465
|
+
|
|
466
|
+
__destroy_into_raw() {
|
|
467
|
+
const ptr = this.__wbg_ptr;
|
|
468
|
+
this.__wbg_ptr = 0;
|
|
469
|
+
WasmAdamFinalization.unregister(this);
|
|
470
|
+
return ptr;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
free() {
|
|
474
|
+
const ptr = this.__destroy_into_raw();
|
|
475
|
+
wasm.__wbg_wasmadam_free(ptr, 0);
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Get current learning rate
|
|
479
|
+
* @returns {number}
|
|
480
|
+
*/
|
|
481
|
+
get learning_rate() {
|
|
482
|
+
const ret = wasm.wasmadam_learning_rate(this.__wbg_ptr);
|
|
483
|
+
return ret;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Set learning rate
|
|
487
|
+
* @param {number} lr
|
|
488
|
+
*/
|
|
489
|
+
set learning_rate(lr) {
|
|
490
|
+
wasm.wasmadam_set_learning_rate(this.__wbg_ptr, lr);
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Create a new Adam optimizer
|
|
494
|
+
*
|
|
495
|
+
* # Arguments
|
|
496
|
+
* * `param_count` - Number of parameters
|
|
497
|
+
* * `learning_rate` - Learning rate
|
|
498
|
+
* @param {number} param_count
|
|
499
|
+
* @param {number} learning_rate
|
|
500
|
+
*/
|
|
501
|
+
constructor(param_count, learning_rate) {
|
|
502
|
+
const ret = wasm.wasmadam_new(param_count, learning_rate);
|
|
503
|
+
this.__wbg_ptr = ret >>> 0;
|
|
504
|
+
WasmAdamFinalization.register(this, this.__wbg_ptr, this);
|
|
505
|
+
return this;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Perform optimization step
|
|
509
|
+
*
|
|
510
|
+
* # Arguments
|
|
511
|
+
* * `params` - Current parameter values (will be updated in-place)
|
|
512
|
+
* * `gradients` - Gradient values
|
|
513
|
+
* @param {Float32Array} params
|
|
514
|
+
* @param {Float32Array} gradients
|
|
515
|
+
*/
|
|
516
|
+
step(params, gradients) {
|
|
517
|
+
var ptr0 = passArrayF32ToWasm0(params, wasm.__wbindgen_export);
|
|
518
|
+
var len0 = WASM_VECTOR_LEN;
|
|
519
|
+
const ptr1 = passArrayF32ToWasm0(gradients, wasm.__wbindgen_export);
|
|
520
|
+
const len1 = WASM_VECTOR_LEN;
|
|
521
|
+
wasm.wasmadam_step(this.__wbg_ptr, ptr0, len0, addHeapObject(params), ptr1, len1);
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Reset optimizer state
|
|
525
|
+
*/
|
|
526
|
+
reset() {
|
|
527
|
+
wasm.wasmadam_reset(this.__wbg_ptr);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
if (Symbol.dispose) WasmAdam.prototype[Symbol.dispose] = WasmAdam.prototype.free;
|
|
531
|
+
|
|
532
|
+
exports.WasmAdam = WasmAdam;
|
|
533
|
+
|
|
534
|
+
const WasmAdamWFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
535
|
+
? { register: () => {}, unregister: () => {} }
|
|
536
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmadamw_free(ptr >>> 0, 1));
|
|
537
|
+
/**
|
|
538
|
+
* AdamW optimizer (Adam with decoupled weight decay)
|
|
539
|
+
*/
|
|
540
|
+
class WasmAdamW {
|
|
541
|
+
|
|
542
|
+
__destroy_into_raw() {
|
|
543
|
+
const ptr = this.__wbg_ptr;
|
|
544
|
+
this.__wbg_ptr = 0;
|
|
545
|
+
WasmAdamWFinalization.unregister(this);
|
|
546
|
+
return ptr;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
free() {
|
|
550
|
+
const ptr = this.__destroy_into_raw();
|
|
551
|
+
wasm.__wbg_wasmadamw_free(ptr, 0);
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Get weight decay
|
|
555
|
+
* @returns {number}
|
|
556
|
+
*/
|
|
557
|
+
get weight_decay() {
|
|
558
|
+
const ret = wasm.wasmadamw_weight_decay(this.__wbg_ptr);
|
|
559
|
+
return ret;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Get current learning rate
|
|
563
|
+
* @returns {number}
|
|
564
|
+
*/
|
|
565
|
+
get learning_rate() {
|
|
566
|
+
const ret = wasm.wasmadam_learning_rate(this.__wbg_ptr);
|
|
567
|
+
return ret;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Set learning rate
|
|
571
|
+
* @param {number} lr
|
|
572
|
+
*/
|
|
573
|
+
set learning_rate(lr) {
|
|
574
|
+
wasm.wasmadam_set_learning_rate(this.__wbg_ptr, lr);
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Create a new AdamW optimizer
|
|
578
|
+
*
|
|
579
|
+
* # Arguments
|
|
580
|
+
* * `param_count` - Number of parameters
|
|
581
|
+
* * `learning_rate` - Learning rate
|
|
582
|
+
* * `weight_decay` - Weight decay coefficient
|
|
583
|
+
* @param {number} param_count
|
|
584
|
+
* @param {number} learning_rate
|
|
585
|
+
* @param {number} weight_decay
|
|
586
|
+
*/
|
|
587
|
+
constructor(param_count, learning_rate, weight_decay) {
|
|
588
|
+
const ret = wasm.wasmadamw_new(param_count, learning_rate, weight_decay);
|
|
589
|
+
this.__wbg_ptr = ret >>> 0;
|
|
590
|
+
WasmAdamWFinalization.register(this, this.__wbg_ptr, this);
|
|
591
|
+
return this;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Perform optimization step with weight decay
|
|
595
|
+
* @param {Float32Array} params
|
|
596
|
+
* @param {Float32Array} gradients
|
|
597
|
+
*/
|
|
598
|
+
step(params, gradients) {
|
|
599
|
+
var ptr0 = passArrayF32ToWasm0(params, wasm.__wbindgen_export);
|
|
600
|
+
var len0 = WASM_VECTOR_LEN;
|
|
601
|
+
const ptr1 = passArrayF32ToWasm0(gradients, wasm.__wbindgen_export);
|
|
602
|
+
const len1 = WASM_VECTOR_LEN;
|
|
603
|
+
wasm.wasmadamw_step(this.__wbg_ptr, ptr0, len0, addHeapObject(params), ptr1, len1);
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Reset optimizer state
|
|
607
|
+
*/
|
|
608
|
+
reset() {
|
|
609
|
+
wasm.wasmadamw_reset(this.__wbg_ptr);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
if (Symbol.dispose) WasmAdamW.prototype[Symbol.dispose] = WasmAdamW.prototype.free;
|
|
613
|
+
|
|
614
|
+
exports.WasmAdamW = WasmAdamW;
|
|
615
|
+
|
|
616
|
+
const WasmFlashAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
617
|
+
? { register: () => {}, unregister: () => {} }
|
|
618
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmflashattention_free(ptr >>> 0, 1));
|
|
619
|
+
/**
|
|
620
|
+
* Flash attention mechanism
|
|
621
|
+
*/
|
|
622
|
+
class WasmFlashAttention {
|
|
623
|
+
|
|
624
|
+
__destroy_into_raw() {
|
|
625
|
+
const ptr = this.__wbg_ptr;
|
|
626
|
+
this.__wbg_ptr = 0;
|
|
627
|
+
WasmFlashAttentionFinalization.unregister(this);
|
|
628
|
+
return ptr;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
free() {
|
|
632
|
+
const ptr = this.__destroy_into_raw();
|
|
633
|
+
wasm.__wbg_wasmflashattention_free(ptr, 0);
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Create a new flash attention instance
|
|
637
|
+
*
|
|
638
|
+
* # Arguments
|
|
639
|
+
* * `dim` - Embedding dimension
|
|
640
|
+
* * `block_size` - Block size for tiling
|
|
641
|
+
* @param {number} dim
|
|
642
|
+
* @param {number} block_size
|
|
643
|
+
*/
|
|
644
|
+
constructor(dim, block_size) {
|
|
645
|
+
const ret = wasm.wasmflashattention_new(dim, block_size);
|
|
646
|
+
this.__wbg_ptr = ret >>> 0;
|
|
647
|
+
WasmFlashAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
648
|
+
return this;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Compute flash attention
|
|
652
|
+
* @param {Float32Array} query
|
|
653
|
+
* @param {any} keys
|
|
654
|
+
* @param {any} values
|
|
655
|
+
* @returns {Float32Array}
|
|
656
|
+
*/
|
|
657
|
+
compute(query, keys, values) {
|
|
658
|
+
try {
|
|
659
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
660
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
661
|
+
const len0 = WASM_VECTOR_LEN;
|
|
662
|
+
wasm.wasmflashattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
|
663
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
664
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
665
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
666
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
667
|
+
if (r3) {
|
|
668
|
+
throw takeObject(r2);
|
|
669
|
+
}
|
|
670
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
671
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
672
|
+
return v2;
|
|
673
|
+
} finally {
|
|
674
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
if (Symbol.dispose) WasmFlashAttention.prototype[Symbol.dispose] = WasmFlashAttention.prototype.free;
|
|
679
|
+
|
|
680
|
+
exports.WasmFlashAttention = WasmFlashAttention;
|
|
681
|
+
|
|
682
|
+
const WasmHyperbolicAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
683
|
+
? { register: () => {}, unregister: () => {} }
|
|
684
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmhyperbolicattention_free(ptr >>> 0, 1));
|
|
685
|
+
/**
|
|
686
|
+
* Hyperbolic attention mechanism
|
|
687
|
+
*/
|
|
688
|
+
class WasmHyperbolicAttention {
|
|
689
|
+
|
|
690
|
+
__destroy_into_raw() {
|
|
691
|
+
const ptr = this.__wbg_ptr;
|
|
692
|
+
this.__wbg_ptr = 0;
|
|
693
|
+
WasmHyperbolicAttentionFinalization.unregister(this);
|
|
694
|
+
return ptr;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
free() {
|
|
698
|
+
const ptr = this.__destroy_into_raw();
|
|
699
|
+
wasm.__wbg_wasmhyperbolicattention_free(ptr, 0);
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Create a new hyperbolic attention instance
|
|
703
|
+
*
|
|
704
|
+
* # Arguments
|
|
705
|
+
* * `dim` - Embedding dimension
|
|
706
|
+
* * `curvature` - Hyperbolic curvature parameter
|
|
707
|
+
* @param {number} dim
|
|
708
|
+
* @param {number} curvature
|
|
709
|
+
*/
|
|
710
|
+
constructor(dim, curvature) {
|
|
711
|
+
const ret = wasm.wasmhyperbolicattention_new(dim, curvature);
|
|
712
|
+
this.__wbg_ptr = ret >>> 0;
|
|
713
|
+
WasmHyperbolicAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
714
|
+
return this;
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Compute hyperbolic attention
|
|
718
|
+
* @param {Float32Array} query
|
|
719
|
+
* @param {any} keys
|
|
720
|
+
* @param {any} values
|
|
721
|
+
* @returns {Float32Array}
|
|
722
|
+
*/
|
|
723
|
+
compute(query, keys, values) {
|
|
724
|
+
try {
|
|
725
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
726
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
727
|
+
const len0 = WASM_VECTOR_LEN;
|
|
728
|
+
wasm.wasmhyperbolicattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
|
729
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
730
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
731
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
732
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
733
|
+
if (r3) {
|
|
734
|
+
throw takeObject(r2);
|
|
735
|
+
}
|
|
736
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
737
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
738
|
+
return v2;
|
|
739
|
+
} finally {
|
|
740
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Get the curvature
|
|
745
|
+
* @returns {number}
|
|
746
|
+
*/
|
|
747
|
+
get curvature() {
|
|
748
|
+
const ret = wasm.wasmhyperbolicattention_curvature(this.__wbg_ptr);
|
|
749
|
+
return ret;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
if (Symbol.dispose) WasmHyperbolicAttention.prototype[Symbol.dispose] = WasmHyperbolicAttention.prototype.free;
|
|
753
|
+
|
|
754
|
+
exports.WasmHyperbolicAttention = WasmHyperbolicAttention;
|
|
755
|
+
|
|
756
|
+
const WasmInfoNCELossFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
757
|
+
? { register: () => {}, unregister: () => {} }
|
|
758
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasminfonceloss_free(ptr >>> 0, 1));
|
|
759
|
+
/**
|
|
760
|
+
* InfoNCE contrastive loss for training
|
|
761
|
+
*/
|
|
762
|
+
class WasmInfoNCELoss {
|
|
763
|
+
|
|
764
|
+
__destroy_into_raw() {
|
|
765
|
+
const ptr = this.__wbg_ptr;
|
|
766
|
+
this.__wbg_ptr = 0;
|
|
767
|
+
WasmInfoNCELossFinalization.unregister(this);
|
|
768
|
+
return ptr;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
free() {
|
|
772
|
+
const ptr = this.__destroy_into_raw();
|
|
773
|
+
wasm.__wbg_wasminfonceloss_free(ptr, 0);
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Create a new InfoNCE loss instance
|
|
777
|
+
*
|
|
778
|
+
* # Arguments
|
|
779
|
+
* * `temperature` - Temperature parameter for softmax
|
|
780
|
+
* @param {number} temperature
|
|
781
|
+
*/
|
|
782
|
+
constructor(temperature) {
|
|
783
|
+
const ret = wasm.wasminfonceloss_new(temperature);
|
|
784
|
+
this.__wbg_ptr = ret >>> 0;
|
|
785
|
+
WasmInfoNCELossFinalization.register(this, this.__wbg_ptr, this);
|
|
786
|
+
return this;
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Compute InfoNCE loss
|
|
790
|
+
*
|
|
791
|
+
* # Arguments
|
|
792
|
+
* * `anchor` - Anchor embedding
|
|
793
|
+
* * `positive` - Positive example embedding
|
|
794
|
+
* * `negatives` - Array of negative example embeddings
|
|
795
|
+
* @param {Float32Array} anchor
|
|
796
|
+
* @param {Float32Array} positive
|
|
797
|
+
* @param {any} negatives
|
|
798
|
+
* @returns {number}
|
|
799
|
+
*/
|
|
800
|
+
compute(anchor, positive, negatives) {
|
|
801
|
+
try {
|
|
802
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
803
|
+
const ptr0 = passArrayF32ToWasm0(anchor, wasm.__wbindgen_export);
|
|
804
|
+
const len0 = WASM_VECTOR_LEN;
|
|
805
|
+
const ptr1 = passArrayF32ToWasm0(positive, wasm.__wbindgen_export);
|
|
806
|
+
const len1 = WASM_VECTOR_LEN;
|
|
807
|
+
wasm.wasminfonceloss_compute(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(negatives));
|
|
808
|
+
var r0 = getDataViewMemory0().getFloat32(retptr + 4 * 0, true);
|
|
809
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
810
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
811
|
+
if (r2) {
|
|
812
|
+
throw takeObject(r1);
|
|
813
|
+
}
|
|
814
|
+
return r0;
|
|
815
|
+
} finally {
|
|
816
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
if (Symbol.dispose) WasmInfoNCELoss.prototype[Symbol.dispose] = WasmInfoNCELoss.prototype.free;
|
|
821
|
+
|
|
822
|
+
exports.WasmInfoNCELoss = WasmInfoNCELoss;
|
|
823
|
+
|
|
824
|
+
const WasmLRSchedulerFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
825
|
+
? { register: () => {}, unregister: () => {} }
|
|
826
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmlrscheduler_free(ptr >>> 0, 1));
|
|
827
|
+
/**
|
|
828
|
+
* Learning rate scheduler
|
|
829
|
+
*/
|
|
830
|
+
class WasmLRScheduler {
|
|
831
|
+
|
|
832
|
+
__destroy_into_raw() {
|
|
833
|
+
const ptr = this.__wbg_ptr;
|
|
834
|
+
this.__wbg_ptr = 0;
|
|
835
|
+
WasmLRSchedulerFinalization.unregister(this);
|
|
836
|
+
return ptr;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
free() {
|
|
840
|
+
const ptr = this.__destroy_into_raw();
|
|
841
|
+
wasm.__wbg_wasmlrscheduler_free(ptr, 0);
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Create a new learning rate scheduler with warmup and cosine decay
|
|
845
|
+
*
|
|
846
|
+
* # Arguments
|
|
847
|
+
* * `initial_lr` - Initial learning rate
|
|
848
|
+
* * `warmup_steps` - Number of warmup steps
|
|
849
|
+
* * `total_steps` - Total training steps
|
|
850
|
+
* @param {number} initial_lr
|
|
851
|
+
* @param {number} warmup_steps
|
|
852
|
+
* @param {number} total_steps
|
|
853
|
+
*/
|
|
854
|
+
constructor(initial_lr, warmup_steps, total_steps) {
|
|
855
|
+
const ret = wasm.wasmlrscheduler_new(initial_lr, warmup_steps, total_steps);
|
|
856
|
+
this.__wbg_ptr = ret >>> 0;
|
|
857
|
+
WasmLRSchedulerFinalization.register(this, this.__wbg_ptr, this);
|
|
858
|
+
return this;
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Advance to next step
|
|
862
|
+
*/
|
|
863
|
+
step() {
|
|
864
|
+
wasm.wasmlrscheduler_step(this.__wbg_ptr);
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Reset scheduler
|
|
868
|
+
*/
|
|
869
|
+
reset() {
|
|
870
|
+
wasm.wasmlrscheduler_reset(this.__wbg_ptr);
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Get learning rate for current step
|
|
874
|
+
* @returns {number}
|
|
875
|
+
*/
|
|
876
|
+
get_lr() {
|
|
877
|
+
const ret = wasm.wasmlrscheduler_get_lr(this.__wbg_ptr);
|
|
878
|
+
return ret;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
if (Symbol.dispose) WasmLRScheduler.prototype[Symbol.dispose] = WasmLRScheduler.prototype.free;
|
|
882
|
+
|
|
883
|
+
exports.WasmLRScheduler = WasmLRScheduler;
|
|
884
|
+
|
|
885
|
+
const WasmLinearAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
886
|
+
? { register: () => {}, unregister: () => {} }
|
|
887
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmlinearattention_free(ptr >>> 0, 1));
|
|
888
|
+
/**
|
|
889
|
+
* Linear attention (Performer-style)
|
|
890
|
+
*/
|
|
891
|
+
class WasmLinearAttention {
|
|
892
|
+
|
|
893
|
+
__destroy_into_raw() {
|
|
894
|
+
const ptr = this.__wbg_ptr;
|
|
895
|
+
this.__wbg_ptr = 0;
|
|
896
|
+
WasmLinearAttentionFinalization.unregister(this);
|
|
897
|
+
return ptr;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
free() {
|
|
901
|
+
const ptr = this.__destroy_into_raw();
|
|
902
|
+
wasm.__wbg_wasmlinearattention_free(ptr, 0);
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Create a new linear attention instance
|
|
906
|
+
*
|
|
907
|
+
* # Arguments
|
|
908
|
+
* * `dim` - Embedding dimension
|
|
909
|
+
* * `num_features` - Number of random features
|
|
910
|
+
* @param {number} dim
|
|
911
|
+
* @param {number} num_features
|
|
912
|
+
*/
|
|
913
|
+
constructor(dim, num_features) {
|
|
914
|
+
const ret = wasm.wasmlinearattention_new(dim, num_features);
|
|
915
|
+
this.__wbg_ptr = ret >>> 0;
|
|
916
|
+
WasmLinearAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
917
|
+
return this;
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Compute linear attention
|
|
921
|
+
* @param {Float32Array} query
|
|
922
|
+
* @param {any} keys
|
|
923
|
+
* @param {any} values
|
|
924
|
+
* @returns {Float32Array}
|
|
925
|
+
*/
|
|
926
|
+
compute(query, keys, values) {
|
|
927
|
+
try {
|
|
928
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
929
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
930
|
+
const len0 = WASM_VECTOR_LEN;
|
|
931
|
+
wasm.wasmlinearattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
|
932
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
933
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
934
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
935
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
936
|
+
if (r3) {
|
|
937
|
+
throw takeObject(r2);
|
|
938
|
+
}
|
|
939
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
940
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
941
|
+
return v2;
|
|
942
|
+
} finally {
|
|
943
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
if (Symbol.dispose) WasmLinearAttention.prototype[Symbol.dispose] = WasmLinearAttention.prototype.free;
|
|
948
|
+
|
|
949
|
+
exports.WasmLinearAttention = WasmLinearAttention;
|
|
950
|
+
|
|
951
|
+
const WasmLocalGlobalAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
952
|
+
? { register: () => {}, unregister: () => {} }
|
|
953
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmlocalglobalattention_free(ptr >>> 0, 1));
|
|
954
|
+
/**
|
|
955
|
+
* Local-global attention mechanism
|
|
956
|
+
*/
|
|
957
|
+
class WasmLocalGlobalAttention {
|
|
958
|
+
|
|
959
|
+
__destroy_into_raw() {
|
|
960
|
+
const ptr = this.__wbg_ptr;
|
|
961
|
+
this.__wbg_ptr = 0;
|
|
962
|
+
WasmLocalGlobalAttentionFinalization.unregister(this);
|
|
963
|
+
return ptr;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
free() {
|
|
967
|
+
const ptr = this.__destroy_into_raw();
|
|
968
|
+
wasm.__wbg_wasmlocalglobalattention_free(ptr, 0);
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Create a new local-global attention instance
|
|
972
|
+
*
|
|
973
|
+
* # Arguments
|
|
974
|
+
* * `dim` - Embedding dimension
|
|
975
|
+
* * `local_window` - Size of local attention window
|
|
976
|
+
* * `global_tokens` - Number of global attention tokens
|
|
977
|
+
* @param {number} dim
|
|
978
|
+
* @param {number} local_window
|
|
979
|
+
* @param {number} global_tokens
|
|
980
|
+
*/
|
|
981
|
+
constructor(dim, local_window, global_tokens) {
|
|
982
|
+
const ret = wasm.wasmlocalglobalattention_new(dim, local_window, global_tokens);
|
|
983
|
+
this.__wbg_ptr = ret >>> 0;
|
|
984
|
+
WasmLocalGlobalAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
985
|
+
return this;
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* Compute local-global attention
|
|
989
|
+
* @param {Float32Array} query
|
|
990
|
+
* @param {any} keys
|
|
991
|
+
* @param {any} values
|
|
992
|
+
* @returns {Float32Array}
|
|
993
|
+
*/
|
|
994
|
+
compute(query, keys, values) {
|
|
995
|
+
try {
|
|
996
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
997
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
998
|
+
const len0 = WASM_VECTOR_LEN;
|
|
999
|
+
wasm.wasmlocalglobalattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
|
1000
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1001
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1002
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1003
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1004
|
+
if (r3) {
|
|
1005
|
+
throw takeObject(r2);
|
|
1006
|
+
}
|
|
1007
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1008
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1009
|
+
return v2;
|
|
1010
|
+
} finally {
|
|
1011
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
if (Symbol.dispose) WasmLocalGlobalAttention.prototype[Symbol.dispose] = WasmLocalGlobalAttention.prototype.free;
|
|
1016
|
+
|
|
1017
|
+
exports.WasmLocalGlobalAttention = WasmLocalGlobalAttention;
|
|
1018
|
+
|
|
1019
|
+
const WasmMoEAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1020
|
+
? { register: () => {}, unregister: () => {} }
|
|
1021
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmmoeattention_free(ptr >>> 0, 1));
|
|
1022
|
+
/**
|
|
1023
|
+
* Mixture of Experts (MoE) attention
|
|
1024
|
+
*/
|
|
1025
|
+
class WasmMoEAttention {
|
|
1026
|
+
|
|
1027
|
+
__destroy_into_raw() {
|
|
1028
|
+
const ptr = this.__wbg_ptr;
|
|
1029
|
+
this.__wbg_ptr = 0;
|
|
1030
|
+
WasmMoEAttentionFinalization.unregister(this);
|
|
1031
|
+
return ptr;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
free() {
|
|
1035
|
+
const ptr = this.__destroy_into_raw();
|
|
1036
|
+
wasm.__wbg_wasmmoeattention_free(ptr, 0);
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Create a new MoE attention instance
|
|
1040
|
+
*
|
|
1041
|
+
* # Arguments
|
|
1042
|
+
* * `dim` - Embedding dimension
|
|
1043
|
+
* * `num_experts` - Number of expert attention mechanisms
|
|
1044
|
+
* * `top_k` - Number of experts to use per query
|
|
1045
|
+
* @param {number} dim
|
|
1046
|
+
* @param {number} num_experts
|
|
1047
|
+
* @param {number} top_k
|
|
1048
|
+
*/
|
|
1049
|
+
constructor(dim, num_experts, top_k) {
|
|
1050
|
+
const ret = wasm.wasmmoeattention_new(dim, num_experts, top_k);
|
|
1051
|
+
this.__wbg_ptr = ret >>> 0;
|
|
1052
|
+
WasmMoEAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
1053
|
+
return this;
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* Compute MoE attention
|
|
1057
|
+
* @param {Float32Array} query
|
|
1058
|
+
* @param {any} keys
|
|
1059
|
+
* @param {any} values
|
|
1060
|
+
* @returns {Float32Array}
|
|
1061
|
+
*/
|
|
1062
|
+
compute(query, keys, values) {
|
|
1063
|
+
try {
|
|
1064
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1065
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
1066
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1067
|
+
wasm.wasmmoeattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
|
1068
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1069
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1070
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1071
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1072
|
+
if (r3) {
|
|
1073
|
+
throw takeObject(r2);
|
|
1074
|
+
}
|
|
1075
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1076
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1077
|
+
return v2;
|
|
1078
|
+
} finally {
|
|
1079
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
if (Symbol.dispose) WasmMoEAttention.prototype[Symbol.dispose] = WasmMoEAttention.prototype.free;
|
|
1084
|
+
|
|
1085
|
+
exports.WasmMoEAttention = WasmMoEAttention;
|
|
1086
|
+
|
|
1087
|
+
const WasmMultiHeadAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1088
|
+
? { register: () => {}, unregister: () => {} }
|
|
1089
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmmultiheadattention_free(ptr >>> 0, 1));
|
|
1090
|
+
/**
|
|
1091
|
+
* Multi-head attention mechanism
|
|
1092
|
+
*/
|
|
1093
|
+
class WasmMultiHeadAttention {
|
|
1094
|
+
|
|
1095
|
+
__destroy_into_raw() {
|
|
1096
|
+
const ptr = this.__wbg_ptr;
|
|
1097
|
+
this.__wbg_ptr = 0;
|
|
1098
|
+
WasmMultiHeadAttentionFinalization.unregister(this);
|
|
1099
|
+
return ptr;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
free() {
|
|
1103
|
+
const ptr = this.__destroy_into_raw();
|
|
1104
|
+
wasm.__wbg_wasmmultiheadattention_free(ptr, 0);
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Get the dimension
|
|
1108
|
+
* @returns {number}
|
|
1109
|
+
*/
|
|
1110
|
+
get dim() {
|
|
1111
|
+
const ret = wasm.wasmmultiheadattention_dim(this.__wbg_ptr);
|
|
1112
|
+
return ret >>> 0;
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* Create a new multi-head attention instance
|
|
1116
|
+
*
|
|
1117
|
+
* # Arguments
|
|
1118
|
+
* * `dim` - Embedding dimension
|
|
1119
|
+
* * `num_heads` - Number of attention heads
|
|
1120
|
+
* @param {number} dim
|
|
1121
|
+
* @param {number} num_heads
|
|
1122
|
+
*/
|
|
1123
|
+
constructor(dim, num_heads) {
|
|
1124
|
+
try {
|
|
1125
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1126
|
+
wasm.wasmmultiheadattention_new(retptr, dim, num_heads);
|
|
1127
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1128
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1129
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1130
|
+
if (r2) {
|
|
1131
|
+
throw takeObject(r1);
|
|
1132
|
+
}
|
|
1133
|
+
this.__wbg_ptr = r0 >>> 0;
|
|
1134
|
+
WasmMultiHeadAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
1135
|
+
return this;
|
|
1136
|
+
} finally {
|
|
1137
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
/**
|
|
1141
|
+
* Compute multi-head attention
|
|
1142
|
+
* @param {Float32Array} query
|
|
1143
|
+
* @param {any} keys
|
|
1144
|
+
* @param {any} values
|
|
1145
|
+
* @returns {Float32Array}
|
|
1146
|
+
*/
|
|
1147
|
+
compute(query, keys, values) {
|
|
1148
|
+
try {
|
|
1149
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1150
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
1151
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1152
|
+
wasm.wasmmultiheadattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
|
1153
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1154
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1155
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1156
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1157
|
+
if (r3) {
|
|
1158
|
+
throw takeObject(r2);
|
|
1159
|
+
}
|
|
1160
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1161
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1162
|
+
return v2;
|
|
1163
|
+
} finally {
|
|
1164
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Get the number of heads
|
|
1169
|
+
* @returns {number}
|
|
1170
|
+
*/
|
|
1171
|
+
get num_heads() {
|
|
1172
|
+
const ret = wasm.wasmmultiheadattention_num_heads(this.__wbg_ptr);
|
|
1173
|
+
return ret >>> 0;
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
if (Symbol.dispose) WasmMultiHeadAttention.prototype[Symbol.dispose] = WasmMultiHeadAttention.prototype.free;
|
|
1177
|
+
|
|
1178
|
+
exports.WasmMultiHeadAttention = WasmMultiHeadAttention;
|
|
1179
|
+
|
|
1180
|
+
const WasmSGDFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1181
|
+
? { register: () => {}, unregister: () => {} }
|
|
1182
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmsgd_free(ptr >>> 0, 1));
|
|
1183
|
+
/**
|
|
1184
|
+
* SGD optimizer with momentum
|
|
1185
|
+
*/
|
|
1186
|
+
class WasmSGD {
|
|
1187
|
+
|
|
1188
|
+
__destroy_into_raw() {
|
|
1189
|
+
const ptr = this.__wbg_ptr;
|
|
1190
|
+
this.__wbg_ptr = 0;
|
|
1191
|
+
WasmSGDFinalization.unregister(this);
|
|
1192
|
+
return ptr;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
free() {
|
|
1196
|
+
const ptr = this.__destroy_into_raw();
|
|
1197
|
+
wasm.__wbg_wasmsgd_free(ptr, 0);
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Get current learning rate
|
|
1201
|
+
* @returns {number}
|
|
1202
|
+
*/
|
|
1203
|
+
get learning_rate() {
|
|
1204
|
+
const ret = wasm.wasmsgd_learning_rate(this.__wbg_ptr);
|
|
1205
|
+
return ret;
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Set learning rate
|
|
1209
|
+
* @param {number} lr
|
|
1210
|
+
*/
|
|
1211
|
+
set learning_rate(lr) {
|
|
1212
|
+
wasm.wasmsgd_set_learning_rate(this.__wbg_ptr, lr);
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* Create a new SGD optimizer
|
|
1216
|
+
*
|
|
1217
|
+
* # Arguments
|
|
1218
|
+
* * `param_count` - Number of parameters
|
|
1219
|
+
* * `learning_rate` - Learning rate
|
|
1220
|
+
* * `momentum` - Momentum coefficient (default: 0)
|
|
1221
|
+
* @param {number} param_count
|
|
1222
|
+
* @param {number} learning_rate
|
|
1223
|
+
* @param {number | null} [momentum]
|
|
1224
|
+
*/
|
|
1225
|
+
constructor(param_count, learning_rate, momentum) {
|
|
1226
|
+
const ret = wasm.wasmsgd_new(param_count, learning_rate, isLikeNone(momentum) ? 0x100000001 : Math.fround(momentum));
|
|
1227
|
+
this.__wbg_ptr = ret >>> 0;
|
|
1228
|
+
WasmSGDFinalization.register(this, this.__wbg_ptr, this);
|
|
1229
|
+
return this;
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Perform optimization step
|
|
1233
|
+
* @param {Float32Array} params
|
|
1234
|
+
* @param {Float32Array} gradients
|
|
1235
|
+
*/
|
|
1236
|
+
step(params, gradients) {
|
|
1237
|
+
var ptr0 = passArrayF32ToWasm0(params, wasm.__wbindgen_export);
|
|
1238
|
+
var len0 = WASM_VECTOR_LEN;
|
|
1239
|
+
const ptr1 = passArrayF32ToWasm0(gradients, wasm.__wbindgen_export);
|
|
1240
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1241
|
+
wasm.wasmsgd_step(this.__wbg_ptr, ptr0, len0, addHeapObject(params), ptr1, len1);
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* Reset optimizer state
|
|
1245
|
+
*/
|
|
1246
|
+
reset() {
|
|
1247
|
+
wasm.wasmsgd_reset(this.__wbg_ptr);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
if (Symbol.dispose) WasmSGD.prototype[Symbol.dispose] = WasmSGD.prototype.free;
|
|
1251
|
+
|
|
1252
|
+
exports.WasmSGD = WasmSGD;
|
|
1253
|
+
|
|
1254
|
+
exports.__wbg_Error_e83987f665cf5504 = function(arg0, arg1) {
|
|
1255
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
1256
|
+
return addHeapObject(ret);
|
|
1257
|
+
};
|
|
1258
|
+
|
|
1259
|
+
exports.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
|
|
1260
|
+
const ret = String(getObject(arg1));
|
|
1261
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1262
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1263
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
1264
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1267
|
+
exports.__wbg___wbindgen_boolean_get_6d5a1ee65bab5f68 = function(arg0) {
|
|
1268
|
+
const v = getObject(arg0);
|
|
1269
|
+
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
1270
|
+
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
1271
|
+
};
|
|
1272
|
+
|
|
1273
|
+
exports.__wbg___wbindgen_copy_to_typed_array_33fbd71146904370 = function(arg0, arg1, arg2) {
|
|
1274
|
+
new Uint8Array(getObject(arg2).buffer, getObject(arg2).byteOffset, getObject(arg2).byteLength).set(getArrayU8FromWasm0(arg0, arg1));
|
|
1275
|
+
};
|
|
1276
|
+
|
|
1277
|
+
exports.__wbg___wbindgen_debug_string_df47ffb5e35e6763 = function(arg0, arg1) {
|
|
1278
|
+
const ret = debugString(getObject(arg1));
|
|
1279
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1280
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1281
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
1282
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
1283
|
+
};
|
|
1284
|
+
|
|
1285
|
+
exports.__wbg___wbindgen_is_function_ee8a6c5833c90377 = function(arg0) {
|
|
1286
|
+
const ret = typeof(getObject(arg0)) === 'function';
|
|
1287
|
+
return ret;
|
|
1288
|
+
};
|
|
1289
|
+
|
|
1290
|
+
exports.__wbg___wbindgen_is_object_c818261d21f283a4 = function(arg0) {
|
|
1291
|
+
const val = getObject(arg0);
|
|
1292
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
1293
|
+
return ret;
|
|
1294
|
+
};
|
|
1295
|
+
|
|
1296
|
+
exports.__wbg___wbindgen_jsval_loose_eq_b664b38a2f582147 = function(arg0, arg1) {
|
|
1297
|
+
const ret = getObject(arg0) == getObject(arg1);
|
|
1298
|
+
return ret;
|
|
1299
|
+
};
|
|
1300
|
+
|
|
1301
|
+
exports.__wbg___wbindgen_number_get_a20bf9b85341449d = function(arg0, arg1) {
|
|
1302
|
+
const obj = getObject(arg1);
|
|
1303
|
+
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
1304
|
+
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
1305
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
1306
|
+
};
|
|
1307
|
+
|
|
1308
|
+
exports.__wbg___wbindgen_string_get_e4f06c90489ad01b = function(arg0, arg1) {
|
|
1309
|
+
const obj = getObject(arg1);
|
|
1310
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
1311
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1312
|
+
var len1 = WASM_VECTOR_LEN;
|
|
1313
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
1314
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
1315
|
+
};
|
|
1316
|
+
|
|
1317
|
+
exports.__wbg___wbindgen_throw_b855445ff6a94295 = function(arg0, arg1) {
|
|
1318
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
1319
|
+
};
|
|
1320
|
+
|
|
1321
|
+
exports.__wbg_call_e762c39fa8ea36bf = function() { return handleError(function (arg0, arg1) {
|
|
1322
|
+
const ret = getObject(arg0).call(getObject(arg1));
|
|
1323
|
+
return addHeapObject(ret);
|
|
1324
|
+
}, arguments) };
|
|
1325
|
+
|
|
1326
|
+
exports.__wbg_done_2042aa2670fb1db1 = function(arg0) {
|
|
1327
|
+
const ret = getObject(arg0).done;
|
|
1328
|
+
return ret;
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
exports.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
|
|
1332
|
+
let deferred0_0;
|
|
1333
|
+
let deferred0_1;
|
|
1334
|
+
try {
|
|
1335
|
+
deferred0_0 = arg0;
|
|
1336
|
+
deferred0_1 = arg1;
|
|
1337
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
1338
|
+
} finally {
|
|
1339
|
+
wasm.__wbindgen_export4(deferred0_0, deferred0_1, 1);
|
|
1340
|
+
}
|
|
1341
|
+
};
|
|
1342
|
+
|
|
1343
|
+
exports.__wbg_error_a7f8fbb0523dae15 = function(arg0) {
|
|
1344
|
+
console.error(getObject(arg0));
|
|
1345
|
+
};
|
|
1346
|
+
|
|
1347
|
+
exports.__wbg_get_7bed016f185add81 = function(arg0, arg1) {
|
|
1348
|
+
const ret = getObject(arg0)[arg1 >>> 0];
|
|
1349
|
+
return addHeapObject(ret);
|
|
1350
|
+
};
|
|
1351
|
+
|
|
1352
|
+
exports.__wbg_get_efcb449f58ec27c2 = function() { return handleError(function (arg0, arg1) {
|
|
1353
|
+
const ret = Reflect.get(getObject(arg0), getObject(arg1));
|
|
1354
|
+
return addHeapObject(ret);
|
|
1355
|
+
}, arguments) };
|
|
1356
|
+
|
|
1357
|
+
exports.__wbg_instanceof_ArrayBuffer_70beb1189ca63b38 = function(arg0) {
|
|
1358
|
+
let result;
|
|
1359
|
+
try {
|
|
1360
|
+
result = getObject(arg0) instanceof ArrayBuffer;
|
|
1361
|
+
} catch (_) {
|
|
1362
|
+
result = false;
|
|
1363
|
+
}
|
|
1364
|
+
const ret = result;
|
|
1365
|
+
return ret;
|
|
1366
|
+
};
|
|
1367
|
+
|
|
1368
|
+
exports.__wbg_instanceof_Uint8Array_20c8e73002f7af98 = function(arg0) {
|
|
1369
|
+
let result;
|
|
1370
|
+
try {
|
|
1371
|
+
result = getObject(arg0) instanceof Uint8Array;
|
|
1372
|
+
} catch (_) {
|
|
1373
|
+
result = false;
|
|
1374
|
+
}
|
|
1375
|
+
const ret = result;
|
|
1376
|
+
return ret;
|
|
1377
|
+
};
|
|
1378
|
+
|
|
1379
|
+
exports.__wbg_isArray_96e0af9891d0945d = function(arg0) {
|
|
1380
|
+
const ret = Array.isArray(getObject(arg0));
|
|
1381
|
+
return ret;
|
|
1382
|
+
};
|
|
1383
|
+
|
|
1384
|
+
exports.__wbg_iterator_e5822695327a3c39 = function() {
|
|
1385
|
+
const ret = Symbol.iterator;
|
|
1386
|
+
return addHeapObject(ret);
|
|
1387
|
+
};
|
|
1388
|
+
|
|
1389
|
+
exports.__wbg_length_69bca3cb64fc8748 = function(arg0) {
|
|
1390
|
+
const ret = getObject(arg0).length;
|
|
1391
|
+
return ret;
|
|
1392
|
+
};
|
|
1393
|
+
|
|
1394
|
+
exports.__wbg_length_cdd215e10d9dd507 = function(arg0) {
|
|
1395
|
+
const ret = getObject(arg0).length;
|
|
1396
|
+
return ret;
|
|
1397
|
+
};
|
|
1398
|
+
|
|
1399
|
+
exports.__wbg_log_8cec76766b8c0e33 = function(arg0) {
|
|
1400
|
+
console.log(getObject(arg0));
|
|
1401
|
+
};
|
|
1402
|
+
|
|
1403
|
+
exports.__wbg_new_5a79be3ab53b8aa5 = function(arg0) {
|
|
1404
|
+
const ret = new Uint8Array(getObject(arg0));
|
|
1405
|
+
return addHeapObject(ret);
|
|
1406
|
+
};
|
|
1407
|
+
|
|
1408
|
+
exports.__wbg_new_8a6f238a6ece86ea = function() {
|
|
1409
|
+
const ret = new Error();
|
|
1410
|
+
return addHeapObject(ret);
|
|
1411
|
+
};
|
|
1412
|
+
|
|
1413
|
+
exports.__wbg_new_e17d9f43105b08be = function() {
|
|
1414
|
+
const ret = new Array();
|
|
1415
|
+
return addHeapObject(ret);
|
|
1416
|
+
};
|
|
1417
|
+
|
|
1418
|
+
exports.__wbg_next_020810e0ae8ebcb0 = function() { return handleError(function (arg0) {
|
|
1419
|
+
const ret = getObject(arg0).next();
|
|
1420
|
+
return addHeapObject(ret);
|
|
1421
|
+
}, arguments) };
|
|
1422
|
+
|
|
1423
|
+
exports.__wbg_next_2c826fe5dfec6b6a = function(arg0) {
|
|
1424
|
+
const ret = getObject(arg0).next;
|
|
1425
|
+
return addHeapObject(ret);
|
|
1426
|
+
};
|
|
1427
|
+
|
|
1428
|
+
exports.__wbg_prototypesetcall_2a6620b6922694b2 = function(arg0, arg1, arg2) {
|
|
1429
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
|
|
1430
|
+
};
|
|
1431
|
+
|
|
1432
|
+
exports.__wbg_random_babe96ffc73e60a2 = function() {
|
|
1433
|
+
const ret = Math.random();
|
|
1434
|
+
return ret;
|
|
1435
|
+
};
|
|
1436
|
+
|
|
1437
|
+
exports.__wbg_set_c213c871859d6500 = function(arg0, arg1, arg2) {
|
|
1438
|
+
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
|
|
1439
|
+
};
|
|
1440
|
+
|
|
1441
|
+
exports.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
|
|
1442
|
+
const ret = getObject(arg1).stack;
|
|
1443
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1444
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1445
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
1446
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
1447
|
+
};
|
|
1448
|
+
|
|
1449
|
+
exports.__wbg_value_692627309814bb8c = function(arg0) {
|
|
1450
|
+
const ret = getObject(arg0).value;
|
|
1451
|
+
return addHeapObject(ret);
|
|
1452
|
+
};
|
|
1453
|
+
|
|
1454
|
+
exports.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
1455
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
1456
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
1457
|
+
return addHeapObject(ret);
|
|
1458
|
+
};
|
|
1459
|
+
|
|
1460
|
+
exports.__wbindgen_object_drop_ref = function(arg0) {
|
|
1461
|
+
takeObject(arg0);
|
|
1462
|
+
};
|
|
1463
|
+
|
|
1464
|
+
const wasmPath = `${__dirname}/ruvector_attention_wasm_bg.wasm`;
|
|
1465
|
+
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
1466
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
1467
|
+
const wasm = exports.__wasm = new WebAssembly.Instance(wasmModule, imports).exports;
|
|
1468
|
+
|
|
1469
|
+
wasm.__wbindgen_start();
|
|
1470
|
+
|