@claude-flow/cli 3.31.3 → 3.32.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/helpers/helpers.manifest.json +2 -2
- package/catalog-manifest.json +2 -2
- package/dist/src/commands/doctor.js +80 -1
- package/dist/src/commands/init.d.ts +5 -0
- package/dist/src/commands/init.js +30 -1
- package/package.json +8 -7
- package/.claude/.proven-config-version +0 -1
- package/.claude/proven-config.json +0 -42
- package/dist/src/ruvector/flash-attention.d.ts +0 -195
- package/dist/src/ruvector/flash-attention.js +0 -643
- package/dist/src/ruvector/moe-router.d.ts +0 -206
- package/dist/src/ruvector/moe-router.js +0 -626
- package/dist/src/services/event-stream.d.ts +0 -25
- package/dist/src/services/event-stream.js +0 -27
- package/dist/src/services/loop-worker-runner.d.ts +0 -16
- package/dist/src/services/loop-worker-runner.js +0 -34
- package/dist/src/services/runtime-capabilities.d.ts +0 -22
- package/dist/src/services/runtime-capabilities.js +0 -45
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest": {
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.32.1",
|
|
4
4
|
"files": {
|
|
5
5
|
"auto-memory-hook.mjs": "e3e1033b24704992ddef6b31c7fa9dd7fcd9e1af7935dd77ef73402b916b31e6",
|
|
6
6
|
"hook-handler.cjs": "f87ec28684bfc5fd0a54c46bd2a53a3fb037defe71d0ea4b8a5cb88a2cd87a3f",
|
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
"statusline.cjs": "7d7bdee732e1c75b863e409afb86ce0d712f4919245e990d806da6752015bffa"
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
|
-
"signature": "
|
|
11
|
+
"signature": "CYSsp2OyERA+JF2szVX7ciFLjnZ07biWZDJ0u6rUH06HbQECCHdAmmZwSbYiW2XrdN9G6Zrp8MJA56GLX8I1Ag==",
|
|
12
12
|
"algorithm": "ed25519"
|
|
13
13
|
}
|
package/catalog-manifest.json
CHANGED
|
@@ -1404,6 +1404,20 @@ export const doctorCommand = {
|
|
|
1404
1404
|
description: 'Verbose output',
|
|
1405
1405
|
type: 'boolean',
|
|
1406
1406
|
default: false
|
|
1407
|
+
},
|
|
1408
|
+
{
|
|
1409
|
+
name: 'fix-handles',
|
|
1410
|
+
// Windows-only mitigation for anthropics/claude-code#67888 — Claude Code's
|
|
1411
|
+
// Bash tool spawns cmd.exe/bash.exe without cleaning up child conhost.exe
|
|
1412
|
+
// handles, so a long session accumulates dozens (observed live: 26+
|
|
1413
|
+
// orphaned conhost.exe after a ~4h session). Each holds a kernel object
|
|
1414
|
+
// + ~1MB, and combined with memory pressure this measurably slows the
|
|
1415
|
+
// machine. This flag kills orphan conhost.exe (safe — Windows respawns
|
|
1416
|
+
// on demand). Deliberately does NOT touch cmd.exe/bash.exe — those can
|
|
1417
|
+
// be the invoking shell, and killing them 255's the caller.
|
|
1418
|
+
description: 'Windows only: kill orphaned conhost.exe processes leaked by Claude Code (mitigation for anthropics/claude-code#67888)',
|
|
1419
|
+
type: 'boolean',
|
|
1420
|
+
default: false
|
|
1407
1421
|
}
|
|
1408
1422
|
],
|
|
1409
1423
|
examples: [
|
|
@@ -1411,13 +1425,78 @@ export const doctorCommand = {
|
|
|
1411
1425
|
{ command: 'claude-flow doctor --fix', description: 'Print suggested fix commands (does not auto-apply)' },
|
|
1412
1426
|
{ command: 'claude-flow doctor --install', description: 'Auto-install missing dependencies' },
|
|
1413
1427
|
{ command: 'claude-flow doctor -c version', description: 'Check for stale npx cache' },
|
|
1414
|
-
{ command: 'claude-flow doctor -c claude', description: 'Check Claude Code CLI only' }
|
|
1428
|
+
{ command: 'claude-flow doctor -c claude', description: 'Check Claude Code CLI only' },
|
|
1429
|
+
{ command: 'claude-flow doctor --fix-handles', description: 'Windows: kill leaked conhost.exe from Claude Code sessions' }
|
|
1415
1430
|
],
|
|
1416
1431
|
action: async (ctx) => {
|
|
1417
1432
|
const showFix = ctx.flags.fix;
|
|
1418
1433
|
const autoInstall = ctx.flags.install;
|
|
1419
1434
|
const component = ctx.flags.component;
|
|
1420
1435
|
const verbose = ctx.flags.verbose;
|
|
1436
|
+
// Parser camelCases kebab-case flag names — read via `fixHandles`, not `['fix-handles']`.
|
|
1437
|
+
const fixHandles = ctx.flags.fixHandles;
|
|
1438
|
+
// Early-return short-circuit: `--fix-handles` is a targeted mitigation, not
|
|
1439
|
+
// part of the health-check flow. Runs, reports, exits.
|
|
1440
|
+
if (fixHandles) {
|
|
1441
|
+
output.writeln();
|
|
1442
|
+
output.writeln(output.bold('RuFlo Doctor — fix-handles'));
|
|
1443
|
+
output.writeln(output.dim('─'.repeat(50)));
|
|
1444
|
+
output.writeln();
|
|
1445
|
+
if (process.platform !== 'win32') {
|
|
1446
|
+
output.printInfo('--fix-handles is a Windows-only mitigation. On this platform (' + process.platform + '), no action taken.');
|
|
1447
|
+
return { success: true };
|
|
1448
|
+
}
|
|
1449
|
+
const { spawnSync } = await import('child_process');
|
|
1450
|
+
// PowerShell one-liner: read before-count, kill conhost, read after-count, report delta.
|
|
1451
|
+
const psScript = [
|
|
1452
|
+
"$before = (Get-Process conhost -EA SilentlyContinue).Count",
|
|
1453
|
+
"$mem_before = [math]::Round((Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory / 1MB, 2)",
|
|
1454
|
+
"$killed = 0",
|
|
1455
|
+
"Get-Process conhost -EA SilentlyContinue | ForEach-Object {",
|
|
1456
|
+
" try { Stop-Process -Id $_.Id -Force -EA Stop; $killed++ } catch {}",
|
|
1457
|
+
"}",
|
|
1458
|
+
"Start-Sleep -Seconds 1",
|
|
1459
|
+
"$after = (Get-Process conhost -EA SilentlyContinue).Count",
|
|
1460
|
+
"$mem_after = [math]::Round((Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory / 1MB, 2)",
|
|
1461
|
+
"Write-Output ('BEFORE_COUNT=' + $before)",
|
|
1462
|
+
"Write-Output ('KILLED=' + $killed)",
|
|
1463
|
+
"Write-Output ('AFTER_COUNT=' + $after)",
|
|
1464
|
+
"Write-Output ('MEM_BEFORE_GB=' + $mem_before)",
|
|
1465
|
+
"Write-Output ('MEM_AFTER_GB=' + $mem_after)",
|
|
1466
|
+
].join('; ');
|
|
1467
|
+
const res = spawnSync('powershell', ['-NoProfile', '-Command', psScript], {
|
|
1468
|
+
encoding: 'utf-8', timeout: 30000, windowsHide: true,
|
|
1469
|
+
});
|
|
1470
|
+
if (res.status !== 0) {
|
|
1471
|
+
output.printError('PowerShell exited with code ' + res.status);
|
|
1472
|
+
if (res.stderr)
|
|
1473
|
+
output.writeln(output.dim(res.stderr));
|
|
1474
|
+
return { success: false, exitCode: 1 };
|
|
1475
|
+
}
|
|
1476
|
+
const parse = (key) => {
|
|
1477
|
+
const line = (res.stdout || '').split('\n').find((l) => l.startsWith(key + '='));
|
|
1478
|
+
return line ? line.slice(key.length + 1).trim() : '?';
|
|
1479
|
+
};
|
|
1480
|
+
const before = parse('BEFORE_COUNT');
|
|
1481
|
+
const killed = parse('KILLED');
|
|
1482
|
+
const after = parse('AFTER_COUNT');
|
|
1483
|
+
const memBefore = parse('MEM_BEFORE_GB');
|
|
1484
|
+
const memAfter = parse('MEM_AFTER_GB');
|
|
1485
|
+
output.writeln('conhost.exe processes:');
|
|
1486
|
+
output.writeln(' before: ' + before);
|
|
1487
|
+
output.writeln(' killed: ' + output.success(killed));
|
|
1488
|
+
output.writeln(' after: ' + after);
|
|
1489
|
+
output.writeln('');
|
|
1490
|
+
output.writeln('Free RAM:');
|
|
1491
|
+
output.writeln(' before: ' + memBefore + ' GB');
|
|
1492
|
+
output.writeln(' after: ' + memAfter + ' GB');
|
|
1493
|
+
output.writeln('');
|
|
1494
|
+
output.writeln(output.dim('Note: does NOT touch cmd.exe/bash.exe/node.exe — those may be the invoking shell'));
|
|
1495
|
+
output.writeln(output.dim(' or an active MCP server. Kill them manually if you need to.'));
|
|
1496
|
+
output.writeln('');
|
|
1497
|
+
output.writeln(output.dim('Upstream tracking: https://github.com/anthropics/claude-code/issues/67888'));
|
|
1498
|
+
return { success: true };
|
|
1499
|
+
}
|
|
1421
1500
|
output.writeln();
|
|
1422
1501
|
output.writeln(output.bold('RuFlo Doctor'));
|
|
1423
1502
|
output.writeln(output.dim('System diagnostics and health check'));
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
* Comprehensive initialization for Claude Flow with Claude Code integration
|
|
4
4
|
*/
|
|
5
5
|
import type { Command } from '../types.js';
|
|
6
|
+
export declare function runCodexInitializerCli(cwd: string, options: {
|
|
7
|
+
template: string;
|
|
8
|
+
force: boolean;
|
|
9
|
+
dual: boolean;
|
|
10
|
+
}): boolean;
|
|
6
11
|
export declare const initCommand: Command;
|
|
7
12
|
export default initCommand;
|
|
8
13
|
//# sourceMappingURL=init.d.ts.map
|
|
@@ -6,6 +6,7 @@ import { output } from '../output.js';
|
|
|
6
6
|
import { confirm, select, multiSelect, input } from '../prompt.js';
|
|
7
7
|
import * as fs from 'fs';
|
|
8
8
|
import * as path from 'path';
|
|
9
|
+
import { spawnSync } from 'node:child_process';
|
|
9
10
|
import { executeInit, executeUpgrade, executeUpgradeWithMissing, DEFAULT_INIT_OPTIONS, MINIMAL_INIT_OPTIONS, FULL_INIT_OPTIONS, } from '../init/index.js';
|
|
10
11
|
import { ENROLLMENT_SCREEN, recordEnrollmentOutcome, shouldOfferEnrollment, } from '../funnel/enrollment.js';
|
|
11
12
|
import { commandExists } from '../services/harness-hosts.js';
|
|
@@ -82,6 +83,27 @@ async function resolveCodexInitializer(cwd) {
|
|
|
82
83
|
}
|
|
83
84
|
return undefined;
|
|
84
85
|
}
|
|
86
|
+
// Keep Codex out of the CLI dependency graph so cold `npx ruflo --version`
|
|
87
|
+
// remains fast (#2561). An explicit `init --codex` may fetch the small,
|
|
88
|
+
// stable adapter on demand when it is not already installed by an umbrella
|
|
89
|
+
// package, the current project, or the global npm prefix.
|
|
90
|
+
export function runCodexInitializerCli(cwd, options) {
|
|
91
|
+
const npxArgs = [
|
|
92
|
+
'-y',
|
|
93
|
+
'@claude-flow/codex@latest',
|
|
94
|
+
'init',
|
|
95
|
+
'--template',
|
|
96
|
+
options.template,
|
|
97
|
+
...(options.force ? ['--force'] : []),
|
|
98
|
+
...(options.dual ? ['--dual'] : []),
|
|
99
|
+
];
|
|
100
|
+
const result = process.platform === 'win32'
|
|
101
|
+
? spawnSync(process.env.ComSpec || 'cmd.exe', ['/d', '/s', '/c', ['npx', ...npxArgs].join(' ')], { cwd, stdio: 'inherit', windowsHide: true })
|
|
102
|
+
: spawnSync('npx', npxArgs, { cwd, stdio: 'inherit' });
|
|
103
|
+
if (result.error)
|
|
104
|
+
throw result.error;
|
|
105
|
+
return result.status === 0;
|
|
106
|
+
}
|
|
85
107
|
// #2666-adjacent — quietly wire up Codex too when a plain `ruflo init` (no
|
|
86
108
|
// --codex/--dual) runs on a machine that also has the OpenAI Codex CLI on
|
|
87
109
|
// PATH: registers its MCP server and installs skills alongside the Claude
|
|
@@ -194,7 +216,14 @@ async function initCodexAction(ctx, options) {
|
|
|
194
216
|
try {
|
|
195
217
|
const CodexInitializer = await resolveCodexInitializer(ctx.cwd);
|
|
196
218
|
if (!CodexInitializer) {
|
|
197
|
-
|
|
219
|
+
spinner.stop();
|
|
220
|
+
output.printInfo('Fetching the stable Codex adapter for this initialization...');
|
|
221
|
+
const success = runCodexInitializerCli(ctx.cwd, { template, force, dual: dualMode });
|
|
222
|
+
if (!success) {
|
|
223
|
+
output.printError('Codex initialization failed while running @claude-flow/codex@latest.');
|
|
224
|
+
return { success: false, exitCode: 1 };
|
|
225
|
+
}
|
|
226
|
+
return { success: true, data: { adapter: '@claude-flow/codex@latest' } };
|
|
198
227
|
}
|
|
199
228
|
const initializer = new CodexInitializer();
|
|
200
229
|
const result = await initializer.initialize({
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claude-flow/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.32.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Ruflo CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
7
7
|
"types": "dist/src/index.d.ts",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"bin": {
|
|
10
|
-
"cli": "
|
|
11
|
-
"claude-flow": "
|
|
12
|
-
"claude-flow-mcp": "
|
|
10
|
+
"cli": "bin/cli.js",
|
|
11
|
+
"claude-flow": "bin/cli.js",
|
|
12
|
+
"claude-flow-mcp": "bin/mcp-server.js"
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://github.com/ruvnet/claude-flow#readme",
|
|
15
15
|
"bugs": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "https://github.com/ruvnet/claude-flow.git",
|
|
20
|
+
"url": "git+https://github.com/ruvnet/claude-flow.git",
|
|
21
21
|
"directory": "v3/@claude-flow/cli"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [
|
|
@@ -90,8 +90,9 @@
|
|
|
90
90
|
"test:plugin-store": "npx tsx src/plugins/tests/standalone-test.ts",
|
|
91
91
|
"test:pattern-store": "npx tsx src/transfer/store/tests/standalone-test.ts",
|
|
92
92
|
"postinstall": "node ./scripts/postinstall.cjs",
|
|
93
|
-
"prepublishOnly": "
|
|
94
|
-
"release": "npm
|
|
93
|
+
"prepublishOnly": "node scripts/prepare-publish.mjs",
|
|
94
|
+
"release": "npm publish --access public --tag latest",
|
|
95
|
+
"release:alpha": "npm version prerelease --preid=alpha && npm run publish:all",
|
|
95
96
|
"publish:all": "./scripts/publish.sh"
|
|
96
97
|
},
|
|
97
98
|
"devDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
sha256:6141a8ea990c5063b77e090ae8f37f9c539d8aa8f58dcceb30f3a82f97e57319
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"adoptedAt": 1784038945014,
|
|
3
|
-
"championId": "sha256:6141a8ea990c5063b77e090ae8f37f9c539d8aa8f58dcceb30f3a82f97e57319",
|
|
4
|
-
"manifest": {
|
|
5
|
-
"schema": "ruflo.proven-config/v1",
|
|
6
|
-
"policy": {
|
|
7
|
-
"ref": "sha256:6141a8ea990c5063b77e090ae8f37f9c539d8aa8f58dcceb30f3a82f97e57319",
|
|
8
|
-
"value": {
|
|
9
|
-
"alpha": 0.3,
|
|
10
|
-
"subjectWeight": 1,
|
|
11
|
-
"mmrLambda": 0.5,
|
|
12
|
-
"bodyWeight": 1.5,
|
|
13
|
-
"typePenaltyFactor": 0.5
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"layer": "framework/node-cli",
|
|
17
|
-
"compatibility": {
|
|
18
|
-
"ruflo": ">=3.24.0"
|
|
19
|
-
},
|
|
20
|
-
"benchmark": {
|
|
21
|
-
"corpus": "ADR-081-labelled-v1",
|
|
22
|
-
"corpusHash": "sha256:2f700b5c363e20a3bd88ce2bc9b87bbbbaa61732c6177894c6ec37890f888982"
|
|
23
|
-
},
|
|
24
|
-
"receipt": {
|
|
25
|
-
"heldOutDelta": 0.07381404928570845,
|
|
26
|
-
"redblue": "PASS",
|
|
27
|
-
"drift": 0,
|
|
28
|
-
"canary": {
|
|
29
|
-
"rollbackRate": 0,
|
|
30
|
-
"latencyP95": 244.612458000076,
|
|
31
|
-
"costPerTask": 0
|
|
32
|
-
},
|
|
33
|
-
"receiptCoverage": 1
|
|
34
|
-
},
|
|
35
|
-
"platform": [
|
|
36
|
-
"linux",
|
|
37
|
-
"macOS",
|
|
38
|
-
"windows"
|
|
39
|
-
]
|
|
40
|
-
},
|
|
41
|
-
"previous": ""
|
|
42
|
-
}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flash Attention Implementation for RuVector Intelligence System
|
|
3
|
-
*
|
|
4
|
-
* Implements block-wise attention computation for faster similarity calculations.
|
|
5
|
-
* Achieves O(N) memory instead of O(N^2) through tiling strategy.
|
|
6
|
-
*
|
|
7
|
-
* Key optimizations:
|
|
8
|
-
* - Block-wise computation to fit in L1 cache
|
|
9
|
-
* - Fused softmax-matmul operations
|
|
10
|
-
* - Float32Array for all operations
|
|
11
|
-
* - Online softmax for numerical stability
|
|
12
|
-
*
|
|
13
|
-
* Target: 2-5x speedup on CPU vs naive attention
|
|
14
|
-
*
|
|
15
|
-
* Created with love by ruv.io
|
|
16
|
-
*/
|
|
17
|
-
export interface FlashAttentionConfig {
|
|
18
|
-
/** Block size for tiling (32-64 optimal for CPU L1 cache) */
|
|
19
|
-
blockSize: number;
|
|
20
|
-
/** Number of dimensions in embedding vectors */
|
|
21
|
-
dimensions: number;
|
|
22
|
-
/** Temperature for softmax scaling */
|
|
23
|
-
temperature: number;
|
|
24
|
-
/** Enable numerical stability optimizations */
|
|
25
|
-
useStableMode: boolean;
|
|
26
|
-
/** Use optimized CPU path (default: true) */
|
|
27
|
-
useCPUOptimizations: boolean;
|
|
28
|
-
}
|
|
29
|
-
export interface AttentionResult {
|
|
30
|
-
/** Output vectors after attention */
|
|
31
|
-
output: Float32Array[];
|
|
32
|
-
/** Attention weights (optional, for debugging) */
|
|
33
|
-
weights?: Float32Array[];
|
|
34
|
-
/** Computation time in milliseconds */
|
|
35
|
-
computeTimeMs: number;
|
|
36
|
-
}
|
|
37
|
-
export interface BenchmarkResult {
|
|
38
|
-
/** Naive attention time in milliseconds */
|
|
39
|
-
naiveTimeMs: number;
|
|
40
|
-
/** Flash attention time in milliseconds */
|
|
41
|
-
flashTimeMs: number;
|
|
42
|
-
/** Speedup factor (naive / flash) */
|
|
43
|
-
speedup: number;
|
|
44
|
-
/** Number of vectors benchmarked */
|
|
45
|
-
numVectors: number;
|
|
46
|
-
/** Dimensions of vectors */
|
|
47
|
-
dimensions: number;
|
|
48
|
-
/** Memory usage estimate for naive (bytes) */
|
|
49
|
-
naiveMemoryBytes: number;
|
|
50
|
-
/** Memory usage estimate for flash (bytes) */
|
|
51
|
-
flashMemoryBytes: number;
|
|
52
|
-
/** Memory reduction factor */
|
|
53
|
-
memoryReduction: number;
|
|
54
|
-
}
|
|
55
|
-
export declare class FlashAttention {
|
|
56
|
-
private config;
|
|
57
|
-
private lastSpeedup;
|
|
58
|
-
private benchmarkHistory;
|
|
59
|
-
private scoreBuffer;
|
|
60
|
-
private expBuffer;
|
|
61
|
-
private accumBuffer;
|
|
62
|
-
constructor(config?: Partial<FlashAttentionConfig>);
|
|
63
|
-
/**
|
|
64
|
-
* Main attention computation using Flash Attention algorithm
|
|
65
|
-
*
|
|
66
|
-
* @param queries - Query vectors [N x D]
|
|
67
|
-
* @param keys - Key vectors [M x D]
|
|
68
|
-
* @param values - Value vectors [M x D]
|
|
69
|
-
* @returns Attention output [N x D]
|
|
70
|
-
*/
|
|
71
|
-
attention(queries: Float32Array[], keys: Float32Array[], values: Float32Array[]): AttentionResult;
|
|
72
|
-
/**
|
|
73
|
-
* CPU-optimized attention with aggressive optimizations
|
|
74
|
-
*
|
|
75
|
-
* Key optimizations:
|
|
76
|
-
* - Blocked score computation (better cache utilization)
|
|
77
|
-
* - Top-K sparse attention (only use most relevant keys)
|
|
78
|
-
* - Pre-allocated buffers to avoid GC pressure
|
|
79
|
-
* - 8x loop unrolling for dot products
|
|
80
|
-
* - Fused max-finding during score computation
|
|
81
|
-
*/
|
|
82
|
-
private cpuOptimizedAttention;
|
|
83
|
-
/**
|
|
84
|
-
* Partial dot product using only first N dimensions (for screening)
|
|
85
|
-
*/
|
|
86
|
-
private partialDotProduct;
|
|
87
|
-
/**
|
|
88
|
-
* Partial sort to get top-K elements (QuickSelect-like)
|
|
89
|
-
* Only ensures first K elements are the largest, not sorted
|
|
90
|
-
*/
|
|
91
|
-
private partialSort;
|
|
92
|
-
/**
|
|
93
|
-
* Swap two indices in array
|
|
94
|
-
*/
|
|
95
|
-
private swapIndices;
|
|
96
|
-
/**
|
|
97
|
-
* Fast dot product with 8x unrolling
|
|
98
|
-
*/
|
|
99
|
-
private fastDotProduct;
|
|
100
|
-
/**
|
|
101
|
-
* Block-wise attention computation (Flash Attention core algorithm)
|
|
102
|
-
*
|
|
103
|
-
* Algorithm:
|
|
104
|
-
* For each block of queries Q_b:
|
|
105
|
-
* For each block of keys K_b:
|
|
106
|
-
* S_b = Q_b @ K_b.T / sqrt(d) // Block scores
|
|
107
|
-
* P_b = softmax(S_b) // Block attention
|
|
108
|
-
* O_b += P_b @ V_b // Accumulate output
|
|
109
|
-
*
|
|
110
|
-
* @param Q - Query vectors
|
|
111
|
-
* @param K - Key vectors
|
|
112
|
-
* @param V - Value vectors
|
|
113
|
-
* @param blockSize - Block size for tiling
|
|
114
|
-
*/
|
|
115
|
-
blockAttention(Q: Float32Array[], K: Float32Array[], V: Float32Array[], blockSize: number): Float32Array[];
|
|
116
|
-
/**
|
|
117
|
-
* Get the speedup factor from the last benchmark
|
|
118
|
-
*/
|
|
119
|
-
getSpeedup(): number;
|
|
120
|
-
/**
|
|
121
|
-
* Run benchmark comparing naive vs CPU-optimized attention
|
|
122
|
-
*
|
|
123
|
-
* @param numVectors - Number of vectors to test
|
|
124
|
-
* @param dimensions - Dimensions per vector
|
|
125
|
-
* @param iterations - Number of iterations for averaging
|
|
126
|
-
*/
|
|
127
|
-
benchmark(numVectors?: number, dimensions?: number, iterations?: number): BenchmarkResult;
|
|
128
|
-
/**
|
|
129
|
-
* Get benchmark history
|
|
130
|
-
*/
|
|
131
|
-
getBenchmarkHistory(): BenchmarkResult[];
|
|
132
|
-
/**
|
|
133
|
-
* Get configuration
|
|
134
|
-
*/
|
|
135
|
-
getConfig(): FlashAttentionConfig;
|
|
136
|
-
/**
|
|
137
|
-
* Update configuration
|
|
138
|
-
*/
|
|
139
|
-
setConfig(config: Partial<FlashAttentionConfig>): void;
|
|
140
|
-
/**
|
|
141
|
-
* Naive O(N^2) attention implementation for comparison
|
|
142
|
-
*/
|
|
143
|
-
private naiveAttention;
|
|
144
|
-
/**
|
|
145
|
-
* Compute block of attention scores
|
|
146
|
-
*/
|
|
147
|
-
private computeBlockScores;
|
|
148
|
-
/**
|
|
149
|
-
* Online softmax with output accumulation (key to Flash Attention)
|
|
150
|
-
*
|
|
151
|
-
* Uses the online softmax trick to maintain numerical stability
|
|
152
|
-
* while processing blocks incrementally.
|
|
153
|
-
*/
|
|
154
|
-
private onlineSoftmaxAccumulate;
|
|
155
|
-
/**
|
|
156
|
-
* Compute dot product of two vectors
|
|
157
|
-
*/
|
|
158
|
-
private dotProduct;
|
|
159
|
-
/**
|
|
160
|
-
* Stable softmax implementation
|
|
161
|
-
*/
|
|
162
|
-
private softmax;
|
|
163
|
-
/**
|
|
164
|
-
* Generate random vectors for benchmarking
|
|
165
|
-
*/
|
|
166
|
-
private generateRandomVectors;
|
|
167
|
-
/**
|
|
168
|
-
* Validate input arrays
|
|
169
|
-
*/
|
|
170
|
-
private validateInputs;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Get singleton FlashAttention instance
|
|
174
|
-
*
|
|
175
|
-
* @param config - Optional configuration (only used on first call)
|
|
176
|
-
* @returns FlashAttention instance
|
|
177
|
-
*/
|
|
178
|
-
export declare function getFlashAttention(config?: Partial<FlashAttentionConfig>): FlashAttention;
|
|
179
|
-
/**
|
|
180
|
-
* Reset singleton (for testing)
|
|
181
|
-
*/
|
|
182
|
-
export declare function resetFlashAttention(): void;
|
|
183
|
-
/**
|
|
184
|
-
* Compute attention using Flash Attention
|
|
185
|
-
*/
|
|
186
|
-
export declare function computeAttention(queries: Float32Array[], keys: Float32Array[], values: Float32Array[], config?: Partial<FlashAttentionConfig>): AttentionResult;
|
|
187
|
-
/**
|
|
188
|
-
* Run Flash Attention benchmark
|
|
189
|
-
*/
|
|
190
|
-
export declare function benchmarkFlashAttention(numVectors?: number, dimensions?: number, iterations?: number): BenchmarkResult;
|
|
191
|
-
/**
|
|
192
|
-
* Get current speedup from last benchmark
|
|
193
|
-
*/
|
|
194
|
-
export declare function getFlashAttentionSpeedup(): number;
|
|
195
|
-
//# sourceMappingURL=flash-attention.d.ts.map
|