From 1232bc9855b7d02edc2db79dcc518ad4c262418c Mon Sep 17 00:00:00 2001 From: simba Date: Sun, 22 Mar 2026 18:26:18 -0700 Subject: [PATCH] feat: auto-detect local directory path for --model flag If --model points to an existing local directory, uses ModelConfiguration(directory:) for instant loading from disk. Otherwise treats as HF repo ID and downloads via Hub. Enables pre-downloaded models from Aegis-AI to load without re-downloading. --- Sources/mlx-server/main.swift | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Sources/mlx-server/main.swift b/Sources/mlx-server/main.swift index c56b01a..85867e0 100644 --- a/Sources/mlx-server/main.swift +++ b/Sources/mlx-server/main.swift @@ -59,7 +59,23 @@ struct MLXServer: AsyncParsableCommand { let modelId = model // ── Load model ── - let modelConfig = ModelConfiguration(id: modelId) + // Auto-detect: if --model points to an existing local directory, load + // from disk directly (no download). Otherwise treat as HF repo ID. + let modelConfig: ModelConfiguration + let fileManager = FileManager.default + if fileManager.fileExists(atPath: modelId) { + var isDir: ObjCBool = false + fileManager.fileExists(atPath: modelId, isDirectory: &isDir) + if isDir.boolValue { + print("[mlx-server] Loading from local directory: \(modelId)") + modelConfig = ModelConfiguration(directory: URL(filePath: modelId)) + } else { + modelConfig = ModelConfiguration(id: modelId) + } + } else { + modelConfig = ModelConfiguration(id: modelId) + } + let container = try await LLMModelFactory.shared.loadContainer( configuration: modelConfig ) { progress in