ruvnet/ruflo · error

[MoE] No cached forward pass for gradient computation

Error message

[MoE] No cached forward pass for gradient computation

What it means

Log warning in updateExpertWeights: no forward pass has been cached on this router instance (lastInput missing), so the gradient needed for the REINFORCE update cannot be computed and the update is skipped.

Source

Thrown at v3/@claude-flow/neural/src/moe-router.ts:462

  /**
   * Update expert weights based on reward signal
   *
   * Uses REINFORCE-style gradient update:
   * gradient = reward * d_log_prob / d_weights
   *
   * @param expert - Expert that received the reward
   * @param reward - Reward signal (-1 to 1, positive = good)
   */
  updateExpertWeights(expert: ExpertType | number, reward: number): void {
    const expertIdx = typeof expert === 'number' ? expert : EXPERT_NAMES.indexOf(expert);

    if (expertIdx < 0 || expertIdx >= NUM_EXPERTS) {
      console.warn(`[MoE] Invalid expert: ${expert}`);
      return;
    }

    if (!this.lastInput || !this.lastHiddenActivated || !this.lastProbs) {
      console.warn('[MoE] No cached forward pass for gradient computation');
      return;
    }

    // Clamp reward to [-1, 1]
    const clampedReward = Math.max(-1, Math.min(1, reward));

    // Compute gradients using REINFORCE
    // For softmax: d_log_p_i / d_logit_j = delta_ij - p_j
    // gradient = reward * (1 - p_expert) for selected expert
    // gradient = reward * (-p_j) for other experts

    // Clear gradient buffers
    this.gradW2.fill(0);
    this.gradb2.fill(0);
    this.gradW1.fill(0);
    this.gradb1.fill(0);
    this.gradHidden.fill(0);

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Run a forward pass before requesting gradients; the cache is populated during forward.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at v3/@claude-flow/neural/src/moe-router.ts:462 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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