]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
common : ensure llama_batch size does not exceed max size (#9668)
authormatiaslin <redacted>
Sun, 29 Sep 2024 12:25:00 +0000 (05:25 -0700)
committerGitHub <redacted>
Sun, 29 Sep 2024 12:25:00 +0000 (15:25 +0300)
A crash was observed when the number of tokens added to a batch exceeds
llama_batch size. An assertion in llama_batch_add was added to protect
against llama_batch size overflow.

common/common.cpp

index e2b8574bf77d7ad9e2c8b2a4bbd615276d4e915c..a0611f3d1734b228203821f129086408fb0d02a9 100644 (file)
@@ -1437,6 +1437,8 @@ void llama_batch_add(
                           llama_pos   pos,
     const std::vector<llama_seq_id> & seq_ids,
                                bool   logits) {
+    GGML_ASSERT(batch.seq_id[batch.n_tokens] && "llama_batch size exceeded");
+
     batch.token   [batch.n_tokens] = id;
     batch.pos     [batch.n_tokens] = pos;
     batch.n_seq_id[batch.n_tokens] = seq_ids.size();