@@ -36,6 +36,7 @@ const char * llm_type_name(llm_type type) {
3636 case LLM_TYPE_80M: return "80M";
3737 case LLM_TYPE_109M: return "109M";
3838 case LLM_TYPE_137M: return "137M";
39+ case LLM_TYPE_140M: return "140M";
3940 case LLM_TYPE_160M: return "160M";
4041 case LLM_TYPE_190M: return "190M";
4142 case LLM_TYPE_220M: return "220M";
@@ -44,13 +45,15 @@ const char * llm_type_name(llm_type type) {
4445 case LLM_TYPE_270M: return "270M";
4546 case LLM_TYPE_335M: return "335M";
4647 case LLM_TYPE_350M: return "350M";
48+ case LLM_TYPE_360M: return "360M";
4749 case LLM_TYPE_410M: return "410M";
4850 case LLM_TYPE_450M: return "450M";
4951 case LLM_TYPE_475M: return "475M";
5052 case LLM_TYPE_558M: return "558M";
5153 case LLM_TYPE_700M: return "700M";
5254 case LLM_TYPE_770M: return "770M";
5355 case LLM_TYPE_780M: return "780M";
56+ case LLM_TYPE_950M: return "950M";
5457 case LLM_TYPE_0_3B: return "0.3B";
5558 case LLM_TYPE_0_5B: return "0.5B";
5659 case LLM_TYPE_0_6B: return "0.6B";
@@ -622,19 +625,32 @@ void llama_model::load_hparams(llama_model_loader & ml) {
622625 ml.get_key(LLM_KV_EXPERT_FEED_FORWARD_LENGTH, hparams.n_ff_exp);
623626 ml.get_key(LLM_KV_INTERLEAVE_MOE_LAYER_STEP, hparams.n_moe_layer_step);
624627
625- hparams.swa_type = LLAMA_SWA_TYPE_CHUNKED;
626- hparams.n_swa = 8192; // should this be a gguf kv? currently it's the same for Scout and Maverick
627- hparams.set_swa_pattern(4); // pattern: 3 chunked - 1 full
628+ const bool found_swa = ml.get_key(LLM_KV_ATTENTION_SLIDING_WINDOW, hparams.n_swa, false);
629+ if (found_swa && hparams.n_swa == 0) {
630+ hparams.swa_type = LLAMA_SWA_TYPE_NONE;
631+ hparams.n_no_rope_layer_step = hparams.n_layer; // always use rope
632+ } else {
633+ hparams.swa_type = LLAMA_SWA_TYPE_CHUNKED;
634+ hparams.n_swa = 8192;
635+ hparams.set_swa_pattern(4); // pattern: 3 chunked - 1 full
636+ }
628637
629638 switch (hparams.n_expert) {
639+ case 0: {
640+ // MobileLLM (no MoE)
641+ switch (hparams.n_embd) {
642+ case 2048: type = LLM_TYPE_140M; break;
643+ case 4096: type = LLM_TYPE_360M; break;
644+ case 6144: type = LLM_TYPE_950M; break;
645+ default: type = LLM_TYPE_UNKNOWN;
646+ }
647+ } break;
630648 case 16: type = LLM_TYPE_17B_16E; break;
631649 case 128: type = LLM_TYPE_17B_128E; break;
632650 default: type = LLM_TYPE_UNKNOWN;
633651 }
634652
635- if (type == LLM_TYPE_17B_128E) {
636- hparams.use_kq_norm = false;
637- }
653+ hparams.use_kq_norm = type != LLM_TYPE_17B_128E;
638654 } break;
639655 case LLM_ARCH_ARCEE:
640656 {
@@ -2454,9 +2470,8 @@ bool llama_model::load_tensors(llama_model_loader & ml) {
24542470 output = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}, TENSOR_DUPLICATED);
24552471 }
24562472
2457- GGML_ASSERT(hparams.n_moe_layer_step > 0 && "Llama 4 requires n_moe_layer_step > 0");
24582473 for (int i = 0; i < n_layer; ++i) {
2459- bool is_moe_layer = (i + 1) % hparams.n_moe_layer_step == 0;
2474+ bool is_moe_layer = hparams.n_moe_layer_step > 0 && (i + 1) % hparams.n_moe_layer_step == 0;
24602475
24612476 auto & layer = layers[i];
24622477
@@ -6328,6 +6343,14 @@ struct llm_build_llama : public llm_graph_context {
63286343 cb(Kcur, "Kcur", il);
63296344 cb(Vcur, "Vcur", il);
63306345
6346+ if (hparams.use_kq_norm) {
6347+ // Llama4TextL2Norm
6348+ Qcur = ggml_rms_norm(ctx0, Qcur, hparams.f_norm_rms_eps);
6349+ Kcur = ggml_rms_norm(ctx0, Kcur, hparams.f_norm_rms_eps);
6350+ cb(Qcur, "Qcur_normed", il);
6351+ cb(Kcur, "Kcur_normed", il);
6352+ }
6353+
63316354 cur = build_attn(inp_attn,
63326355 model.layers[il].wo, model.layers[il].bo,
63336356 Qcur, Kcur, Vcur, nullptr, nullptr, nullptr, kq_scale, il);
@@ -6435,7 +6458,8 @@ struct llm_build_llama_iswa : public llm_graph_context {
64356458 for (int il = 0; il < n_layer; ++il) {
64366459 ggml_tensor * inpSA = inpL;
64376460
6438- const bool use_rope = (il + 1) % hparams.n_no_rope_layer_step != 0;
6461+ const bool use_rope = hparams.n_no_rope_layer_step > 0 &&
6462+ (il + 1) % hparams.n_no_rope_layer_step != 0;
64396463
64406464 // norm
64416465 cur = build_norm(inpL,
@@ -18981,7 +19005,11 @@ ggml_cgraph * llama_model::build_graph(const llm_graph_params & params) const {
1898119005 } break;
1898219006 case LLM_ARCH_LLAMA4:
1898319007 {
18984- llm = std::make_unique<llm_build_llama_iswa>(*this, params);
19008+ if (hparams.swa_type == LLAMA_SWA_TYPE_NONE) {
19009+ llm = std::make_unique<llm_build_llama>(*this, params);
19010+ } else {
19011+ llm = std::make_unique<llm_build_llama_iswa>(*this, params);
19012+ }
1898519013 } break;
1898619014 case LLM_ARCH_DECI:
1898719015 {
0 commit comments