char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
237958db3
char/aliceai-t5-moe
1#include "models.h" 2 3ggml_cgraph * clip_graph_paddleocr::build () { 4const int n_pos = n_patches ; 5const int num_position_ids = n_pos * 4 ;// m-rope requires 4 dim per position 6 7int mrope_sections [4 ]= {d_head /4 ,d_head /4 ,d_head /4 ,d_head /4 }; 8 9ggml_tensor * positions = ggml_new_tensor_1d (ctx0 ,GGML_TYPE_I32 ,num_position_ids ); 10ggml_set_name (positions ,"positions" ); 11ggml_set_input (positions ); 12 13auto add_pos = [& ](ggml_tensor * cur ,const clip_layer & ) { 14return ggml_rope_multi ( 15ctx0 ,cur ,positions ,nullptr , 16d_head /2 ,mrope_sections ,GGML_ROPE_TYPE_VISION , 1732768 ,10000 ,1 ,0 ,1 ,32 ,1 ); 18 }; 19 20ggml_tensor * learned_pos_embd = resize_position_embeddings (); 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// mlp_AR paddleocr projector 33float proj_norm_eps = 1e-5 ; 34cur = build_norm (cur , 35model .mm_input_norm_w ,model .mm_input_norm_b , 36NORM_TYPE_NORMAL ,proj_norm_eps ,-1 ); 37 38const int scale_factor = model .hparams .n_merge ; 39cur = build_patch_merge_permute (cur ,scale_factor ); 40cur = build_ffn (cur , 41model .mm_1_w ,model .mm_1_b , 42nullptr ,nullptr , 43model .mm_2_w ,model .mm_2_b , 44hparams .ffn_op ,-1 ); 45cb (cur ,"mlp_out" ,-1 ); 46 } 47 48// build the graph 49ggml_build_forward_expand (gf ,cur ); 50 51return gf ; 52}