Skip to content

Commit d7f5f4e

Browse files
authored
simple-chat : fix context-exceeded condition (#14494)
* simple-chat : fix context-exceeded condition ggml-ci * cont : fix n_ctx_used computation ggml-ci
1 parent c8a4e47 commit d7f5f4e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

examples/simple-chat/simple-chat.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,16 @@ int main(int argc, char ** argv) {
113113
while (true) {
114114
// check if we have enough space in the context to evaluate this batch
115115
int n_ctx = llama_n_ctx(ctx);
116-
int n_ctx_used = llama_memory_seq_pos_max(llama_get_memory(ctx), 0);
116+
int n_ctx_used = llama_memory_seq_pos_max(llama_get_memory(ctx), 0) + 1;
117117
if (n_ctx_used + batch.n_tokens > n_ctx) {
118118
printf("\033[0m\n");
119119
fprintf(stderr, "context size exceeded\n");
120120
exit(0);
121121
}
122122

123-
if (llama_decode(ctx, batch)) {
124-
GGML_ABORT("failed to decode\n");
123+
int ret = llama_decode(ctx, batch);
124+
if (ret != 0) {
125+
GGML_ABORT("failed to decode, ret = %d\n", ret);
125126
}
126127

127128
// sample the next token

0 commit comments

Comments
 (0)