@inferrlm/react-native-mlx 0.4.1 → 0.4.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/Sources/HybridLLM.swift +44 -0
- package/package.json +1 -1
|
@@ -66,6 +66,34 @@ class HybridLLM: HybridLLMSpec {
|
|
|
66
66
|
allocatedMB, cacheMB, peakMB)
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
private func parseEosTokenIds(from modelDir: URL) -> Set<Int> {
|
|
70
|
+
let configURL = modelDir.appendingPathComponent("config.json")
|
|
71
|
+
guard let data = try? Data(contentsOf: configURL),
|
|
72
|
+
let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any]
|
|
73
|
+
else { return [] }
|
|
74
|
+
|
|
75
|
+
if let ids = extractEosIds(from: json) {
|
|
76
|
+
return ids
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if let textConfig = json["text_config"] as? [String: Any],
|
|
80
|
+
let ids = extractEosIds(from: textConfig) {
|
|
81
|
+
return ids
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return []
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private func extractEosIds(from dict: [String: Any]) -> Set<Int>? {
|
|
88
|
+
if let id = dict["eos_token_id"] as? Int {
|
|
89
|
+
return [id]
|
|
90
|
+
}
|
|
91
|
+
if let ids = dict["eos_token_id"] as? [Int], !ids.isEmpty {
|
|
92
|
+
return Set(ids)
|
|
93
|
+
}
|
|
94
|
+
return nil
|
|
95
|
+
}
|
|
96
|
+
|
|
69
97
|
private func buildToolSchema(from tool: ToolDefinition) -> ToolSpec {
|
|
70
98
|
var properties: [String: [String: Any]] = [:]
|
|
71
99
|
var required: [String] = []
|
|
@@ -125,6 +153,22 @@ class HybridLLM: HybridLLMSpec {
|
|
|
125
153
|
|
|
126
154
|
try Task.checkCancellation()
|
|
127
155
|
|
|
156
|
+
/*
|
|
157
|
+
mlx-swift-lm only reads top-level eos_token_id from config.json.
|
|
158
|
+
Models like Qwen3.5 nest it inside text_config, leaving the stop
|
|
159
|
+
set empty. Parse it ourselves and patch the container.
|
|
160
|
+
*/
|
|
161
|
+
let containerEos = await loadedContainer.configuration.eosTokenIds
|
|
162
|
+
if containerEos.isEmpty {
|
|
163
|
+
let parsed = self.parseEosTokenIds(from: modelDir)
|
|
164
|
+
if !parsed.isEmpty {
|
|
165
|
+
log("Patching eosTokenIds from config: \(parsed)")
|
|
166
|
+
await loadedContainer.update { ctx in
|
|
167
|
+
ctx.configuration.eosTokenIds = parsed
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
128
172
|
let memoryAfterContainer = self.getMemoryUsage()
|
|
129
173
|
let gpuAfterContainer = self.getGPUMemoryUsage()
|
|
130
174
|
log("Model loaded - Host: \(memoryAfterContainer), GPU: \(gpuAfterContainer)")
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inferrlm/react-native-mlx",
|
|
3
3
|
"description": "MLX Swift integration for React Native - InferrLM fork with enhanced features",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.2-alpha.0",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"module": "./lib/module/index.js",
|
|
7
7
|
"types": "./lib/typescript/src/index.d.ts",
|