char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
7acb4e8cd
char/aliceai-t5-moe
1#include "models.h" 2 3void llama_model_phimoe::load_arch_hparams (llama_model_loader & ml ) { 4ml .get_key (LLM_KV_ATTENTION_LAYERNORM_RMS_EPS ,hparams .f_norm_rms_eps ); 5 6switch (hparams .n_layer ()) { 7case 32 :type = LLM_TYPE_16x3_8B ;break ; 8default :type = LLM_TYPE_UNKNOWN ; 9 } 10} 11 12void llama_model_phimoe::load_arch_tensors (llama_model_loader & ) { 13LLAMA_LOAD_LOCALS ; 14 15const int64_t n_embd_head = n_embd /n_head ; 16 17tok_embd = create_tensor (tn (LLM_TENSOR_TOKEN_EMBD ,"weight" ), {n_embd ,n_vocab },0 ); 18 19// output 20output_norm = create_tensor (tn (LLM_TENSOR_OUTPUT_NORM ,"weight" ), {n_embd },0 ); 21output_norm_b = create_tensor (tn (LLM_TENSOR_OUTPUT_NORM ,"bias" ), {n_embd },0 ); 22output = create_tensor (tn (LLM_TENSOR_OUTPUT ,"weight" ), {n_embd ,n_vocab },0 ); 23output_b = create_tensor (tn (LLM_TENSOR_OUTPUT ,"bias" ), {n_vocab },0 ); 24 25for (int i = 0 ;i < n_layer ;++ i ) { 26auto & layer = layers [i ]; 27 28layer .attn_norm = create_tensor (tn (LLM_TENSOR_ATTN_NORM ,"weight" ,i ), {n_embd },0 ); 29layer .attn_norm_b = create_tensor (tn (LLM_TENSOR_ATTN_NORM ,"bias" ,i ), {n_embd },0 ); 30 31create_tensor_qkv (layer ,i ,n_embd ,n_embd ,n_embd_gqa ,n_embd_gqa ,0 ); 32layer .wo = create_tensor (tn (LLM_TENSOR_ATTN_OUT ,"weight" ,i ), {n_embd ,n_embd },0 ); 33layer .wo_b = create_tensor (tn (LLM_TENSOR_ATTN_OUT ,"bias" ,i ), {n_embd },0 ); 34 35layer .ffn_norm = create_tensor (tn (LLM_TENSOR_FFN_NORM ,"weight" ,i ), {n_embd },0 ); 36layer .ffn_norm_b = create_tensor (tn (LLM_TENSOR_FFN_NORM ,"bias" ,i ), {n_embd },0 ); 37 38layer .ffn_gate_inp = create_tensor (tn (LLM_TENSOR_FFN_GATE_INP ,"weight" ,i ), {n_embd ,n_expert },0 ); 39layer .ffn_gate_exps = create_tensor (tn (LLM_TENSOR_FFN_GATE_EXPS ,"weight" ,i ), {n_embd ,n_ff ,n_expert },0 ); 40layer .ffn_down_exps = create_tensor (tn (LLM_TENSOR_FFN_DOWN_EXPS ,"weight" ,i ), {n_ff ,n_embd ,n_expert },0 ); 41layer .ffn_up_exps = create_tensor (tn (LLM_TENSOR_FFN_UP_EXPS ,"weight" ,i ), {n_embd ,n_ff ,n_expert },0 ); 42 43layer .rope_long = create_tensor (tn (LLM_TENSOR_ROPE_FACTORS_LONG ,"weight" ,i ), {n_embd_head /2 },TENSOR_NOT_REQUIRED | (i != 0 ?TENSOR_DUPLICATED :0 )); 44layer .rope_short = create_tensor (tn (LLM_TENSOR_ROPE_FACTORS_SHORT ,"weight" ,i ), {n_embd_head /2 },TENSOR_NOT_REQUIRED | (i != 0 ?TENSOR_DUPLICATED :0 )); 45 } 46} 47 48std::unique_ptr < llm_graph_context > llama_model_phimoe::build_arch_graph (const llm_graph_params & params )const { 49if (hparams .swa_type != LLAMA_SWA_TYPE_NONE ) { 50return std::make_unique < graph < true>> (* this ,params ); 51 }else { 52return std::make_unique < graph < false>> (* this ,params ); 53 } 54} 55