char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
994118a18
char/aliceai-t5-moe
1#include "models.h" 2 3void llama_model_t5encoder::load_arch_hparams (llama_model_loader & ml ) { 4ml .get_key (LLM_KV_ATTENTION_LAYERNORM_RMS_EPS ,hparams .f_norm_rms_eps ); 5ml .get_key (LLM_KV_ATTENTION_RELATIVE_BUCKETS_COUNT ,hparams .n_rel_attn_bkts ); 6type = LLM_TYPE_UNKNOWN ; 7} 8 9void llama_model_t5encoder::load_arch_tensors (llama_model_loader & ) { 10LLAMA_LOAD_LOCALS ; 11 12const auto n_rel_attn_bkts = hparams .n_rel_attn_bkts ; 13 14tok_embd = create_tensor (tn (LLM_TENSOR_TOKEN_EMBD ,"weight" ), {n_embd ,n_vocab },0 ); 15 16// output 17output_norm_enc = create_tensor (tn (LLM_TENSOR_ENC_OUTPUT_NORM ,"weight" ), {n_embd },0 ); 18output = create_tensor (tn (LLM_TENSOR_OUTPUT ,"weight" ), {n_embd ,n_vocab },TENSOR_NOT_REQUIRED ); 19// if output is NULL, init from the input tok embed 20if (output == NULL ) { 21output = create_tensor (tn (LLM_TENSOR_TOKEN_EMBD ,"weight" ), {n_embd ,n_vocab },TENSOR_DUPLICATED ); 22 } 23 24for (int i = 0 ;i < n_layer ;++ i ) { 25auto & layer = layers [i ]; 26 27layer .attn_norm_enc = create_tensor (tn (LLM_TENSOR_ENC_ATTN_NORM ,"weight" ,i ), {n_embd },0 ); 28layer .attn_rel_b_enc = create_tensor (tn (LLM_TENSOR_ENC_ATTN_REL_B ,"weight" ,i ), {n_head ,n_rel_attn_bkts },TENSOR_NOT_REQUIRED ); 29 30layer .wq_enc = create_tensor (tn (LLM_TENSOR_ENC_ATTN_Q ,"weight" ,i ), {n_embd ,n_embd_k_gqa },0 ); 31layer .wk_enc = create_tensor (tn (LLM_TENSOR_ENC_ATTN_K ,"weight" ,i ), {n_embd ,n_embd_k_gqa },0 ); 32layer .wv_enc = create_tensor (tn (LLM_TENSOR_ENC_ATTN_V ,"weight" ,i ), {n_embd ,n_embd_v_gqa },0 ); 33layer .wo_enc = create_tensor (tn (LLM_TENSOR_ENC_ATTN_OUT ,"weight" ,i ), {n_embd_v_gqa ,n_embd },0 ); 34 35layer .ffn_norm_enc = create_tensor (tn (LLM_TENSOR_ENC_FFN_NORM ,"weight" ,i ), {n_embd },0 ); 36layer .ffn_gate_enc = create_tensor (tn (LLM_TENSOR_ENC_FFN_GATE ,"weight" ,i ), {n_embd ,n_ff },TENSOR_NOT_REQUIRED ); 37layer .ffn_down_enc = create_tensor (tn (LLM_TENSOR_ENC_FFN_DOWN ,"weight" ,i ), {n_ff ,n_embd },0 ); 38layer .ffn_up_enc = create_tensor (tn (LLM_TENSOR_ENC_FFN_UP ,"weight" ,i ), {n_embd ,n_ff },0 ); 39 } 40} 41 42std::unique_ptr < llm_graph_context > llama_model_t5encoder::build_arch_graph (const llm_graph_params & params )const { 43return std::make_unique < graph > (* this ,params ); 44}