@@ -16,15 +16,18 @@ void llama_model_minimax_m3::load_arch_hparams(llama_model_loader & ml) {
1616 ml.get_key (LLM_KV_EXPERT_SHARED_COUNT , hparams.n_expert_shared );
1717 ml.get_key (LLM_KV_EXPERT_WEIGHTS_SCALE , hparams.expert_weights_scale , false );
1818 ml.get_key (LLM_KV_EXPERT_WEIGHTS_NORM , hparams.expert_weights_norm , false );
19- ml.get_key (LLM_KV_EXPERT_GATING_FUNC , hparams.expert_gating_func , false );
19+ ml.get_key (LLM_KV_EXPERT_GATING_FUNC , hparams.expert_gating_func );
2020 ml.get_key (LLM_KV_ATTENTION_INDEXER_HEAD_COUNT , hparams.indexer_n_head , false );
2121 ml.get_key (LLM_KV_ATTENTION_INDEXER_KEY_LENGTH , hparams.indexer_head_size , false );
2222 ml.get_key (LLM_KV_ATTENTION_INDEXER_TOP_K , hparams.indexer_top_k , false );
2323 ml.get_key (LLM_KV_ATTENTION_INDEXER_BLOCK_SIZE , hparams.indexer_block_size , false );
2424 ml.get_key (LLM_KV_ATTENTION_INDEXER_LOCAL_BLOCKS , hparams.indexer_local_blocks , false );
2525 msa_p = { (int ) hparams.indexer_block_size , (int ) hparams.indexer_top_k , (int ) hparams.indexer_local_blocks };
2626
27- type = LLM_TYPE_UNKNOWN ;
27+ switch (hparams.n_layer ()) {
28+ case 60 : type = LLM_TYPE_428B_A23B ; break ;
29+ default : type = LLM_TYPE_UNKNOWN ;
30+ }
2831}
2932
3033void llama_model_minimax_m3::load_arch_tensors (llama_model_loader &) {
@@ -389,10 +392,6 @@ llama_model_minimax_m3::graph::graph(const llama_model & model, const llm_graph_
389392 GGML_ASSERT (n_embd_head == hparams.n_embd_head_k ());
390393 // partial rotary: head_dim != n_rot, so don't assert n_embd_head == n_rot
391394
392- // swigluoai params, shared by dense and expert FFNs
393- const float swiglu_alpha = 1 .702f ;
394- const float swiglu_limit = 7 .0f ;
395-
396395 ggml_tensor * cur;
397396 ggml_tensor * inpL;
398397
@@ -452,16 +451,8 @@ llama_model_minimax_m3::graph::graph(const llama_model & model, const llm_graph_
452451 cur = build_norm (inpL, model.layers [il].attn_norm , NULL , LLM_NORM_RMS , il);
453452 cb (cur, " attn_norm" , il);
454453
455- ggml_tensor * Qcur = build_lora_mm (model.layers [il].wq , cur);
456- cb (Qcur, " Qcur" , il);
457- ggml_tensor * Kcur = build_lora_mm (model.layers [il].wk , cur);
458- cb (Kcur, " Kcur" , il);
459- ggml_tensor * Vcur = build_lora_mm (model.layers [il].wv , cur);
460- cb (Vcur, " Vcur" , il);
461-
462- Qcur = ggml_reshape_3d (ctx0, Qcur, n_embd_head, n_head, n_tokens);
463- Kcur = ggml_reshape_3d (ctx0, Kcur, n_embd_head, n_head_kv, n_tokens);
464- Vcur = ggml_reshape_3d (ctx0, Vcur, n_embd_head, n_head_kv, n_tokens);
454+ auto [Qcur, Kcur, Vcur] = build_qkv (model.layers [il], cur,
455+ n_embd_head, n_head, n_head_kv, il);
465456
466457 // per-head QK RMSNorm (weights already include Gemma's +1)
467458 Qcur = build_norm (Qcur, model.layers [il].attn_q_norm , NULL , LLM_NORM_RMS , il);
@@ -574,10 +565,12 @@ llama_model_minimax_m3::graph::graph(const llama_model & model, const llm_graph_
574565
575566 if ((uint32_t ) il < hparams.n_layer_dense_lead ) {
576567 // leading dense FFN (swigluoai)
577- ggml_tensor * g = build_lora_mm (model.layers [il].ffn_gate , cur);
578- ggml_tensor * u = build_lora_mm (model.layers [il].ffn_up , cur);
579- g = ggml_swiglu_oai (ctx0, g, u, swiglu_alpha, swiglu_limit);
580- cur = build_lora_mm (model.layers [il].ffn_down , g);
568+ cur = build_ffn (cur,
569+ model.layers [il].ffn_up , NULL , NULL ,
570+ model.layers [il].ffn_gate , NULL , NULL ,
571+ model.layers [il].ffn_down , NULL , NULL ,
572+ NULL ,
573+ LLM_FFN_SWIGLU_OAI , LLM_FFN_PAR , il);
581574 cb (cur, " ffn_out" , il);
582575 } else {
583576 // routed experts (swigluoai MoE)
@@ -595,10 +588,12 @@ llama_model_minimax_m3::graph::graph(const llama_model & model, const llm_graph_
595588 cb (moe_out, " ffn_moe_out" , il);
596589
597590 // shared expert (swigluoai)
598- ggml_tensor * sg = build_lora_mm (model.layers [il].ffn_gate_shexp , cur);
599- ggml_tensor * su = build_lora_mm (model.layers [il].ffn_up_shexp , cur);
600- sg = ggml_swiglu_oai (ctx0, sg, su, swiglu_alpha, swiglu_limit);
601- ggml_tensor * ffn_shexp = build_lora_mm (model.layers [il].ffn_down_shexp , sg);
591+ ggml_tensor * ffn_shexp = build_ffn (cur,
592+ model.layers [il].ffn_up_shexp , NULL , NULL ,
593+ model.layers [il].ffn_gate_shexp , NULL , NULL ,
594+ model.layers [il].ffn_down_shexp , NULL , NULL ,
595+ NULL ,
596+ LLM_FFN_SWIGLU_OAI , LLM_FFN_PAR , il);
602597 cb (ffn_shexp, " ffn_shexp" , il);
603598
604599 cur = ggml_add (ctx0, moe_out, ffn_shexp);
0 commit comments