@@ -33,28 +33,42 @@ public struct ModelConfiguration {
3333 /// overrides for TokenizerModel/knownTokenizers -- useful before swift-transformers is updated
3434 public let overrideTokenizer : String ?
3535
36+ /// A reasonable default prompt for the model
37+ public let defaultPrompt : String
38+
39+ /// Additional tokens to use for end of string
40+ public let extraEOSTokens : Set < String >
41+
3642 /// custom preparation logic for the prompt. custom tokenizers provide more capability, but this
3743 /// allows some minor formtting changes, e.g. wrapping the user input in the expected prompt
3844 /// format
3945 private let preparePrompt : ( ( String ) -> String ) ?
4046
4147 public init (
4248 id: String , tokenizerId: String ? = nil , overrideTokenizer: String ? = nil ,
49+ defaultPrompt: String = " hello " ,
50+ extraEOSTokens: Set < String > = [ ] ,
4351 preparePrompt: ( ( String ) -> String ) ? = nil
4452 ) {
4553 self . id = . id( id)
4654 self . tokenizerId = tokenizerId
4755 self . overrideTokenizer = overrideTokenizer
56+ self . defaultPrompt = defaultPrompt
57+ self . extraEOSTokens = extraEOSTokens
4858 self . preparePrompt = preparePrompt
4959 }
5060
5161 public init (
5262 directory: URL , tokenizerId: String ? = nil , overrideTokenizer: String ? = nil ,
63+ defaultPrompt: String = " hello " ,
64+ extraEOSTokens: Set < String > = [ ] ,
5365 preparePrompt: ( ( String ) -> String ) ? = nil
5466 ) {
5567 self . id = . directory( directory)
5668 self . tokenizerId = tokenizerId
5769 self . overrideTokenizer = overrideTokenizer
70+ self . defaultPrompt = defaultPrompt
71+ self . extraEOSTokens = extraEOSTokens
5872 self . preparePrompt = preparePrompt
5973 }
6074
@@ -98,11 +112,16 @@ public struct ModelConfiguration {
98112extension ModelConfiguration {
99113
100114 public static let mistral7B4bit = ModelConfiguration (
101- id: " mlx-community/Mistral-7B-v0.1-hf-4bit-mlx " )
115+ id: " mlx-community/Mistral-7B-v0.1-hf-4bit-mlx " ,
116+
117+ // https://www.promptingguide.ai/models/mistral-7b
118+ defaultPrompt: " describe the swift language "
119+ )
102120
103121 public static let codeLlama13b4bit = ModelConfiguration (
104122 id: " mlx-community/CodeLlama-13b-Instruct-hf-4bit-MLX " ,
105- overrideTokenizer: " PreTrainedTokenizer "
123+ overrideTokenizer: " PreTrainedTokenizer " ,
124+ defaultPrompt: " func sortArray(_ array: [Int]) -> String { <FILL_ME> } "
106125 ) { prompt in
107126 // given the prompt: func sortArray(_ array: [Int]) -> String { <FILL_ME> }
108127 // the python code produces this (via its custom tokenizer):
@@ -111,40 +130,53 @@ extension ModelConfiguration {
111130 " <PRE> " + prompt. replacingOccurrences ( of: " <FILL_ME> " , with: " <SUF> " ) + " <MID> "
112131 }
113132
114- public static let phi4bit = ModelConfiguration ( id: " mlx-community/phi-2-hf-4bit-mlx " ) {
115- prompt in
116- " Instruct: \( prompt) \n Output: "
117- }
133+ public static let phi4bit = ModelConfiguration (
134+ id: " mlx-community/phi-2-hf-4bit-mlx " ,
135+
136+ // https://www.promptingguide.ai/models/phi-2
137+ defaultPrompt: " Why is the sky blue? "
138+ )
118139
119140 public static let phi34bit = ModelConfiguration (
120- id: " mlx-community/Phi-3-mini-4k-instruct-4bit-no-q-embed "
141+ id: " mlx-community/Phi-3-mini-4k-instruct-4bit-no-q-embed " ,
142+ defaultPrompt: " what is the gravity on mars and the moon? " ,
143+ extraEOSTokens: [ " <|end|> " ]
121144 ) {
122145 prompt in
123146 " <s><|user|> \n \( prompt) <|end|> \n <|assistant|> \n "
124147 }
125148
126149 public static let gemma2bQuantized = ModelConfiguration (
127150 id: " mlx-community/quantized-gemma-2b-it " ,
128- overrideTokenizer: " PreTrainedTokenizer "
151+ overrideTokenizer: " PreTrainedTokenizer " ,
152+
153+ // https://www.promptingguide.ai/models/gemma
154+ defaultPrompt: " what is the difference between lettuce and cabbage? "
155+
129156 ) { prompt in
130157 " <start_of_turn>user \( prompt) <end_of_turn><start_of_turn>model "
131158 }
132159
133160 public static let qwen205b4bit = ModelConfiguration (
134161 id: " mlx-community/Qwen1.5-0.5B-Chat-4bit " ,
135- overrideTokenizer: " PreTrainedTokenizer "
162+ overrideTokenizer: " PreTrainedTokenizer " ,
163+ defaultPrompt: " why is the sky blue? "
136164 ) { prompt in
137165 " <|im_start|>system \n You are a helpful assistant<|im_end|> \n <|im_start|>user \n \( prompt) <|im_end|> \n <|im_start|>assistant "
138166 }
139167
140168 public static let openelm270m4bit = ModelConfiguration (
141- id: " mlx-community/OpenELM-270M-Instruct "
169+ id: " mlx-community/OpenELM-270M-Instruct " ,
170+
171+ // https://huggingface.co/apple/OpenELM
172+ defaultPrompt: " Once upon a time there was "
142173 ) { prompt in
143174 " \( prompt) "
144175 }
145176
146177 public static let llama38B4bit = ModelConfiguration (
147- id: " mlx-community/Meta-Llama-3-8B-Instruct-4bit "
178+ id: " mlx-community/Meta-Llama-3-8B-Instruct-4bit " ,
179+ defaultPrompt: " what is the difference between a fruit and a vegetable? "
148180 ) {
149181 prompt in
150182 " <|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|> "
0 commit comments