@@ -938,7 +938,7 @@ void llama_model::load_hparams(llama_model_loader & ml) {
938938 break;
939939 case LLM_ARCH_LLADA_MOE:
940940 {
941- ml.get_key(LLM_KV_EXPERT_FEED_FORWARD_LENGTH, hparams.n_ff_exp, false);
941+ ml.get_key(LLM_KV_EXPERT_FEED_FORWARD_LENGTH, hparams.n_ff_exp, false);
942942
943943 ml.get_key(LLM_KV_ATTENTION_LAYERNORM_RMS_EPS, hparams.f_norm_rms_eps);
944944 // diffusion language model uses non-causal attention
@@ -2407,6 +2407,9 @@ bool llama_model::load_tensors(llama_model_loader & ml) {
24072407 output_norm = create_tensor(tn(LLM_TENSOR_OUTPUT_NORM, "weight"), {n_embd}, 0);
24082408 output = create_tensor(tn(LLM_TENSOR_OUTPUT, "weight"), {n_embd, n_vocab}, 0);
24092409
2410+ GGML_ASSERT(n_expert > 0 && "n_expert must be > 0 for llada-moe");
2411+ GGML_ASSERT(n_expert_used > 0 && "n_expert_used must be > 0 for llada-moe");
2412+
24102413 for (int i = 0; i < n_layer; ++i) {
24112414 auto & layer = layers[i];
24122415
@@ -2423,13 +2426,6 @@ bool llama_model::load_tensors(llama_model_loader & ml) {
24232426
24242427 layer.ffn_gate_inp = create_tensor(tn(LLM_TENSOR_FFN_GATE_INP, "weight", i), {n_embd, n_expert}, 0);
24252428
2426- if (n_expert == 0) {
2427- throw std::runtime_error("n_expert must be > 0");
2428- }
2429- if (n_expert_used == 0) {
2430- throw std::runtime_error("n_expert_used must be > 0");
2431- }
2432-
24332429 const int64_t n_ff_exp = hparams.n_ff_exp ? hparams.n_ff_exp : n_ff / n_expert_used;
24342430
24352431 layer.ffn_gate_exps = create_tensor(tn(LLM_TENSOR_FFN_GATE_EXPS, "weight", i), { n_embd, n_ff_exp, n_expert}, 0);
@@ -12535,15 +12531,15 @@ struct llm_build_llada_moe : public llm_graph_context {
1253512531 cb(Vcur, "Vcur", il);
1253612532
1253712533 Qcur = ggml_reshape_3d(ctx0, Qcur, n_embd_head, n_head, n_tokens);
12534+ Kcur = ggml_reshape_3d(ctx0, Kcur, n_embd_head, n_head_kv, n_tokens);
12535+ Vcur = ggml_reshape_3d(ctx0, Vcur, n_embd_head, n_head_kv, n_tokens);
12536+
1253812537 Qcur = build_norm(Qcur, model.layers[il].attn_q_norm, NULL, LLM_NORM_RMS, il);
1253912538 cb(Qcur, "Qcur_normed", il);
1254012539
12541- Kcur = ggml_reshape_3d(ctx0, Kcur, n_embd_head, n_head_kv, n_tokens);
1254212540 Kcur = build_norm(Kcur, model.layers[il].attn_k_norm, NULL, LLM_NORM_RMS, il);
1254312541 cb(Kcur, "Kcur_normed", il);
1254412542
12545- Vcur = ggml_reshape_3d(ctx0, Vcur, n_embd_head, n_head_kv, n_tokens);
12546-
1254712543 Qcur = ggml_rope_ext(
1254812544 ctx0, Qcur, inp_pos, nullptr,
1254912545 n_rot, rope_type, n_ctx_orig, freq_base, freq_scale,
0 commit comments