@@ -993,13 +993,11 @@ struct clip_graph {
993993 feat = ggml_reshape_3d (ctx0, feat, n_embd * merge_factor, n_pos / merge_factor, batch_size);
994994
995995 feat = build_norm (feat, merger.norm_w , merger.norm_b , norm_t , eps, il);
996- feat = ggml_mul_mat (ctx0, merger.fc1_w , feat);
997- feat = ggml_add (ctx0, feat, merger.fc1_b );
998-
999- feat = ggml_gelu (ctx0, feat);
1000-
1001- feat = ggml_mul_mat (ctx0, merger.fc2_w , feat);
1002- feat = ggml_add (ctx0, feat, merger.fc2_b );
996+ feat = build_ffn (feat,
997+ merger.fc1_w , merger.fc1_b ,
998+ nullptr , nullptr ,
999+ merger.fc2_w , merger.fc2_b ,
1000+ ffn_op_type::FFN_GELU, il);
10031001
10041002 if (!deepstack_features) {
10051003 deepstack_features = feat;
@@ -1021,15 +1019,11 @@ struct clip_graph {
10211019 ggml_tensor * embeddings = inpL;
10221020 embeddings = ggml_reshape_3d (ctx0, embeddings, n_embd * 4 , n_pos / 4 , batch_size);
10231021
1024- embeddings = ggml_mul_mat (ctx0, model.mm_0_w , embeddings);
1025- embeddings = ggml_add (ctx0, embeddings, model.mm_0_b );
1026-
1027- // GELU activation
1028- embeddings = ggml_gelu (ctx0, embeddings);
1029-
1030- // Second linear layer
1031- embeddings = ggml_mul_mat (ctx0, model.mm_1_w , embeddings);
1032- embeddings = ggml_add (ctx0, embeddings, model.mm_1_b );
1022+ embeddings = build_ffn (embeddings,
1023+ model.mm_0_w , model.mm_0_b ,
1024+ nullptr , nullptr ,
1025+ model.mm_1_w , model.mm_1_b ,
1026+ ffn_op_type::FFN_GELU, -1 );
10331027
10341028 embeddings = ggml_concat (ctx0, embeddings, deepstack_features, 0 ); // concat along the feature dimension
10351029
0 commit comments