Skip to content

Commit 4df8071

Browse files
authored
Merge pull request #94 from Picovoice/android-speedup-patch
2 parents 1e66fda + 99e6d9b commit 4df8071

File tree

35 files changed

+113
-65
lines changed

35 files changed

+113
-65
lines changed

binding/android/PicoLLM/picollm/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ apply plugin: 'com.android.library'
22

33
ext {
44
PUBLISH_GROUP_ID = 'ai.picovoice'
5-
PUBLISH_VERSION = '1.3.0'
5+
PUBLISH_VERSION = '1.3.1'
66
PUBLISH_ARTIFACT_ID = 'picollm-android'
77
}
88

99
android {
10+
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
11+
if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
12+
namespace 'ai.picovoice.picollm'
13+
}
14+
1015
compileSdkVersion defaultTargetSdkVersion
1116
buildToolsVersion "30.0.3"
1217

binding/android/PicoLLM/picollm/src/main/java/ai/picovoice/picollm/dialog/Llama2ChatDialog.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024 Picovoice Inc.
2+
Copyright 2024-2025 Picovoice Inc.
33
44
You may not use this file except in compliance with the license. A copy of the license is
55
located in the "LICENSE" file accompanying this source.
@@ -74,16 +74,25 @@ public String getPrompt() throws PicoLLMException {
7474
for (int i = 0; i < llm.size(); i++) {
7575
String instruction = human.get(i).trim();
7676

77-
if (system != null && i == 0) {
78-
instruction = String.format("<<SYS>>\n%s\n<</SYS>>\n\n%s", system, instruction);
77+
if (this.system != null && i == 0) {
78+
instruction = String.format(
79+
"<<SYS>>\n%s\n<</SYS>>\n\n%s",
80+
this.system.trim(),
81+
instruction);
7982
}
8083

81-
res.append(String.format("<s>[INST] %s [/INST] %s </s>", instruction, llm.get(i).trim()));
84+
res.append(String.format(
85+
"<s>[INST] %s [/INST] %s </s>",
86+
instruction,
87+
llm.get(i).trim()));
8288
}
8389

8490
String instruction = human.get(human.size() - 1).trim();
85-
if (system != null && human.size() == 1) {
86-
instruction = String.format("<<SYS>>\n%s\n<</SYS>>\n\n%s", system, instruction);
91+
if (this.system != null && human.size() == 1) {
92+
instruction = String.format(
93+
"<<SYS>>\n%s\n<</SYS>>\n\n%s",
94+
this.system.trim(),
95+
instruction);
8796
}
8897
res.append(String.format("<s>[INST] %s [/INST]", instruction));
8998

binding/android/PicoLLM/picollm/src/main/java/ai/picovoice/picollm/dialog/Llama3ChatDialog.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024 Picovoice Inc.
2+
Copyright 2024-2025 Picovoice Inc.
33
44
You may not use this file except in compliance with the license. A copy of the license is
55
located in the "LICENSE" file accompanying this source.
@@ -69,6 +69,12 @@ public String getPrompt() throws PicoLLMException {
6969
this.llmResponses.size());
7070

7171
StringBuilder res = new StringBuilder("<|begin_of_text|>");
72+
if (this.system != null) {
73+
res.append(String.format(
74+
"<|start_header_id|>system<|end_header_id|>\n\n%s<|eot_id|>",
75+
this.system.trim()));
76+
}
77+
7278
for (int i = 0; i < llm.size(); i++) {
7379
res.append(String.format(
7480
"<|start_header_id|>user<|end_header_id|>\n\n%s<|eot_id|>",

binding/android/PicoLLM/picollm/src/main/java/ai/picovoice/picollm/dialog/Phi3ChatDialog.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024 Picovoice Inc.
2+
Copyright 2024-2025 Picovoice Inc.
33
44
You may not use this file except in compliance with the license. A copy of the license is
55
located in the "LICENSE" file accompanying this source.
@@ -73,8 +73,8 @@ public String getPrompt() throws PicoLLMException {
7373
this.llmResponses.size());
7474

7575
StringBuilder res = new StringBuilder();
76-
if (system != null) {
77-
res.append(String.format("<|system|>\n%s<|end|>\n", system));
76+
if (this.system != null) {
77+
res.append(String.format("<|system|>\n%s<|end|>\n", this.system.trim()));
7878
}
7979

8080
for (int i = 0; i < llm.size(); i++) {

binding/android/PicoLLMTestApp/picollm-test-app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ dependencies {
8181
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
8282
implementation 'com.google.code.gson:gson:2.10'
8383

84-
implementation 'ai.picovoice:picollm-android:1.3.0'
84+
implementation 'ai.picovoice:picollm-android:1.3.1'
8585

8686
// Espresso UI Testing
8787
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
rootProject.name = "PicoLLMTestApp"
2-
include ':picollm-test-app'
2+
include ':picollm-test-app'

binding/dotnet/PicoLLM/PicoLLM.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>net8.0;net6.0;netcoreapp3.0;netstandard2.0</TargetFrameworks>
4-
<Version>1.3.0</Version>
4+
<Version>1.3.1</Version>
55
<Authors>Picovoice</Authors>
66
<Company />
77
<Product>picoLLM Inference Engine</Product>

binding/dotnet/PicoLLM/PicoLLMDialog.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public override string Prompt()
179179
string result = "";
180180
if (_system != null)
181181
{
182-
result += $"<|system|>\n{_system}<|end|>\n";
182+
result += $"<|system|>\n{_system.Trim()}<|end|>\n";
183183
}
184184

185185
for (int i = 0; i < llmResponses.Count; i++)
@@ -271,7 +271,7 @@ public override string Prompt()
271271
string instruction = humanRequests[i].Trim();
272272
if (_system != null && i == 0)
273273
{
274-
instruction = $"<<SYS>>\n{_system}\n<</SYS>>\n\n{instruction}";
274+
instruction = $"<<SYS>>\n{_system.Trim()}\n<</SYS>>\n\n{instruction}";
275275
}
276276

277277
result += $"<s>[INST] {instruction} [/INST] {llmResponses[i].Trim()} </s>";
@@ -280,7 +280,7 @@ public override string Prompt()
280280
string lastInstruction = humanRequests.Last().Trim();
281281
if (_system != null && humanRequests.Count == 1)
282282
{
283-
lastInstruction = $"<<SYS>>\n{_system}\n<</SYS>>\n\n{lastInstruction}";
283+
lastInstruction = $"<<SYS>>\n{_system.Trim()}\n<</SYS>>\n\n{lastInstruction}";
284284
}
285285

286286
result += $"<s>[INST] {lastInstruction} [/INST]";
@@ -311,6 +311,10 @@ public override string Prompt()
311311
: _llmResponses.Skip(_llmResponses.Count - (int)_history).ToList();
312312

313313
string result = "<|begin_of_text|>";
314+
if (_system != null)
315+
{
316+
result += $"<|start_header_id|>system<|end_header_id|>\n\n{_system.Trim()}<|eot_id|>";
317+
}
314318
for (int i = 0; i < llmResponses.Count; i++)
315319
{
316320
result += $"<|start_header_id|>user<|end_header_id|>\n\n{humanRequests[i].Trim()}<|eot_id|>";

binding/ios/PicoLLMAppTest/PicoLLMAppTest.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@
563563
repositoryURL = "https://github.com/picovoice/picollm";
564564
requirement = {
565565
kind = exactVersion;
566-
version = 1.3.0;
566+
version = 1.3.1;
567567
};
568568
};
569569
/* End XCRemoteSwiftPackageReference section */

binding/ios/PicoLLMDialog.swift

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2024 Picovoice Inc.
2+
// Copyright 2024-2025 Picovoice Inc.
33
// You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
44
// file accompanying this source.
55
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
@@ -175,8 +175,11 @@ public class Phi3ChatDialog: BasePicoLLMDialog {
175175
self.llmResponses[(self.llmResponses.count - Int(self.history!))...]
176176

177177
var res = ""
178-
if system != nil {
179-
res += String(format: "<|system|>\n%@<|end|>\n", system!)
178+
if self.system != nil {
179+
res += String(
180+
format: "<|system|>\n%@<|end|>\n",
181+
self.system!.trimmingCharacters(in: .whitespacesAndNewlines)
182+
)
180183
}
181184
for i in 0..<llmResponses.count {
182185
res += String(
@@ -260,8 +263,12 @@ public class Llama2ChatDialog: BasePicoLLMDialog {
260263
var res = ""
261264
for i in 0..<llmResponses.count {
262265
var instruction = humanRequests[i].trimmingCharacters(in: .whitespacesAndNewlines)
263-
if system != nil && i == 0 {
264-
instruction = String(format: "<<SYS>>\n%@\n<</SYS>>\n\n%@", system!, instruction)
266+
if self.system != nil && i == 0 {
267+
instruction = String(
268+
format: "<<SYS>>\n%@\n<</SYS>>\n\n%@",
269+
self.system!.trimmingCharacters(in: .whitespacesAndNewlines),
270+
instruction
271+
)
265272
}
266273

267274
res += String(
@@ -272,8 +279,12 @@ public class Llama2ChatDialog: BasePicoLLMDialog {
272279
}
273280

274281
var instruction = humanRequests.last!.trimmingCharacters(in: .whitespacesAndNewlines)
275-
if system != nil && humanRequests.count == 1 {
276-
instruction = String(format: "<<SYS>>\n%@\n<</SYS>>\n\n%@", system!, instruction)
282+
if self.system != nil && humanRequests.count == 1 {
283+
instruction = String(
284+
format: "<<SYS>>\n%@\n<</SYS>>\n\n%@",
285+
self.system!.trimmingCharacters(in: .whitespacesAndNewlines),
286+
instruction
287+
)
277288
}
278289

279290
res += String(
@@ -300,6 +311,11 @@ public class Llama3ChatDialog: BasePicoLLMDialog {
300311
self.llmResponses[(self.llmResponses.count - Int(self.history!))...]
301312

302313
var res = "<|begin_of_text|>"
314+
if self.system != nil {
315+
res += String(
316+
format: "<|start_header_id|>system<|end_header_id|>\n\n%@<|eot_id|>",
317+
self.system!.trimmingCharacters(in: .whitespacesAndNewlines))
318+
}
303319
for i in 0..<llmResponses.count {
304320
res += String(
305321
format: "<|start_header_id|>user<|end_header_id|>\n\n%@<|eot_id|>",

0 commit comments

Comments
 (0)