From: fairydreaming Date: Sun, 11 Aug 2024 08:35:26 +0000 (+0200) Subject: llama : check all graph nodes when searching for result_embd_pooled (#8956) X-Git-Tag: upstream/0.0.4488~920 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=33309f661a93c9c0ab65a79e5e7e30fa6162992e;p=pkg%2Fggml%2Fsources%2Fllama.cpp llama : check all graph nodes when searching for result_embd_pooled (#8956) Co-authored-by: Stanisław Szymczyk --- diff --git a/src/llama.cpp b/src/llama.cpp index e0fe8013..aaf8db49 100644 --- a/src/llama.cpp +++ b/src/llama.cpp @@ -14722,12 +14722,15 @@ static int llama_decode_internal( res = nullptr; embd = nullptr; } else if (cparams.embeddings) { - res = nullptr; // do not extract logits for embedding case - embd = gf->nodes[gf->n_nodes - 1]; - if (strcmp(embd->name, "result_embd_pooled") != 0) { - embd = gf->nodes[gf->n_nodes - 2]; + res = nullptr; // do not extract logits for embedding case + embd = nullptr; + for (int i = gf->n_nodes - 1; i >= 0; --i) { + if (strcmp(gf->nodes[i]->name, "result_embd_pooled") == 0) { + embd = gf->nodes[i]; + break; + } } - GGML_ASSERT(strcmp(embd->name, "result_embd_pooled") == 0 && "missing embeddings tensor"); + GGML_ASSERT(embd != nullptr && "missing embeddings tensor"); } else { embd = nullptr; // do not extract embeddings when not needed GGML_ASSERT(strcmp(res->name, "result_output") == 0 && "missing result_output tensor");