Skip to content

Commit 8b98541

Browse files
fluffy314cursoragent
authored andcommitted
fix(prefill): isolate cache budget policy from MLX runtime
Keep adaptive memory arithmetic importable on Linux without loading the MLX worker entrypoint, preserving the platform-neutral CI contract. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 953b586 commit 8b98541

3 files changed

Lines changed: 17 additions & 15 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""Platform-neutral cache-budget policy for model-loaded offload workers."""
2+
3+
4+
def adaptive_cache_budget(
5+
*,
6+
total_bytes: int,
7+
active_model_bytes: int,
8+
ceiling_bytes: int,
9+
minimum_bytes: int,
10+
reserve_bytes: int,
11+
) -> int:
12+
if min(total_bytes, ceiling_bytes, minimum_bytes) <= 0 or reserve_bytes < 0:
13+
raise ValueError("adaptive cache budget inputs are invalid")
14+
available = max(0, total_bytes - active_model_bytes - reserve_bytes)
15+
return max(minimum_bytes, min(ceiling_bytes, available))

scripts/start_prefill_worker_node.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
NodeEndpoint,
3434
PrefillWorkerCapability,
3535
)
36+
from inference_engine.distributed.cache_budget import adaptive_cache_budget
3637
from inference_engine.distributed.exchange import (
3738
add_capability_service,
3839
exchange_once,
@@ -68,20 +69,6 @@ def physical_memory_bytes() -> int:
6869
return 0
6970

7071

71-
def adaptive_cache_budget(
72-
*,
73-
total_bytes: int,
74-
active_model_bytes: int,
75-
ceiling_bytes: int,
76-
minimum_bytes: int,
77-
reserve_bytes: int,
78-
) -> int:
79-
if min(total_bytes, ceiling_bytes, minimum_bytes) <= 0 or reserve_bytes < 0:
80-
raise ValueError("adaptive cache budget inputs are invalid")
81-
available = max(0, total_bytes - active_model_bytes - reserve_bytes)
82-
return max(minimum_bytes, min(ceiling_bytes, available))
83-
84-
8572
def mlx_active_memory_bytes() -> int:
8673
try:
8774
import mlx.core as mx

tests/inference_engine/bridge/test_prefill_worker_memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from scripts.start_prefill_worker_node import adaptive_cache_budget
3+
from inference_engine.distributed.cache_budget import adaptive_cache_budget
44

55

66
def test_adaptive_budget_uses_only_model_headroom():

0 commit comments

Comments
 (0)