Skip to content

Commit 2aa777d

Browse files
authored
examples : switch retrieval to llama_encode (#13685)
* switch retrieval to llama_encode * enable --no-warmup for retrieval
1 parent eb0f5c2 commit 2aa777d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

common/arg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
16781678
[](common_params & params) {
16791679
params.warmup = false;
16801680
}
1681-
).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_EMBEDDING}));
1681+
).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_EMBEDDING, LLAMA_EXAMPLE_RETRIEVAL}));
16821682
add_opt(common_arg(
16831683
{"--spm-infill"},
16841684
string_format(

examples/retrieval/retrieval.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ static void batch_add_seq(llama_batch & batch, const std::vector<int32_t> & toke
8181
}
8282
}
8383

84-
static void batch_decode(llama_context * ctx, llama_batch & batch, float * output, int n_seq, int n_embd) {
84+
static void batch_encode(llama_context * ctx, llama_batch & batch, float * output, int n_seq, int n_embd) {
8585
// clear previous kv_cache values (irrelevant for embeddings)
8686
llama_kv_self_clear(ctx);
8787

8888
// run model
8989
LOG_INF("%s: n_tokens = %d, n_seq = %d\n", __func__, batch.n_tokens, n_seq);
90-
if (llama_decode(ctx, batch) < 0) {
91-
LOG_ERR("%s : failed to decode\n", __func__);
90+
if (llama_encode(ctx, batch) < 0) {
91+
LOG_ERR("%s : failed to encode\n", __func__);
9292
}
9393

9494
for (int i = 0; i < batch.n_tokens; i++) {
@@ -233,7 +233,7 @@ int main(int argc, char ** argv) {
233233
// encode if at capacity
234234
if (batch.n_tokens + n_toks > n_batch) {
235235
float * out = emb + p * n_embd;
236-
batch_decode(ctx, batch, out, s, n_embd);
236+
batch_encode(ctx, batch, out, s, n_embd);
237237
common_batch_clear(batch);
238238
p += s;
239239
s = 0;
@@ -246,7 +246,7 @@ int main(int argc, char ** argv) {
246246

247247
// final batch
248248
float * out = emb + p * n_embd;
249-
batch_decode(ctx, batch, out, s, n_embd);
249+
batch_encode(ctx, batch, out, s, n_embd);
250250

251251
// save embeddings to chunks
252252
for (int i = 0; i < n_chunks; i++) {
@@ -267,7 +267,7 @@ int main(int argc, char ** argv) {
267267
batch_add_seq(query_batch, query_tokens, 0);
268268

269269
std::vector<float> query_emb(n_embd, 0);
270-
batch_decode(ctx, query_batch, query_emb.data(), 1, n_embd);
270+
batch_encode(ctx, query_batch, query_emb.data(), 1, n_embd);
271271

272272
common_batch_clear(query_batch);
273273

0 commit comments

Comments
 (0)