@claude-flow/cli 3.18.1 → 3.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/commands/neural.d.ts.map +1 -1
- package/dist/src/commands/neural.js +74 -13
- package/dist/src/commands/neural.js.map +1 -1
- package/dist/src/ruvector/lora-adapter.d.ts +8 -0
- package/dist/src/ruvector/lora-adapter.d.ts.map +1 -1
- package/dist/src/ruvector/lora-adapter.js +36 -1
- package/dist/src/ruvector/lora-adapter.js.map +1 -1
- package/dist/src/services/native-training.d.ts +40 -0
- package/dist/src/services/native-training.d.ts.map +1 -0
- package/dist/src/services/native-training.js +84 -0
- package/dist/src/services/native-training.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"neural.d.ts","sourceRoot":"","sources":["../../../src/commands/neural.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAiC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"neural.d.ts","sourceRoot":"","sources":["../../../src/commands/neural.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAiC,MAAM,aAAa,CAAC;AA2tI1E,eAAO,MAAM,aAAa,EAAE,OAmB3B,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -23,6 +23,7 @@ const trainCommand = {
|
|
|
23
23
|
{ name: 'hyperbolic', type: 'boolean', description: 'Enable hyperbolic attention for hierarchical patterns', default: 'false' },
|
|
24
24
|
{ name: 'contrastive', type: 'boolean', description: 'Use contrastive learning (InfoNCE)', default: 'true' },
|
|
25
25
|
{ name: 'curriculum', type: 'boolean', description: 'Enable curriculum learning', default: 'false' },
|
|
26
|
+
{ name: 'backend', type: 'string', description: 'Training backend: auto (native when available), native (@ruvector/ruvllm TrainingPipeline, disk checkpoints), wasm (RuVector MicroLoRA/InfoNCE)', default: 'auto' },
|
|
26
27
|
],
|
|
27
28
|
examples: [
|
|
28
29
|
{ command: 'claude-flow neural train -p coordination -e 100', description: 'Train coordination patterns' },
|
|
@@ -35,6 +36,11 @@ const trainCommand = {
|
|
|
35
36
|
const learningRate = parseFloat(ctx.flags['learning-rate'] || '0.01');
|
|
36
37
|
const batchSize = parseInt(ctx.flags['batch-size'] || '32', 10);
|
|
37
38
|
const dim = Math.min(parseInt(ctx.flags.dim || '256', 10), 256);
|
|
39
|
+
// #2549 follow-up — backend routing: 'native' = @ruvector/ruvllm
|
|
40
|
+
// TrainingPipeline (real epochs/early-stopping/disk checkpoints),
|
|
41
|
+
// 'wasm' = RuVector MicroLoRA/InfoNCE (pre-3.19 behavior),
|
|
42
|
+
// 'auto' = native when the module resolves, else wasm.
|
|
43
|
+
const backendFlag = String(ctx.flags.backend || 'auto');
|
|
38
44
|
const useWasm = ctx.flags.wasm !== false;
|
|
39
45
|
const useFlash = ctx.flags.flash !== false;
|
|
40
46
|
const useMoE = ctx.flags.moe === true;
|
|
@@ -181,6 +187,34 @@ const trainCommand = {
|
|
|
181
187
|
}
|
|
182
188
|
}
|
|
183
189
|
spinner.setText(`Training with ${embeddings.length} embeddings...`);
|
|
190
|
+
// #2549 — native TrainingPipeline leg. In 'auto'/'native' mode the
|
|
191
|
+
// LoRA training runs through @ruvector/ruvllm with the checkpoint
|
|
192
|
+
// taken from the TRAINED pipeline (the old best-effort block saved
|
|
193
|
+
// a fresh adapter's untrained weights). SONA/ReasoningBank
|
|
194
|
+
// persistence in the loop below runs regardless of backend.
|
|
195
|
+
const nativeTraining = await import('../services/native-training.js');
|
|
196
|
+
const useNative = backendFlag === 'native'
|
|
197
|
+
|| (backendFlag === 'auto' && nativeTraining.nativeTrainingAvailable());
|
|
198
|
+
let nativeResult = null;
|
|
199
|
+
if (useNative) {
|
|
200
|
+
spinner.setText(`Training ${patternType} on native @ruvector/ruvllm pipeline...`);
|
|
201
|
+
const path = await import('path');
|
|
202
|
+
nativeResult = await nativeTraining.runNativeTraining({
|
|
203
|
+
embeddings,
|
|
204
|
+
epochs,
|
|
205
|
+
batchSize,
|
|
206
|
+
learningRate,
|
|
207
|
+
dim,
|
|
208
|
+
checkpointPath: path.join(process.cwd(), '.claude-flow', 'neural', `lora-checkpoint-${Date.now()}.json`),
|
|
209
|
+
});
|
|
210
|
+
if (!nativeResult && backendFlag === 'native') {
|
|
211
|
+
spinner.fail('Native backend requested (--backend native) but @ruvector/ruvllm training failed');
|
|
212
|
+
return { success: false, exitCode: 1 };
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// Native handles the LoRA leg; WASM contrastive runs when native
|
|
216
|
+
// didn't (absent module, or explicit --backend wasm).
|
|
217
|
+
const runWasmLeg = !nativeResult;
|
|
184
218
|
// Main training loop with WASM acceleration
|
|
185
219
|
for (let epoch = 0; epoch < epochs; epoch++) {
|
|
186
220
|
const epochStart = performance.now();
|
|
@@ -192,7 +226,7 @@ const trainCommand = {
|
|
|
192
226
|
if (batch.length === 0)
|
|
193
227
|
continue;
|
|
194
228
|
// Training step with contrastive learning
|
|
195
|
-
if (useContrastive && batch.length >= 3 && useWasm && wasmFeatures.length > 0) {
|
|
229
|
+
if (runWasmLeg && useContrastive && batch.length >= 3 && useWasm && wasmFeatures.length > 0) {
|
|
196
230
|
const anchor = batch[0];
|
|
197
231
|
const positives = [batch[1]];
|
|
198
232
|
const negatives = batch.slice(2);
|
|
@@ -260,17 +294,22 @@ const trainCommand = {
|
|
|
260
294
|
// Flush patterns to disk
|
|
261
295
|
flushPatterns();
|
|
262
296
|
const persistence = getPersistenceStatus();
|
|
263
|
-
//
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
297
|
+
// Checkpoint: when the native pipeline trained, its checkpoint (the
|
|
298
|
+
// TRAINED weights) was already written by runNativeTraining. The
|
|
299
|
+
// pre-3.19 fallback below saved a FRESH adapter's weights — only
|
|
300
|
+
// meaningful as a fallback when the native leg didn't run.
|
|
301
|
+
if (!nativeResult?.checkpointPath) {
|
|
302
|
+
try {
|
|
303
|
+
const { LoRAAdapter } = await import('../ruvector/lora-adapter.js');
|
|
304
|
+
const path = await import('path');
|
|
305
|
+
const cpDir = path.join(process.cwd(), '.claude-flow', 'neural');
|
|
306
|
+
const cpPath = path.join(cpDir, `lora-checkpoint-${Date.now()}.json`);
|
|
307
|
+
const adapter = new LoRAAdapter({ inputDim: dim, outputDim: dim, rank: 4 });
|
|
308
|
+
await adapter.initBackend();
|
|
309
|
+
await adapter.saveCheckpoint(cpPath);
|
|
310
|
+
}
|
|
311
|
+
catch { /* checkpoint save is best-effort */ }
|
|
272
312
|
}
|
|
273
|
-
catch { /* checkpoint save is best-effort */ }
|
|
274
313
|
output.writeln();
|
|
275
314
|
// Display results
|
|
276
315
|
const tableData = [
|
|
@@ -284,8 +323,18 @@ const trainCommand = {
|
|
|
284
323
|
{ metric: 'Total Time', value: `${(totalTime / 1000).toFixed(1)}s` },
|
|
285
324
|
{ metric: 'Avg Epoch Time', value: `${(epochTimes.reduce((a, b) => a + b, 0) / epochTimes.length).toFixed(2)}ms` },
|
|
286
325
|
];
|
|
326
|
+
// Native pipeline metrics (#2549 — the LoRA leg trained on ruvllm)
|
|
327
|
+
if (nativeResult) {
|
|
328
|
+
tableData.push({ metric: 'Backend', value: 'native (@ruvector/ruvllm TrainingPipeline)' }, { metric: 'Native Steps', value: String(nativeResult.steps) }, { metric: 'Final Loss', value: nativeResult.finalLoss.toExponential(3) }, { metric: 'Early Stopped', value: nativeResult.earlyStopped ? 'yes' : 'no' });
|
|
329
|
+
if (nativeResult.checkpointPath) {
|
|
330
|
+
tableData.push({
|
|
331
|
+
metric: 'Checkpoint',
|
|
332
|
+
value: `${nativeResult.checkpointPath}${nativeResult.checkpointBytes ? ` (${(nativeResult.checkpointBytes / 1024).toFixed(1)} KB)` : ''}`,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
287
336
|
// Add WASM-specific metrics
|
|
288
|
-
if (useWasm && wasmFeatures.length > 0) {
|
|
337
|
+
if (runWasmLeg && useWasm && wasmFeatures.length > 0) {
|
|
289
338
|
const backendUsed = ruvectorStats?.backend || 'unknown';
|
|
290
339
|
tableData.push({ metric: 'Backend', value: backendUsed === 'wasm' ? 'WASM (native)' : 'JS (fallback)' }, { metric: 'WASM Features', value: wasmFeatures.slice(0, 3).join(', ') }, { metric: 'LoRA Adaptations', value: String(adaptations) }, { metric: 'Avg Loss', value: (totalLoss / Math.max(1, epochs)).toFixed(4) });
|
|
291
340
|
if (ruvectorStats?.microLoraStats) {
|
|
@@ -469,8 +518,20 @@ const statusCommand = {
|
|
|
469
518
|
{
|
|
470
519
|
component: 'Training Pipeline',
|
|
471
520
|
status: stats._trainingBackend === 'ruvllm' ? output.success('Available') : output.dim(stats._trainingBackend || 'Unavailable'),
|
|
521
|
+
// Checkpoint capability is version-gated: saveCheckpoint(path)
|
|
522
|
+
// was a silent no-op before @ruvector/ruvllm 2.5.7 (#2549).
|
|
472
523
|
details: stats._trainingBackend === 'ruvllm'
|
|
473
|
-
?
|
|
524
|
+
? await (async () => {
|
|
525
|
+
try {
|
|
526
|
+
const { nativeCheckpointsSupported } = await import('../ruvector/lora-adapter.js');
|
|
527
|
+
return nativeCheckpointsSupported()
|
|
528
|
+
? 'native @ruvector/ruvllm pipeline + disk checkpoints'
|
|
529
|
+
: 'native @ruvector/ruvllm pipeline (checkpoints need >=2.5.7)';
|
|
530
|
+
}
|
|
531
|
+
catch {
|
|
532
|
+
return 'native @ruvector/ruvllm pipeline';
|
|
533
|
+
}
|
|
534
|
+
})()
|
|
474
535
|
: 'JS fallback',
|
|
475
536
|
},
|
|
476
537
|
await (async () => {
|