ruvnet/ruflo · error · Error

Flash attention not initialized

Error message

Flash attention not initialized

What it means

Thrown by computeFlashAttention() when the module-level flashAttention is null. It is set by initializeTraining() only when (a) the optional @ruvector/attention package imports successfully AND (b) config.useFlashAttention !== false (it is on by default). So the error means either init never ran, the attention package is missing/unresolvable in your install, flash attention was explicitly disabled, or cleanup() nulled it.

Source

Thrown at v3/@claude-flow/cli/src/services/ruvector-training.ts:591

    successRate: trajectoryBuffer.success_rate(),
    meanImprovement: trajectoryBuffer.mean_improvement(),
    bestImprovement: trajectoryBuffer.best_improvement(),
    totalCount: trajectoryBuffer.total_count(),
    highQualityCount: trajectoryBuffer.high_quality_count(0.1),
    variance: trajectoryBuffer.variance(),
  };
}

/**
 * Compute attention with Flash Attention (2.49x-7.47x faster)
 */
export function computeFlashAttention(
  query: Float32Array,
  keys: Float32Array[],
  values: Float32Array[]
): Float32Array {
  if (!flashAttention) {
    throw new Error('Flash attention not initialized');
  }

  return flashAttention.computeRaw(query, keys, values);
}

/**
 * Compute MoE routing
 */
export function computeMoEAttention(
  query: Float32Array,
  keys: Float32Array[],
  values: Float32Array[]
): Float32Array {
  if (!moeAttention) {
    throw new Error('MoE attention not initialized');
  }

  return moeAttention.computeRaw(query, keys, values);

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Run initializeTraining() (flash attention is enabled by default — just don't pass useFlashAttention: false) and assert 'FlashAttention' appears in the returned features array.
  2. Install/restore the optional dependency: npm install (without --omit=optional) or explicitly add @ruvector/attention, then re-check node_modules.
  3. Remove the disabling flag from your TrainingConfig if you intentionally turned it off but still call computeFlashAttention.
  4. After cleanup(), re-initialize before using attention again.

Example fix

// before
const { initializeTraining } = await import('./services/ruvector-training.js');
await initializeTraining({ useFlashAttention: false }); // preset disables it
const out = computeFlashAttention(q, keys, values); // throws 'Flash attention not initialized'

// after
const init = await initializeTraining({}); // default enables flash attention
if (!init.features.includes('FlashAttention')) {
  throw new Error(`@ruvector/attention missing — got features: ${init.features.join(', ')}`);
}
const out = computeFlashAttention(q, keys, values);
Defensive patterns

Strategy: validation

Validate before calling

const init = await initializeTraining({}); // flash attention defaults ON — do not pass false
if (!init.features.includes('FlashAttention')) {
  throw new Error(`FlashAttention unavailable — install @ruvector/attention. Features: ${init.features.join(', ')}`);
}
// safe to call now:
const out = computeFlashAttention(query, keys, values);

Type guard

type AttentionReady = { hasFlash: boolean };
async function probeAttentionFeatures(cfg: TrainingConfig = {}): Promise<AttentionReady> {
  const init = await initializeTraining(cfg);
  return { hasFlash: init.features.includes('FlashAttention') };
}

Try / catch

try {
  return computeFlashAttention(q, keys, values);
} catch (e) {
  if (e instanceof Error && e.message === 'Flash attention not initialized') {
    // fall back to plain scaled dot-product or re-init with defaults, then retry
    return scaledDotProduct(q, keys, values);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling computeFlashAttention before initializeTraining; initializing with { useFlashAttention: false } and still calling the function; running in an install where the optional @ruvector/attention dependency was pruned (npm ci with --omit=optional, partial install, wrong package manager resolution) — init logs '[ruvector] @ruvector/attention unavailable …, attention features disabled' and continues without it.

Common situations: Production images that strip optionalDependencies to slim the bundle; pnpm/yarn hoisting differences leaving @ruvector/attention unresolvable; a config preset that disables flash attention for reproducibility while legacy code still calls the fast path; init warnings scrolling past unnoticed in verbose logs.

Related errors


AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18). Data as JSON: /api/errors/c3c79409131c35a9. Report an issue: GitHub.