Skip to content

Commit 25f40ca

Browse files
authored
completion : simplify batch (embd) processing (ggml-org#19286)
* completion : simplify batch (embd) processing This commit simplifies the processing of embd by removing the for loop that currently exists which uses params.n_batch as its increment. This commit also removes the clamping of n_eval as the size of embd is always at most the size of params.n_batch. The motivation is to clarify the code as it is currently a little confusing when looking at this for loop in isolation and thinking that it can process multiple batches. * add an assert to verify n_eval is not greater than n_batch
1 parent 015deb9 commit 25f40ca

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

tools/completion/completion.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -674,15 +674,12 @@ int main(int argc, char ** argv) {
674674
}
675675
}
676676

677-
for (int i = 0; i < (int) embd.size(); i += params.n_batch) {
678-
int n_eval = (int) embd.size() - i;
679-
if (n_eval > params.n_batch) {
680-
n_eval = params.n_batch;
681-
}
682-
677+
if (!embd.empty()) {
678+
int n_eval = (int) embd.size();
683679
LOG_DBG("eval: %s\n", string_from(ctx, embd).c_str());
684680

685-
if (llama_decode(ctx, llama_batch_get_one(&embd[i], n_eval))) {
681+
GGML_ASSERT(n_eval <= params.n_batch);
682+
if (llama_decode(ctx, llama_batch_get_one(embd.data(), n_eval))) {
686683
LOG_ERR("%s : failed to eval\n", __func__);
687684
return 1;
688685
}
@@ -743,7 +740,7 @@ int main(int argc, char ** argv) {
743740
common_sampler_accept(smpl, embd_inp[n_consumed], /* accept_grammar= */ false);
744741

745742
++n_consumed;
746-
if ((int) embd.size() >= params.n_batch) {
743+
if ((int) embd.size() == params.n_batch) {
747744
break;
748745
}
749746
}

0 commit comments

Comments
 (0)