Squashed 'vendor/ruvector/' content from commit b64c2172
git-subtree-dir: vendor/ruvector git-subtree-split: b64c21726f2bb37286d9ee36a7869fef60cc6900
This commit is contained in:
77
crates/sona/wasm-example/README.md
Normal file
77
crates/sona/wasm-example/README.md
Normal file
@@ -0,0 +1,77 @@
|
||||
# SONA WASM Example
|
||||
|
||||
Interactive browser demo of the Self-Optimizing Neural Architecture (SONA).
|
||||
|
||||
## Quick Start
|
||||
|
||||
1. Build the WASM module (if not already built):
|
||||
```bash
|
||||
cd ..
|
||||
wasm-pack build --target web --features wasm
|
||||
cp -r pkg wasm-example/
|
||||
```
|
||||
|
||||
2. Serve the example:
|
||||
```bash
|
||||
cd wasm-example
|
||||
python3 -m http.server 8080
|
||||
```
|
||||
|
||||
3. Open in browser:
|
||||
```
|
||||
http://localhost:8080
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- **Real-time Learning**: Record trajectories and see instant updates
|
||||
- **LoRA Visualization**: Watch transformation in real-time
|
||||
- **Statistics Dashboard**: Monitor patterns, quality, and performance
|
||||
- **Interactive Controls**: Adjust configuration and run experiments
|
||||
|
||||
## Files
|
||||
|
||||
- `index.html` - Demo page with UI
|
||||
- `index.js` - JavaScript logic using WASM bindings
|
||||
- `package.json` - NPM configuration
|
||||
- `pkg/` - Generated WASM package
|
||||
- `sona.js` - JavaScript bindings
|
||||
- `sona_bg.wasm` - WebAssembly binary
|
||||
- `sona.d.ts` - TypeScript definitions
|
||||
|
||||
## Usage Example
|
||||
|
||||
```javascript
|
||||
import init, { WasmSonaEngine } from './pkg/sona.js';
|
||||
|
||||
async function main() {
|
||||
await init();
|
||||
|
||||
const engine = new WasmSonaEngine(256);
|
||||
const trajectoryId = engine.start_trajectory(new Float32Array(256).fill(0.1));
|
||||
engine.record_step(trajectoryId, 42, 0.8, 1000);
|
||||
engine.end_trajectory(trajectoryId, 0.85);
|
||||
|
||||
const output = engine.apply_lora(new Float32Array(256).fill(1.0));
|
||||
console.log('Transformed output:', output);
|
||||
}
|
||||
|
||||
main();
|
||||
```
|
||||
|
||||
## Performance
|
||||
|
||||
- WASM file size: ~1.5MB (release build)
|
||||
- Initialization: < 100ms
|
||||
- Per-trajectory overhead: < 1ms
|
||||
- LoRA application: < 0.1ms (256-dim)
|
||||
|
||||
## Browser Support
|
||||
|
||||
- Chrome/Edge 91+
|
||||
- Firefox 89+
|
||||
- Safari 14.1+
|
||||
|
||||
## License
|
||||
|
||||
MIT OR Apache-2.0
|
||||
281
crates/sona/wasm-example/index.html
Normal file
281
crates/sona/wasm-example/index.html
Normal file
@@ -0,0 +1,281 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>SONA WASM Demo - Self-Optimizing Neural Architecture</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
header h1 {
|
||||
font-size: 2.5em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
header p {
|
||||
font-size: 1.1em;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 30px;
|
||||
padding: 20px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
border-left: 4px solid #667eea;
|
||||
}
|
||||
|
||||
.section h2 {
|
||||
color: #667eea;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.controls {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 15px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
button {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 12px 24px;
|
||||
border-radius: 6px;
|
||||
font-size: 1em;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background: #764ba2;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
button:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
background: #ccc;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
input[type="number"], input[type="range"] {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 4px;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
||||
gap: 15px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background: white;
|
||||
padding: 15px;
|
||||
border-radius: 6px;
|
||||
text-align: center;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.stat-card .value {
|
||||
font-size: 2em;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.stat-card .label {
|
||||
font-size: 0.9em;
|
||||
color: #666;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
#console {
|
||||
background: #1e1e1e;
|
||||
color: #00ff00;
|
||||
padding: 15px;
|
||||
border-radius: 6px;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 0.9em;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.visualization {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 6px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
canvas {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
font-size: 1.2em;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
border: 4px solid #f3f3f3;
|
||||
border-top: 4px solid #667eea;
|
||||
border-radius: 50%;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
animation: spin 1s linear infinite;
|
||||
margin: 20px auto;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.success {
|
||||
color: #28a745;
|
||||
}
|
||||
|
||||
.warning {
|
||||
color: #ffc107;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #dc3545;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header>
|
||||
<h1>🧠 SONA WASM Demo</h1>
|
||||
<p>Self-Optimizing Neural Architecture in Your Browser</p>
|
||||
</header>
|
||||
|
||||
<div class="content">
|
||||
<div id="loading" class="loading">
|
||||
<div class="spinner"></div>
|
||||
<p>Loading WASM module...</p>
|
||||
</div>
|
||||
|
||||
<div id="app" style="display: none;">
|
||||
<!-- Configuration Section -->
|
||||
<div class="section">
|
||||
<h2>⚙️ Configuration</h2>
|
||||
<div class="controls">
|
||||
<div>
|
||||
<label>Hidden Dimension:</label>
|
||||
<input type="number" id="hiddenDim" value="256" min="64" max="2048" step="64">
|
||||
</div>
|
||||
<div>
|
||||
<label>Micro-LoRA Rank:</label>
|
||||
<input type="number" id="microRank" value="2" min="1" max="8">
|
||||
</div>
|
||||
<div>
|
||||
<label>Base-LoRA Rank:</label>
|
||||
<input type="number" id="baseRank" value="16" min="4" max="64" step="4">
|
||||
</div>
|
||||
</div>
|
||||
<button onclick="initializeEngine()">Initialize Engine</button>
|
||||
</div>
|
||||
|
||||
<!-- Learning Section -->
|
||||
<div class="section">
|
||||
<h2>📚 Learning Controls</h2>
|
||||
<div class="controls">
|
||||
<button onclick="runSingleTrajectory()">Run Single Trajectory</button>
|
||||
<button onclick="runBatch()">Run Batch (10 trajectories)</button>
|
||||
<button onclick="forceLearn()">Force Background Learning</button>
|
||||
<button onclick="clearEngine()">Reset Engine</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Statistics Section -->
|
||||
<div class="section">
|
||||
<h2>📊 Engine Statistics</h2>
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card">
|
||||
<div class="value" id="trajCount">0</div>
|
||||
<div class="label">Trajectories</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="value" id="patternCount">0</div>
|
||||
<div class="label">Patterns</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="value" id="loraUpdates">0</div>
|
||||
<div class="label">LoRA Updates</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="value" id="avgQuality">0.00</div>
|
||||
<div class="label">Avg Quality</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Visualization Section -->
|
||||
<div class="section">
|
||||
<h2>📈 LoRA Transformation Visualization</h2>
|
||||
<div class="visualization">
|
||||
<canvas id="loraCanvas"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Console Section -->
|
||||
<div class="section">
|
||||
<h2>💻 Console Output</h2>
|
||||
<div id="console"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="module" src="./index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
20
crates/sona/wasm-example/package.json
Normal file
20
crates/sona/wasm-example/package.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "sona-wasm-example",
|
||||
"version": "0.1.0",
|
||||
"description": "SONA WASM Example - Self-Optimizing Neural Architecture in the browser",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "cd .. && wasm-pack build --target web --features wasm --out-dir wasm-example/pkg",
|
||||
"serve": "python3 -m http.server 8080",
|
||||
"dev": "npm run build && npm run serve"
|
||||
},
|
||||
"keywords": [
|
||||
"wasm",
|
||||
"neural",
|
||||
"learning",
|
||||
"lora",
|
||||
"adaptive"
|
||||
],
|
||||
"author": "RuVector Team",
|
||||
"license": "MIT OR Apache-2.0"
|
||||
}
|
||||
Reference in New Issue
Block a user