Skip to content

Commit 06f012b

Browse files
blightbowclaude
andcommitted
refactor(mlx): move mlx_cache.py from common to mlx backend
The ThreadSafeLRUPromptCache is only used by the mlx backend. After evaluating mlx-vlm, it was determined that the cache cannot be shared because mlx-vlm's generate/stream_generate functions don't support the prompt_cache parameter that mlx_lm provides. - Move mlx_cache.py from backend/python/common/ to backend/python/mlx/ - Remove sys.path manipulation from backend.py and test.py - Fix test assertion to expect "MLX model loaded successfully" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: Blightbow <[email protected]>
1 parent 022eede commit 06f012b

File tree

3 files changed

+1
-6
lines changed

3 files changed

+1
-6
lines changed

backend/python/mlx/backend.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import base64
2020
import io
2121

22-
# Add common module to path for shared cache
23-
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'common'))
2422
from mlx_cache import ThreadSafeLRUPromptCache
2523

2624
_ONE_DAY_IN_SECONDS = 60 * 60 * 24

backend/python/mlx/test.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_load_model(self):
4949
stub = backend_pb2_grpc.BackendStub(channel)
5050
response = stub.LoadModel(backend_pb2.ModelOptions(Model="mlx-community/Llama-3.2-1B-Instruct-4bit"))
5151
self.assertTrue(response.success)
52-
self.assertEqual(response.message, "Model loaded successfully")
52+
self.assertEqual(response.message, "MLX model loaded successfully")
5353
except Exception as err:
5454
print(err)
5555
self.fail("LoadModel service failed")
@@ -245,9 +245,6 @@ class TestThreadSafeLRUPromptCache(unittest.TestCase):
245245
"""
246246

247247
def setUp(self):
248-
import sys
249-
import os
250-
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'common'))
251248
from mlx_cache import ThreadSafeLRUPromptCache
252249
self.cache = ThreadSafeLRUPromptCache(max_size=3)
253250

0 commit comments

Comments
 (0)