@@ -989,9 +989,11 @@ static const char * GGML_OP_NAME[GGML_OP_COUNT] = {
989989 "CROSS_ENTROPY_LOSS" ,
990990 "CROSS_ENTROPY_LOSS_BACK" ,
991991 "OPT_STEP_ADAMW" ,
992+
993+ "GLU" ,
992994};
993995
994- static_assert (GGML_OP_COUNT == 82 , "GGML_OP_COUNT != 82 " );
996+ static_assert (GGML_OP_COUNT == 83 , "GGML_OP_COUNT != 83 " );
995997
996998static const char * GGML_OP_SYMBOL [GGML_OP_COUNT ] = {
997999 "none" ,
@@ -1084,9 +1086,11 @@ static const char * GGML_OP_SYMBOL[GGML_OP_COUNT] = {
10841086 "cross_entropy_loss(x,y)" ,
10851087 "cross_entropy_loss_back(x,y)" ,
10861088 "adamw(x)" ,
1089+
1090+ "glu(x)" ,
10871091};
10881092
1089- static_assert (GGML_OP_COUNT == 82 , "GGML_OP_COUNT != 82 " );
1093+ static_assert (GGML_OP_COUNT == 83 , "GGML_OP_COUNT != 83 " );
10901094
10911095static_assert (GGML_OP_POOL_COUNT == 2 , "GGML_OP_POOL_COUNT != 2" );
10921096
@@ -1107,12 +1111,18 @@ static const char * GGML_UNARY_OP_NAME[GGML_UNARY_OP_COUNT] = {
11071111 "HARDSIGMOID" ,
11081112 "EXP" ,
11091113 "GELU_ERF" ,
1114+ };
1115+
1116+ static_assert (GGML_UNARY_OP_COUNT == 15 , "GGML_UNARY_OP_COUNT != 15" );
1117+
1118+
1119+ static const char * GGML_GLU_OP_NAME [GGML_GLU_OP_COUNT ] = {
11101120 "REGLU" ,
11111121 "GEGLU" ,
11121122 "SWIGLU" ,
11131123};
11141124
1115- static_assert (GGML_UNARY_OP_COUNT == 18 , "GGML_UNARY_OP_COUNT != 18 " );
1125+ static_assert (GGML_GLU_OP_COUNT == 3 , "GGML_GLU_OP_COUNT != 3 " );
11161126
11171127
11181128static_assert (sizeof (struct ggml_object )%GGML_MEM_ALIGN == 0 , "ggml_object size must be a multiple of GGML_MEM_ALIGN" );
@@ -1217,11 +1227,19 @@ const char * ggml_unary_op_name(enum ggml_unary_op op) {
12171227 return GGML_UNARY_OP_NAME [op ];
12181228}
12191229
1230+ const char * ggml_glu_op_name (enum ggml_glu_op op ) {
1231+ return GGML_GLU_OP_NAME [op ];
1232+ }
1233+
12201234const char * ggml_op_desc (const struct ggml_tensor * t ) {
12211235 if (t -> op == GGML_OP_UNARY ) {
12221236 enum ggml_unary_op uop = ggml_get_unary_op (t );
12231237 return ggml_unary_op_name (uop );
12241238 }
1239+ if (t -> op == GGML_OP_GLU ) {
1240+ enum ggml_glu_op gop = ggml_get_glu_op (t );
1241+ return ggml_glu_op_name (gop );
1242+ }
12251243 return ggml_op_name (t -> op );
12261244}
12271245
@@ -1740,6 +1758,11 @@ enum ggml_unary_op ggml_get_unary_op(const struct ggml_tensor * tensor) {
17401758 return (enum ggml_unary_op ) ggml_get_op_params_i32 (tensor , 0 );
17411759}
17421760
1761+ enum ggml_glu_op ggml_get_glu_op (const struct ggml_tensor * tensor ) {
1762+ GGML_ASSERT (tensor -> op == GGML_OP_GLU );
1763+ return (enum ggml_glu_op ) ggml_get_op_params_i32 (tensor , 0 );
1764+ }
1765+
17431766const char * ggml_get_name (const struct ggml_tensor * tensor ) {
17441767 return tensor -> name ;
17451768}
@@ -2619,58 +2642,47 @@ struct ggml_tensor * ggml_exp_inplace(
26192642 return ggml_unary_inplace (ctx , a , GGML_UNARY_OP_EXP );
26202643}
26212644
2622- // ggml_reglu
2645+ // ggml_glu
26232646
2624- struct ggml_tensor * ggml_reglu (
2647+ struct ggml_tensor * ggml_glu (
26252648 struct ggml_context * ctx ,
2626- struct ggml_tensor * a ) {
2649+ struct ggml_tensor * a ,
2650+ enum ggml_glu_op op ) {
26272651 GGML_ASSERT (ggml_is_contiguous_1 (a ));
26282652
26292653 int64_t ne [GGML_MAX_DIMS ] = { a -> ne [0 ] / 2 }; for (int i = 1 ; i < GGML_MAX_DIMS ; i ++ ) ne [i ] = a -> ne [i ];
26302654 struct ggml_tensor * result = ggml_new_tensor_impl (ctx , a -> type , GGML_MAX_DIMS , ne , NULL , 0 );
26312655
2632- ggml_set_op_params_i32 (result , 0 , (int32_t ) GGML_UNARY_OP_REGLU );
2656+ ggml_set_op_params_i32 (result , 0 , (int32_t ) op );
26332657
2634- result -> op = GGML_OP_UNARY ;
2658+ result -> op = GGML_OP_GLU ;
26352659 result -> src [0 ] = a ;
26362660
26372661 return result ;
26382662}
26392663
2640- // ggml_geglu
2664+ // ggml_reglu
26412665
2642- struct ggml_tensor * ggml_geglu (
2666+ struct ggml_tensor * ggml_reglu (
26432667 struct ggml_context * ctx ,
26442668 struct ggml_tensor * a ) {
2645- GGML_ASSERT (ggml_is_contiguous_1 (a ));
2646-
2647- int64_t ne [GGML_MAX_DIMS ] = { a -> ne [0 ] / 2 }; for (int i = 1 ; i < GGML_MAX_DIMS ; i ++ ) ne [i ] = a -> ne [i ];
2648- struct ggml_tensor * result = ggml_new_tensor_impl (ctx , a -> type , GGML_MAX_DIMS , ne , NULL , 0 );
2649-
2650- ggml_set_op_params_i32 (result , 0 , (int32_t ) GGML_UNARY_OP_GEGLU );
2669+ return ggml_glu (ctx , a , GGML_GLU_OP_REGLU );
2670+ }
26512671
2652- result -> op = GGML_OP_UNARY ;
2653- result -> src [0 ] = a ;
2672+ // ggml_geglu
26542673
2655- return result ;
2674+ struct ggml_tensor * ggml_geglu (
2675+ struct ggml_context * ctx ,
2676+ struct ggml_tensor * a ) {
2677+ return ggml_glu (ctx , a , GGML_GLU_OP_GEGLU );
26562678}
26572679
26582680// ggml_swiglu
26592681
26602682struct ggml_tensor * ggml_swiglu (
26612683 struct ggml_context * ctx ,
26622684 struct ggml_tensor * a ) {
2663- GGML_ASSERT (ggml_is_contiguous_1 (a ));
2664-
2665- int64_t ne [GGML_MAX_DIMS ] = { a -> ne [0 ] / 2 }; for (int i = 1 ; i < GGML_MAX_DIMS ; i ++ ) ne [i ] = a -> ne [i ];
2666- struct ggml_tensor * result = ggml_new_tensor_impl (ctx , a -> type , GGML_MAX_DIMS , ne , NULL , 0 );
2667-
2668- ggml_set_op_params_i32 (result , 0 , (int32_t ) GGML_UNARY_OP_SWIGLU );
2669-
2670- result -> op = GGML_OP_UNARY ;
2671- result -> src [0 ] = a ;
2672-
2673- return result ;
2685+ return ggml_glu (ctx , a , GGML_GLU_OP_SWIGLU );
26742686}
26752687
26762688// ggml_norm
0 commit comments