char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
d344123fe
char/aliceai-t5-moe
1#include "models.h" 2 3void llama_model_nomic_bert_moe::load_arch_hparams (llama_model_loader & ml ) { 4ml .get_key (LLM_KV_ATTENTION_LAYERNORM_EPS ,hparams .f_norm_eps ); 5ml .get_key (LLM_KV_MOE_EVERY_N_LAYERS ,hparams .moe_every_n_layers ,0 ); 6 7switch (hparams .n_layer ()) { 8case 12 : 9type = LLM_TYPE_475M ;break ; 10default :type = LLM_TYPE_UNKNOWN ; 11 } 12} 13 14void llama_model_nomic_bert_moe::load_arch_tensors (llama_model_loader & ) { 15LLAMA_LOAD_LOCALS ; 16 17if (n_token_types == 0 ) { 18throw std::runtime_error (arch_name ()+ " model needs to define token type count" ); 19 } 20tok_embd = create_tensor (tn (LLM_TENSOR_TOKEN_EMBD ,"weight" ), {n_embd ,n_vocab },0 ); 21type_embd = create_tensor (tn (LLM_TENSOR_TOKEN_TYPES ,"weight" ), {n_embd ,n_token_types },TENSOR_NOT_REQUIRED ); 22 23tok_norm = create_tensor (tn (LLM_TENSOR_TOKEN_EMBD_NORM ,"weight" ,0 ), {n_embd },0 ); 24tok_norm_b = create_tensor (tn (LLM_TENSOR_TOKEN_EMBD_NORM ,"bias" ,0 ), {n_embd },0 ); 25 26for (int i = 0 ;i < n_layer ;++ i ) { 27auto & layer = layers [i ]; 28 29create_tensor_qkv (layer ,i ,n_embd ,n_embd ,n_embd_gqa ,n_embd_gqa ,0 ); 30 31layer .wo = create_tensor (tn (LLM_TENSOR_ATTN_OUT ,"weight" ,i ), {n_embd ,n_embd },0 ); 32layer .wo_b = create_tensor (tn (LLM_TENSOR_ATTN_OUT ,"bias" ,i ), {n_embd },TENSOR_NOT_REQUIRED ); 33 34layer .attn_out_norm = create_tensor (tn (LLM_TENSOR_ATTN_OUT_NORM ,"weight" ,i ), {n_embd },0 ); 35layer .attn_out_norm_b = create_tensor (tn (LLM_TENSOR_ATTN_OUT_NORM ,"bias" ,i ), {n_embd },0 ); 36 37if (hparams .moe_every_n_layers > 0 && i %hparams .moe_every_n_layers == 1 ) { 38layer .ffn_up_exps = create_tensor (tn (LLM_TENSOR_FFN_UP_EXPS ,"weight" ,i ), {n_embd ,n_ff ,n_expert },0 ); 39layer .ffn_down_exps = create_tensor (tn (LLM_TENSOR_FFN_DOWN_EXPS ,"weight" ,i ), {n_ff ,n_embd ,n_expert },0 ); 40layer .ffn_gate_inp = create_tensor (tn (LLM_TENSOR_FFN_GATE_INP ,"weight" ,i ), {n_embd ,n_expert },0 ); 41 }else { 42layer .ffn_up = create_tensor (tn (LLM_TENSOR_FFN_UP ,"weight" ,i ), {n_embd ,n_ff },0 ); 43layer .ffn_up_b = create_tensor (tn (LLM_TENSOR_FFN_UP ,"bias" ,i ), {n_ff },TENSOR_NOT_REQUIRED ); 44layer .ffn_down = create_tensor (tn (LLM_TENSOR_FFN_DOWN ,"weight" ,i ), {n_ff ,n_embd },0 ); 45layer .ffn_down_b = create_tensor (tn (LLM_TENSOR_FFN_DOWN ,"bias" ,i ), {n_embd },TENSOR_NOT_REQUIRED ); 46 } 47 48layer .layer_out_norm = create_tensor (tn (LLM_TENSOR_LAYER_OUT_NORM ,"weight" ,i ), {n_embd },0 ); 49layer .layer_out_norm_b = create_tensor (tn (LLM_TENSOR_LAYER_OUT_NORM ,"bias" ,i ), {n_embd },0 ); 50 } 51} 52 53std::unique_ptr < llm_graph_context > llama_model_nomic_bert_moe::build_arch_graph (const llm_graph_params & params )const { 54return std::make_unique < graph > (* this ,params ); 55} 56