Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/llama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21139,6 +21139,10 @@ struct llama_batch_allocr {
// optionally fulfill the batch returned by llama_batch_get_one
llama_batch_allocr(struct llama_context * ctx, struct llama_batch in_batch) {
batch = in_batch;
if (batch.n_tokens == 0) {
// llama_(de|en)code_internal will return an error in this case
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My experience is that constructors should be as simple as possible and avoid branches if possible since they can leave the object in partially initialized state without a way to handle this. Suggest to replace this block with assert() and move llama_batch_allocr from llama_encode/llama_decode to llama_..._internal after the empty batch check.

if (!batch.pos) {
// determine the last position in KV cache
llama_pos last_pos = -1;
Expand Down
Loading