Skip to content

Commit d8931a7

Browse files
committed
llama.android : update to new API
ggml-ci
1 parent 330bd07 commit d8931a7

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

examples/batched.swift/Sources/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ defer {
2323
}
2424

2525
let model_params = llama_model_default_params()
26-
guard let model = llama_load_model_from_file(modelPath.cString(using: .utf8), model_params) else {
26+
guard let model = llama_model_load_from_file(modelPath.cString(using: .utf8), model_params) else {
2727
print("Failed to load model")
2828
exit(1)
2929
}
3030
defer {
31-
llama_free_model(model)
31+
llama_model_free(model)
3232
}
3333

3434
var tokens = tokenize(text: prompt, add_bos: true)

examples/llama.android/llama/src/main/cpp/llama-android.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Java_android_llama_cpp_LLamaAndroid_load_1model(JNIEnv *env, jobject, jstring fi
8787
auto path_to_model = env->GetStringUTFChars(filename, 0);
8888
LOGi("Loading model from %s", path_to_model);
8989

90-
auto model = llama_load_model_from_file(path_to_model, model_params);
90+
auto model = llama_model_load_from_file(path_to_model, model_params);
9191
env->ReleaseStringUTFChars(filename, path_to_model);
9292

9393
if (!model) {
@@ -102,7 +102,7 @@ Java_android_llama_cpp_LLamaAndroid_load_1model(JNIEnv *env, jobject, jstring fi
102102
extern "C"
103103
JNIEXPORT void JNICALL
104104
Java_android_llama_cpp_LLamaAndroid_free_1model(JNIEnv *, jobject, jlong model) {
105-
llama_free_model(reinterpret_cast<llama_model *>(model));
105+
llama_model_free(reinterpret_cast<llama_model *>(model));
106106
}
107107

108108
extern "C"
@@ -405,6 +405,7 @@ Java_android_llama_cpp_LLamaAndroid_completion_1loop(
405405
const auto batch = reinterpret_cast<llama_batch *>(batch_pointer);
406406
const auto sampler = reinterpret_cast<llama_sampler *>(sampler_pointer);
407407
const auto model = llama_get_model(context);
408+
const auto vocab = llama_get_vocab(model);
408409

409410
if (!la_int_var) la_int_var = env->GetObjectClass(intvar_ncur);
410411
if (!la_int_var_value) la_int_var_value = env->GetMethodID(la_int_var, "getValue", "()I");
@@ -414,7 +415,7 @@ Java_android_llama_cpp_LLamaAndroid_completion_1loop(
414415
const auto new_token_id = llama_sampler_sample(sampler, context, -1);
415416

416417
const auto n_cur = env->CallIntMethod(intvar_ncur, la_int_var_value);
417-
if (llama_token_is_eog(model, new_token_id) || n_cur == n_len) {
418+
if (llama_token_is_eog(vocab, new_token_id) || n_cur == n_len) {
418419
return nullptr;
419420
}
420421

examples/llama.swiftui/llama.cpp.swift/LibLlama.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ actor LlamaContext {
5252
deinit {
5353
llama_sampler_free(sampling)
5454
llama_batch_free(batch)
55+
llama_model_free(model)
5556
llama_free(context)
56-
llama_free_model(model)
5757
llama_backend_free()
5858
}
5959

@@ -65,7 +65,7 @@ actor LlamaContext {
6565
model_params.n_gpu_layers = 0
6666
print("Running on simulator, force use n_gpu_layers = 0")
6767
#endif
68-
let model = llama_load_model_from_file(path, model_params)
68+
let model = llama_model_load_from_file(path, model_params)
6969
guard let model else {
7070
print("Could not load model at \(path)")
7171
throw LlamaError.couldNotInitializeContext

tests/test-tokenizer-random.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(self, libllama: LibLlama, path_model: str, mparams={}, cparams={}):
7676
self.ffi = libllama.ffi
7777
if isinstance(mparams, dict):
7878
mparams = libllama.model_default_params(**mparams)
79-
self.model = self.lib.llama_load_model_from_file(path_model.encode(), mparams)
79+
self.model = self.lib.llama_model_load_from_file(path_model.encode(), mparams)
8080
if not self.model:
8181
raise RuntimeError("error: failed to load model '%s'" % path_model)
8282
if isinstance(cparams, dict):
@@ -92,7 +92,7 @@ def free(self):
9292
if self.ctx:
9393
self.lib.llama_free(self.ctx)
9494
if self.model:
95-
self.lib.llama_free_model(self.model)
95+
self.lib.llama_model_free(self.model)
9696
self.ctx = None
9797
self.model = None
9898
self.lib = None

0 commit comments

Comments
 (0)