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::load_arch_hparams (llama_model_loader & ml ) { 4ml .get_key (LLM_KV_ATTENTION_LAYERNORM_EPS ,hparams .f_norm_eps ); 5 6switch (hparams .n_layer ()) { 7case 12 : 8type = LLM_TYPE_137M ;break ; 9default :type = LLM_TYPE_UNKNOWN ; 10 } 11} 12 13void llama_model_nomic_bert::load_arch_tensors (llama_model_loader & ) { 14LLAMA_LOAD_LOCALS ; 15 16if (n_token_types == 0 ) { 17throw std::runtime_error (arch_name ()+ " model needs to define token type count" ); 18 } 19tok_embd = create_tensor (tn (LLM_TENSOR_TOKEN_EMBD ,"weight" ), {n_embd ,n_vocab },0 ); 20type_embd = create_tensor (tn (LLM_TENSOR_TOKEN_TYPES ,"weight" ), {n_embd ,n_token_types },TENSOR_NOT_REQUIRED ); 21 22tok_norm = create_tensor (tn (LLM_TENSOR_TOKEN_EMBD_NORM ,"weight" ,0 ), {n_embd },0 ); 23tok_norm_b = create_tensor (tn (LLM_TENSOR_TOKEN_EMBD_NORM ,"bias" ,0 ), {n_embd },0 ); 24 25for (int i = 0 ;i < n_layer ;++ i ) { 26auto & layer = layers [i ]; 27 28create_tensor_qkv (layer ,i ,n_embd ,n_embd ,n_embd_gqa ,n_embd_gqa ,0 ); 29 30layer .wo = create_tensor (tn (LLM_TENSOR_ATTN_OUT ,"weight" ,i ), {n_embd ,n_embd },0 ); 31layer .wo_b = create_tensor (tn (LLM_TENSOR_ATTN_OUT ,"bias" ,i ), {n_embd },TENSOR_NOT_REQUIRED ); 32 33layer .attn_out_norm = create_tensor (tn (LLM_TENSOR_ATTN_OUT_NORM ,"weight" ,i ), {n_embd },0 ); 34layer .attn_out_norm_b = create_tensor (tn (LLM_TENSOR_ATTN_OUT_NORM ,"bias" ,i ), {n_embd },0 ); 35 36layer .ffn_up = create_tensor (tn (LLM_TENSOR_FFN_UP ,"weight" ,i ), {n_embd ,n_ff },0 ); 37layer .ffn_up_b = create_tensor (tn (LLM_TENSOR_FFN_UP ,"bias" ,i ), {n_ff },TENSOR_NOT_REQUIRED ); 38layer .ffn_down = create_tensor (tn (LLM_TENSOR_FFN_DOWN ,"weight" ,i ), {n_ff ,n_embd },0 ); 39layer .ffn_down_b = create_tensor (tn (LLM_TENSOR_FFN_DOWN ,"bias" ,i ), {n_embd },TENSOR_NOT_REQUIRED ); 40 41layer .ffn_gate = create_tensor (tn (LLM_TENSOR_FFN_GATE ,"weight" ,i ), {n_embd ,n_ff },0 ); 42 43layer .layer_out_norm = create_tensor (tn (LLM_TENSOR_LAYER_OUT_NORM ,"weight" ,i ), {n_embd },0 ); 44layer .layer_out_norm_b = create_tensor (tn (LLM_TENSOR_LAYER_OUT_NORM ,"bias" ,i ), {n_embd },0 ); 45 } 46} 47 48std::unique_ptr < llm_graph_context > llama_model_nomic_bert::build_arch_graph (const llm_graph_params & params )const { 49return std::make_unique < graph > (* this ,params ); 50} 51