abhigyanpatwari/GitNexus · error

No suitable device found for embedding model

Error message

No suitable device found for embedding model

What it means

Thrown by getEmbedder() when the @huggingface/transformers pipeline() call fails to create an ONNX Runtime session on every candidate device. Devices tried are [requestedDevice, 'cpu'] for GITNEXUS_EMBEDDING_DEVICE=cuda|dml, or just ['cpu']/['wasm'] otherwise; note that when the LAST device fails, the original deviceError propagates (embedder.ts:247), so this literal message is the defensive exhaustiveness guard for the no-device-succeeded path.

Solutions

  1. Set GITNEXUS_EMBEDDING_DEVICE=cpu explicitly and retry to bypass GPU probing.
  2. Clear the HuggingFace cache (rm -rf ~/.cache/huggingface or your HF_HOME dir) so the model re-downloads cleanly.
  3. Free memory or reduce GITNEXUS_EMBEDDING_THREADS; fp32 sessions are large.
  4. Reinstall gitnexus so onnxruntime-node native bindings match your Node version.
  5. Switch to HTTP embedding mode (set GITNEXUS_EMBEDDING_URL + GITNEXUS_EMBEDDING_MODEL) to skip local ONNX entirely.

Example fix

# before
GITNEXUS_EMBEDDING_DEVICE=cuda npx gitnexus analyze --embeddings
# after (force CPU, or use an HTTP endpoint)
GITNEXUS_EMBEDDING_DEVICE=cpu npx gitnexus analyze --embeddings
# or: export GITNEXUS_EMBEDDING_URL=http://localhost:11434/v1 GITNEXUS_EMBEDDING_MODEL=nomic-embed-text
Defensive patterns

Strategy: fallback

Validate before calling

import { isEmbedderReady, getEmbedder } from './embedder';
// warm the model at startup, not lazily mid-query
if (!isEmbedderReady()) {
  await getEmbedder(); // throws early with the real deviceError
}

Type guard

const isDeviceError = (e: unknown): boolean =>
  e instanceof Error && /No suitable device found|device/i.test(e.message);

Try / catch

try {
  await getEmbedder();
} catch (e) {
  if (e instanceof Error && e.message.includes('No suitable device')) {
    // fall back to HTTP embedding mode or skip embeddings
  } else throw e;
}

Prevention

When it happens

Trigger: Initializing the local embedding model with GITNEXUS_EMBEDDING_DEVICE=cuda or dml where GPU init fails AND the CPU fallback also fails (or a direct cpu/wasm request failing), e.g. onnxruntime native module mismatch, corrupted model cache under ~/.cache/huggingface, or insufficient memory for even the CPU session.

Common situations: Node/onnxruntime-node version skew after a package upgrade, a partially downloaded model in the HF cache, CI containers without GPU libs where even CPU WASM init fails, or low-memory environments where the fp32 session cannot allocate.

Related errors


AI-assisted analysis of abhigyanpatwari/GitNexus@aac7515d2a (2026-08-20). Data as JSON: /api/errors/a0be2c45f3191287. Report an issue: GitHub.

Appendix: source

Thrown at gitnexus/src/core/embeddings/embedder.ts:252

              ? `The configured endpoint (${process.env.HF_ENDPOINT}) may be unreachable.`
              : `huggingface.co may be unreachable from your network.\n` +
                `  Set HF_ENDPOINT to a mirror and retry:\n` +
                `    HF_ENDPOINT=https://hf-mirror.com npx gitnexus analyze --embeddings\n` +
                `    (Windows: set HF_ENDPOINT=https://hf-mirror.com && npx gitnexus analyze --embeddings)`;
            throw new Error(`Failed to download embedding model: ${errMsg}\n  ${endpointHint}`);
          }
          if (isDev && (device === 'cuda' || device === 'dml')) {
            const gpuType = device === 'dml' ? 'DirectML' : 'CUDA';
            logger.info(`⚠️  ${gpuType} not available, falling back to CPU...`);
          }
          // Continue to next device in list
          if (device === devicesToTry[devicesToTry.length - 1]) {
            throw deviceError; // Last device failed, propagate error
          }
        }
      }

      throw new Error('No suitable device found for embedding model');
    } catch (error) {
      isInitializing = false;
      initPromise = null;
      embedderInstance = null;
      throw error;
    } finally {
      isInitializing = false;
    }
  })();

  return initPromise;
};

/**
 * Check if the embedder is initialized and ready
 */
export const isEmbedderReady = (): boolean => {
  return isHttpMode() || embedderInstance !== null;

View on GitHub (pinned to aac7515d2a)