char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
501aeed18
char/aliceai-t5-moe
1#include "models.h" 2 3ggml_cgraph * clip_graph_dotsocr::build () { 4const int n_pos = n_patches ; 5const int num_position_ids = n_pos * 4 ;// m-rope requires 4 dim per position 6 7// note: similar to PaddleOCR 8int mrope_sections [4 ]= {d_head /4 ,d_head /4 ,d_head /4 ,d_head /4 }; 9 10ggml_tensor * positions = ggml_new_tensor_1d (ctx0 ,GGML_TYPE_I32 ,num_position_ids ); 11ggml_set_name (positions ,"positions" ); 12ggml_set_input (positions ); 13 14auto add_pos = [& ](ggml_tensor * cur ,const clip_layer & ) { 15return ggml_rope_multi ( 16ctx0 ,cur ,positions ,nullptr , 17d_head /2 ,mrope_sections ,GGML_ROPE_TYPE_VISION , 1832768 ,10000 ,1 ,0 ,1 ,32 ,1 ); 19 }; 20 21ggml_tensor * inp = build_inp (); 22ggml_tensor * cur = build_vit ( 23inp ,n_patches , 24NORM_TYPE_RMS , 25hparams .ffn_op , 26nullptr , 27add_pos ); 28 29cb (cur ,"vit_out" ,-1 ); 30 31// dots.ocr patch merger + projector 32 { 33GGML_ASSERT (hparams .n_merge > 0 ); 34cur = build_norm (cur ,model .mm_input_norm_w ,model .mm_input_norm_b ,NORM_TYPE_NORMAL ,1e-6 ,-1 ); 35cur = build_patch_merge_permute (cur ,hparams .n_merge ); 36cb (cur ,"after_patch_merger" ,-1 ); 37cur = build_ffn (cur , 38model .mm_0_w ,model .mm_0_b , 39nullptr ,nullptr ,// no gate 40model .mm_2_w ,model .mm_2_b , 41FFN_GELU_ERF ,-1 );// nn.GELU() defaults to exact erf-based GELU 42cb (cur ,"after_projector" ,-1 ); 43 } 44 45// build the graph 46ggml_build_forward_expand (gf ,cur ); 47 48return gf ; 49}