mirror of
https://github.com/ruvnet/RuView
synced 2026-08-05 19:41:44 +00:00
feat: RSSI visualization, RuVector attention WASM, cache-bust fixes
- Add animated RSSI Signal Strength panel with sparkline history - Fix RuVector WasmMultiHeadAttention retptr calling convention - Wire up RuVector Multi-Head + Flash Attention in CNN embedder - Add ambient temporal drift to CSI simulator for visible heatmap animation - Fix embedding space projection (sparse projection replaces cancelling sum) - Add auto-scaling to embedding space renderer - Add cache busters (?v=4) to all ES module imports to prevent stale caches - Add diagnostic logging for module version verification - Add RSSI tracking with quality labels and color-coded dBm display - Includes ruvector-attention-wasm v2.0.5 browser ESM wrapper Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 rUv
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,220 @@
|
||||
# ruvector-attention-wasm
|
||||
|
||||
WebAssembly bindings for the ruvector-attention package, providing high-performance attention mechanisms for browser and Node.js environments.
|
||||
|
||||
## Features
|
||||
|
||||
- **Multiple Attention Mechanisms**:
|
||||
- Scaled Dot-Product Attention
|
||||
- Multi-Head Attention
|
||||
- Hyperbolic Attention (for hierarchical data)
|
||||
- Linear Attention (Performer-style)
|
||||
- Flash Attention (memory-efficient)
|
||||
- Local-Global Attention
|
||||
- Mixture of Experts (MoE) Attention
|
||||
- **CGT Sheaf Attention** (coherence-gated via Prime-Radiant)
|
||||
|
||||
- **Training Utilities**:
|
||||
- InfoNCE contrastive loss
|
||||
- Adam optimizer
|
||||
- AdamW optimizer (with decoupled weight decay)
|
||||
- Learning rate scheduler (warmup + cosine decay)
|
||||
|
||||
- **TypeScript Support**: Full type definitions and modern API
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install ruvector-attention-wasm
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### TypeScript/JavaScript
|
||||
|
||||
```typescript
|
||||
import { initialize, MultiHeadAttention, utils } from 'ruvector-attention-wasm';
|
||||
|
||||
// Initialize WASM module
|
||||
await initialize();
|
||||
|
||||
// Create multi-head attention
|
||||
const attention = new MultiHeadAttention({ dim: 64, numHeads: 8 });
|
||||
|
||||
// Prepare inputs
|
||||
const query = new Float32Array(64);
|
||||
const keys = [new Float32Array(64), new Float32Array(64)];
|
||||
const values = [new Float32Array(64), new Float32Array(64)];
|
||||
|
||||
// Compute attention
|
||||
const output = attention.compute(query, keys, values);
|
||||
|
||||
// Use utilities
|
||||
const similarity = utils.cosineSimilarity(query, keys[0]);
|
||||
```
|
||||
|
||||
### Advanced Examples
|
||||
|
||||
#### Hyperbolic Attention
|
||||
|
||||
```typescript
|
||||
import { HyperbolicAttention } from 'ruvector-attention-wasm';
|
||||
|
||||
const hyperbolic = new HyperbolicAttention({
|
||||
dim: 128,
|
||||
curvature: 1.0
|
||||
});
|
||||
|
||||
const output = hyperbolic.compute(query, keys, values);
|
||||
```
|
||||
|
||||
#### MoE Attention with Expert Stats
|
||||
|
||||
```typescript
|
||||
import { MoEAttention } from 'ruvector-attention-wasm';
|
||||
|
||||
const moe = new MoEAttention({
|
||||
dim: 64,
|
||||
numExperts: 4,
|
||||
topK: 2
|
||||
});
|
||||
|
||||
const output = moe.compute(query, keys, values);
|
||||
|
||||
// Get expert utilization
|
||||
const stats = moe.getExpertStats();
|
||||
console.log('Load balance:', stats.loadBalance);
|
||||
```
|
||||
|
||||
#### Training with InfoNCE Loss
|
||||
|
||||
```typescript
|
||||
import { InfoNCELoss, Adam } from 'ruvector-attention-wasm';
|
||||
|
||||
const loss = new InfoNCELoss(0.07);
|
||||
const optimizer = new Adam(paramCount, {
|
||||
learningRate: 0.001,
|
||||
beta1: 0.9,
|
||||
beta2: 0.999,
|
||||
});
|
||||
|
||||
// Training loop
|
||||
const lossValue = loss.compute(anchor, positive, negatives);
|
||||
optimizer.step(params, gradients);
|
||||
```
|
||||
|
||||
#### Learning Rate Scheduling
|
||||
|
||||
```typescript
|
||||
import { LRScheduler, AdamW } from 'ruvector-attention-wasm';
|
||||
|
||||
const scheduler = new LRScheduler({
|
||||
initialLR: 0.001,
|
||||
warmupSteps: 1000,
|
||||
totalSteps: 10000,
|
||||
});
|
||||
|
||||
const optimizer = new AdamW(paramCount, {
|
||||
learningRate: scheduler.getLR(),
|
||||
weightDecay: 0.01,
|
||||
});
|
||||
|
||||
// Training loop
|
||||
for (let step = 0; step < 10000; step++) {
|
||||
optimizer.learningRate = scheduler.getLR();
|
||||
optimizer.step(params, gradients);
|
||||
scheduler.step();
|
||||
}
|
||||
```
|
||||
|
||||
## Building from Source
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Rust 1.70+
|
||||
- wasm-pack
|
||||
|
||||
### Build Commands
|
||||
|
||||
```bash
|
||||
# Build for web (ES modules)
|
||||
wasm-pack build --target web --out-dir pkg
|
||||
|
||||
# Build for Node.js
|
||||
wasm-pack build --target nodejs --out-dir pkg-node
|
||||
|
||||
# Build for bundlers (webpack, vite, etc.)
|
||||
wasm-pack build --target bundler --out-dir pkg-bundler
|
||||
|
||||
# Run tests
|
||||
wasm-pack test --headless --firefox
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
### Attention Mechanisms
|
||||
|
||||
- `MultiHeadAttention` - Standard multi-head attention
|
||||
- `HyperbolicAttention` - Attention in hyperbolic space
|
||||
- `LinearAttention` - Linear complexity attention (Performer)
|
||||
- `FlashAttention` - Memory-efficient attention
|
||||
- `LocalGlobalAttention` - Combined local and global attention
|
||||
- `MoEAttention` - Mixture of Experts attention
|
||||
- `CGTSheafAttention` - Coherence-gated via Prime-Radiant energy
|
||||
- `scaledDotAttention()` - Functional API for basic attention
|
||||
|
||||
### CGT Sheaf Attention (Prime-Radiant Integration)
|
||||
|
||||
The CGT (Coherence-Gated Transformer) Sheaf Attention mechanism uses Prime-Radiant's sheaf Laplacian energy to gate attention based on mathematical consistency:
|
||||
|
||||
```typescript
|
||||
import { CGTSheafAttention } from 'ruvector-attention-wasm';
|
||||
|
||||
const cgtAttention = new CGTSheafAttention({
|
||||
dim: 128,
|
||||
numHeads: 8,
|
||||
coherenceThreshold: 0.3, // Block if energy > threshold
|
||||
});
|
||||
|
||||
// Attention is gated by coherence energy
|
||||
const result = cgtAttention.compute(query, keys, values);
|
||||
console.log('Coherence energy:', result.energy);
|
||||
console.log('Is coherent:', result.isCoherent);
|
||||
```
|
||||
|
||||
**Key features:**
|
||||
- Energy-weighted attention: Lower coherence energy → higher attention
|
||||
- Automatic hallucination detection via residual analysis
|
||||
- GPU-accelerated with wgpu WGSL shaders (vec4 optimized)
|
||||
- SIMD fallback (AVX-512/AVX2/NEON)
|
||||
|
||||
### Training
|
||||
|
||||
- `InfoNCELoss` - Contrastive loss function
|
||||
- `Adam` - Adam optimizer
|
||||
- `AdamW` - AdamW optimizer with weight decay
|
||||
- `LRScheduler` - Learning rate scheduler
|
||||
|
||||
### Utilities
|
||||
|
||||
- `utils.cosineSimilarity()` - Cosine similarity between vectors
|
||||
- `utils.l2Norm()` - L2 norm of a vector
|
||||
- `utils.normalize()` - Normalize vector to unit length
|
||||
- `utils.softmax()` - Apply softmax transformation
|
||||
- `utils.attentionWeights()` - Compute attention weights from scores
|
||||
- `utils.batchNormalize()` - Batch normalization
|
||||
- `utils.randomOrthogonalMatrix()` - Generate random orthogonal matrix
|
||||
- `utils.pairwiseDistances()` - Compute pairwise distances
|
||||
|
||||
## Performance
|
||||
|
||||
The WASM bindings provide near-native performance for attention computations:
|
||||
|
||||
- Optimized with `opt-level = "s"` and LTO
|
||||
- SIMD acceleration where available
|
||||
- Efficient memory management
|
||||
- Zero-copy data transfer where possible
|
||||
|
||||
## License
|
||||
|
||||
MIT OR Apache-2.0
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "ruvector-attention-wasm",
|
||||
"collaborators": [
|
||||
"Ruvector Team"
|
||||
],
|
||||
"description": "High-performance WebAssembly attention mechanisms: Multi-Head, Flash, Hyperbolic, MoE, CGT Sheaf Attention with GPU acceleration for transformers and LLMs",
|
||||
"version": "2.0.5",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ruvnet/ruvector"
|
||||
},
|
||||
"files": [
|
||||
"ruvector_attention_wasm_bg.wasm",
|
||||
"ruvector_attention_wasm.js",
|
||||
"ruvector_attention_wasm.d.ts"
|
||||
],
|
||||
"main": "ruvector_attention_wasm.js",
|
||||
"homepage": "https://ruv.io/ruvector",
|
||||
"types": "ruvector_attention_wasm.d.ts",
|
||||
"keywords": [
|
||||
"wasm",
|
||||
"attention",
|
||||
"transformer",
|
||||
"flash-attention",
|
||||
"llm"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,483 @@
|
||||
/**
|
||||
* Browser ESM wrapper for ruvector-attention-wasm v2.0.5
|
||||
*
|
||||
* The upstream pkg/ was built with wasm-pack --target nodejs (CJS + fs.readFileSync).
|
||||
* This wrapper loads the same WASM binary via fetch() for browser use.
|
||||
*
|
||||
* Usage:
|
||||
* import initWasm, { WasmMultiHeadAttention, ... } from './ruvector_attention_browser.js';
|
||||
* await initWasm();
|
||||
* const attn = new WasmMultiHeadAttention(dim, heads);
|
||||
*/
|
||||
|
||||
let _wasm;
|
||||
let _initialized = false;
|
||||
|
||||
// The entire CJS module runs inside this IIFE to avoid polluting global scope.
|
||||
// We capture all exports in _mod.
|
||||
const _mod = {};
|
||||
|
||||
(function(exports, wasm_getter) {
|
||||
|
||||
// ── wasm-bindgen heap management ──────────────────────────────────
|
||||
const heap = new Array(128).fill(undefined);
|
||||
heap.push(undefined, null, true, false);
|
||||
let heap_next = heap.length;
|
||||
|
||||
function addHeapObject(obj) {
|
||||
if (heap_next === heap.length) heap.push(heap.length + 1);
|
||||
const idx = heap_next;
|
||||
heap_next = heap[idx];
|
||||
heap[idx] = obj;
|
||||
return idx;
|
||||
}
|
||||
function getObject(idx) { return heap[idx]; }
|
||||
function dropObject(idx) {
|
||||
if (idx < 132) return;
|
||||
heap[idx] = heap_next;
|
||||
heap_next = idx;
|
||||
}
|
||||
function takeObject(idx) {
|
||||
const ret = getObject(idx);
|
||||
dropObject(idx);
|
||||
return ret;
|
||||
}
|
||||
function isLikeNone(x) { return x === undefined || x === null; }
|
||||
|
||||
// ── Memory views ──────────────────────────────────────────────────
|
||||
let cachedDataViewMemory0 = null;
|
||||
let cachedUint8ArrayMemory0 = null;
|
||||
let cachedFloat32ArrayMemory0 = null;
|
||||
|
||||
function wasm() { return wasm_getter(); }
|
||||
|
||||
function getDataViewMemory0() {
|
||||
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer !== wasm().memory.buffer)
|
||||
cachedDataViewMemory0 = new DataView(wasm().memory.buffer);
|
||||
return cachedDataViewMemory0;
|
||||
}
|
||||
function getUint8ArrayMemory0() {
|
||||
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.buffer !== wasm().memory.buffer)
|
||||
cachedUint8ArrayMemory0 = new Uint8Array(wasm().memory.buffer);
|
||||
return cachedUint8ArrayMemory0;
|
||||
}
|
||||
function getFloat32ArrayMemory0() {
|
||||
if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.buffer !== wasm().memory.buffer)
|
||||
cachedFloat32ArrayMemory0 = new Float32Array(wasm().memory.buffer);
|
||||
return cachedFloat32ArrayMemory0;
|
||||
}
|
||||
function getArrayF32FromWasm0(ptr, len) {
|
||||
ptr = ptr >>> 0;
|
||||
return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
||||
}
|
||||
function getArrayU8FromWasm0(ptr, len) {
|
||||
ptr = ptr >>> 0;
|
||||
return getUint8ArrayMemory0().subarray(ptr, ptr + len);
|
||||
}
|
||||
|
||||
let WASM_VECTOR_LEN = 0;
|
||||
|
||||
function passArrayF32ToWasm0(arg, malloc) {
|
||||
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
||||
getFloat32ArrayMemory0().set(arg, ptr / 4);
|
||||
WASM_VECTOR_LEN = arg.length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
const cachedTextEncoder = new TextEncoder();
|
||||
const cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
||||
cachedTextDecoder.decode();
|
||||
|
||||
function getStringFromWasm0(ptr, len) {
|
||||
ptr = ptr >>> 0;
|
||||
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
||||
}
|
||||
|
||||
function passStringToWasm0(arg, malloc, realloc) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
const ptr = malloc(buf.length, 1) >>> 0;
|
||||
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
||||
WASM_VECTOR_LEN = buf.length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
function debugString(val) {
|
||||
const type = typeof val;
|
||||
if (type == 'number' || type == 'boolean' || val == null) return `${val}`;
|
||||
if (type == 'string') return `"${val}"`;
|
||||
if (type == 'symbol') return val.description ? `Symbol(${val.description})` : 'Symbol';
|
||||
if (type == 'function') return 'Function';
|
||||
if (Array.isArray(val)) return `[${val.map(debugString).join(', ')}]`;
|
||||
try {
|
||||
const keys = Object.keys(val);
|
||||
return `{${keys.map(k => `${k}: ${debugString(val[k])}`).join(', ')}}`;
|
||||
} catch (_) { return Object.prototype.toString.call(val); }
|
||||
}
|
||||
|
||||
function handleError(f, args) {
|
||||
try { return f.apply(this, args); }
|
||||
catch (e) { wasm().__wbindgen_export3(addHeapObject(e)); }
|
||||
}
|
||||
|
||||
// ── FinalizationRegistry ──────────────────────────────────────────
|
||||
const FR = typeof FinalizationRegistry !== 'undefined'
|
||||
? FinalizationRegistry
|
||||
: class { register() {} unregister() {} };
|
||||
|
||||
const WasmMultiHeadAttentionFinalization = new FR(ptr => wasm().__wbg_wasmmultiheadattention_free(ptr >>> 0, 1));
|
||||
const WasmFlashAttentionFinalization = new FR(ptr => wasm().__wbg_wasmflashattention_free(ptr >>> 0, 1));
|
||||
const WasmHyperbolicAttentionFinalization = new FR(ptr => wasm().__wbg_wasmhyperbolicattention_free(ptr >>> 0, 1));
|
||||
const WasmMoEAttentionFinalization = new FR(ptr => wasm().__wbg_wasmmoeattention_free(ptr >>> 0, 1));
|
||||
const WasmLinearAttentionFinalization = new FR(ptr => wasm().__wbg_wasmlinearattention_free(ptr >>> 0, 1));
|
||||
const WasmLocalGlobalAttentionFinalization = new FR(ptr => wasm().__wbg_wasmlocalglobalattention_free(ptr >>> 0, 1));
|
||||
|
||||
// ── Classes ───────────────────────────────────────────────────────
|
||||
|
||||
class WasmMultiHeadAttention {
|
||||
constructor(dim, num_heads) {
|
||||
const retptr = wasm().__wbindgen_add_to_stack_pointer(-16);
|
||||
try {
|
||||
wasm().wasmmultiheadattention_new(retptr, dim, num_heads);
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4, true);
|
||||
var r2 = getDataViewMemory0().getInt32(retptr + 8, true);
|
||||
if (r2) throw takeObject(r1);
|
||||
this.__wbg_ptr = r0 >>> 0;
|
||||
WasmMultiHeadAttentionFinalization.register(this, this.__wbg_ptr, this);
|
||||
} finally {
|
||||
wasm().__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
free() {
|
||||
const ptr = this.__wbg_ptr; this.__wbg_ptr = 0;
|
||||
WasmMultiHeadAttentionFinalization.unregister(this);
|
||||
wasm().__wbg_wasmmultiheadattention_free(ptr, 0);
|
||||
}
|
||||
get dim() { return wasm().wasmmultiheadattention_dim(this.__wbg_ptr); }
|
||||
get num_heads() { return wasm().wasmmultiheadattention_num_heads(this.__wbg_ptr); }
|
||||
compute(query, keys, values) {
|
||||
const retptr = wasm().__wbindgen_add_to_stack_pointer(-16);
|
||||
try {
|
||||
const ptr0 = passArrayF32ToWasm0(query, wasm().__wbindgen_export);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm().wasmmultiheadattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4, true);
|
||||
var r2 = getDataViewMemory0().getInt32(retptr + 8, true);
|
||||
var r3 = getDataViewMemory0().getInt32(retptr + 12, true);
|
||||
if (r3) throw takeObject(r2);
|
||||
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
||||
wasm().__wbindgen_export4(r0, r1 * 4, 4);
|
||||
return v1;
|
||||
} finally {
|
||||
wasm().__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class WasmFlashAttention {
|
||||
constructor(dim, block_size) {
|
||||
const ret = wasm().wasmflashattention_new(dim, block_size);
|
||||
this.__wbg_ptr = ret >>> 0;
|
||||
WasmFlashAttentionFinalization.register(this, this.__wbg_ptr, this);
|
||||
}
|
||||
free() {
|
||||
const ptr = this.__wbg_ptr; this.__wbg_ptr = 0;
|
||||
WasmFlashAttentionFinalization.unregister(this);
|
||||
wasm().__wbg_wasmflashattention_free(ptr, 0);
|
||||
}
|
||||
compute(query, keys, values) {
|
||||
const retptr = wasm().__wbindgen_add_to_stack_pointer(-16);
|
||||
try {
|
||||
const ptr0 = passArrayF32ToWasm0(query, wasm().__wbindgen_export);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm().wasmflashattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4, true);
|
||||
var r2 = getDataViewMemory0().getInt32(retptr + 8, true);
|
||||
var r3 = getDataViewMemory0().getInt32(retptr + 12, true);
|
||||
if (r3) throw takeObject(r2);
|
||||
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
||||
wasm().__wbindgen_export4(r0, r1 * 4, 4);
|
||||
return v1;
|
||||
} finally {
|
||||
wasm().__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class WasmHyperbolicAttention {
|
||||
constructor(dim, curvature) {
|
||||
const ret = wasm().wasmhyperbolicattention_new(dim, curvature);
|
||||
this.__wbg_ptr = ret >>> 0;
|
||||
WasmHyperbolicAttentionFinalization.register(this, this.__wbg_ptr, this);
|
||||
}
|
||||
free() {
|
||||
const ptr = this.__wbg_ptr; this.__wbg_ptr = 0;
|
||||
WasmHyperbolicAttentionFinalization.unregister(this);
|
||||
wasm().__wbg_wasmhyperbolicattention_free(ptr, 0);
|
||||
}
|
||||
get curvature() { return wasm().wasmhyperbolicattention_curvature(this.__wbg_ptr); }
|
||||
compute(query, keys, values) {
|
||||
const retptr = wasm().__wbindgen_add_to_stack_pointer(-16);
|
||||
try {
|
||||
const ptr0 = passArrayF32ToWasm0(query, wasm().__wbindgen_export);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm().wasmhyperbolicattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4, true);
|
||||
var r2 = getDataViewMemory0().getInt32(retptr + 8, true);
|
||||
var r3 = getDataViewMemory0().getInt32(retptr + 12, true);
|
||||
if (r3) throw takeObject(r2);
|
||||
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
||||
wasm().__wbindgen_export4(r0, r1 * 4, 4);
|
||||
return v1;
|
||||
} finally {
|
||||
wasm().__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class WasmMoEAttention {
|
||||
constructor(dim, num_experts, top_k) {
|
||||
const ret = wasm().wasmmoeattention_new(dim, num_experts, top_k);
|
||||
this.__wbg_ptr = ret >>> 0;
|
||||
WasmMoEAttentionFinalization.register(this, this.__wbg_ptr, this);
|
||||
}
|
||||
free() {
|
||||
const ptr = this.__wbg_ptr; this.__wbg_ptr = 0;
|
||||
WasmMoEAttentionFinalization.unregister(this);
|
||||
wasm().__wbg_wasmmoeattention_free(ptr, 0);
|
||||
}
|
||||
compute(query, keys, values) {
|
||||
const retptr = wasm().__wbindgen_add_to_stack_pointer(-16);
|
||||
try {
|
||||
const ptr0 = passArrayF32ToWasm0(query, wasm().__wbindgen_export);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm().wasmmoeattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4, true);
|
||||
var r2 = getDataViewMemory0().getInt32(retptr + 8, true);
|
||||
var r3 = getDataViewMemory0().getInt32(retptr + 12, true);
|
||||
if (r3) throw takeObject(r2);
|
||||
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
||||
wasm().__wbindgen_export4(r0, r1 * 4, 4);
|
||||
return v1;
|
||||
} finally {
|
||||
wasm().__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Standalone functions ──────────────────────────────────────────
|
||||
|
||||
function cosine_similarity(a, b) {
|
||||
const retptr = wasm().__wbindgen_add_to_stack_pointer(-16);
|
||||
try {
|
||||
const ptr0 = passArrayF32ToWasm0(a, wasm().__wbindgen_export);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
const ptr1 = passArrayF32ToWasm0(b, wasm().__wbindgen_export);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
wasm().cosine_similarity(retptr, ptr0, len0, ptr1, len1);
|
||||
var r0 = getDataViewMemory0().getFloat64(retptr + 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 8, true);
|
||||
var r2 = getDataViewMemory0().getInt32(retptr + 12, true);
|
||||
if (r2) throw takeObject(r1);
|
||||
return r0;
|
||||
} finally {
|
||||
wasm().__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
|
||||
function normalize(vec) {
|
||||
const ptr0 = passArrayF32ToWasm0(vec, wasm().__wbindgen_export);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm().normalize(ptr0, len0, addHeapObject(vec));
|
||||
}
|
||||
|
||||
function l2_norm(vec) {
|
||||
const retptr = wasm().__wbindgen_add_to_stack_pointer(-16);
|
||||
try {
|
||||
const ptr0 = passArrayF32ToWasm0(vec, wasm().__wbindgen_export);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm().l2_norm(retptr, ptr0, len0);
|
||||
var r0 = getDataViewMemory0().getFloat64(retptr + 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 8, true);
|
||||
var r2 = getDataViewMemory0().getInt32(retptr + 12, true);
|
||||
if (r2) throw takeObject(r1);
|
||||
return r0;
|
||||
} finally {
|
||||
wasm().__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
|
||||
function softmax(vec) {
|
||||
const ptr0 = passArrayF32ToWasm0(vec, wasm().__wbindgen_export);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm().softmax(ptr0, len0, addHeapObject(vec));
|
||||
}
|
||||
|
||||
function rv_init() { wasm().init(); }
|
||||
|
||||
function rv_version() {
|
||||
let d0, d1;
|
||||
const retptr = wasm().__wbindgen_add_to_stack_pointer(-16);
|
||||
try {
|
||||
wasm().version(retptr);
|
||||
d0 = getDataViewMemory0().getInt32(retptr + 0, true);
|
||||
d1 = getDataViewMemory0().getInt32(retptr + 4, true);
|
||||
return getStringFromWasm0(d0, d1);
|
||||
} finally {
|
||||
wasm().__wbindgen_add_to_stack_pointer(16);
|
||||
if (d0 !== undefined) wasm().__wbindgen_export4(d0, d1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Collect exports ───────────────────────────────────────────────
|
||||
exports.WasmMultiHeadAttention = WasmMultiHeadAttention;
|
||||
exports.WasmFlashAttention = WasmFlashAttention;
|
||||
exports.WasmHyperbolicAttention = WasmHyperbolicAttention;
|
||||
exports.WasmMoEAttention = WasmMoEAttention;
|
||||
exports.cosine_similarity = cosine_similarity;
|
||||
exports.normalize = normalize;
|
||||
exports.l2_norm = l2_norm;
|
||||
exports.softmax = softmax;
|
||||
exports.init = rv_init;
|
||||
exports.version = rv_version;
|
||||
|
||||
// ── Build WASM import object ──────────────────────────────────────
|
||||
exports.__wbg_get_imports = function() {
|
||||
const import0 = {
|
||||
__proto__: null,
|
||||
__wbg_Error_4577686b3a6d9b3a: (arg0, arg1) => addHeapObject(Error(getStringFromWasm0(arg0, arg1))),
|
||||
__wbg_String_8564e559799eccda: (arg0, arg1) => {
|
||||
const ret = String(getObject(arg1));
|
||||
const ptr1 = passStringToWasm0(ret, wasm().__wbindgen_export, wasm().__wbindgen_export2);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
|
||||
getDataViewMemory0().setInt32(arg0, ptr1, true);
|
||||
},
|
||||
__wbg___wbindgen_boolean_get_18c4ed9422296fff: (arg0) => {
|
||||
const v = getObject(arg0);
|
||||
const ret = typeof v === 'boolean' ? v : undefined;
|
||||
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
||||
},
|
||||
__wbg___wbindgen_copy_to_typed_array_5294f8e46aecc086: (arg0, arg1, arg2) => {
|
||||
new Uint8Array(getObject(arg2).buffer, getObject(arg2).byteOffset, getObject(arg2).byteLength).set(getArrayU8FromWasm0(arg0, arg1));
|
||||
},
|
||||
__wbg___wbindgen_debug_string_ddde1867f49c2442: (arg0, arg1) => {
|
||||
const ret = debugString(getObject(arg1));
|
||||
const ptr1 = passStringToWasm0(ret, wasm().__wbindgen_export, wasm().__wbindgen_export2);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
|
||||
getDataViewMemory0().setInt32(arg0, ptr1, true);
|
||||
},
|
||||
__wbg___wbindgen_is_function_d633e708baf0d146: (arg0) => typeof getObject(arg0) === 'function',
|
||||
__wbg___wbindgen_is_object_4b3de556756ee8a8: (arg0) => {
|
||||
const val = getObject(arg0);
|
||||
return typeof val === 'object' && val !== null;
|
||||
},
|
||||
__wbg___wbindgen_jsval_loose_eq_1562ceb9af84e990: (arg0, arg1) => getObject(arg0) == getObject(arg1),
|
||||
__wbg___wbindgen_number_get_5854912275df1894: (arg0, arg1) => {
|
||||
const obj = getObject(arg1);
|
||||
const ret = typeof obj === 'number' ? obj : undefined;
|
||||
getDataViewMemory0().setFloat64(arg0 + 8, isLikeNone(ret) ? 0 : ret, true);
|
||||
getDataViewMemory0().setInt32(arg0, !isLikeNone(ret), true);
|
||||
},
|
||||
__wbg___wbindgen_string_get_3e5751597f39a112: (arg0, arg1) => {
|
||||
const obj = getObject(arg1);
|
||||
const ret = typeof obj === 'string' ? obj : undefined;
|
||||
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm().__wbindgen_export, wasm().__wbindgen_export2);
|
||||
var len1 = WASM_VECTOR_LEN;
|
||||
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
|
||||
getDataViewMemory0().setInt32(arg0, ptr1, true);
|
||||
},
|
||||
__wbg___wbindgen_throw_39bc967c0e5a9b58: (arg0, arg1) => { throw new Error(getStringFromWasm0(arg0, arg1)); },
|
||||
__wbg_call_73af281463ec8b58: function() { return handleError(function(arg0, arg1) {
|
||||
return addHeapObject(getObject(arg0).call(getObject(arg1)));
|
||||
}, arguments); },
|
||||
__wbg_done_5aad55ec6b1954b1: (arg0) => getObject(arg0).done,
|
||||
__wbg_error_a6fa202b58aa1cd3: (arg0, arg1) => {
|
||||
try { console.error(getStringFromWasm0(arg0, arg1)); }
|
||||
finally { wasm().__wbindgen_export4(arg0, arg1, 1); }
|
||||
},
|
||||
__wbg_error_ad28debb48b5c6bb: (arg0) => console.error(getObject(arg0)),
|
||||
__wbg_get_4920fefd3451364b: function() { return handleError(function(arg0, arg1) {
|
||||
return addHeapObject(Reflect.get(getObject(arg0), getObject(arg1)));
|
||||
}, arguments); },
|
||||
__wbg_get_unchecked_3d0f4b91c8eca4f0: (arg0, arg1) => addHeapObject(getObject(arg0)[arg1 >>> 0]),
|
||||
__wbg_instanceof_ArrayBuffer_15859862b80b732d: (arg0) => {
|
||||
try { return getObject(arg0) instanceof ArrayBuffer; } catch (_) { return false; }
|
||||
},
|
||||
__wbg_instanceof_Uint8Array_2240b7046ac16f05: (arg0) => {
|
||||
try { return getObject(arg0) instanceof Uint8Array; } catch (_) { return false; }
|
||||
},
|
||||
__wbg_isArray_fad08a0d12828686: (arg0) => Array.isArray(getObject(arg0)),
|
||||
__wbg_iterator_fc7ad8d33bab9e26: () => addHeapObject(Symbol.iterator),
|
||||
__wbg_length_5855c1f289dfffc1: (arg0) => getObject(arg0).length,
|
||||
__wbg_length_a31e05262e09b7f8: (arg0) => getObject(arg0).length,
|
||||
__wbg_log_3c5e4b64af29e724: (arg0) => console.log(getObject(arg0)),
|
||||
__wbg_new_09959f7b4c92c246: (arg0) => addHeapObject(new Uint8Array(getObject(arg0))),
|
||||
__wbg_new_227d7c05414eb861: () => addHeapObject(new Error()),
|
||||
__wbg_new_cbee8c0d5c479eac: () => addHeapObject(new Array()),
|
||||
__wbg_next_a5fe6f328f7affc2: (arg0) => addHeapObject(getObject(arg0).next),
|
||||
__wbg_next_e592122bb4ed4c67: function() { return handleError(function(arg0) {
|
||||
return addHeapObject(getObject(arg0).next());
|
||||
}, arguments); },
|
||||
__wbg_prototypesetcall_f034d444741426c3: (arg0, arg1, arg2) => {
|
||||
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
|
||||
},
|
||||
__wbg_random_2b7bed8995d680fb: () => Math.random(),
|
||||
__wbg_set_4c81cfb5dc3a333c: (arg0, arg1, arg2) => { getObject(arg0)[arg1 >>> 0] = takeObject(arg2); },
|
||||
__wbg_stack_3b0d974bbf31e44f: (arg0, arg1) => {
|
||||
const ret = getObject(arg1).stack;
|
||||
const ptr1 = passStringToWasm0(ret, wasm().__wbindgen_export, wasm().__wbindgen_export2);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
|
||||
getDataViewMemory0().setInt32(arg0, ptr1, true);
|
||||
},
|
||||
__wbg_value_667dcb90597486a6: (arg0) => addHeapObject(getObject(arg0).value),
|
||||
__wbindgen_cast_0000000000000001: (arg0, arg1) => addHeapObject(getStringFromWasm0(arg0, arg1)),
|
||||
__wbindgen_object_drop_ref: (arg0) => takeObject(arg0),
|
||||
};
|
||||
return { __proto__: null, "./ruvector_attention_wasm_bg.js": import0 };
|
||||
};
|
||||
|
||||
})(_mod, () => _wasm);
|
||||
|
||||
|
||||
// ── Async WASM init (fetch-based for browsers) ───────────────────
|
||||
|
||||
export default async function initWasm() {
|
||||
if (_initialized) return;
|
||||
const wasmUrl = new URL('ruvector_attention_wasm_bg.wasm', import.meta.url);
|
||||
const imports = _mod.__wbg_get_imports();
|
||||
let result;
|
||||
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
||||
try {
|
||||
result = await WebAssembly.instantiateStreaming(fetch(wasmUrl), imports);
|
||||
} catch (e) {
|
||||
// Fallback if streaming fails (e.g. wrong MIME type)
|
||||
const bytes = await (await fetch(wasmUrl)).arrayBuffer();
|
||||
result = await WebAssembly.instantiate(bytes, imports);
|
||||
}
|
||||
} else {
|
||||
const bytes = await (await fetch(wasmUrl)).arrayBuffer();
|
||||
result = await WebAssembly.instantiate(bytes, imports);
|
||||
}
|
||||
_wasm = result.instance.exports;
|
||||
_wasm.__wbindgen_start();
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
// ── ESM re-exports ────────────────────────────────────────────────
|
||||
export const WasmMultiHeadAttention = _mod.WasmMultiHeadAttention;
|
||||
export const WasmFlashAttention = _mod.WasmFlashAttention;
|
||||
export const WasmHyperbolicAttention = _mod.WasmHyperbolicAttention;
|
||||
export const WasmMoEAttention = _mod.WasmMoEAttention;
|
||||
export const cosine_similarity = _mod.cosine_similarity;
|
||||
export const normalize = _mod.normalize;
|
||||
export const l2_norm = _mod.l2_norm;
|
||||
export const softmax = _mod.softmax;
|
||||
export const init = _mod.init;
|
||||
export const version = _mod.version;
|
||||
@@ -0,0 +1,359 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
/**
|
||||
* Adam optimizer
|
||||
*/
|
||||
export class WasmAdam {
|
||||
free(): void;
|
||||
[Symbol.dispose](): void;
|
||||
/**
|
||||
* Create a new Adam optimizer
|
||||
*
|
||||
* # Arguments
|
||||
* * `param_count` - Number of parameters
|
||||
* * `learning_rate` - Learning rate
|
||||
*/
|
||||
constructor(param_count: number, learning_rate: number);
|
||||
/**
|
||||
* Reset optimizer state
|
||||
*/
|
||||
reset(): void;
|
||||
/**
|
||||
* Perform optimization step
|
||||
*
|
||||
* # Arguments
|
||||
* * `params` - Current parameter values (will be updated in-place)
|
||||
* * `gradients` - Gradient values
|
||||
*/
|
||||
step(params: Float32Array, gradients: Float32Array): void;
|
||||
/**
|
||||
* Get current learning rate
|
||||
*/
|
||||
learning_rate: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* AdamW optimizer (Adam with decoupled weight decay)
|
||||
*/
|
||||
export class WasmAdamW {
|
||||
free(): void;
|
||||
[Symbol.dispose](): void;
|
||||
/**
|
||||
* Create a new AdamW optimizer
|
||||
*
|
||||
* # Arguments
|
||||
* * `param_count` - Number of parameters
|
||||
* * `learning_rate` - Learning rate
|
||||
* * `weight_decay` - Weight decay coefficient
|
||||
*/
|
||||
constructor(param_count: number, learning_rate: number, weight_decay: number);
|
||||
/**
|
||||
* Reset optimizer state
|
||||
*/
|
||||
reset(): void;
|
||||
/**
|
||||
* Perform optimization step with weight decay
|
||||
*/
|
||||
step(params: Float32Array, gradients: Float32Array): void;
|
||||
/**
|
||||
* Get current learning rate
|
||||
*/
|
||||
learning_rate: number;
|
||||
/**
|
||||
* Get weight decay
|
||||
*/
|
||||
readonly weight_decay: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flash attention mechanism
|
||||
*/
|
||||
export class WasmFlashAttention {
|
||||
free(): void;
|
||||
[Symbol.dispose](): void;
|
||||
/**
|
||||
* Compute flash attention
|
||||
*/
|
||||
compute(query: Float32Array, keys: any, values: any): Float32Array;
|
||||
/**
|
||||
* Create a new flash attention instance
|
||||
*
|
||||
* # Arguments
|
||||
* * `dim` - Embedding dimension
|
||||
* * `block_size` - Block size for tiling
|
||||
*/
|
||||
constructor(dim: number, block_size: number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hyperbolic attention mechanism
|
||||
*/
|
||||
export class WasmHyperbolicAttention {
|
||||
free(): void;
|
||||
[Symbol.dispose](): void;
|
||||
/**
|
||||
* Compute hyperbolic attention
|
||||
*/
|
||||
compute(query: Float32Array, keys: any, values: any): Float32Array;
|
||||
/**
|
||||
* Create a new hyperbolic attention instance
|
||||
*
|
||||
* # Arguments
|
||||
* * `dim` - Embedding dimension
|
||||
* * `curvature` - Hyperbolic curvature parameter
|
||||
*/
|
||||
constructor(dim: number, curvature: number);
|
||||
/**
|
||||
* Get the curvature
|
||||
*/
|
||||
readonly curvature: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* InfoNCE contrastive loss for training
|
||||
*/
|
||||
export class WasmInfoNCELoss {
|
||||
free(): void;
|
||||
[Symbol.dispose](): void;
|
||||
/**
|
||||
* Compute InfoNCE loss
|
||||
*
|
||||
* # Arguments
|
||||
* * `anchor` - Anchor embedding
|
||||
* * `positive` - Positive example embedding
|
||||
* * `negatives` - Array of negative example embeddings
|
||||
*/
|
||||
compute(anchor: Float32Array, positive: Float32Array, negatives: any): number;
|
||||
/**
|
||||
* Create a new InfoNCE loss instance
|
||||
*
|
||||
* # Arguments
|
||||
* * `temperature` - Temperature parameter for softmax
|
||||
*/
|
||||
constructor(temperature: number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Learning rate scheduler
|
||||
*/
|
||||
export class WasmLRScheduler {
|
||||
free(): void;
|
||||
[Symbol.dispose](): void;
|
||||
/**
|
||||
* Get learning rate for current step
|
||||
*/
|
||||
get_lr(): number;
|
||||
/**
|
||||
* Create a new learning rate scheduler with warmup and cosine decay
|
||||
*
|
||||
* # Arguments
|
||||
* * `initial_lr` - Initial learning rate
|
||||
* * `warmup_steps` - Number of warmup steps
|
||||
* * `total_steps` - Total training steps
|
||||
*/
|
||||
constructor(initial_lr: number, warmup_steps: number, total_steps: number);
|
||||
/**
|
||||
* Reset scheduler
|
||||
*/
|
||||
reset(): void;
|
||||
/**
|
||||
* Advance to next step
|
||||
*/
|
||||
step(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Linear attention (Performer-style)
|
||||
*/
|
||||
export class WasmLinearAttention {
|
||||
free(): void;
|
||||
[Symbol.dispose](): void;
|
||||
/**
|
||||
* Compute linear attention
|
||||
*/
|
||||
compute(query: Float32Array, keys: any, values: any): Float32Array;
|
||||
/**
|
||||
* Create a new linear attention instance
|
||||
*
|
||||
* # Arguments
|
||||
* * `dim` - Embedding dimension
|
||||
* * `num_features` - Number of random features
|
||||
*/
|
||||
constructor(dim: number, num_features: number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Local-global attention mechanism
|
||||
*/
|
||||
export class WasmLocalGlobalAttention {
|
||||
free(): void;
|
||||
[Symbol.dispose](): void;
|
||||
/**
|
||||
* Compute local-global attention
|
||||
*/
|
||||
compute(query: Float32Array, keys: any, values: any): Float32Array;
|
||||
/**
|
||||
* Create a new local-global attention instance
|
||||
*
|
||||
* # Arguments
|
||||
* * `dim` - Embedding dimension
|
||||
* * `local_window` - Size of local attention window
|
||||
* * `global_tokens` - Number of global attention tokens
|
||||
*/
|
||||
constructor(dim: number, local_window: number, global_tokens: number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mixture of Experts (MoE) attention
|
||||
*/
|
||||
export class WasmMoEAttention {
|
||||
free(): void;
|
||||
[Symbol.dispose](): void;
|
||||
/**
|
||||
* Compute MoE attention
|
||||
*/
|
||||
compute(query: Float32Array, keys: any, values: any): Float32Array;
|
||||
/**
|
||||
* Create a new MoE attention instance
|
||||
*
|
||||
* # Arguments
|
||||
* * `dim` - Embedding dimension
|
||||
* * `num_experts` - Number of expert attention mechanisms
|
||||
* * `top_k` - Number of experts to use per query
|
||||
*/
|
||||
constructor(dim: number, num_experts: number, top_k: number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multi-head attention mechanism
|
||||
*/
|
||||
export class WasmMultiHeadAttention {
|
||||
free(): void;
|
||||
[Symbol.dispose](): void;
|
||||
/**
|
||||
* Compute multi-head attention
|
||||
*/
|
||||
compute(query: Float32Array, keys: any, values: any): Float32Array;
|
||||
/**
|
||||
* Create a new multi-head attention instance
|
||||
*
|
||||
* # Arguments
|
||||
* * `dim` - Embedding dimension
|
||||
* * `num_heads` - Number of attention heads
|
||||
*/
|
||||
constructor(dim: number, num_heads: number);
|
||||
/**
|
||||
* Get the dimension
|
||||
*/
|
||||
readonly dim: number;
|
||||
/**
|
||||
* Get the number of heads
|
||||
*/
|
||||
readonly num_heads: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* SGD optimizer with momentum
|
||||
*/
|
||||
export class WasmSGD {
|
||||
free(): void;
|
||||
[Symbol.dispose](): void;
|
||||
/**
|
||||
* Create a new SGD optimizer
|
||||
*
|
||||
* # Arguments
|
||||
* * `param_count` - Number of parameters
|
||||
* * `learning_rate` - Learning rate
|
||||
* * `momentum` - Momentum coefficient (default: 0)
|
||||
*/
|
||||
constructor(param_count: number, learning_rate: number, momentum?: number | null);
|
||||
/**
|
||||
* Reset optimizer state
|
||||
*/
|
||||
reset(): void;
|
||||
/**
|
||||
* Perform optimization step
|
||||
*/
|
||||
step(params: Float32Array, gradients: Float32Array): void;
|
||||
/**
|
||||
* Get current learning rate
|
||||
*/
|
||||
learning_rate: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute attention weights from scores
|
||||
*/
|
||||
export function attention_weights(scores: Float32Array, temperature?: number | null): void;
|
||||
|
||||
/**
|
||||
* Get information about available attention mechanisms
|
||||
*/
|
||||
export function available_mechanisms(): any;
|
||||
|
||||
/**
|
||||
* Batch normalize vectors
|
||||
*/
|
||||
export function batch_normalize(vectors: any, epsilon?: number | null): Float32Array;
|
||||
|
||||
/**
|
||||
* Compute cosine similarity between two vectors
|
||||
*/
|
||||
export function cosine_similarity(a: Float32Array, b: Float32Array): number;
|
||||
|
||||
/**
|
||||
* Initialize the WASM module with panic hook
|
||||
*/
|
||||
export function init(): void;
|
||||
|
||||
/**
|
||||
* Compute L2 norm of a vector
|
||||
*/
|
||||
export function l2_norm(vec: Float32Array): number;
|
||||
|
||||
/**
|
||||
* Log a message to the browser console
|
||||
*/
|
||||
export function log(message: string): void;
|
||||
|
||||
/**
|
||||
* Log an error to the browser console
|
||||
*/
|
||||
export function log_error(message: string): void;
|
||||
|
||||
/**
|
||||
* Normalize a vector to unit length
|
||||
*/
|
||||
export function normalize(vec: Float32Array): void;
|
||||
|
||||
/**
|
||||
* Compute pairwise distances between vectors
|
||||
*/
|
||||
export function pairwise_distances(vectors: any): Float32Array;
|
||||
|
||||
/**
|
||||
* Generate random orthogonal matrix (for initialization)
|
||||
*/
|
||||
export function random_orthogonal_matrix(dim: number): Float32Array;
|
||||
|
||||
/**
|
||||
* Compute scaled dot-product attention
|
||||
*
|
||||
* # Arguments
|
||||
* * `query` - Query vector as Float32Array
|
||||
* * `keys` - Array of key vectors
|
||||
* * `values` - Array of value vectors
|
||||
* * `scale` - Optional scaling factor (defaults to 1/sqrt(dim))
|
||||
*/
|
||||
export function scaled_dot_attention(query: Float32Array, keys: any, values: any, scale?: number | null): Float32Array;
|
||||
|
||||
/**
|
||||
* Compute softmax of a vector
|
||||
*/
|
||||
export function softmax(vec: Float32Array): void;
|
||||
|
||||
/**
|
||||
* Get the version of the ruvector-attention-wasm crate
|
||||
*/
|
||||
export function version(): string;
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,71 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export const memory: WebAssembly.Memory;
|
||||
export const __wbg_wasmadam_free: (a: number, b: number) => void;
|
||||
export const __wbg_wasmadamw_free: (a: number, b: number) => void;
|
||||
export const __wbg_wasmflashattention_free: (a: number, b: number) => void;
|
||||
export const __wbg_wasmhyperbolicattention_free: (a: number, b: number) => void;
|
||||
export const __wbg_wasminfonceloss_free: (a: number, b: number) => void;
|
||||
export const __wbg_wasmlinearattention_free: (a: number, b: number) => void;
|
||||
export const __wbg_wasmmoeattention_free: (a: number, b: number) => void;
|
||||
export const __wbg_wasmmultiheadattention_free: (a: number, b: number) => void;
|
||||
export const __wbg_wasmsgd_free: (a: number, b: number) => void;
|
||||
export const attention_weights: (a: number, b: number, c: number, d: number) => void;
|
||||
export const available_mechanisms: () => number;
|
||||
export const batch_normalize: (a: number, b: number, c: number) => void;
|
||||
export const cosine_similarity: (a: number, b: number, c: number, d: number, e: number) => void;
|
||||
export const l2_norm: (a: number, b: number) => number;
|
||||
export const log: (a: number, b: number) => void;
|
||||
export const log_error: (a: number, b: number) => void;
|
||||
export const normalize: (a: number, b: number, c: number, d: number) => void;
|
||||
export const pairwise_distances: (a: number, b: number) => void;
|
||||
export const random_orthogonal_matrix: (a: number, b: number) => void;
|
||||
export const scaled_dot_attention: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
||||
export const softmax: (a: number, b: number, c: number) => void;
|
||||
export const version: (a: number) => void;
|
||||
export const wasmadam_learning_rate: (a: number) => number;
|
||||
export const wasmadam_new: (a: number, b: number) => number;
|
||||
export const wasmadam_reset: (a: number) => void;
|
||||
export const wasmadam_set_learning_rate: (a: number, b: number) => void;
|
||||
export const wasmadam_step: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
||||
export const wasmadamw_new: (a: number, b: number, c: number) => number;
|
||||
export const wasmadamw_reset: (a: number) => void;
|
||||
export const wasmadamw_step: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
||||
export const wasmadamw_weight_decay: (a: number) => number;
|
||||
export const wasmflashattention_compute: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
||||
export const wasmflashattention_new: (a: number, b: number) => number;
|
||||
export const wasmhyperbolicattention_compute: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
||||
export const wasmhyperbolicattention_curvature: (a: number) => number;
|
||||
export const wasmhyperbolicattention_new: (a: number, b: number) => number;
|
||||
export const wasminfonceloss_compute: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
||||
export const wasminfonceloss_new: (a: number) => number;
|
||||
export const wasmlinearattention_compute: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
||||
export const wasmlinearattention_new: (a: number, b: number) => number;
|
||||
export const wasmlocalglobalattention_compute: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
||||
export const wasmlocalglobalattention_new: (a: number, b: number, c: number) => number;
|
||||
export const wasmlrscheduler_get_lr: (a: number) => number;
|
||||
export const wasmlrscheduler_new: (a: number, b: number, c: number) => number;
|
||||
export const wasmlrscheduler_reset: (a: number) => void;
|
||||
export const wasmlrscheduler_step: (a: number) => void;
|
||||
export const wasmmoeattention_compute: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
||||
export const wasmmoeattention_new: (a: number, b: number, c: number) => number;
|
||||
export const wasmmultiheadattention_compute: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
||||
export const wasmmultiheadattention_dim: (a: number) => number;
|
||||
export const wasmmultiheadattention_new: (a: number, b: number, c: number) => void;
|
||||
export const wasmmultiheadattention_num_heads: (a: number) => number;
|
||||
export const wasmsgd_learning_rate: (a: number) => number;
|
||||
export const wasmsgd_new: (a: number, b: number, c: number) => number;
|
||||
export const wasmsgd_reset: (a: number) => void;
|
||||
export const wasmsgd_set_learning_rate: (a: number, b: number) => void;
|
||||
export const wasmsgd_step: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
||||
export const init: () => void;
|
||||
export const wasmadamw_set_learning_rate: (a: number, b: number) => void;
|
||||
export const wasmadamw_learning_rate: (a: number) => number;
|
||||
export const __wbg_wasmlocalglobalattention_free: (a: number, b: number) => void;
|
||||
export const __wbg_wasmlrscheduler_free: (a: number, b: number) => void;
|
||||
export const __wbindgen_export: (a: number, b: number) => number;
|
||||
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
||||
export const __wbindgen_export3: (a: number) => void;
|
||||
export const __wbindgen_export4: (a: number, b: number, c: number) => void;
|
||||
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
||||
export const __wbindgen_start: () => void;
|
||||
Reference in New Issue
Block a user