05-embeddings.diff 1.88 KB
Newer Older
1
diff --git a/src/llama.cpp b/src/llama.cpp
2
index 4c0a1bb6..17e5bc2a 100644
3
4
--- a/src/llama.cpp
+++ b/src/llama.cpp
5
@@ -16928,7 +16928,7 @@ static size_t llama_output_reserve(llama_context & lctx, size_t n_outputs) {
6
     const auto n_embd  = hparams.n_embd;
7

8
9
10
11
     // TODO: use a per-batch flag for logits presence instead
-    const bool has_logits = !cparams.embeddings;
+    const bool has_logits =  cparams.causal_attn;
     const bool has_embd   =  cparams.embeddings && (cparams.pooling_type == LLAMA_POOLING_TYPE_NONE);
12

13
     const size_t logits_size = has_logits ? n_vocab*n_outputs_max : 0;
14
@@ -17200,20 +17200,23 @@ static int llama_decode_internal(
15
16
17
18
19
20
             // no output
             res  = nullptr;
             embd = nullptr;
-        } else if (cparams.embeddings) {
-            res  = nullptr; // do not extract logits for embedding case
-            embd = nullptr;
21
-            for (int i = ggml_graph_n_nodes(gf) - 1; i >= 0; --i) {
22
23
24
+        }
+
+        if (cparams.embeddings) {
25
26
27
28
+            for (int i = ggml_graph_n_nodes(gf) - 1; i >= 0; --i) {
+                embd = ggml_graph_node(gf, i);
                 if (strcmp(ggml_graph_node(gf, i)->name, "result_embd_pooled") == 0) {
-                    embd = ggml_graph_node(gf, i);
29
30
31
32
33
34
35
36
37
38
39
40
41
                     break;
                 }
             }
-            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");
         }
+
+        if (!cparams.causal_attn) {
+            res = nullptr; // do not extract logits when not needed
+        }
         // LLAMA_LOG_INFO("graph build time: %.3f ms (%d nodes, %d leafs)\n", (ggml_time_us() - t_start_us)/1000.0, gf->n_nodes, gf->n_leafs);
42

43
         ggml_backend_sched_alloc_graph(lctx.sched, gf);