Skip to content

Commit

Permalink
Use chat template
Browse files Browse the repository at this point in the history
  • Loading branch information
DePasqualeOrg committed Sep 29, 2024
1 parent 0907d7f commit 8e36c71
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
11 changes: 5 additions & 6 deletions Applications/LLMEval/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ class LLMEvaluator {

/// This controls which model loads. `phi3_5_4bit` is one of the smaller ones, so this will fit on
/// more devices.
let modelConfiguration = ModelConfiguration.phi3_5_4bit
// let modelConfiguration = ModelConfiguration.phi3_5_4bit
let modelConfiguration = ModelConfiguration.mistral7B4bit

/// parameters controlling the output
let generateParameters = GenerateParameters(temperature: 0.6)
Expand Down Expand Up @@ -212,11 +213,9 @@ class LLMEvaluator {
do {
let modelContainer = try await load()

// augment the prompt as needed
let prompt = modelConfiguration.prepare(prompt: prompt)

let promptTokens = await modelContainer.perform { _, tokenizer in
tokenizer.encode(text: prompt)
let messages = [["role": "user", "content": prompt]]
let promptTokens = try await modelContainer.perform { _, tokenizer in
try tokenizer.applyChatTemplate(messages: messages)
}

// each time you generate you will get something new
Expand Down
3 changes: 2 additions & 1 deletion Libraries/LLM/Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ extension ModelConfiguration {

public static let mistral7B4bit = ModelConfiguration(
id: "mlx-community/Mistral-7B-Instruct-v0.3-4bit",
defaultPrompt: "Describe the Swift language."
defaultPrompt: "Describe the Swift language.",
extraEOSTokens: ["<|im_end|>"] // !! This doesn't seem to work
) { prompt in
"<s>[INST] \(prompt) [/INST] "
}
Expand Down

0 comments on commit 8e36c71

Please sign in to comment.