Skip to content

Commit 6992a04

Browse files
committed
wip
1 parent f12f2d8 commit 6992a04

21 files changed

+546
-130
lines changed

android/build-android-aar.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
--no-daemon \
33
--console=plain \
44
--info --stacktrace \
5-
-Pandroid.native.buildOutput=verbose
5+
-Pandroid.native.buildOutput=verbose \
6+
-Dcmake.verbose=true
67

78
# check /Users/adel/Workspace/llama_cpp_dart/android/llamalib/build/outputs/aar

android/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ buildscript {
1010
}
1111

1212
dependencies {
13-
classpath 'com.android.tools.build:gradle:7.3.1'
13+
// classpath 'com.android.tools.build:gradle:7.3.1'
14+
classpath 'com.android.tools.build:gradle:8.2.2'
1415
}
1516
}
1617

android/llamalib/build.gradle

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,35 @@ plugins {
55
android {
66
namespace 'io.github.netdur.llama_cpp_dart.llamalib'
77
compileSdk 34
8+
ndkVersion "27.0.12077973"
89

910
defaultConfig {
1011
minSdk 24
1112

1213
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1314
consumerProguardFiles "consumer-rules.pro"
1415

16+
ndk { abiFilters "arm64-v8a", "x86_64" }
17+
1518
externalNativeBuild {
1619
cmake {
17-
abiFilters 'arm64-v8a', 'x86_64'
20+
// abiFilters 'arm64-v8a', 'x86_64'
21+
cppFlags "-std=c++17", "-fexceptions", "-frtti"
22+
arguments "-DBUILD_SHARED_LIBS=ON",
23+
"-DLLAMA_CURL=OFF",
24+
"-DGGML_VULKAN=ON",
25+
"-DGGML_VULKAN_COOPMAT_GLSLC_SUPPORT=OFF",
26+
"-DGGML_VULKAN_COOPMAT2_GLSLC_SUPPORT=OFF",
27+
"-DGGML_VULKAN_BFLOAT16_GLSLC_SUPPORT=OFF",
28+
// "-DVK_USE_PLATFORM_ANDROID_KHR=ON",
29+
// "-DGGML_VULKAN_VALIDATE=OFF",
30+
"-DLLAMA_BUILD_TESTS=OFF",
31+
"-DLLAMA_BUILD_EXAMPLES=OFF",
32+
"-DLLAMA_BUILD_SERVER=OFF",
33+
"-DLLAMA_BUILD_TOOLS=ON",
34+
"-DCMAKE_PROJECT_INCLUDE=/Users/adel/Workspace/llama_cpp_dart/darwin/no_bundle.cmake",
35+
"-DANDROID_STL=c++_static"
36+
1837
}
1938
}
2039
}

darwin/create_xcframework.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ set -euo pipefail
55
# 🛠 CONFIGURATION – adjust names/paths if your project changes
66
###############################################################################
77
FRAMEWORK_NAME="Llama"
8-
MAIN_LIB_NAME="libllama.dylib"
9-
FRAMEWORK_VERSION="0.0.9"
8+
MAIN_LIB_NAME="libmtmd.dylib"
9+
FRAMEWORK_VERSION="0.1.0"
1010
FRAMEWORK_ID="io.github.netdur.llama_cpp_dart"
1111

1212
MIN_IOS_VERSION="13.0"
1313
MIN_MACOS_VERSION="12.0"
1414

1515
DEPENDENCY_LIBS=(
1616
"libggml.dylib" "libggml-metal.dylib" "libggml-base.dylib"
17-
"libggml-cpu.dylib" "libggml-blas.dylib"
17+
"libggml-cpu.dylib" "libggml-blas.dylib" "libmtmd.dylib"
1818
)
1919

2020
# paths where YOUR build system placed the thin architectures

example/test_isolated.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void main() async {
1717
samplerParams.topP = 0.95;
1818
samplerParams.penaltyRepeat = 1.1;
1919

20-
String modelPath = "/Users/adel/Workspace/gguf/gemma-3-12b-it-q4_0.gguf";
20+
String modelPath = "/Users/adel/Workspace/gguf/gemma-3-4b-it-q4_0.gguf";
2121
final loadCommand = LlamaLoad(
2222
path: modelPath,
2323
modelParams: ModelParams(),

example/test_vision.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:io';
22
import 'package:llama_cpp_dart/llama_cpp_dart.dart';
3-
import 'package:llama_cpp_dart/src/llama_input.dart';
43

54
Future<void> main() async {
65
Llama.libraryPath = "bin/MAC_ARM64/libmtmd.dylib";
@@ -26,7 +25,7 @@ Future<void> main() async {
2625
false,
2726
"/Users/adel/Workspace/gguf/mmproj-model-f16-4B.gguf");
2827

29-
final image = LlamaImage.fromFile(File("/Users/adel/Downloads/test-1.jpeg"));
28+
final image = LlamaImage.fromFile(File("/Users/adel/Downloads/test.jpg"));
3029
final prompt = """
3130
<start_of_turn>user\n
3231
<image>\n

example/test_vision.finetuned.dart

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import 'dart:io';
2+
import 'package:llama_cpp_dart/llama_cpp_dart.dart';
3+
4+
Future<void> main() async {
5+
Llama.libraryPath = "bin/MAC_ARM64/libmtmd.dylib";
6+
7+
final modelParams = ModelParams()..nGpuLayers = 99;
8+
9+
final contextParams = ContextParams()
10+
..nPredict = -1
11+
..nCtx = 8192
12+
..nBatch = 8192;
13+
14+
final samplerParams = SamplerParams()
15+
..temp = 0.7
16+
..topK = 64
17+
..topP = 0.95
18+
..penaltyRepeat = 1.1;
19+
20+
final llama = Llama(
21+
"/Users/adel/Downloads/gemma-3n-E2B-it-plantvillage-model-Q4_K_M.gguf",
22+
modelParams,
23+
contextParams,
24+
samplerParams,
25+
true,
26+
"/Users/adel/Downloads/gemma-3n-E2B-it-plantvillage -mmproj.gguf");
27+
28+
final image =
29+
LlamaImage.fromFile(File("/Users/adel/Downloads/plantvillage-test.png"));
30+
final prompt = """
31+
<start_of_turn>user\n
32+
<image>\n
33+
You are an expert plant pathologist.
34+
Your task is to identify the plant species and its health status from the image.
35+
<start_of_turn>model\n""";
36+
37+
try {
38+
final stream = llama.generateWithMeda(prompt, inputs: [image]);
39+
40+
await for (final token in stream) {
41+
stdout.write(token);
42+
}
43+
await stdout.flush();
44+
stdout.writeln();
45+
} on LlamaException catch (e) {
46+
stderr.writeln("An error occurred: $e");
47+
} finally {
48+
llama.dispose();
49+
}
50+
}

example/test_vision.gemma3.dart

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import 'dart:io';
2+
import 'package:llama_cpp_dart/llama_cpp_dart.dart';
3+
4+
Future<void> main() async {
5+
Llama.libraryPath = "bin/MAC_ARM64/libmtmd.dylib";
6+
7+
final modelParams = ModelParams()..nGpuLayers = 0;
8+
9+
final contextParams = ContextParams()
10+
..nPredict = -1
11+
..nCtx = 8192
12+
..nBatch = 8192;
13+
14+
final samplerParams = SamplerParams()
15+
..temp = 0.7
16+
..topK = 64
17+
..topP = 0.95
18+
..penaltyRepeat = 1.1;
19+
20+
final llama = Llama(
21+
"/Users/adel/Workspace/gguf/model_tq2_0.gguf",
22+
modelParams,
23+
contextParams,
24+
samplerParams,
25+
false,
26+
"/Users/adel/Workspace/gguf/mmproj_tq2_0.gguf");
27+
28+
final image = LlamaImage.fromFile(File("/Users/adel/Downloads/test.jpg"));
29+
var prompt = """
30+
Generate a detailed product listing for this item,
31+
including a title, key features, and a description.
32+
output shouly be only, title, key features and description, DO NOT ADD ANYTHING ELSE OR ASK QUESTION OR MAKE SUGGESTIONS
33+
example of output:
34+
35+
**Title:** {title}"
36+
37+
**Key Features:**
38+
- feature
39+
40+
**Description:** {description}"
41+
""";
42+
prompt = """
43+
<start_of_turn>user\n
44+
<image>\n $prompt
45+
<start_of_turn>model\n""";
46+
47+
try {
48+
final stream = llama.generateWithMeda(prompt, inputs: [image]);
49+
50+
await for (final token in stream) {
51+
stdout.write(token);
52+
}
53+
await stdout.flush();
54+
stdout.writeln();
55+
} on LlamaException catch (e) {
56+
stderr.writeln("An error occurred: $e");
57+
} finally {
58+
llama.dispose();
59+
}
60+
}

example/test_vision.ocr.dart renamed to example/test_vision.radiology.dart

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import 'dart:io';
22
import 'package:llama_cpp_dart/llama_cpp_dart.dart';
3-
import 'package:llama_cpp_dart/src/llama_input.dart';
43

54
Future<void> main() async {
65
Llama.libraryPath = "bin/MAC_ARM64/libmtmd.dylib";
76

8-
final modelParams = ModelParams()..nGpuLayers = 99;
7+
final modelParams = ModelParams()..nGpuLayers = -1;
98

109
final contextParams = ContextParams()
11-
..nPredict = -1
10+
..nPredict = 512
1211
..nCtx = 8192
1312
..nBatch = 8192;
1413

@@ -19,27 +18,21 @@ Future<void> main() async {
1918
..penaltyRepeat = 1.1;
2019

2120
final llama = Llama(
22-
"/Users/adel/Workspace/gguf/gemma-3-4b-it-q4_0.gguf",
21+
"/Users/adel/Workspace/gguf/model-radiology-Q4_K_M.gguf",
2322
modelParams,
2423
contextParams,
2524
samplerParams,
2625
false,
27-
"/Users/adel/Workspace/gguf/mmproj-model-f16-4B.gguf");
28-
29-
final image = LlamaImage.fromFile(
30-
File("/Users/adel/Desktop/Screenshot 2025-06-30 at 23.35.12.png"));
31-
32-
var prompt = """<image> extract information in structured JSON
33-
{
34-
"country": "",
35-
"card_type": "",
36-
"date_of_expiry": "31/12/2000",
37-
"card_number": "",
38-
"holder_name": "",
39-
"holder_surname": "",
40-
"holder_date_of_birth": "31/12/2000"
41-
}
42-
""";
26+
"/Users/adel/Workspace/gguf/mmproj-radiology.gguf");
27+
28+
final image =
29+
LlamaImage.fromFile(File("/Users/adel/Downloads/radiology.png"));
30+
31+
final chat = ChatHistory();
32+
chat.addMessage(role: Role.user, content: """<image>
33+
You are an expert radiographer. Describe accurately what you see in this image.""");
34+
final prompt =
35+
chat.exportFormat(ChatFormat.gemini, leaveLastAssistantOpen: true);
4336

4437
final sw = Stopwatch()..start();
4538
try {

example/test_vision.smolvlm2.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:io';
22
import 'package:llama_cpp_dart/llama_cpp_dart.dart';
3-
import 'package:llama_cpp_dart/src/llama_input.dart';
43

54
Future<void> main() async {
65
Llama.libraryPath = "bin/MAC_ARM64/libmtmd.dylib";
@@ -14,15 +13,14 @@ Future<void> main() async {
1413
..topP = 0.90;
1514

1615
final llama = Llama(
17-
"/Users/adel/Workspace/gguf/SmolVLM-256M-Instruct-Q8_0.gguf",
16+
"/Users/adel/Workspace/gguf/SmolVLM-500M-Instruct-Q8_0.gguf",
1817
modelParams,
1918
contextParams,
2019
samplerParams,
2120
false,
22-
"/Users/adel/Workspace/gguf/mmproj-SmolVLM-256M-Instruct-Q8_0.gguf");
21+
"/Users/adel/Workspace/gguf/mmproj-SmolVLM-500M-Instruct-Q8_0.gguf");
2322

24-
final image =
25-
LlamaImage.fromFile(File("/Users/adel/Downloads/image (8).png"));
23+
final image = LlamaImage.fromFile(File("/Users/adel/Downloads/test.jpg"));
2624

2725
const prompt = '''
2826
[

0 commit comments

Comments
 (0)