Skip to content

Commit bebf5d7

Browse files
committed
cont
1 parent 9836067 commit bebf5d7

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

Diff for: examples/batched.swift/Sources/main.swift

+9-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ guard let model = llama_load_model_from_file(modelPath.cString(using: .utf8), mo
2727
print("Failed to load model")
2828
exit(1)
2929
}
30-
3130
defer {
3231
llama_free_model(model)
3332
}
@@ -44,17 +43,23 @@ context_params.n_threads = 8
4443
context_params.n_threads_batch = 8
4544

4645
let context = llama_new_context_with_model(model, context_params)
47-
let smpl = llama_get_sampling(context)
48-
4946
guard context != nil else {
5047
print("Failed to initialize context")
5148
exit(1)
5249
}
53-
5450
defer {
5551
llama_free(context)
5652
}
5753

54+
let smpl = llama_sampling_init(model, nil, nil)
55+
guard smpl != nil else {
56+
print("Failed to initialize sampling")
57+
exit(1)
58+
}
59+
defer {
60+
llama_sampling_free(smpl)
61+
}
62+
5863
let n_ctx = llama_n_ctx(context)
5964

6065
print("\nn_len = \(n_len), n_ctx = \(n_ctx), n_batch = \(context_params.n_batch), n_parallel = \(n_parallel), n_kv_req = \(n_kv_req)\n")

Diff for: examples/llama.android/llama/src/main/cpp/llama-android.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,13 @@ Java_android_llama_cpp_LLamaAndroid_completion_1loop(
380380
JNIEnv * env,
381381
jobject,
382382
jlong context_pointer,
383+
jlong sampling_pointer,
383384
jlong batch_pointer,
384385
jint n_len,
385386
jobject intvar_ncur
386387
) {
387388
const auto context = reinterpret_cast<llama_context *>(context_pointer);
388-
const auto sampling = reinterpret_cast<llama_sampling *>(llama_get_sampling(context));
389+
const auto sampling = reinterpret_cast<llama_sampling *>(sampling_pointer);
389390
const auto batch = reinterpret_cast<llama_batch *>(batch_pointer);
390391
const auto model = llama_get_model(context);
391392

Diff for: examples/llama.swiftui/llama.cpp.swift/LibLlama.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ actor LlamaContext {
4343
self.tokens_list = []
4444
self.batch = llama_batch_init(512, 0, 1)
4545
self.temporary_invalid_cchars = []
46-
self.sampling = llama_get_sampling(context)
46+
self.sampling = llama_sampling_init(context, nil, nil);
4747
}
4848

4949
deinit {
50+
llama_sampling_free(sampling)
5051
llama_batch_free(batch)
5152
llama_free(context)
5253
llama_free_model(model)
53-
llama_sampling_free(sampling)
5454
llama_backend_free()
5555
}
5656

Diff for: include/llama.h

+1
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ extern "C" {
406406

407407
LLAMA_API void llama_free_model(struct llama_model * model);
408408

409+
// TODO: rename to llama_init_from_model
409410
LLAMA_API struct llama_context * llama_new_context_with_model(
410411
struct llama_model * model,
411412
struct llama_context_params params);

0 commit comments

Comments
 (0)