Skip to content

Commit 0afa563

Browse files
huydt84huydt-bti
authored andcommitted
add geglu activation function (ggml-org#14074)
Co-authored-by: dinhhuy <huy.dinh@brains-tech.co.jp>
1 parent 05322ab commit 0afa563

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/llama-graph.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,28 @@ ggml_tensor * llm_graph_context::build_ffn(
613613
cur = ggml_reglu(ctx0, cur);
614614
cb(cur, "ffn_reglu", il);
615615
} break;
616+
case LLM_FFN_GEGLU:
617+
{
618+
// Split into two equal parts
619+
int64_t split_point = cur->ne[0] / 2;
620+
ggml_tensor * output_ffn_up = ggml_cont(ctx0, ggml_view_2d(
621+
ctx0, cur, split_point,
622+
cur->ne[1], cur->nb[1], 0
623+
));
624+
ggml_tensor * output_ffn_gate = ggml_cont(ctx0, ggml_view_2d(
625+
ctx0, cur, split_point,
626+
cur->ne[1], cur->nb[1],
627+
split_point * ggml_element_size(cur)
628+
));
629+
630+
// Apply GELU activation function to the first part
631+
output_ffn_up = ggml_gelu(ctx0, output_ffn_up);
632+
cb(output_ffn_up, "ffn_gelu", il);
633+
634+
// Element-wise multiplication between the activated part and the gate part
635+
cur = ggml_mul(ctx0, output_ffn_up, output_ffn_gate);
636+
cb(cur, "ffn_geglu", il);
637+
} break;
616638
}
617639

618640
if (gate && type_gate == LLM_FFN_PAR) {

src/llama-graph.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ enum llm_ffn_op_type {
3838
LLM_FFN_RELU_SQR,
3939
LLM_FFN_SWIGLU,
4040
LLM_FFN_GEGLU,
41-
LLM_FFN_REGLU,
4241
};
4342

4443
enum llm_ffn_gate_type {

0 commit comments

Comments
 (0)