Skip to content

Commit 1232bc9

Browse files
simbasimba
authored andcommitted
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.
1 parent 19717cf commit 1232bc9

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

Sources/mlx-server/main.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,23 @@ struct MLXServer: AsyncParsableCommand {
5959
let modelId = model
6060

6161
// ── Load model ──
62-
let modelConfig = ModelConfiguration(id: modelId)
62+
// Auto-detect: if --model points to an existing local directory, load
63+
// from disk directly (no download). Otherwise treat as HF repo ID.
64+
let modelConfig: ModelConfiguration
65+
let fileManager = FileManager.default
66+
if fileManager.fileExists(atPath: modelId) {
67+
var isDir: ObjCBool = false
68+
fileManager.fileExists(atPath: modelId, isDirectory: &isDir)
69+
if isDir.boolValue {
70+
print("[mlx-server] Loading from local directory: \(modelId)")
71+
modelConfig = ModelConfiguration(directory: URL(filePath: modelId))
72+
} else {
73+
modelConfig = ModelConfiguration(id: modelId)
74+
}
75+
} else {
76+
modelConfig = ModelConfiguration(id: modelId)
77+
}
78+
6379
let container = try await LLMModelFactory.shared.loadContainer(
6480
configuration: modelConfig
6581
) { progress in

0 commit comments

Comments
 (0)