From e26098237d3292b40ecd293c6444ff39066a0458 Mon Sep 17 00:00:00 2001 From: Anatoly Koptev Date: Fri, 6 Feb 2026 22:17:51 -0800 Subject: [PATCH] fix: activation memory config crashes get_default() with OpenAI backend Two bugs in `get_default_config()` / `get_default_cube_config()`: 1. `get_default_config()` injects `act_mem` dict into MOSConfig when `enable_activation_memory=True`, but MOSConfig has no `act_mem` field and inherits `extra="forbid"` from BaseConfig. This causes a `ValidationError: Extra inputs are not permitted` for any user calling `get_default()` with activation memory enabled. 2. `get_default_cube_config()` hardcodes `extractor_llm` backend to `"openai"` for KV cache activation memory, but `KVCacheMemoryConfig` validator requires `huggingface`/`huggingface_singleton`/`vllm` (KV cache needs local model access for attention tensor extraction). This causes `ConfigurationError` even if bug #1 is fixed. Fix: Remove `act_mem` from MOSConfig dict (the `enable_activation_memory` bool flag is sufficient). In MemCube config, require explicit `activation_memory_backend` kwarg instead of hardcoding `"openai"`. Co-Authored-By: Claude Opus 4.6 --- src/memos/mem_os/utils/default_config.py | 56 +++++++++++++----------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/memos/mem_os/utils/default_config.py b/src/memos/mem_os/utils/default_config.py index edb7875d4..9898cbe8c 100644 --- a/src/memos/mem_os/utils/default_config.py +++ b/src/memos/mem_os/utils/default_config.py @@ -3,12 +3,15 @@ Provides simplified configuration generation for users. """ +import logging from typing import Literal from memos.configs.mem_cube import GeneralMemCubeConfig from memos.configs.mem_os import MOSConfig from memos.mem_cube.general import GeneralMemCube +logger = logging.getLogger(__name__) + def get_default_config( openai_api_key: str, @@ -116,20 +119,9 @@ def get_default_config( }, } - # Add activation memory if enabled - if config_dict.get("enable_activation_memory", False): - config_dict["act_mem"] = { - "backend": "kv_cache", - "config": { - "memory_filename": kwargs.get( - "activation_memory_filename", "activation_memory.pickle" - ), - "extractor_llm": { - "backend": "openai", - "config": openai_config, - }, - }, - } + # Note: act_mem configuration belongs in MemCube config (get_default_cube_config), + # not in MOSConfig which doesn't have an act_mem field (extra="forbid"). + # The enable_activation_memory flag above is sufficient for MOSConfig. return MOSConfig(**config_dict) @@ -237,21 +229,33 @@ def get_default_cube_config( }, } - # Configure activation memory if enabled + # Configure activation memory if enabled. + # KV cache activation memory requires a local HuggingFace/vLLM model (it + # extracts internal attention KV tensors via build_kv_cache), so it cannot + # work with remote API backends like OpenAI. + # Only create act_mem when activation_memory_backend is explicitly provided. act_mem_config = {} if kwargs.get("enable_activation_memory", False): - act_mem_config = { - "backend": "kv_cache", - "config": { - "memory_filename": kwargs.get( - "activation_memory_filename", "activation_memory.pickle" - ), - "extractor_llm": { - "backend": "openai", - "config": openai_config, + extractor_backend = kwargs.get("activation_memory_backend") + if extractor_backend in ("huggingface", "huggingface_singleton", "vllm"): + act_mem_config = { + "backend": "kv_cache", + "config": { + "memory_filename": kwargs.get( + "activation_memory_filename", "activation_memory.pickle" + ), + "extractor_llm": { + "backend": extractor_backend, + "config": kwargs.get("activation_memory_llm_config", {}), + }, }, - }, - } + } + else: + logger.info( + "Activation memory (kv_cache) requires a local model backend " + "(huggingface/vllm) via activation_memory_backend kwarg. " + "Skipping act_mem in MemCube config." + ) # Create MemCube configuration cube_config_dict = {