| 1 | #include "models.h" |
| 2 | |
| 3 | ggml_cgraph * clip_graph_whisper_enc::build() { |
| 4 | const int n_frames = img.nx; |
| 5 | const int n_pos = n_frames / 2; |
| 6 | GGML_ASSERT(model.position_embeddings->ne[1] >= n_pos); |
| 7 | |
| 8 | ggml_tensor * inp = build_inp_raw(1); |
| 9 | |
| 10 | // conv1d block |
| 11 | { |
| 12 | // convolution + gelu |
| 13 | ggml_tensor * cur = ggml_conv_1d_ph(ctx0, model.conv1d_1_w, inp, 1, 1); |
| 14 | cur = ggml_add(ctx0, cur, model.conv1d_1_b); |
| 15 | |
| 16 | cur = ggml_gelu_erf(ctx0, cur); |
| 17 | |
| 18 | cur = ggml_conv_1d_ph(ctx0, model.conv1d_2_w, cur, 2, 1); |
| 19 | cur = ggml_add(ctx0, cur, model.conv1d_2_b); |
| 20 | |
| 21 | cur = ggml_gelu_erf(ctx0, cur); |
| 22 | // transpose |
| 23 | inp = ggml_cont(ctx0, ggml_transpose(ctx0, cur)); |
| 24 | cb(inp, "after_conv1d", -1); |
| 25 | } |
| 26 | |
| 27 | // sanity check (only check one layer, but it should be the same for all) |
| 28 | GGML_ASSERT(model.layers[0].ln_1_w && model.layers[0].ln_1_b); |
| 29 | GGML_ASSERT(model.layers[0].ln_2_w && model.layers[0].ln_2_b); |
| 30 | GGML_ASSERT(model.layers[0].q_b); |
| 31 | GGML_ASSERT(model.layers[0].v_b); |
| 32 | GGML_ASSERT(!model.layers[0].k_b); // no bias for k |
| 33 | |
| 34 | ggml_tensor * pos_embd_selected = ggml_view_2d( |
| 35 | ctx0, model.position_embeddings, |
| 36 | model.position_embeddings->ne[0], n_pos, |
| 37 | model.position_embeddings->nb[1], 0 |
| 38 | ); |
| 39 | ggml_tensor * cur = build_vit( |
| 40 | inp, n_pos, |
| 41 | NORM_TYPE_NORMAL, |
| 42 | hparams.ffn_op, |
| 43 | pos_embd_selected, |
| 44 | nullptr); |
| 45 | |
| 46 | cb(cur, "after_transformer", -1); |
| 47 | |
| 48 | if (model.audio_has_stack_frames()) { |
| 49 | // StackAudioFrames |
| 50 | // https://huggingface.co/fixie-ai/ultravox-v0_5-llama-3_2-1b/blob/main/ultravox_model.py |
| 51 | cur = build_stack(cur, hparams.proj_stack_factor, n_embd); |
| 52 | cb(cur, "after_stacked", -1); |
| 53 | } |
| 54 | |
| 55 | if (proj_type == PROJECTOR_TYPE_ULTRAVOX) { |
| 56 | // UltravoxProjector |
| 57 | // pre-norm |
| 58 | cur = ggml_rms_norm(ctx0, cur, 1e-6); |
| 59 | cur = ggml_mul(ctx0, cur, model.mm_norm_pre_w); |
| 60 |
nothing calls this directly
no test coverage detected