]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
server : fix off-by-1 in server_tokens::size_up_to_pos() (#20279)
authorGeorgi Gerganov <redacted>
Mon, 9 Mar 2026 14:43:38 +0000 (16:43 +0200)
committerGitHub <redacted>
Mon, 9 Mar 2026 14:43:38 +0000 (16:43 +0200)
* server : fix off-by-1 in server_tokens::size_up_to_pos()

* cont : fix typo [no ci]

tools/server/server-common.cpp
tools/server/server-common.h
tools/server/server-context.cpp

index 13ea8c690f3067b20b72f3220af6ab618262b4b2..5b8895b341ef852d1c9be987c570f592f6f2eb52 100644 (file)
@@ -276,7 +276,7 @@ llama_pos server_tokens::pos_next(int64_t n_tokens) const {
 
 size_t server_tokens::size_up_to_pos(llama_pos max_pos) const {
     if (!has_mtmd) {
-        return std::min((size_t)(max_pos + 1), tokens.size());
+        return std::min((size_t)max_pos, tokens.size());
     }
 
     size_t idx = 0;
@@ -296,7 +296,7 @@ size_t server_tokens::size_up_to_pos(llama_pos max_pos) const {
             idx++;
         }
 
-        if (pos > max_pos) {
+        if (pos >= max_pos) {
             break;
         }
     }
index 4fb9e488dfdec6c6b3ab9fc86f4a42dfb59906da..a234541e199fd012f10e826c8e8eb666acd53614 100644 (file)
@@ -170,7 +170,7 @@ public:
     // the next position after n_tokens. if n_tokens < 0, return the next position after all tokens.
     llama_pos pos_next(int64_t n_tokens = -1) const;
 
-    // number of tokens with position <= max_pos
+    // number of tokens with position < max_pos
     size_t size_up_to_pos(llama_pos max_pos) const;
 
     const mtmd::input_chunk_ptr & find_chunk(size_t idx) const;
index b67190a469837936754ececb33be941c26579c61..33bec85c23fe51785e26ff8ce107a94c6e8ad469 100644 (file)
@@ -570,7 +570,7 @@ private:
     std::vector<server_slot> slots;
 
     int slots_debug = 0;
-    int n_empty_consequtive = 0;
+    int n_empty_consecutive = 0;
 
     std::unique_ptr<server_prompt_cache> prompt_cache;
 
@@ -2372,7 +2372,7 @@ private:
                                         } else {
                                             pos_next = std::min(pos_next, std::max(it->pos_min + 1, it->pos_max));
                                             n_past = std::min(slot.prompt.tokens.size_up_to_pos(pos_next), (size_t) it->n_tokens);
-                                            SLT_WRN(slot, "restored context checkpoint (pos_min = %d, pos_max = %d, n_tokens = %" PRId64 ", size = %.3f MiB)\n", it->pos_min, it->pos_max, it->n_tokens, (float) checkpoint_size / 1024 / 1024);
+                                            SLT_WRN(slot, "restored context checkpoint (pos_min = %d, pos_max = %d, n_tokens = %" PRId64 ", n_past = %d, size = %.3f MiB)\n", it->pos_min, it->pos_max, it->n_tokens, n_past, (float) checkpoint_size / 1024 / 1024);
                                         }
                                     }
 
@@ -2630,11 +2630,11 @@ private:
         if (batch.n_tokens == 0) {
             SRV_WRN("%s", "no tokens to decode\n");
 
-            if (++n_empty_consequtive > 3) {
+            if (++n_empty_consecutive > 3) {
                 GGML_ABORT("fatal error - please provide logs and repro in %s\n", "https://github.com/ggml-org/llama.cpp/pull/20277");
             }
         } else {
-            n_empty_consequtive = 0;
+            n_empty_consecutive = 0;
         }
 
         int32_t i_next = 0;