From fe9b3120674e7f176bb5aac55da50fa201798290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Sampaio?= Date: Fri, 27 Sep 2024 09:46:46 +0100 Subject: [PATCH 1/3] Add LLama 3.2 1B and 3B lightweight models --- Libraries/LLM/Models.swift | 16 ++++++++++++++++ mlx-swift-examples.xcodeproj/project.pbxproj | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Libraries/LLM/Models.swift b/Libraries/LLM/Models.swift index db44a91..3238386 100644 --- a/Libraries/LLM/Models.swift +++ b/Libraries/LLM/Models.swift @@ -228,6 +228,22 @@ extension ModelConfiguration { prompt in "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\nYou 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|>" } + + public static let llama3_2_1B_4bit = ModelConfiguration( + id: "mlx-community/Llama-3.2-1B-Instruct-4bit", + defaultPrompt: "What is the difference between a fruit and a vegetable?" + ) { + prompt in + "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\nYou 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|>" + } + + public static let llama3_2_3B_4bit = ModelConfiguration( + id: "mlx-community/Llama-3.2-3B-Instruct-4bit", + defaultPrompt: "What is the difference between a fruit and a vegetable?" + ) { + prompt in + "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\nYou 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|>" + } private enum BootstrapState: Sendable { case idle diff --git a/mlx-swift-examples.xcodeproj/project.pbxproj b/mlx-swift-examples.xcodeproj/project.pbxproj index 52c03ba..9546d99 100644 --- a/mlx-swift-examples.xcodeproj/project.pbxproj +++ b/mlx-swift-examples.xcodeproj/project.pbxproj @@ -3543,7 +3543,7 @@ repositoryURL = "https://github.com/huggingface/swift-transformers"; requirement = { kind = upToNextMajorVersion; - minimumVersion = 0.1.9; + minimumVersion = 0.1.12; }; }; C392736E2B60699100368D5D /* XCRemoteSwiftPackageReference "swift-argument-parser" */ = { From b754c710f59d34c965f2965d370237f30b83a807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Sampaio?= Date: Fri, 27 Sep 2024 09:46:46 +0100 Subject: [PATCH 2/3] Add LLama 3.2 1B and 3B lightweight models --- Libraries/LLM/Models.swift | 18 ++++++++++++++++++ mlx-swift-examples.xcodeproj/project.pbxproj | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Libraries/LLM/Models.swift b/Libraries/LLM/Models.swift index db44a91..4ffa175 100644 --- a/Libraries/LLM/Models.swift +++ b/Libraries/LLM/Models.swift @@ -228,6 +228,22 @@ extension ModelConfiguration { prompt in "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\nYou 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|>" } + + public static let llama3_2_1B_4bit = ModelConfiguration( + id: "mlx-community/Llama-3.2-1B-Instruct-4bit", + defaultPrompt: "What is the difference between a fruit and a vegetable?" + ) { + prompt in + "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\nYou 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|>" + } + + public static let llama3_2_3B_4bit = ModelConfiguration( + id: "mlx-community/Llama-3.2-3B-Instruct-4bit", + defaultPrompt: "What is the difference between a fruit and a vegetable?" + ) { + prompt in + "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\nYou 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|>" + } private enum BootstrapState: Sendable { case idle @@ -245,6 +261,8 @@ extension ModelConfiguration { bootstrapState = .bootstrapping register(configurations: [ llama3_1_8B_4bit, + llama3_2_1B_4bit, + llama3_2_3B_4bit, mistralNeMo4bit, smolLM_135M_4bit, mistral7B4bit, diff --git a/mlx-swift-examples.xcodeproj/project.pbxproj b/mlx-swift-examples.xcodeproj/project.pbxproj index 52c03ba..9546d99 100644 --- a/mlx-swift-examples.xcodeproj/project.pbxproj +++ b/mlx-swift-examples.xcodeproj/project.pbxproj @@ -3543,7 +3543,7 @@ repositoryURL = "https://github.com/huggingface/swift-transformers"; requirement = { kind = upToNextMajorVersion; - minimumVersion = 0.1.9; + minimumVersion = 0.1.12; }; }; C392736E2B60699100368D5D /* XCRemoteSwiftPackageReference "swift-argument-parser" */ = { From cd7d0189be0e11ea708158bba24aba8774c3b6cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Sampaio?= Date: Sun, 29 Sep 2024 11:09:14 +0100 Subject: [PATCH 3/3] Fix formatting --- Libraries/LLM/Models.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Libraries/LLM/Models.swift b/Libraries/LLM/Models.swift index 4ffa175..4ec9354 100644 --- a/Libraries/LLM/Models.swift +++ b/Libraries/LLM/Models.swift @@ -228,7 +228,7 @@ extension ModelConfiguration { prompt in "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\nYou 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|>" } - + public static let llama3_2_1B_4bit = ModelConfiguration( id: "mlx-community/Llama-3.2-1B-Instruct-4bit", defaultPrompt: "What is the difference between a fruit and a vegetable?" @@ -236,11 +236,11 @@ extension ModelConfiguration { prompt in "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\nYou 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|>" } - + public static let llama3_2_3B_4bit = ModelConfiguration( id: "mlx-community/Llama-3.2-3B-Instruct-4bit", defaultPrompt: "What is the difference between a fruit and a vegetable?" - ) { + ) { prompt in "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\nYou 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|>" }