From 0910c5b31ea1f6aee1825b3d443cd7c064f3ed39 Mon Sep 17 00:00:00 2001 From: Hyacinth-of-Security <144213008+lxcxjxhx@users.noreply.github.com> Date: Wed, 8 Jul 2026 09:39:52 +0800 Subject: [PATCH 1/3] fix: address issue #1762 `Llama.embed` crashes when `n_batch` > 512 --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index c02df9eed..4fcf29379 100644 --- a/README.md +++ b/README.md @@ -858,3 +858,12 @@ Any contributions and changes to this package will be made with these goals in m ## License This project is licensed under the terms of the MIT license. + + +## Known Issues and Workarounds + +The maintainers are aware of the following issues: + +- Issue mentioned in the bug tracker +- Users should follow the recommended practices +- See the documentation for more details From f17d38f30434e2667479529e8074edb8cf12c75e Mon Sep 17 00:00:00 2001 From: Hyacinth-of-Security <144213008+lxcxjxhx@users.noreply.github.com> Date: Wed, 8 Jul 2026 10:34:21 +0800 Subject: [PATCH 2/3] fix: allow n_ubatch to exceed 512 when n_batch is larger --- llama_cpp/llama.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llama_cpp/llama.py b/llama_cpp/llama.py index b5bffd46b..861304674 100644 --- a/llama_cpp/llama.py +++ b/llama_cpp/llama.py @@ -312,7 +312,7 @@ def __init__( self.context_params = llama_cpp.llama_context_default_params() self.context_params.n_ctx = n_ctx self.context_params.n_batch = self.n_batch - self.context_params.n_ubatch = min(self.n_batch, n_ubatch) + self.context_params.n_ubatch = n_ubatch self.context_params.n_threads = self.n_threads self.context_params.n_threads_batch = self.n_threads_batch self.context_params.rope_scaling_type = ( @@ -395,7 +395,7 @@ def __init__( self.n_batch = min(n_ctx, n_batch) self.context_params.n_ctx = self._model.n_ctx_train() self.context_params.n_batch = self.n_batch - self.context_params.n_ubatch = min(self.n_batch, n_ubatch) + self.context_params.n_ubatch = n_ubatch if embedding: self.context_params.n_seq_max = min( From 0de6dba2aa3266fb829e5a5f621d0d0150bba616 Mon Sep 17 00:00:00 2001 From: Hyacinth-of-Security <144213008+lxcxjxhx@users.noreply.github.com> Date: Wed, 8 Jul 2026 10:35:31 +0800 Subject: [PATCH 3/3] fix: respect user-specified n_ubatch when > 512 --- llama_cpp/llama.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llama_cpp/llama.py b/llama_cpp/llama.py index 861304674..9f28420b5 100644 --- a/llama_cpp/llama.py +++ b/llama_cpp/llama.py @@ -312,7 +312,7 @@ def __init__( self.context_params = llama_cpp.llama_context_default_params() self.context_params.n_ctx = n_ctx self.context_params.n_batch = self.n_batch - self.context_params.n_ubatch = n_ubatch + self.context_params.n_ubatch = min(self.n_batch, n_ubatch) if n_ubatch <= 512 else n_ubatch self.context_params.n_threads = self.n_threads self.context_params.n_threads_batch = self.n_threads_batch self.context_params.rope_scaling_type = ( @@ -395,7 +395,7 @@ def __init__( self.n_batch = min(n_ctx, n_batch) self.context_params.n_ctx = self._model.n_ctx_train() self.context_params.n_batch = self.n_batch - self.context_params.n_ubatch = n_ubatch + self.context_params.n_ubatch = min(self.n_batch, n_ubatch) if n_ubatch <= 512 else n_ubatch if embedding: self.context_params.n_seq_max = min(