]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
add geglu activation function (#14074)
authorĐinh Trọng Huy <redacted>
Mon, 9 Jun 2025 04:15:31 +0000 (13:15 +0900)
committerGitHub <redacted>
Mon, 9 Jun 2025 04:15:31 +0000 (05:15 +0100)
Co-authored-by: dinhhuy <redacted>
src/llama-graph.cpp
src/llama-graph.h

index c4bdd6603927754b9377b2691e852dffc7098235..55390d42e72caa0e70ec779b0040aa99cfaf1df2 100644 (file)
@@ -659,6 +659,28 @@ ggml_tensor * llm_graph_context::build_ffn(
                 cur = ggml_mul(ctx0, x0, x1);
                 cb(cur, "ffn_mul", il);
             } break;
+        case LLM_FFN_GEGLU:
+            {
+                // Split into two equal parts
+                int64_t split_point = cur->ne[0] / 2;
+                ggml_tensor * output_ffn_up = ggml_cont(ctx0, ggml_view_2d(
+                                                ctx0, cur, split_point,
+                                                cur->ne[1], cur->nb[1], 0
+                                            ));
+                ggml_tensor * output_ffn_gate = ggml_cont(ctx0, ggml_view_2d(
+                                                ctx0, cur, split_point,
+                                                cur->ne[1], cur->nb[1],
+                                                split_point * ggml_element_size(cur)
+                                            ));
+
+                // Apply GELU activation function to the first part
+                output_ffn_up = ggml_gelu(ctx0, output_ffn_up);
+                cb(output_ffn_up, "ffn_gelu", il);
+
+                // Element-wise multiplication between the activated part and the gate part
+                cur = ggml_mul(ctx0, output_ffn_up, output_ffn_gate);
+                cb(cur, "ffn_geglu", il);
+            } break;
     }
 
     if (gate && type_gate == LLM_FFN_PAR) {
index 2b1cfa5b7e2e778021c06a19c271e70248c88e78..28da6a5228bdcbb928d2d16c8da1e2a6bce7b027 100644 (file)
@@ -36,6 +36,7 @@ enum llm_ffn_op_type {
     LLM_FFN_RELU,
     LLM_FFN_RELU_SQR,
     LLM_FFN_SWIGLU,
+    LLM_FFN_GEGLU,
 };
 
 enum llm_ffn_gate_type {