From 46ad54fee45df9d4d5e3fb461e43b8bf6c10e14f Mon Sep 17 00:00:00 2001 From: Marcus Dunn Date: Fri, 19 Jan 2024 00:23:52 +0000 Subject: [PATCH 1/2] updated llama.cpp --- llama-cpp-sys-2/llama.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llama-cpp-sys-2/llama.cpp b/llama-cpp-sys-2/llama.cpp index 5c999609..57e2a7a5 160000 --- a/llama-cpp-sys-2/llama.cpp +++ b/llama-cpp-sys-2/llama.cpp @@ -1 +1 @@ -Subproject commit 5c999609013a30c06e6fd28be8db5c2074bcc196 +Subproject commit 57e2a7a52a819883f40dada8a2edc24ecf48186b From bfbbf0faa986d014babbd415315359a58106bb0f Mon Sep 17 00:00:00 2001 From: marcus Date: Fri, 19 Jan 2024 14:29:00 -0800 Subject: [PATCH 2/2] added `cb_eval` & `cb_eval_user_data` to context_params. --- llama-cpp-2/examples/simple.rs | 2 +- llama-cpp-2/src/context/params.rs | 14 ++++++++++++-- llama-cpp-2/src/model.rs | 10 +++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/llama-cpp-2/examples/simple.rs b/llama-cpp-2/examples/simple.rs index 1188751c..21197659 100644 --- a/llama-cpp-2/examples/simple.rs +++ b/llama-cpp-2/examples/simple.rs @@ -62,7 +62,7 @@ fn main() -> Result<()> { ..LlamaContextParams::default() }; - let mut ctx = model.new_context(&backend, &ctx_params) + let mut ctx = model.new_context(&backend, ctx_params) .with_context(|| "unable to create the llama_context")?; // tokenize the prompt diff --git a/llama-cpp-2/src/context/params.rs b/llama-cpp-2/src/context/params.rs index a5a80978..2352c548 100644 --- a/llama-cpp-2/src/context/params.rs +++ b/llama-cpp-2/src/context/params.rs @@ -43,7 +43,7 @@ impl From for i8 { } /// A safe wrapper around `llama_context_params`. -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, PartialEq)] #[allow( missing_docs, clippy::struct_excessive_bools, @@ -71,6 +71,8 @@ pub struct LlamaContextParams { pub logits_all: bool, pub embedding: bool, pub offload_kqv: bool, + pub cb_eval: llama_cpp_sys_2::ggml_backend_sched_eval_callback, + pub cb_eval_user_data: *mut std::ffi::c_void, } /// Default parameters for `LlamaContext`. (as defined in llama.cpp by `llama_context_default_params`) @@ -97,6 +99,8 @@ impl From for LlamaContextParams { n_threads_batch, rope_freq_base, rope_freq_scale, + cb_eval, + cb_eval_user_data, type_k, type_v, mul_mat_q, @@ -131,6 +135,8 @@ impl From for LlamaContextParams { yarn_beta_slow, yarn_orig_ctx, offload_kqv, + cb_eval, + cb_eval_user_data, } } } @@ -157,6 +163,8 @@ impl From for llama_context_params { yarn_beta_slow, yarn_orig_ctx, offload_kqv, + cb_eval, + cb_eval_user_data, }: LlamaContextParams, ) -> Self { llama_context_params { @@ -179,6 +187,8 @@ impl From for llama_context_params { yarn_beta_slow, yarn_orig_ctx, offload_kqv, + cb_eval, + cb_eval_user_data, } } -} +} \ No newline at end of file diff --git a/llama-cpp-2/src/model.rs b/llama-cpp-2/src/model.rs index f790e98a..50584453 100644 --- a/llama-cpp-2/src/model.rs +++ b/llama-cpp-2/src/model.rs @@ -309,12 +309,12 @@ impl LlamaModel { /// # Errors /// /// There is many ways this can fail. See [`LlamaContextLoadError`] for more information. - pub fn new_context<'a>( - &'a self, + pub fn new_context( + &self, _: &LlamaBackend, - params: &LlamaContextParams, - ) -> Result, LlamaContextLoadError> { - let context_params = llama_context_params::from(*params); + params: LlamaContextParams, + ) -> Result { + let context_params = llama_context_params::from(params); let context = unsafe { llama_cpp_sys_2::llama_new_context_with_model(self.model.as_ptr(), context_params) };