@ruvector/ruvllm 2.5.5 → 2.5.6
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 +282 -282
- package/bin/cli.js +1020 -1020
- package/dist/cjs/benchmarks/embedding-benchmark.js +1 -1
- package/dist/cjs/benchmarks/index.js +1 -1
- package/dist/cjs/benchmarks/model-comparison.js +1 -1
- package/dist/cjs/benchmarks/routing-benchmark.js +1 -1
- package/dist/cjs/contrastive.js +70 -70
- package/dist/cjs/engine.js +13 -13
- package/dist/cjs/export.js +31 -31
- package/dist/cjs/federated.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/intelligence.js +1 -1
- package/dist/cjs/lora.js +1 -1
- package/dist/cjs/models.js +1 -1
- package/dist/cjs/native.js +1 -1
- package/dist/cjs/session.js +1 -1
- package/dist/cjs/simd.js +1 -1
- package/dist/cjs/sona.d.ts +36 -0
- package/dist/cjs/sona.d.ts.map +1 -1
- package/dist/cjs/sona.js +66 -4
- package/dist/cjs/streaming.js +1 -1
- package/dist/cjs/training.js +1 -1
- package/dist/cjs/types.js +1 -1
- package/dist/esm/benchmarks/embedding-benchmark.js +1 -1
- package/dist/esm/benchmarks/index.js +1 -1
- package/dist/esm/benchmarks/model-comparison.js +1 -1
- package/dist/esm/benchmarks/routing-benchmark.js +1 -1
- package/dist/esm/contrastive.js +70 -70
- package/dist/esm/engine.js +13 -13
- package/dist/esm/export.js +31 -31
- package/dist/esm/federated.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/intelligence.js +1 -1
- package/dist/esm/lora.js +1 -1
- package/dist/esm/models.js +1 -1
- package/dist/esm/native.js +1 -1
- package/dist/esm/session.js +1 -1
- package/dist/esm/simd.js +1 -1
- package/dist/esm/sona.d.ts +36 -0
- package/dist/esm/sona.d.ts.map +1 -1
- package/dist/esm/sona.js +66 -4
- package/dist/esm/streaming.js +1 -1
- package/dist/esm/training.js +1 -1
- package/dist/esm/types.js +1 -1
- package/package.json +133 -133
- package/scripts/ensemble-model-compare.js +287 -287
- package/scripts/huggingface/README.md +537 -537
- package/scripts/huggingface/publish.sh +112 -112
- package/scripts/hybrid-model-compare.js +373 -373
- package/scripts/improved-model-compare.js +288 -288
- package/scripts/optimized-model-compare.js +364 -364
- package/scripts/real-model-compare.js +280 -280
- package/scripts/training/agentic-flow-capabilities.json +329 -329
- package/scripts/training/claude-code-synth.js +505 -505
- package/scripts/training/claude-flow-capabilities.json +1322 -1322
- package/scripts/training/claude-hard-negatives.js +222 -222
- package/scripts/training/contrastive-finetune.js +517 -517
- package/scripts/training/ecosystem-triplets.jsonl +1466 -1466
- package/scripts/training/generate-ecosystem-triplets.js +1324 -1324
- package/scripts/training/routing-dataset.js +634 -634
- package/scripts/training/ruvector-capabilities.json +798 -798
- package/scripts/training/validate-ecosystem.js +381 -381
- package/scripts/training/validation-results.json +22 -22
package/README.md
CHANGED
|
@@ -1,282 +1,282 @@
|
|
|
1
|
-
# @ruvector/ruvllm
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@ruvector/ruvllm)
|
|
4
|
-
[](https://www.npmjs.com/package/@ruvector/ruvllm)
|
|
5
|
-
[](https://opensource.org/licenses/MIT)
|
|
6
|
-
[](https://github.com/ruvnet/ruvector)
|
|
7
|
-
|
|
8
|
-
**Self-learning LLM runtime for Node.js** — GGUF inference, TurboQuant KV-cache compression (6-8x memory savings), SONA adaptive learning, FlashAttention, speculative decoding, and SIMD-optimized kernels. Built in Rust, runs everywhere.
|
|
9
|
-
|
|
10
|
-
> Inference at **88-135 tok/s** on M4 Pro | **<1ms** SONA adaptation | **6-8x** KV-cache compression via TurboQuant
|
|
11
|
-
|
|
12
|
-
## Installation
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
npm install @ruvector/ruvllm
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Quick Start
|
|
19
|
-
|
|
20
|
-
```typescript
|
|
21
|
-
import { RuvLLM, RuvLLMConfig } from '@ruvector/ruvllm';
|
|
22
|
-
|
|
23
|
-
// Initialize with default configuration
|
|
24
|
-
const llm = new RuvLLM();
|
|
25
|
-
|
|
26
|
-
// Or with custom configuration
|
|
27
|
-
const llm = new RuvLLM({
|
|
28
|
-
modelPath: './models/ruvltra-small-q4km.gguf',
|
|
29
|
-
sonaEnabled: true,
|
|
30
|
-
flashAttention: true,
|
|
31
|
-
maxTokens: 256,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Generate text
|
|
35
|
-
const response = await llm.query('Explain quantum computing');
|
|
36
|
-
console.log(response.text);
|
|
37
|
-
|
|
38
|
-
// Stream generation
|
|
39
|
-
for await (const token of llm.stream('Write a haiku about Rust')) {
|
|
40
|
-
process.stdout.write(token);
|
|
41
|
-
}
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## What's New in v2.5
|
|
45
|
-
|
|
46
|
-
| Feature | Description |
|
|
47
|
-
|---------|-------------|
|
|
48
|
-
| **TurboQuant KV-Cache** | 2-4 bit asymmetric quantization with per-channel scale/zero-point — 6-8x memory reduction, <0.5% perplexity loss |
|
|
49
|
-
| **TurboQuant Embedding Store** | Quantized vector storage with compressed search — 10-30x memory savings |
|
|
50
|
-
| **H2O / PyramidKV Eviction** | Intelligent cache eviction policies for long-context inference |
|
|
51
|
-
| **Optimized Inner Product** | Asymmetric distance on quantized data — skip decompression for 2-4x faster search |
|
|
52
|
-
| **RuvLTRA Models** | Purpose-built 0.5B & 3B models for Claude Flow |
|
|
53
|
-
| **Task-Specific LoRA** | 5 pre-trained adapters (coder, researcher, security, architect, reviewer) |
|
|
54
|
-
| **HuggingFace Hub** | Download/upload models directly |
|
|
55
|
-
| **Adapter Merging** | TIES, DARE, SLERP strategies |
|
|
56
|
-
| **HNSW Routing** | 150x faster semantic matching |
|
|
57
|
-
| **Evaluation Harness** | SWE-Bench testing with 5 ablation modes |
|
|
58
|
-
| **mistral-rs Backend** | Production serving with PagedAttention, X-LoRA, ISQ |
|
|
59
|
-
|
|
60
|
-
## TurboQuant — KV-Cache Compression
|
|
61
|
-
|
|
62
|
-
Reduce inference memory by 6-8x with <0.5% quality loss:
|
|
63
|
-
|
|
64
|
-
```typescript
|
|
65
|
-
import { simd } from '@ruvector/ruvllm/simd';
|
|
66
|
-
|
|
67
|
-
// TurboQuant compresses KV-cache entries at 2-4 bit precision
|
|
68
|
-
// with per-channel asymmetric quantization (scale + zero-point).
|
|
69
|
-
// Eviction policies (H2O, Sliding Window, PyramidKV) keep the
|
|
70
|
-
// most important tokens in cache during long-context generation.
|
|
71
|
-
|
|
72
|
-
// Supported bit widths: 2-bit (32x), 3-bit (10.7x), 4-bit (8x), 8-bit (4x)
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
| Bits | Compression | Perplexity Loss | Use Case |
|
|
76
|
-
|------|-------------|-----------------|----------|
|
|
77
|
-
| 2-bit | 32x | ~2% | Maximum compression, edge devices |
|
|
78
|
-
| 3-bit | 10.7x | <1% | Balanced — recommended for most uses |
|
|
79
|
-
| 4-bit | 8x | <0.5% | High quality, long-context inference |
|
|
80
|
-
| 8-bit | 4x | ~0% | Baseline quantization |
|
|
81
|
-
|
|
82
|
-
## CLI Usage
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
# Query a model
|
|
86
|
-
ruvllm query "What is machine learning?"
|
|
87
|
-
|
|
88
|
-
# Stream output
|
|
89
|
-
ruvllm query --stream "Write a poem"
|
|
90
|
-
|
|
91
|
-
# Download a model
|
|
92
|
-
ruvllm download ruvector/ruvltra-small-q4km
|
|
93
|
-
|
|
94
|
-
# Benchmark
|
|
95
|
-
ruvllm bench ./models/model.gguf
|
|
96
|
-
|
|
97
|
-
# Run evaluation (SWE-Bench)
|
|
98
|
-
ruvllm eval --model ./models/model.gguf --subset lite --max-tasks 50
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
## API Reference
|
|
102
|
-
|
|
103
|
-
### RuvLLM Class
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
class RuvLLM {
|
|
107
|
-
constructor(config?: RuvLLMConfig);
|
|
108
|
-
|
|
109
|
-
// Generate text
|
|
110
|
-
query(prompt: string, params?: GenerateParams): Promise<Response>;
|
|
111
|
-
|
|
112
|
-
// Stream generation
|
|
113
|
-
stream(prompt: string, params?: GenerateParams): AsyncIterable<string>;
|
|
114
|
-
|
|
115
|
-
// Load a model
|
|
116
|
-
loadModel(path: string): Promise<void>;
|
|
117
|
-
|
|
118
|
-
// Get SONA learning stats
|
|
119
|
-
sonaStats(): SonaStats | null;
|
|
120
|
-
|
|
121
|
-
// Adapt on feedback
|
|
122
|
-
adapt(input: Float32Array, quality: number): void;
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### Configuration
|
|
127
|
-
|
|
128
|
-
```typescript
|
|
129
|
-
interface RuvLLMConfig {
|
|
130
|
-
modelPath?: string; // Path to GGUF model
|
|
131
|
-
sonaEnabled?: boolean; // Enable SONA learning (default: true)
|
|
132
|
-
flashAttention?: boolean; // Use Flash Attention 2 (default: true)
|
|
133
|
-
maxTokens?: number; // Max generation tokens (default: 256)
|
|
134
|
-
temperature?: number; // Sampling temperature (default: 0.7)
|
|
135
|
-
topP?: number; // Top-p sampling (default: 0.9)
|
|
136
|
-
}
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### Generate Parameters
|
|
140
|
-
|
|
141
|
-
```typescript
|
|
142
|
-
interface GenerateParams {
|
|
143
|
-
maxTokens?: number;
|
|
144
|
-
temperature?: number;
|
|
145
|
-
topP?: number;
|
|
146
|
-
topK?: number;
|
|
147
|
-
repetitionPenalty?: number;
|
|
148
|
-
stopSequences?: string[];
|
|
149
|
-
}
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
## SIMD Module
|
|
153
|
-
|
|
154
|
-
For direct access to optimized SIMD kernels:
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
import { simd } from '@ruvector/ruvllm/simd';
|
|
158
|
-
|
|
159
|
-
// Dot product
|
|
160
|
-
const result = simd.dotProduct(vecA, vecB);
|
|
161
|
-
|
|
162
|
-
// Matrix multiplication
|
|
163
|
-
const output = simd.matmul(matrix, vector);
|
|
164
|
-
|
|
165
|
-
// Flash Attention
|
|
166
|
-
const attended = simd.flashAttention(query, key, value, scale);
|
|
167
|
-
|
|
168
|
-
// RMS Normalization
|
|
169
|
-
simd.rmsNorm(hidden, weights, epsilon);
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
## Performance (M4 Pro)
|
|
173
|
-
|
|
174
|
-
| Operation | Performance |
|
|
175
|
-
|-----------|-------------|
|
|
176
|
-
| Inference | 88-135 tok/s |
|
|
177
|
-
| Flash Attention | 320µs (seq=2048) |
|
|
178
|
-
| HNSW Search | 17-62µs |
|
|
179
|
-
| SONA Adapt | <1ms |
|
|
180
|
-
| Evaluation | 5 ablation modes |
|
|
181
|
-
|
|
182
|
-
## Evaluation Harness
|
|
183
|
-
|
|
184
|
-
Run model evaluations with SWE-Bench integration:
|
|
185
|
-
|
|
186
|
-
```typescript
|
|
187
|
-
import { RuvLLM, EvaluationHarness, AblationMode } from '@ruvector/ruvllm';
|
|
188
|
-
|
|
189
|
-
const harness = new EvaluationHarness({
|
|
190
|
-
modelPath: './models/model.gguf',
|
|
191
|
-
enableHnsw: true,
|
|
192
|
-
enableSona: true,
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
// Run single evaluation
|
|
196
|
-
const result = await harness.evaluate(
|
|
197
|
-
'Fix the null pointer exception',
|
|
198
|
-
'def process(data): return data.split()',
|
|
199
|
-
AblationMode.Full
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
console.log(`Success: ${result.success}, Quality: ${result.qualityScore}`);
|
|
203
|
-
|
|
204
|
-
// Run ablation study (Baseline, RetrievalOnly, AdaptersOnly, R+A, Full)
|
|
205
|
-
const report = await harness.runAblationStudy(tasks);
|
|
206
|
-
for (const [mode, metrics] of Object.entries(report.modeMetrics)) {
|
|
207
|
-
console.log(`${mode}: ${metrics.successRate * 100}% success`);
|
|
208
|
-
}
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
## mistral-rs Backend (Production Serving)
|
|
212
|
-
|
|
213
|
-
For production deployments with 10-100+ concurrent users, use the mistral-rs backend:
|
|
214
|
-
|
|
215
|
-
```typescript
|
|
216
|
-
import { RuvLLM, MistralBackend, PagedAttentionConfig } from '@ruvector/ruvllm';
|
|
217
|
-
|
|
218
|
-
// Configure for production serving
|
|
219
|
-
const backend = new MistralBackend({
|
|
220
|
-
// PagedAttention: 5-10x more concurrent users
|
|
221
|
-
pagedAttention: {
|
|
222
|
-
blockSize: 16,
|
|
223
|
-
maxBlocks: 4096,
|
|
224
|
-
gpuMemoryFraction: 0.9,
|
|
225
|
-
prefixCaching: true,
|
|
226
|
-
},
|
|
227
|
-
// X-LoRA: Per-token adapter routing
|
|
228
|
-
xlora: {
|
|
229
|
-
adapters: ['./adapters/coder', './adapters/researcher'],
|
|
230
|
-
topK: 2,
|
|
231
|
-
},
|
|
232
|
-
// ISQ: Runtime quantization
|
|
233
|
-
isq: {
|
|
234
|
-
bits: 4,
|
|
235
|
-
method: 'awq',
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
const llm = new RuvLLM({ backend });
|
|
240
|
-
await llm.loadModel('mistralai/Mistral-7B-Instruct-v0.2');
|
|
241
|
-
|
|
242
|
-
// Serve multiple concurrent requests
|
|
243
|
-
const response = await llm.query('Write production code');
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
> **Note**: mistral-rs features require the Rust backend with `mistral-rs` feature enabled. Native bindings will use mistral-rs when available.
|
|
247
|
-
|
|
248
|
-
## Supported Models
|
|
249
|
-
|
|
250
|
-
- **RuvLTRA-Small** (494M) - Q4K, Q5K, Q8
|
|
251
|
-
- **RuvLTRA-Medium** (3B) - Q4K, Q5K, Q8
|
|
252
|
-
- **Qwen 2.5** (0.5B-72B)
|
|
253
|
-
- **Llama 3.x** (8B-70B)
|
|
254
|
-
- **Mistral** (7B-22B)
|
|
255
|
-
- **Phi-3** (3.8B-14B)
|
|
256
|
-
- **Gemma-2** (2B-27B)
|
|
257
|
-
|
|
258
|
-
## Platform Support
|
|
259
|
-
|
|
260
|
-
| Platform | Architecture | Status |
|
|
261
|
-
|----------|--------------|--------|
|
|
262
|
-
| macOS | arm64 (M1-M4) | ✅ Full support |
|
|
263
|
-
| macOS | x64 | ✅ Supported |
|
|
264
|
-
| Linux | x64 | ✅ Supported |
|
|
265
|
-
| Linux | arm64 | ✅ Supported |
|
|
266
|
-
| Windows | x64 | ✅ Supported |
|
|
267
|
-
|
|
268
|
-
## Related Packages
|
|
269
|
-
|
|
270
|
-
- [@ruvector/core](https://www.npmjs.com/package/@ruvector/core) - Vector operations
|
|
271
|
-
- [@ruvector/sona](https://www.npmjs.com/package/@ruvector/sona) - SONA learning engine
|
|
272
|
-
- [@ruvector/ruvector](https://www.npmjs.com/package/@ruvector/ruvector) - Full Ruvector SDK
|
|
273
|
-
|
|
274
|
-
## Links
|
|
275
|
-
|
|
276
|
-
- [GitHub Repository](https://github.com/ruvnet/ruvector)
|
|
277
|
-
- [API Documentation](https://docs.rs/ruvllm)
|
|
278
|
-
- [Crate (Rust)](https://crates.io/crates/ruvllm)
|
|
279
|
-
|
|
280
|
-
## License
|
|
281
|
-
|
|
282
|
-
MIT OR Apache-2.0
|
|
1
|
+
# @ruvector/ruvllm
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@ruvector/ruvllm)
|
|
4
|
+
[](https://www.npmjs.com/package/@ruvector/ruvllm)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://github.com/ruvnet/ruvector)
|
|
7
|
+
|
|
8
|
+
**Self-learning LLM runtime for Node.js** — GGUF inference, TurboQuant KV-cache compression (6-8x memory savings), SONA adaptive learning, FlashAttention, speculative decoding, and SIMD-optimized kernels. Built in Rust, runs everywhere.
|
|
9
|
+
|
|
10
|
+
> Inference at **88-135 tok/s** on M4 Pro | **<1ms** SONA adaptation | **6-8x** KV-cache compression via TurboQuant
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @ruvector/ruvllm
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { RuvLLM, RuvLLMConfig } from '@ruvector/ruvllm';
|
|
22
|
+
|
|
23
|
+
// Initialize with default configuration
|
|
24
|
+
const llm = new RuvLLM();
|
|
25
|
+
|
|
26
|
+
// Or with custom configuration
|
|
27
|
+
const llm = new RuvLLM({
|
|
28
|
+
modelPath: './models/ruvltra-small-q4km.gguf',
|
|
29
|
+
sonaEnabled: true,
|
|
30
|
+
flashAttention: true,
|
|
31
|
+
maxTokens: 256,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Generate text
|
|
35
|
+
const response = await llm.query('Explain quantum computing');
|
|
36
|
+
console.log(response.text);
|
|
37
|
+
|
|
38
|
+
// Stream generation
|
|
39
|
+
for await (const token of llm.stream('Write a haiku about Rust')) {
|
|
40
|
+
process.stdout.write(token);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## What's New in v2.5
|
|
45
|
+
|
|
46
|
+
| Feature | Description |
|
|
47
|
+
|---------|-------------|
|
|
48
|
+
| **TurboQuant KV-Cache** | 2-4 bit asymmetric quantization with per-channel scale/zero-point — 6-8x memory reduction, <0.5% perplexity loss |
|
|
49
|
+
| **TurboQuant Embedding Store** | Quantized vector storage with compressed search — 10-30x memory savings |
|
|
50
|
+
| **H2O / PyramidKV Eviction** | Intelligent cache eviction policies for long-context inference |
|
|
51
|
+
| **Optimized Inner Product** | Asymmetric distance on quantized data — skip decompression for 2-4x faster search |
|
|
52
|
+
| **RuvLTRA Models** | Purpose-built 0.5B & 3B models for Claude Flow |
|
|
53
|
+
| **Task-Specific LoRA** | 5 pre-trained adapters (coder, researcher, security, architect, reviewer) |
|
|
54
|
+
| **HuggingFace Hub** | Download/upload models directly |
|
|
55
|
+
| **Adapter Merging** | TIES, DARE, SLERP strategies |
|
|
56
|
+
| **HNSW Routing** | 150x faster semantic matching |
|
|
57
|
+
| **Evaluation Harness** | SWE-Bench testing with 5 ablation modes |
|
|
58
|
+
| **mistral-rs Backend** | Production serving with PagedAttention, X-LoRA, ISQ |
|
|
59
|
+
|
|
60
|
+
## TurboQuant — KV-Cache Compression
|
|
61
|
+
|
|
62
|
+
Reduce inference memory by 6-8x with <0.5% quality loss:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { simd } from '@ruvector/ruvllm/simd';
|
|
66
|
+
|
|
67
|
+
// TurboQuant compresses KV-cache entries at 2-4 bit precision
|
|
68
|
+
// with per-channel asymmetric quantization (scale + zero-point).
|
|
69
|
+
// Eviction policies (H2O, Sliding Window, PyramidKV) keep the
|
|
70
|
+
// most important tokens in cache during long-context generation.
|
|
71
|
+
|
|
72
|
+
// Supported bit widths: 2-bit (32x), 3-bit (10.7x), 4-bit (8x), 8-bit (4x)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
| Bits | Compression | Perplexity Loss | Use Case |
|
|
76
|
+
|------|-------------|-----------------|----------|
|
|
77
|
+
| 2-bit | 32x | ~2% | Maximum compression, edge devices |
|
|
78
|
+
| 3-bit | 10.7x | <1% | Balanced — recommended for most uses |
|
|
79
|
+
| 4-bit | 8x | <0.5% | High quality, long-context inference |
|
|
80
|
+
| 8-bit | 4x | ~0% | Baseline quantization |
|
|
81
|
+
|
|
82
|
+
## CLI Usage
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Query a model
|
|
86
|
+
ruvllm query "What is machine learning?"
|
|
87
|
+
|
|
88
|
+
# Stream output
|
|
89
|
+
ruvllm query --stream "Write a poem"
|
|
90
|
+
|
|
91
|
+
# Download a model
|
|
92
|
+
ruvllm download ruvector/ruvltra-small-q4km
|
|
93
|
+
|
|
94
|
+
# Benchmark
|
|
95
|
+
ruvllm bench ./models/model.gguf
|
|
96
|
+
|
|
97
|
+
# Run evaluation (SWE-Bench)
|
|
98
|
+
ruvllm eval --model ./models/model.gguf --subset lite --max-tasks 50
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## API Reference
|
|
102
|
+
|
|
103
|
+
### RuvLLM Class
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
class RuvLLM {
|
|
107
|
+
constructor(config?: RuvLLMConfig);
|
|
108
|
+
|
|
109
|
+
// Generate text
|
|
110
|
+
query(prompt: string, params?: GenerateParams): Promise<Response>;
|
|
111
|
+
|
|
112
|
+
// Stream generation
|
|
113
|
+
stream(prompt: string, params?: GenerateParams): AsyncIterable<string>;
|
|
114
|
+
|
|
115
|
+
// Load a model
|
|
116
|
+
loadModel(path: string): Promise<void>;
|
|
117
|
+
|
|
118
|
+
// Get SONA learning stats
|
|
119
|
+
sonaStats(): SonaStats | null;
|
|
120
|
+
|
|
121
|
+
// Adapt on feedback
|
|
122
|
+
adapt(input: Float32Array, quality: number): void;
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Configuration
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
interface RuvLLMConfig {
|
|
130
|
+
modelPath?: string; // Path to GGUF model
|
|
131
|
+
sonaEnabled?: boolean; // Enable SONA learning (default: true)
|
|
132
|
+
flashAttention?: boolean; // Use Flash Attention 2 (default: true)
|
|
133
|
+
maxTokens?: number; // Max generation tokens (default: 256)
|
|
134
|
+
temperature?: number; // Sampling temperature (default: 0.7)
|
|
135
|
+
topP?: number; // Top-p sampling (default: 0.9)
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Generate Parameters
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
interface GenerateParams {
|
|
143
|
+
maxTokens?: number;
|
|
144
|
+
temperature?: number;
|
|
145
|
+
topP?: number;
|
|
146
|
+
topK?: number;
|
|
147
|
+
repetitionPenalty?: number;
|
|
148
|
+
stopSequences?: string[];
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## SIMD Module
|
|
153
|
+
|
|
154
|
+
For direct access to optimized SIMD kernels:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { simd } from '@ruvector/ruvllm/simd';
|
|
158
|
+
|
|
159
|
+
// Dot product
|
|
160
|
+
const result = simd.dotProduct(vecA, vecB);
|
|
161
|
+
|
|
162
|
+
// Matrix multiplication
|
|
163
|
+
const output = simd.matmul(matrix, vector);
|
|
164
|
+
|
|
165
|
+
// Flash Attention
|
|
166
|
+
const attended = simd.flashAttention(query, key, value, scale);
|
|
167
|
+
|
|
168
|
+
// RMS Normalization
|
|
169
|
+
simd.rmsNorm(hidden, weights, epsilon);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Performance (M4 Pro)
|
|
173
|
+
|
|
174
|
+
| Operation | Performance |
|
|
175
|
+
|-----------|-------------|
|
|
176
|
+
| Inference | 88-135 tok/s |
|
|
177
|
+
| Flash Attention | 320µs (seq=2048) |
|
|
178
|
+
| HNSW Search | 17-62µs |
|
|
179
|
+
| SONA Adapt | <1ms |
|
|
180
|
+
| Evaluation | 5 ablation modes |
|
|
181
|
+
|
|
182
|
+
## Evaluation Harness
|
|
183
|
+
|
|
184
|
+
Run model evaluations with SWE-Bench integration:
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { RuvLLM, EvaluationHarness, AblationMode } from '@ruvector/ruvllm';
|
|
188
|
+
|
|
189
|
+
const harness = new EvaluationHarness({
|
|
190
|
+
modelPath: './models/model.gguf',
|
|
191
|
+
enableHnsw: true,
|
|
192
|
+
enableSona: true,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Run single evaluation
|
|
196
|
+
const result = await harness.evaluate(
|
|
197
|
+
'Fix the null pointer exception',
|
|
198
|
+
'def process(data): return data.split()',
|
|
199
|
+
AblationMode.Full
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
console.log(`Success: ${result.success}, Quality: ${result.qualityScore}`);
|
|
203
|
+
|
|
204
|
+
// Run ablation study (Baseline, RetrievalOnly, AdaptersOnly, R+A, Full)
|
|
205
|
+
const report = await harness.runAblationStudy(tasks);
|
|
206
|
+
for (const [mode, metrics] of Object.entries(report.modeMetrics)) {
|
|
207
|
+
console.log(`${mode}: ${metrics.successRate * 100}% success`);
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## mistral-rs Backend (Production Serving)
|
|
212
|
+
|
|
213
|
+
For production deployments with 10-100+ concurrent users, use the mistral-rs backend:
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
import { RuvLLM, MistralBackend, PagedAttentionConfig } from '@ruvector/ruvllm';
|
|
217
|
+
|
|
218
|
+
// Configure for production serving
|
|
219
|
+
const backend = new MistralBackend({
|
|
220
|
+
// PagedAttention: 5-10x more concurrent users
|
|
221
|
+
pagedAttention: {
|
|
222
|
+
blockSize: 16,
|
|
223
|
+
maxBlocks: 4096,
|
|
224
|
+
gpuMemoryFraction: 0.9,
|
|
225
|
+
prefixCaching: true,
|
|
226
|
+
},
|
|
227
|
+
// X-LoRA: Per-token adapter routing
|
|
228
|
+
xlora: {
|
|
229
|
+
adapters: ['./adapters/coder', './adapters/researcher'],
|
|
230
|
+
topK: 2,
|
|
231
|
+
},
|
|
232
|
+
// ISQ: Runtime quantization
|
|
233
|
+
isq: {
|
|
234
|
+
bits: 4,
|
|
235
|
+
method: 'awq',
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
const llm = new RuvLLM({ backend });
|
|
240
|
+
await llm.loadModel('mistralai/Mistral-7B-Instruct-v0.2');
|
|
241
|
+
|
|
242
|
+
// Serve multiple concurrent requests
|
|
243
|
+
const response = await llm.query('Write production code');
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
> **Note**: mistral-rs features require the Rust backend with `mistral-rs` feature enabled. Native bindings will use mistral-rs when available.
|
|
247
|
+
|
|
248
|
+
## Supported Models
|
|
249
|
+
|
|
250
|
+
- **RuvLTRA-Small** (494M) - Q4K, Q5K, Q8
|
|
251
|
+
- **RuvLTRA-Medium** (3B) - Q4K, Q5K, Q8
|
|
252
|
+
- **Qwen 2.5** (0.5B-72B)
|
|
253
|
+
- **Llama 3.x** (8B-70B)
|
|
254
|
+
- **Mistral** (7B-22B)
|
|
255
|
+
- **Phi-3** (3.8B-14B)
|
|
256
|
+
- **Gemma-2** (2B-27B)
|
|
257
|
+
|
|
258
|
+
## Platform Support
|
|
259
|
+
|
|
260
|
+
| Platform | Architecture | Status |
|
|
261
|
+
|----------|--------------|--------|
|
|
262
|
+
| macOS | arm64 (M1-M4) | ✅ Full support |
|
|
263
|
+
| macOS | x64 | ✅ Supported |
|
|
264
|
+
| Linux | x64 | ✅ Supported |
|
|
265
|
+
| Linux | arm64 | ✅ Supported |
|
|
266
|
+
| Windows | x64 | ✅ Supported |
|
|
267
|
+
|
|
268
|
+
## Related Packages
|
|
269
|
+
|
|
270
|
+
- [@ruvector/core](https://www.npmjs.com/package/@ruvector/core) - Vector operations
|
|
271
|
+
- [@ruvector/sona](https://www.npmjs.com/package/@ruvector/sona) - SONA learning engine
|
|
272
|
+
- [@ruvector/ruvector](https://www.npmjs.com/package/@ruvector/ruvector) - Full Ruvector SDK
|
|
273
|
+
|
|
274
|
+
## Links
|
|
275
|
+
|
|
276
|
+
- [GitHub Repository](https://github.com/ruvnet/ruvector)
|
|
277
|
+
- [API Documentation](https://docs.rs/ruvllm)
|
|
278
|
+
- [Crate (Rust)](https://crates.io/crates/ruvllm)
|
|
279
|
+
|
|
280
|
+
## License
|
|
281
|
+
|
|
282
|
+
MIT OR Apache-2.0
|