From d173ddac9e7c78567d7b279a6c7a8a74ddad9c7a Mon Sep 17 00:00:00 2001 From: marcus Date: Tue, 19 Dec 2023 15:06:49 -0800 Subject: [PATCH 1/4] allowed getting n_batch from llama_context in c api --- llama.cpp | 4 ++++ llama.h | 1 + 2 files changed, 5 insertions(+) diff --git a/llama.cpp b/llama.cpp index edd2910b3ad29..f8a540773ce21 100644 --- a/llama.cpp +++ b/llama.cpp @@ -9536,6 +9536,10 @@ int llama_n_ctx(const struct llama_context * ctx) { return ctx->cparams.n_ctx; } +int llama_n_batch(const struct llama_context * ctx) { + return ctx->cparams.n_batch; +} + enum llama_vocab_type llama_vocab_type(const struct llama_model * model) { return model->vocab.type; } diff --git a/llama.h b/llama.h index 15ab4f80e2334..62f02260db280 100644 --- a/llama.h +++ b/llama.h @@ -315,6 +315,7 @@ extern "C" { LLAMA_API const struct llama_model * llama_get_model(const struct llama_context * ctx); LLAMA_API int llama_n_ctx (const struct llama_context * ctx); + LLAMA_API int llama_n_batch (const struct llama_context * ctx); LLAMA_API enum llama_vocab_type llama_vocab_type(const struct llama_model * model); From 9b57750b69ce86cd9179fd034fc8ee11df55842b Mon Sep 17 00:00:00 2001 From: marcus Date: Tue, 19 Dec 2023 15:19:26 -0800 Subject: [PATCH 2/4] changed to use `uint32_t` instead of `int` --- llama.cpp | 2 +- llama.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/llama.cpp b/llama.cpp index f8a540773ce21..c84292ca99599 100644 --- a/llama.cpp +++ b/llama.cpp @@ -9536,7 +9536,7 @@ int llama_n_ctx(const struct llama_context * ctx) { return ctx->cparams.n_ctx; } -int llama_n_batch(const struct llama_context * ctx) { +uint32_t llama_n_batch(const struct llama_context * ctx) { return ctx->cparams.n_batch; } diff --git a/llama.h b/llama.h index 62f02260db280..9c9e9f970f224 100644 --- a/llama.h +++ b/llama.h @@ -315,7 +315,7 @@ extern "C" { LLAMA_API const struct llama_model * llama_get_model(const struct llama_context * ctx); LLAMA_API int llama_n_ctx (const struct llama_context * ctx); - LLAMA_API int llama_n_batch (const struct llama_context * ctx); + LLAMA_API uint32_t llama_n_batch (const struct llama_context * ctx); LLAMA_API enum llama_vocab_type llama_vocab_type(const struct llama_model * model); From e4c510441e678c31b0a0f9f4ac458fdfb83e8a23 Mon Sep 17 00:00:00 2001 From: marcus Date: Tue, 19 Dec 2023 15:20:28 -0800 Subject: [PATCH 3/4] changed to use `uint32_t` instead of `int` in `llama_n_ctx` --- llama.cpp | 2 +- llama.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/llama.cpp b/llama.cpp index c84292ca99599..e2409475babda 100644 --- a/llama.cpp +++ b/llama.cpp @@ -9532,7 +9532,7 @@ const llama_model * llama_get_model(const struct llama_context * ctx) { return &ctx->model; } -int llama_n_ctx(const struct llama_context * ctx) { +uint32_t llama_n_ctx(const struct llama_context * ctx) { return ctx->cparams.n_ctx; } diff --git a/llama.h b/llama.h index 9c9e9f970f224..d43cfc953eae8 100644 --- a/llama.h +++ b/llama.h @@ -314,7 +314,7 @@ extern "C" { LLAMA_API const struct llama_model * llama_get_model(const struct llama_context * ctx); - LLAMA_API int llama_n_ctx (const struct llama_context * ctx); + LLAMA_API uint32_t llama_n_ctx (const struct llama_context * ctx); LLAMA_API uint32_t llama_n_batch (const struct llama_context * ctx); LLAMA_API enum llama_vocab_type llama_vocab_type(const struct llama_model * model); From 74d109bebc029db047c417f1b8c62e2a44a52c00 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Thu, 21 Dec 2023 21:57:32 +0200 Subject: [PATCH 4/4] Update llama.h --- llama.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llama.h b/llama.h index d43cfc953eae8..0be4b1337b963 100644 --- a/llama.h +++ b/llama.h @@ -314,6 +314,7 @@ extern "C" { LLAMA_API const struct llama_model * llama_get_model(const struct llama_context * ctx); + // TODO: become more consistent with returned int types across the API LLAMA_API uint32_t llama_n_ctx (const struct llama_context * ctx); LLAMA_API uint32_t llama_n_batch (const struct llama_context * ctx);