char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
e39a2ce66
char/aliceai-t5-moe
1#include "models.h" 2 3ggml_cgraph * clip_graph_kimivl::build () { 4// 2D input positions 5ggml_tensor * pos_h = ggml_new_tensor_1d (ctx0 ,GGML_TYPE_I32 ,n_patches ); 6ggml_set_name (pos_h ,"pos_h" ); 7ggml_set_input (pos_h ); 8 9ggml_tensor * pos_w = ggml_new_tensor_1d (ctx0 ,GGML_TYPE_I32 ,n_patches ); 10ggml_set_name (pos_w ,"pos_w" ); 11ggml_set_input (pos_w ); 12 13ggml_tensor * learned_pos_embd = resize_position_embeddings (); 14 15// build ViT with 2D position embeddings 16auto add_pos = [& ](ggml_tensor * cur ,const clip_layer & ) { 17// first half is X axis and second half is Y axis 18return build_rope_2d (ctx0 ,cur ,pos_w ,pos_h ,hparams .rope_theta , false); 19 }; 20 21ggml_tensor * inp = build_inp (); 22ggml_tensor * cur = build_vit ( 23inp ,n_patches , 24NORM_TYPE_NORMAL , 25hparams .ffn_op , 26learned_pos_embd , 27add_pos ); 28 29cb (cur ,"vit_out" ,-1 ); 30 31 { 32// patch_merger 33const int scale_factor = model .hparams .n_merge ; 34cur = build_patch_merge_permute (cur ,scale_factor ); 35 36// projection norm 37int proj_inp_dim = cur -> ne [0 ]; 38cur = ggml_view_2d (ctx0 ,cur , 39n_embd ,cur -> ne [1 ]* scale_factor * scale_factor , 40ggml_row_size (cur -> type ,n_embd ),0 ); 41cur = ggml_norm (ctx0 ,cur ,1e-5 );// default nn.LayerNorm 42cur = ggml_mul (ctx0 ,cur ,model .mm_input_norm_w ); 43cur = ggml_add (ctx0 ,cur ,model .mm_input_norm_b ); 44cur = ggml_view_2d (ctx0 ,cur , 45proj_inp_dim ,cur -> ne [1 ] /scale_factor /scale_factor , 46ggml_row_size (cur -> type ,proj_inp_dim ),0 ); 47cb (cur ,"proj_inp_normed" ,-1 ); 48 49// projection mlp 50cur = build_ffn (cur , 51model .mm_1_w ,model .mm_1_b , 52nullptr ,nullptr , 53model .mm_2_w ,model .mm_2_b , 54FFN_GELU , 55-1 ); 56cb (cur ,"proj_out" ,-1 ); 57 } 58 59// build the graph 60ggml_build_forward_expand (gf ,cur ); 61 62return gf ; 63}