Skip to content

Commit a5d27aa

Browse files
committed
server : fix server_tokens clear()
1 parent 4e9e319 commit a5d27aa

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

tools/server/server.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,8 +3946,11 @@ struct server_context {
39463946

39473947
// truncate any tokens that are beyond n_past for this slot
39483948
const llama_pos p0 = slot.prompt.tokens.pos_next();
3949+
3950+
SLT_INF(slot, "n_tokens = %d, memory_seq_rm [%d, end)\n", slot.prompt.n_tokens(), p0);
3951+
39493952
if (!llama_memory_seq_rm(llama_get_memory(ctx), slot.id, p0, -1)) {
3950-
SLT_WRN(slot, "failed to truncate tokens with position >= %d\n", p0);
3953+
SLT_WRN(slot, "failed to truncate tokens with position >= %d - clearing the memory\n", p0);
39513954
llama_memory_seq_rm(llama_get_memory(ctx), slot.id, -1, -1);
39523955

39533956
// there is no common part left
@@ -3956,8 +3959,6 @@ struct server_context {
39563959
slot.prompt.tokens.clear();
39573960
}
39583961

3959-
SLT_INF(slot, "n_tokens = %d, memory_seq_rm [%d, end)\n", slot.prompt.n_tokens(), p0);
3960-
39613962
// check if we should process the image
39623963
if (slot.prompt.n_tokens() < slot.task->n_tokens() && input_tokens[slot.prompt.n_tokens()] == LLAMA_TOKEN_NULL) {
39633964
// process the image

tools/server/utils.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ struct server_tokens {
12101210
for (auto it = tokens.map_idx_to_media.begin(); it != tokens.map_idx_to_media.end(); ) {
12111211
auto * chunk = tokens.map_idx_to_media[it->first].get();
12121212
mtmd::input_chunk_ptr new_chunk(mtmd_input_chunk_copy(chunk));
1213-
map_idx_to_media[start_idx+it->first] = std::move(new_chunk);
1213+
map_idx_to_media[start_idx + it->first] = std::move(new_chunk);
12141214
}
12151215
}
12161216
}
@@ -1242,6 +1242,7 @@ struct server_tokens {
12421242
}
12431243

12441244
void clear() {
1245+
map_idx_to_media.clear();
12451246
tokens.clear();
12461247
}
12471248

0 commit comments

Comments
 (0)