@@ -39,11 +39,6 @@ public struct ModelConfiguration: Sendable {
39
39
/// Additional tokens to use for end of string
40
40
public let extraEOSTokens : Set < String >
41
41
42
- /// custom preparation logic for the prompt. custom tokenizers provide more capability, but this
43
- /// allows some minor formtting changes, e.g. wrapping the user input in the expected prompt
44
- /// format
45
- private let preparePrompt : ( @Sendable ( String ) -> String ) ?
46
-
47
42
public init (
48
43
id: String , tokenizerId: String ? = nil , overrideTokenizer: String ? = nil ,
49
44
defaultPrompt: String = " hello " ,
@@ -55,25 +50,18 @@ public struct ModelConfiguration: Sendable {
55
50
self . overrideTokenizer = overrideTokenizer
56
51
self . defaultPrompt = defaultPrompt
57
52
self . extraEOSTokens = extraEOSTokens
58
- self . preparePrompt = preparePrompt
59
53
}
60
54
61
55
public init (
62
56
directory: URL , tokenizerId: String ? = nil , overrideTokenizer: String ? = nil ,
63
57
defaultPrompt: String = " hello " ,
64
- extraEOSTokens: Set < String > = [ ] ,
65
- preparePrompt: ( @Sendable ( String ) -> String ) ? = nil
58
+ extraEOSTokens: Set < String > = [ ]
66
59
) {
67
60
self . id = . directory( directory)
68
61
self . tokenizerId = tokenizerId
69
62
self . overrideTokenizer = overrideTokenizer
70
63
self . defaultPrompt = defaultPrompt
71
64
self . extraEOSTokens = extraEOSTokens
72
- self . preparePrompt = preparePrompt
73
- }
74
-
75
- public func prepare( prompt: String ) -> String {
76
- preparePrompt ? ( prompt) ?? prompt
77
65
}
78
66
79
67
public func modelDirectory( hub: HubApi = HubApi ( ) ) -> URL {
@@ -116,40 +104,26 @@ extension ModelConfiguration {
116
104
public static let smolLM_135M_4bit = ModelConfiguration (
117
105
id: " mlx-community/SmolLM-135M-Instruct-4bit " ,
118
106
defaultPrompt: " Tell me about the history of Spain. "
119
- ) {
120
- prompt in
121
- " <|im_start|>user \n \( prompt) <|im_end|> \n <|im_start|>assistant \n "
122
- }
107
+ )
123
108
124
109
public static let mistralNeMo4bit = ModelConfiguration (
125
110
id: " mlx-community/Mistral-Nemo-Instruct-2407-4bit " ,
126
111
defaultPrompt: " Explain quaternions. "
127
- ) { prompt in
128
- " <s>[INST] \( prompt) [/INST] "
129
- }
112
+ )
130
113
131
114
public static let mistral7B4bit = ModelConfiguration (
132
115
id: " mlx-community/Mistral-7B-Instruct-v0.3-4bit " ,
133
116
defaultPrompt: " Describe the Swift language. "
134
- ) { prompt in
135
- " <s>[INST] \( prompt) [/INST] "
136
- }
117
+ )
137
118
138
119
public static let codeLlama13b4bit = ModelConfiguration (
139
120
id: " mlx-community/CodeLlama-13b-Instruct-hf-4bit-MLX " ,
140
121
overrideTokenizer: " PreTrainedTokenizer " ,
141
122
defaultPrompt: " func sortArray(_ array: [Int]) -> String { <FILL_ME> } "
142
- ) { prompt in
143
- // given the prompt: func sortArray(_ array: [Int]) -> String { <FILL_ME> }
144
- // the python code produces this (via its custom tokenizer):
145
- // <PRE> func sortArray(_ array: [Int]) -> String { <SUF> } <MID>
146
-
147
- " <PRE> " + prompt. replacingOccurrences ( of: " <FILL_ME> " , with: " <SUF> " ) + " <MID> "
148
- }
123
+ )
149
124
150
125
public static let phi4bit = ModelConfiguration (
151
126
id: " mlx-community/phi-2-hf-4bit-mlx " ,
152
-
153
127
// https://www.promptingguide.ai/models/phi-2
154
128
defaultPrompt: " Why is the sky blue? "
155
129
)
@@ -158,92 +132,60 @@ extension ModelConfiguration {
158
132
id: " mlx-community/Phi-3.5-mini-instruct-4bit " ,
159
133
defaultPrompt: " What is the gravity on Mars and the moon? " ,
160
134
extraEOSTokens: [ " <|end|> " ]
161
- ) {
162
- prompt in
163
- " <s><|user|> \n \( prompt) <|end|> \n <|assistant|> \n "
164
- }
135
+ )
165
136
166
137
public static let gemma2bQuantized = ModelConfiguration (
167
138
id: " mlx-community/quantized-gemma-2b-it " ,
168
139
overrideTokenizer: " PreTrainedTokenizer " ,
169
-
170
140
// https://www.promptingguide.ai/models/gemma
171
141
defaultPrompt: " what is the difference between lettuce and cabbage? "
172
-
173
- ) { prompt in
174
- " <start_of_turn>user \n \( prompt) <end_of_turn> \n <start_of_turn>model \n "
175
- }
142
+ )
176
143
177
144
public static let gemma_2_9b_it_4bit = ModelConfiguration (
178
145
id: " mlx-community/gemma-2-9b-it-4bit " ,
179
146
overrideTokenizer: " PreTrainedTokenizer " ,
180
-
181
147
// https://www.promptingguide.ai/models/gemma
182
148
defaultPrompt: " What is the difference between lettuce and cabbage? "
183
-
184
- ) { prompt in
185
- " <start_of_turn>user \n \( prompt) <end_of_turn> \n <start_of_turn>model \n "
186
- }
149
+ )
187
150
188
151
public static let gemma_2_2b_it_4bit = ModelConfiguration (
189
152
id: " mlx-community/gemma-2-2b-it-4bit " ,
190
153
overrideTokenizer: " PreTrainedTokenizer " ,
191
-
192
154
// https://www.promptingguide.ai/models/gemma
193
155
defaultPrompt: " What is the difference between lettuce and cabbage? "
194
-
195
- ) { prompt in
196
- " <start_of_turn>user \( prompt) <end_of_turn><start_of_turn>model "
197
- }
156
+ )
198
157
199
158
public static let qwen205b4bit = ModelConfiguration (
200
159
id: " mlx-community/Qwen1.5-0.5B-Chat-4bit " ,
201
160
overrideTokenizer: " PreTrainedTokenizer " ,
202
161
defaultPrompt: " why is the sky blue? "
203
- ) { prompt in
204
- " <|im_start|>system \n You are a helpful assistant<|im_end|> \n <|im_start|>user \n \( prompt) <|im_end|> \n <|im_start|>assistant "
205
- }
162
+ )
206
163
207
164
public static let openelm270m4bit = ModelConfiguration (
208
165
id: " mlx-community/OpenELM-270M-Instruct " ,
209
-
210
166
// https://huggingface.co/apple/OpenELM
211
167
defaultPrompt: " Once upon a time there was "
212
- ) { prompt in
213
- " \( prompt) "
214
- }
168
+ )
215
169
216
170
public static let llama3_1_8B_4bit = ModelConfiguration (
217
171
id: " mlx-community/Meta-Llama-3.1-8B-Instruct-4bit " ,
218
172
defaultPrompt: " What is the difference between a fruit and a vegetable? "
219
- ) {
220
- prompt in
221
- " <|begin_of_text|><|start_header_id|>system<|end_header_id|> \n You are a helpful assistant<|eot_id|> \n <|start_header_id|>user<|end_header_id|> \n \( prompt) <|eot_id|> \n <|start_header_id|>assistant<|end_header_id|> "
222
- }
173
+ )
223
174
224
175
public static let llama3_8B_4bit = ModelConfiguration (
225
176
id: " mlx-community/Meta-Llama-3-8B-Instruct-4bit " ,
226
177
defaultPrompt: " What is the difference between a fruit and a vegetable? "
227
- ) {
228
- prompt in
229
- " <|begin_of_text|><|start_header_id|>system<|end_header_id|> \n You are a helpful assistant<|eot_id|> \n <|start_header_id|>user<|end_header_id|> \n \( prompt) <|eot_id|> \n <|start_header_id|>assistant<|end_header_id|> "
230
- }
178
+ )
231
179
232
180
public static let llama3_2_1B_4bit = ModelConfiguration (
233
181
id: " mlx-community/Llama-3.2-1B-Instruct-4bit " ,
234
182
defaultPrompt: " What is the difference between a fruit and a vegetable? "
235
- ) {
236
- prompt in
237
- " <|begin_of_text|><|start_header_id|>system<|end_header_id|> \n You are a helpful assistant<|eot_id|> \n <|start_header_id|>user<|end_header_id|> \n \( prompt) <|eot_id|> \n <|start_header_id|>assistant<|end_header_id|> "
238
- }
183
+ )
239
184
240
185
public static let llama3_2_3B_4bit = ModelConfiguration (
241
186
id: " mlx-community/Llama-3.2-3B-Instruct-4bit " ,
242
187
defaultPrompt: " What is the difference between a fruit and a vegetable? "
243
- ) {
244
- prompt in
245
- " <|begin_of_text|><|start_header_id|>system<|end_header_id|> \n You are a helpful assistant<|eot_id|> \n <|start_header_id|>user<|end_header_id|> \n \( prompt) <|eot_id|> \n <|start_header_id|>assistant<|end_header_id|> "
246
- }
188
+ )
247
189
248
190
private enum BootstrapState : Sendable {
249
191
case idle
0 commit comments