Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:24kchengYe MemoMind Force CPU Daemon Mode

From Leeroopedia
Knowledge Sources
Domains macOS, Performance, Deployment
Last Updated 2026-10-28 14:45 GMT

Overview

Force CPU mode for local embeddings and reranker models when running MemoMind as a macOS daemon to avoid MPS/XPC instability issues.

Description

On macOS with Apple Silicon (M1/M2/M3), PyTorch can use the Metal Performance Shaders (MPS) backend for GPU acceleration. However, when MemoMind runs as a background daemon (e.g., via the embedded server), MPS/XPC inter-process communication can become unstable — causing hangs, crashes, or silent failures. The `FORCE_CPU` flag (separate for embeddings and reranker) bypasses MPS detection and forces CPU inference. This is slower but stable for daemon/background operation.

Usage

Use this heuristic when running MemoMind as a daemon on macOS. Set both `HINDSIGHT_API_EMBEDDINGS_LOCAL_FORCE_CPU=true` and `HINDSIGHT_API_RERANKER_LOCAL_FORCE_CPU=true`. Not needed for interactive/foreground use or on Linux (where CUDA is used if available, otherwise CPU is the default).

The Insight (Rule of Thumb)

  • Action: Set `FORCE_CPU=true` for local embeddings and reranker when running in macOS daemon mode.
  • Value: `HINDSIGHT_API_EMBEDDINGS_LOCAL_FORCE_CPU=true` and `HINDSIGHT_API_RERANKER_LOCAL_FORCE_CPU=true`.
  • Trade-off: CPU inference is slower than MPS (roughly 2-3x for small models like bge-small) but avoids XPC instability that can hang the daemon indefinitely.
  • Compatibility: Only relevant on macOS with Apple Silicon. Linux production Docker already uses CPU-only torch. No effect on remote providers (OpenAI, Cohere, TEI).

Reasoning

The MPS backend on macOS communicates with the GPU via XPC (Apple's inter-process communication mechanism). When the MemoMind process runs as a daemon (not attached to a user session), the XPC connection to the GPU daemon can become unreliable — the process may hang waiting for a GPU response that never arrives. This is a known macOS issue with background processes using MPS. Forcing CPU mode eliminates this dependency, trading speed for reliability. The performance impact is minimal for MemoMind's use case: embedding generation and reranking are small-batch operations (bge-small: 384-dim, ms-marco-MiniLM: 80MB model), where CPU inference is fast enough for interactive use.

Code Evidence

Embeddings CPU force from `embeddings.py:146-149`:

# Force CPU mode if configured (used in daemon mode to avoid MPS/XPC issues on macOS)
if self.force_cpu:
    device = "cpu"
    logger.info("Embeddings: forcing CPU mode")

GPU auto-detection with fallback from `embeddings.py:154-162`:

device = "cpu"  # Default to CPU
try:
    has_gpu = torch.cuda.is_available() or (
        hasattr(torch.backends, "mps") and torch.backends.mps.is_available()
    )
    if has_gpu:
        device = None  # Let sentence-transformers auto-detect GPU/MPS
except Exception as e:
    logger.warning(f"Failed to detect GPU/MPS, falling back to CPU: {e}")

Config defaults from `config.py:380, 387`:

DEFAULT_EMBEDDINGS_LOCAL_FORCE_CPU = False  # Force CPU mode (avoids MPS/XPC issues on macOS)
DEFAULT_RERANKER_LOCAL_FORCE_CPU = False  # Force CPU mode (avoids MPS/XPC issues on macOS)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment