Skip to content

Commit f3bca29

Browse files
ggerganovMinh141120
authored andcommitted
batch : fix check for empty sequences in memory (ggml-org#14364)
* batch : fix check for empty sequences in memory ggml-ci * cont : reuse the var ggml-ci
1 parent e7e42a6 commit f3bca29

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/llama-batch.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,21 @@ bool llama_batch_allocr::init(
250250
continue;
251251
}
252252

253-
if (memory) {
253+
const llama_pos p0 = memory ? memory->seq_pos_max(s) : -1;
254+
255+
if (p0 >= 0) {
254256
bool ok = true;
255257

256258
if (batch.token) {
257-
if (seq_pos_min(s) != memory->seq_pos_max(s) + 1) {
259+
if (seq_pos_min(s) != p0 + 1) {
258260
ok = false;
259261
}
260262
} else {
261263
assert(batch.embd);
262264

263265
// for embeddings (typically used as vision input), we allow them to have repeating positions
264266
// ref: https://github.com/ggml-org/llama.cpp/issues/13694#issuecomment-2983871762
265-
if (seq_pos_min(s) != memory->seq_pos_max(s) && seq_pos_min(s) != memory->seq_pos_max(s) + 1) {
267+
if (seq_pos_min(s) != p0 && seq_pos_min(s) != p0 + 1) {
266268
ok = false;
267269
}
268270
}
@@ -273,7 +275,7 @@ bool llama_batch_allocr::init(
273275
" - the last position stored in the memory module of the context (i.e. the KV cache) for sequence %d is X = %d\n"
274276
" - the tokens for sequence %d in the input batch have a starting position of Y = %d\n"
275277
" it is required that the sequence positions remain consecutive: Y = X + 1\n",
276-
__func__, s, s, memory->seq_pos_max(s), s, seq_pos_min(s));
278+
__func__, s, s, p0, s, seq_pos_min(s));
277279

278280
return false;
279281
}

0 commit comments

Comments
 (0)