char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
7e1e28cae
char/aliceai-t5-moe
1#include "models.h" 2 3static constexpr int PARAKEET_LOCAL_ATTN_THRESHOLD = 8192 ; 4static constexpr int PARAKEET_LOCAL_ATTN_WINDOW = 128 ; 5 6// conv subsampling + conformer encoder 7ggml_cgraph * clip_graph_parakeet::build () { 8 9// Conv subsampling 10ggml_tensor * inp = build_inp_raw (1 ); 11inp = ggml_cont (ctx0 ,ggml_transpose (ctx0 ,inp )); 12 13// [freq, time, channels, batch] 14ggml_tensor * cur = ggml_conv_2d (ctx0 ,model .pre_encode_conv_X_w [0 ],inp ,2 ,2 ,1 ,1 ,1 ,1 ); 15cur = ggml_add (ctx0 ,cur ,model .pre_encode_conv_X_b [0 ]); 16cb (cur ,"pre_conv_0" ,-1 ); 17 18cur = ggml_relu (ctx0 ,cur ); 19cb (cur ,"pre_conv_0_relu" ,-1 ); 20 21// [freq, time, channels, batch] 22cur = ggml_conv_2d_dw_direct (ctx0 ,model .pre_encode_conv_X_w [2 ],cur ,2 ,2 ,1 ,1 ,1 ,1 ); 23cur = ggml_add (ctx0 ,cur ,model .pre_encode_conv_X_b [2 ]); 24cb (cur ,"pre_conv_2" ,-1 ); 25 26// [freq, time, channels, batch] 27cur = ggml_conv_2d (ctx0 ,model .pre_encode_conv_X_w [3 ],cur ,1 ,1 ,0 ,0 ,1 ,1 ); 28cur = ggml_add (ctx0 ,cur ,model .pre_encode_conv_X_b [3 ]); 29cb (cur ,"pre_conv_3" ,-1 ); 30 31cur = ggml_relu (ctx0 ,cur ); 32cb (cur ,"pre_conv_3_relu" ,-1 ); 33 34// [freq, time, channels, batch] 35cur = ggml_conv_2d_dw_direct (ctx0 ,model .pre_encode_conv_X_w [5 ],cur ,2 ,2 ,1 ,1 ,1 ,1 ); 36cb (cur ,"pre_conv_5_direct" ,-1 ); 37cur = ggml_add (ctx0 ,cur ,model .pre_encode_conv_X_b [5 ]); 38cb (cur ,"pre_conv_5" ,-1 ); 39 40// [freq, time, channels, batch] 41cur = ggml_conv_2d (ctx0 ,model .pre_encode_conv_X_w [6 ],cur ,1 ,1 ,0 ,0 ,1 ,1 ); 42cur = ggml_add (ctx0 ,cur ,model .pre_encode_conv_X_b [6 ]); 43cb (cur ,"pre_conv_6" ,-1 ); 44 45cur = ggml_relu (ctx0 ,cur ); 46cb (cur ,"pre_conv_6_relu" ,-1 ); 47 48// [freq, time, chan] 49cur = ggml_permute (ctx0 ,cur ,0 ,2 ,1 ,3 ); 50// [freq, chan, time] 51cur = ggml_cont (ctx0 ,cur ); 52 53const int n_freq = cur -> ne [0 ]; 54const int n_chan = cur -> ne [1 ]; 55const int n_frames = cur -> ne [2 ]; 56 57// [freq, time, chan, batch] -> [(freq * chan), time] 58cur = ggml_reshape_2d (ctx0 ,cur ,n_freq * n_chan ,n_frames ); 59 60cur = build_mm (model .pre_encode_out_w ,cur ); 61cur = ggml_add (ctx0 ,cur ,model .pre_encode_out_b ); 62 63ggml_set_name (cur ,"pre_enc_out" ); 64 65// Encoder 66 67const auto & hparams = model .hparams ; 68const int n_layer = hparams .n_layer ; 69const int n_state = hparams .n_embd ; 70const float fc_factor = 0.5f ; 71 72const int n_time = cur -> ne [1 ]; 73const bool local_attn = n_time > PARAKEET_LOCAL_ATTN_THRESHOLD ; 74const int att_left = local_attn ?PARAKEET_LOCAL_ATTN_WINDOW :n_time - 1 ; 75const int att_right = local_attn ?PARAKEET_LOCAL_ATTN_WINDOW :n_time - 1 ; 76const int window_size = local_attn ?att_left + att_right + 1 :2 * n_time - 1 ; 77const int d_half = n_state /2 ; 78const int mask_dim = local_attn ?window_size :n_time ; 79 80// mask [key, n_time] 81struct ggml_tensor * attn_mask = ggml_new_tensor_2d (ctx0 ,GGML_TYPE_F32 ,mask_dim ,n_time ); 82ggml_set_name (attn_mask ,"attn_mask" ); 83ggml_set_input (attn_mask ); 84 85struct ggml_tensor * local_mask = nullptr ; 86if (local_attn ) { 87const int chunk = att_left + att_right ; 88local_mask = ggml_new_tensor_2d (ctx0 ,GGML_TYPE_F32 ,chunk + window_size - 1 ,chunk ); 89ggml_set_name (local_mask ,"local_mask" ); 90ggml_set_input (local_mask ); 91 } 92 93struct ggml_tensor * pos_freqs = ggml_new_tensor_1d (ctx0 ,GGML_TYPE_F32 ,d_half ); 94ggml_set_name (pos_freqs ,"pos_freqs" ); 95ggml_set_input (pos_freqs ); 96 97struct ggml_tensor * rel_positions = ggml_new_tensor_2d (ctx0 ,GGML_TYPE_F32 ,1 ,window_size ); 98ggml_set_name (rel_positions ,"rel_positions" ); 99ggml_set_input (rel_positions ); 100 101struct ggml_tensor * freqs = ggml_repeat_4d (ctx0 ,pos_freqs ,d_half ,window_size ,1 ,1 ); 102struct ggml_tensor * theta = ggml_mul (ctx0 ,freqs ,rel_positions ); 103 104struct ggml_tensor * sin = ggml_reshape_3d (ctx0 ,ggml_sin (ctx0 ,theta ),1 ,d_half ,window_size ); 105struct ggml_tensor * cos = ggml_reshape_3d (ctx0 ,ggml_cos (ctx0 ,theta ),1 ,d_half ,window_size ); 106struct ggml_tensor * pos_emb = ggml_reshape_2d (ctx0 ,ggml_cont (ctx0 ,ggml_concat (ctx0 ,sin ,cos ,0 )),n_state ,window_size ); 107ggml_set_name (pos_emb ,"pos_emb" ); 108 109for (int il = 0 ;il < n_layer ;++ il ) { 110const auto & layer = model .layers [il ]; 111// FFN1 112 { 113struct ggml_tensor * residual = cur ; 114ggml_format_name (cur ,"enc_%d_res" ,il ); 115 116// norm 117cur = ggml_norm (ctx0 ,cur ,hparams .eps ); 118cur = ggml_add (ctx0 ,ggml_mul (ctx0 ,cur ,layer .ff_norm_w ),layer .ff_norm_b ); 119ggml_format_name (cur ,"enc_%d_ffn_norm_1" ,il ); 120 121cur = build_ffn (cur ,layer .ff_up_w ,nullptr ,nullptr ,nullptr ,layer .ff_down_w ,nullptr ,FFN_SILU ,il ); 122ggml_format_name (cur ,"enc_%d_ffn_1" ,il ); 123 124cur = ggml_add (ctx0 ,residual ,ggml_scale (ctx0 ,cur ,fc_factor )); 125ggml_format_name (cur ,"enc_%d_res_ffn" ,il ); 126 } 127 128// self attention block using relative positional encoding from model.position_embedding. 129 { 130// [feat, time_frames, 1, 1] 131struct ggml_tensor * residual = cur ; 132 133cur = ggml_norm (ctx0 ,cur ,hparams .eps ); 134cur = ggml_add (ctx0 ,ggml_mul (ctx0 ,cur ,layer .ln_1_w ),layer .ln_1_b ); 135ggml_format_name (cur ,"enc_%d_attn_norm" ,il ); 136 137const int n_head = hparams .n_head ; 138const int d_head = n_state /n_head ; 139 140// [feat, time_frames, 1, 1] 141struct ggml_tensor * Q_cur = build_mm (layer .q_w ,cur ); 142struct ggml_tensor * K_cur = build_mm (layer .k_w ,cur ); 143struct ggml_tensor * V_cur = build_mm (layer .v_w ,cur ); 144 145// [d_head, n_heads, n_time, 1] 146Q_cur = ggml_reshape_3d (ctx0 ,Q_cur ,d_head ,n_head ,n_time ); 147K_cur = ggml_reshape_3d (ctx0 ,K_cur ,d_head ,n_head ,n_time ); 148V_cur = ggml_reshape_3d (ctx0 ,V_cur ,d_head ,n_head ,n_time ); 149 150// [n_state, window_size] 151struct ggml_tensor * pos = build_mm (layer .linear_pos_w ,pos_emb ); 152// [feat, head, window_size, 1] 153pos = ggml_reshape_3d (ctx0 ,pos ,d_head ,n_head ,pos_emb -> ne [1 ]); 154// [feat, window_size, head, 1] 155pos = ggml_cont (ctx0 ,ggml_permute (ctx0 ,pos ,0 ,2 ,1 ,3 )); 156ggml_format_name (pos ,"enc_%d_attn_pos" ,il ); 157 158if (local_attn ) { 159const int chunk = att_left + att_right ; 160const int n_group = (n_time + chunk - 1 ) /chunk ; 161const int n_time_padded = n_group * chunk ; 162const int n_kv_chunk = chunk + window_size - 1 ; 163const int n_kv_dense = n_kv_chunk * n_group ; 164const bool need_padding = n_time_padded > n_time ; 165 166Q_cur = ggml_cont (ctx0 ,ggml_permute (ctx0 ,Q_cur ,0 ,2 ,1 ,3 )); 167K_cur = ggml_cont (ctx0 ,ggml_permute (ctx0 ,K_cur ,0 ,2 ,1 ,3 )); 168V_cur = ggml_cont (ctx0 ,ggml_permute (ctx0 ,V_cur ,0 ,2 ,1 ,3 )); 169 170// content bias 171struct ggml_tensor * bias_u = ggml_reshape_3d (ctx0 ,layer .pos_bias_u ,d_head ,1 ,n_head ); 172struct ggml_tensor * Q_u = ggml_add (ctx0 ,Q_cur ,bias_u ); 173 174// position bias 175struct ggml_tensor * bias_v = ggml_reshape_3d (ctx0 ,layer .pos_bias_v ,d_head ,1 ,n_head ); 176struct ggml_tensor * Q_v = ggml_add (ctx0 ,Q_cur ,bias_v ); 177 178// right pad the time dimension 179struct ggml_tensor * Q_u_padded = need_padding ? 180ggml_pad_ext (ctx0 ,Q_u ,0 ,0 ,0 ,n_time_padded - n_time ,0 ,0 ,0 ,0 ) :Q_u ; 181Q_u_padded = ggml_reshape_4d (ctx0 ,Q_u_padded ,d_head ,chunk ,n_group ,n_head ); 182 183// pad front and back for the first and last time frames 184struct ggml_tensor * K_padded = ggml_pad_ext (ctx0 ,K_cur ,0 ,0 ,att_left ,att_right ,0 ,0 ,0 ,0 ); 185if (n_kv_dense > K_padded -> ne [1 ]) { 186K_padded = ggml_pad_ext (ctx0 ,K_padded ,0 ,0 ,0 ,n_kv_dense - K_padded -> ne [1 ],0 ,0 ,0 ,0 ); 187 } 188 189// sliding window view: each group spans n_kv_chunk keys but steps by chunk 190struct ggml_tensor * K_chunk = ggml_view_4d (ctx0 ,K_padded , 191d_head ,n_kv_chunk ,n_group ,n_head , 192K_padded -> nb [1 ], 193 (size_t )chunk * K_padded -> nb [1 ], 194K_padded -> nb [2 ], 1950 ); 196K_chunk = ggml_cont (ctx0 ,K_chunk ); 197 198struct ggml_tensor * content_scores = ggml_mul_mat (ctx0 ,K_chunk ,Q_u_padded ); 199 200// trim the dense output down to window_size scores per query 201content_scores = ggml_view_4d (ctx0 ,content_scores , 202window_size ,chunk ,n_group ,n_head , 203 (size_t ) (chunk + window_size )* content_scores -> nb [0 ], 204content_scores -> nb [2 ], 205content_scores -> nb [3 ], 2060 ); 207content_scores = ggml_cont (ctx0 ,content_scores ); 208 209// ungroup: [window_size, n_time_padded, n_head] 210content_scores = ggml_reshape_3d (ctx0 ,content_scores ,window_size ,n_time_padded ,n_head ); 211if (need_padding ) { 212content_scores = ggml_view_3d (ctx0 ,content_scores , 213window_size ,n_time ,n_head , 214content_scores -> nb [1 ], 215content_scores -> nb [2 ], 2160 ); 217 } 218 219// Q_v: [d_head, time, head] 220Q_v = ggml_cont (ctx0 ,ggml_permute (ctx0 ,Q_v ,0 ,2 ,1 ,3 )); 221struct ggml_tensor * rel_pos_scores = ggml_mul_mat (ctx0 ,pos ,Q_v ); 222 223struct ggml_tensor * attn_scores = ggml_add (ctx0 ,content_scores ,rel_pos_scores ); 224attn_scores = ggml_soft_max_ext (ctx0 ,attn_scores ,attn_mask ,1.0f / std::sqrt (d_head ),0.0f ); 225ggml_format_name (attn_scores ,"enc_%d_attn_probs" ,il ); 226 227// expand probs back to n_kv_chunk width for the V matmul 228struct ggml_tensor * probs_padded = need_padding ? 229ggml_pad_ext (ctx0 ,attn_scores ,0 ,0 ,0 ,n_time_padded - n_time ,0 ,0 ,0 ,0 ) :attn_scores ; 230 231probs_padded = ggml_reshape_4d (ctx0 ,probs_padded ,window_size ,chunk ,n_group ,n_head ); 232probs_padded = ggml_pad_ext (ctx0 ,probs_padded ,0 ,chunk ,0 ,0 ,0 ,0 ,0 ,0 ); 233probs_padded = ggml_view_4d (ctx0 ,probs_padded , 234n_kv_chunk ,chunk ,n_group ,n_head , 235 (size_t )n_kv_chunk * probs_padded -> nb [0 ], 236probs_padded -> nb [2 ], 237probs_padded -> nb [3 ], 2380 ); 239probs_padded = ggml_cont (ctx0 ,probs_padded ); 240probs_padded = ggml_mul (ctx0 ,probs_padded ,local_mask ); 241 242struct ggml_tensor * V_padded = ggml_pad_ext (ctx0 ,V_cur ,0 ,0 ,att_left ,att_right ,0 ,0 ,0 ,0 ); 243if (n_kv_dense > V_padded -> ne [1 ]) { 244V_padded = ggml_pad_ext (ctx0 ,V_padded ,0 ,0 ,0 ,n_kv_dense - V_padded -> ne [1 ],0 ,0 ,0 ,0 ); 245 } 246V_padded = ggml_cont (ctx0 ,ggml_transpose (ctx0 ,V_padded )); 247 248struct ggml_tensor * V_chunk = ggml_view_4d (ctx0 ,V_padded , 249n_kv_chunk ,d_head ,n_group ,n_head , 250V_padded -> nb [1 ], 251 (size_t )chunk * V_padded -> nb [0 ], 252V_padded -> nb [2 ], 2530 ); 254V_chunk = ggml_cont (ctx0 ,V_chunk ); 255 256cur = ggml_mul_mat (ctx0 ,V_chunk ,probs_padded ); 257cur = ggml_reshape_3d (ctx0 ,cur ,d_head ,n_time_padded ,n_head ); 258if (need_padding ) { 259cur = ggml_view_3d (ctx0 ,cur ,d_head ,n_time ,n_head ,cur -> nb [1 ],cur -> nb [2 ],0 ); 260 } 261cur = ggml_cont (ctx0 ,ggml_permute (ctx0 ,cur ,0 ,2 ,1 ,3 )); 262cur = ggml_reshape_2d (ctx0 ,cur ,n_state ,n_time ); 263cur = build_mm (layer .o_w ,cur ); 264 }else { 265// full attention 266struct ggml_tensor * Q_u = ggml_add (ctx0 ,Q_cur ,layer .pos_bias_u ); 267ggml_format_name (Q_u ,"enc_%d_attn_q_u" ,il ); 268 269struct ggml_tensor * K_prep = ggml_permute (ctx0 ,K_cur ,0 ,2 ,1 ,3 ); 270struct ggml_tensor * Q_prep = ggml_permute (ctx0 ,Q_u ,0 ,2 ,1 ,3 ); 271struct ggml_tensor * content_scores = ggml_mul_mat (ctx0 ,K_prep ,Q_prep ); 272ggml_format_name (content_scores ,"enc_%d_attn_content_scores" ,il ); 273 274struct ggml_tensor * Q_v = ggml_add (ctx0 ,Q_cur ,layer .pos_bias_v ); 275ggml_format_name (Q_v ,"enc_%d_attn_q_v" ,il ); 276 277Q_v = ggml_permute (ctx0 ,Q_v ,0 ,2 ,1 ,3 ); 278Q_v = ggml_cont (ctx0 ,Q_v ); 279ggml_format_name (Q_v ,"enc_%d_attn_q_v_perm" ,il ); 280 281struct ggml_tensor * rel_pos_scores = ggml_mul_mat (ctx0 ,pos ,Q_v ); 282ggml_format_name (rel_pos_scores ,"enc_%d_attn_rel_pos" ,il ); 283 284// Relative positional shift 285 { 286const auto pos_window = rel_pos_scores -> ne [0 ]; 287const auto n_frame = rel_pos_scores -> ne [1 ]; 288const auto n_head = rel_pos_scores -> ne [2 ]; 289 290rel_pos_scores = ggml_pad (ctx0 ,rel_pos_scores ,1 ,0 ,0 ,0 ); 291rel_pos_scores = ggml_roll (ctx0 ,rel_pos_scores ,1 ,0 ,0 ,0 ); 292 293rel_pos_scores = ggml_reshape_3d (ctx0 ,rel_pos_scores ,n_frame ,pos_window + 1 ,n_head ); 294rel_pos_scores = ggml_cont (ctx0 ,rel_pos_scores ); 295ggml_format_name (rel_pos_scores ,"enc_%d_attn_rel_pos_reshaped" ,il ); 296 297int center = pos_window /2 ; 298size_t offset = rel_pos_scores -> nb [0 ]* (center + 1 ); 299 300rel_pos_scores = ggml_view_3d (ctx0 ,rel_pos_scores , 301n_frame ,pos_window ,n_head , 302 (pos_window )* 4 , 303rel_pos_scores -> nb [2 ], 304offset ); 305rel_pos_scores = ggml_cont (ctx0 ,rel_pos_scores ); 306ggml_format_name (rel_pos_scores ,"enc_%d_attn_rel_pos_shifted" ,il ); 307 308rel_pos_scores = ggml_view_3d (ctx0 ,rel_pos_scores , 309content_scores -> ne [0 ], 310content_scores -> ne [1 ], 311rel_pos_scores -> ne [2 ], 312rel_pos_scores -> nb [1 ], 313rel_pos_scores -> nb [2 ], 3140 ); 315rel_pos_scores = ggml_cont (ctx0 ,rel_pos_scores ); 316ggml_format_name (rel_pos_scores ,"enc_%d_attn_rel_pos_shifted_view" ,il ); 317 } 318 319struct ggml_tensor * attn_scores = ggml_add (ctx0 ,content_scores ,rel_pos_scores ); 320ggml_format_name (attn_scores ,"enc_%d_attn_scores" ,il ); 321attn_scores = ggml_scale (ctx0 ,attn_scores ,1.0f / std::sqrt (d_head )); 322attn_scores = ggml_add (ctx0 ,attn_scores ,attn_mask ); 323ggml_format_name (attn_scores ,"enc_%d_attn_scores_scaled" ,il ); 324 325struct ggml_tensor * probs = ggml_soft_max (ctx0 ,attn_scores ); 326ggml_format_name (probs ,"enc_%d_attn_probs" ,il ); 327 328V_cur = ggml_cont (ctx0 ,ggml_permute (ctx0 ,V_cur ,1 ,2 ,0 ,3 )); 329ggml_format_name (V_cur ,"enc_%d_attn_v_cur" ,il ); 330cur = ggml_mul_mat (ctx0 ,probs ,V_cur ); 331ggml_format_name (cur ,"enc_%d_attn_inp" ,il ); 332 333cur = ggml_permute (ctx0 ,cur ,2 ,0 ,1 ,3 ); 334cur = ggml_cont_2d (ctx0 ,cur ,n_state ,n_time ); 335cur = build_mm (layer .o_w ,cur ); 336 } 337ggml_format_name (cur ,"enc_%d_attn_out" ,il ); 338 339cur = ggml_add (ctx0 ,residual ,cur ); 340ggml_format_name (cur ,"enc_%d_attn_res" ,il ); 341 } 342 343// Convolution 344 { 345struct ggml_tensor * residual = cur ; 346ggml_format_name (cur ,"enc_%d_residual_conv" ,il ); 347 348cur = ggml_norm (ctx0 ,cur ,hparams .eps ); 349cur = ggml_add (ctx0 ,ggml_mul (ctx0 ,cur ,layer .norm_conv_w ),layer .norm_conv_b ); 350ggml_format_name (cur ,"enc_%d_norm_conv" ,il ); 351 352// pointwise 1d convolution: 353cur = build_mm (layer .conv_pw1_w ,cur ); 354ggml_format_name (cur ,"enc_%d_conv_pw1" ,il ); 355 356 { 357int64_t d = cur -> ne [0 ] /2 ; 358struct ggml_tensor * signal = ggml_view_2d (ctx0 ,cur ,d ,cur -> ne [1 ],cur -> nb [1 ],0 ); 359struct ggml_tensor * gate = ggml_view_2d (ctx0 ,cur ,d ,cur -> ne [1 ],cur -> nb [1 ],d * cur -> nb [0 ]); 360 361cur = ggml_mul (ctx0 ,signal ,ggml_sigmoid (ctx0 ,gate )); 362ggml_format_name (cur ,"enc_%d_conv_glu" ,il ); 363 } 364 365cur = ggml_cont (ctx0 ,ggml_transpose (ctx0 ,cur )); 366 367// use ggml_ssm_conv for f32 precision 368const int dw_pad = (hparams .audio_conv_kernel_size - 1 ) /2 ; 369cur = ggml_pad (ctx0 ,cur ,dw_pad ,0 ,0 ,0 ); 370cur = ggml_roll (ctx0 ,cur ,dw_pad ,0 ,0 ,0 ); 371cur = ggml_pad (ctx0 ,cur ,dw_pad ,0 ,0 ,0 ); 372ggml_format_name (cur ,"enc_%d_conv_dw_pad" ,il ); 373 374cur = ggml_ssm_conv (ctx0 ,cur ,layer .conv_dw_w ); 375ggml_format_name (cur ,"enc_%d_conv_1d_dw" ,il ); 376 377cur = ggml_sub (ctx0 ,cur ,layer .conv_norm_mean ); 378struct ggml_tensor * std = ggml_sqrt (ctx0 ,layer .conv_norm_var ); 379cur = ggml_div (ctx0 ,cur ,std ); 380cur = ggml_add (ctx0 ,ggml_mul (ctx0 ,cur ,layer .conv_norm_w ),layer .conv_norm_b ); 381ggml_format_name (cur ,"enc_%d_conv_bn" ,il ); 382 383cur = ggml_silu (ctx0 ,cur ); 384ggml_format_name (cur ,"enc_%d_conv_silu" ,il ); 385 386cur = build_mm (layer .conv_pw2_w ,cur ); 387ggml_format_name (cur ,"enc_%d_conv_pw2" ,il ); 388 389cur = ggml_add (ctx0 ,residual ,cur ); 390ggml_format_name (cur ,"enc_%d_conv_res" ,il ); 391 } 392 393// FFN2 394 { 395struct ggml_tensor * residual = cur ; 396cur = ggml_norm (ctx0 ,cur ,hparams .eps ); 397cur = ggml_add (ctx0 ,ggml_mul (ctx0 ,cur ,layer .ff_norm_1_w ),layer .ff_norm_1_b ); 398ggml_format_name (cur ,"enc_%d_ffn_norm_2" ,il ); 399 400cur = build_ffn (cur ,layer .ff_up_1_w ,nullptr ,nullptr ,nullptr ,layer .ff_down_1_w ,nullptr ,FFN_SILU ,il ); 401cur = ggml_add (ctx0 ,residual ,ggml_scale (ctx0 ,cur ,0.5 )); 402ggml_format_name (cur ,"enc_%d_ffn_res" ,il ); 403 } 404 405cur = ggml_norm (ctx0 ,cur ,hparams .eps ); 406cur = ggml_add (ctx0 ,ggml_mul (ctx0 ,cur ,layer .ln_2_w ),layer .ln_2_b ); 407 } 408 409cb (cur ,"encoder_out" ,-1 ); 410 411cur = ggml_rms_norm (ctx0 ,cur ,1e-6 ); 412cur = ggml_mul (ctx0 ,cur ,model .mm_norm_pre_w ); 413cb (cur ,"sound_projection.norm" ,-1 ); 414 415cur = build_ffn (cur ,model .mm_0_w ,model .mm_0_b ,nullptr ,nullptr ,model .mm_1_w ,model .mm_1_b ,FFN_RELU_SQR ,-1 ); 416cb (cur ,"projected" ,-1 ); 417 418ggml_build_forward_expand (gf ,cur ); 419 420return gf ; 421}