Skip to content

Commit

Permalink
Actually clear batch data and make dumping cache use the correct sequ…
Browse files Browse the repository at this point in the history
…ence ids
  • Loading branch information
AutonomicPerfectionist committed Jan 10, 2024
1 parent 810a803 commit d23ab1d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,15 @@ struct llama_context_params llama_context_params_from_gpt_params(const gpt_param
}

void llama_batch_clear(struct llama_batch & batch) {
for (int token = 0; token < batch.n_tokens; token++) {
batch.token[token] = 0;
batch.pos[token] = -1;
batch.logits[token] = false;
for (int seq_id = 0; seq_id < batch.n_seq_id[token]; seq_id++) {
batch.seq_id[token][seq_id] = 0;
}
batch.n_seq_id[token] = 0;
}
batch.n_tokens = 0;
}

Expand Down Expand Up @@ -1621,7 +1630,7 @@ void dump_kv_cache_view(const llama_kv_cache_view & view, int row_size) {
for (int j = 0; j < view.n_max_seq; j++) {
if (cs_curr[j] >= 0) { seq_count++; }
}
putchar(slot_chars[std::min(sizeof(slot_chars) - 2, size_t(seq_count))]);
printf("%4d ",c_curr->pos);
}

printf("\n=== Done dumping\n");
Expand All @@ -1642,7 +1651,7 @@ void dump_kv_cache_view_seqs(const llama_kv_cache_view & view, int row_size) {
if (cs_curr[j] < 0) { continue; }
if (seqs.find(cs_curr[j]) == seqs.end()) {
if (seqs.size() + 1 >= sizeof(slot_chars)) { break; }
seqs[cs_curr[j]] = seqs.size();
seqs[cs_curr[j]] = cs_curr[j];
}
}
if (seqs.size() + 1 >= sizeof(slot_chars)) { break; }
Expand All @@ -1668,7 +1677,8 @@ void dump_kv_cache_view_seqs(const llama_kv_cache_view & view, int row_size) {
putchar('.');
}
}
putchar(' ');
printf(" (%d) ", c_curr->pos);
//putchar(' ');
}

printf("\n=== Done dumping\n");
Expand Down

0 comments on commit d23ab1d

Please sign in to comment.