|
3 | 3 | Provides simplified configuration generation for users. |
4 | 4 | """ |
5 | 5 |
|
| 6 | +import logging |
6 | 7 | from typing import Literal |
7 | 8 |
|
8 | 9 | from memos.configs.mem_cube import GeneralMemCubeConfig |
9 | 10 | from memos.configs.mem_os import MOSConfig |
10 | 11 | from memos.mem_cube.general import GeneralMemCube |
11 | 12 |
|
| 13 | +logger = logging.getLogger(__name__) |
| 14 | + |
12 | 15 |
|
13 | 16 | def get_default_config( |
14 | 17 | openai_api_key: str, |
@@ -116,20 +119,9 @@ def get_default_config( |
116 | 119 | }, |
117 | 120 | } |
118 | 121 |
|
119 | | - # Add activation memory if enabled |
120 | | - if config_dict.get("enable_activation_memory", False): |
121 | | - config_dict["act_mem"] = { |
122 | | - "backend": "kv_cache", |
123 | | - "config": { |
124 | | - "memory_filename": kwargs.get( |
125 | | - "activation_memory_filename", "activation_memory.pickle" |
126 | | - ), |
127 | | - "extractor_llm": { |
128 | | - "backend": "openai", |
129 | | - "config": openai_config, |
130 | | - }, |
131 | | - }, |
132 | | - } |
| 122 | + # Note: act_mem configuration belongs in MemCube config (get_default_cube_config), |
| 123 | + # not in MOSConfig which doesn't have an act_mem field (extra="forbid"). |
| 124 | + # The enable_activation_memory flag above is sufficient for MOSConfig. |
133 | 125 |
|
134 | 126 | return MOSConfig(**config_dict) |
135 | 127 |
|
@@ -237,21 +229,33 @@ def get_default_cube_config( |
237 | 229 | }, |
238 | 230 | } |
239 | 231 |
|
240 | | - # Configure activation memory if enabled |
| 232 | + # Configure activation memory if enabled. |
| 233 | + # KV cache activation memory requires a local HuggingFace/vLLM model (it |
| 234 | + # extracts internal attention KV tensors via build_kv_cache), so it cannot |
| 235 | + # work with remote API backends like OpenAI. |
| 236 | + # Only create act_mem when activation_memory_backend is explicitly provided. |
241 | 237 | act_mem_config = {} |
242 | 238 | if kwargs.get("enable_activation_memory", False): |
243 | | - act_mem_config = { |
244 | | - "backend": "kv_cache", |
245 | | - "config": { |
246 | | - "memory_filename": kwargs.get( |
247 | | - "activation_memory_filename", "activation_memory.pickle" |
248 | | - ), |
249 | | - "extractor_llm": { |
250 | | - "backend": "openai", |
251 | | - "config": openai_config, |
| 239 | + extractor_backend = kwargs.get("activation_memory_backend") |
| 240 | + if extractor_backend in ("huggingface", "huggingface_singleton", "vllm"): |
| 241 | + act_mem_config = { |
| 242 | + "backend": "kv_cache", |
| 243 | + "config": { |
| 244 | + "memory_filename": kwargs.get( |
| 245 | + "activation_memory_filename", "activation_memory.pickle" |
| 246 | + ), |
| 247 | + "extractor_llm": { |
| 248 | + "backend": extractor_backend, |
| 249 | + "config": kwargs.get("activation_memory_llm_config", {}), |
| 250 | + }, |
252 | 251 | }, |
253 | | - }, |
254 | | - } |
| 252 | + } |
| 253 | + else: |
| 254 | + logger.info( |
| 255 | + "Activation memory (kv_cache) requires a local model backend " |
| 256 | + "(huggingface/vllm) via activation_memory_backend kwarg. " |
| 257 | + "Skipping act_mem in MemCube config." |
| 258 | + ) |
255 | 259 |
|
256 | 260 | # Create MemCube configuration |
257 | 261 | cube_config_dict = { |
|
0 commit comments