File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -4901,7 +4901,6 @@ static void llm_load_hparams(
49014901 } break;
49024902 case LLM_ARCH_PHI3:
49034903 {
4904- ml.get_key(LLM_KV_ATTENTION_SLIDING_WINDOW, hparams.n_swa);
49054904 ml.get_key(LLM_KV_ATTENTION_LAYERNORM_RMS_EPS, hparams.f_norm_rms_eps);
49064905
49074906 switch (hparams.n_layer) {
@@ -4910,6 +4909,22 @@ static void llm_load_hparams(
49104909 case 40: model.type = e_model::MODEL_14B; break;
49114910 default: model.type = e_model::MODEL_UNKNOWN;
49124911 }
4912+
4913+ // for backward compatibility ; see: https://github.com/ggerganov/llama.cpp/pull/8931
4914+ if ((hparams.n_layer == 32 || hparams.n_layer == 40) && hparams.n_ctx_train == 4096) {
4915+ // default value for Phi-3-mini-4k-instruct and Phi-3-medium-4k-instruct
4916+ hparams.n_swa = 2047;
4917+ } else if (hparams.n_layer == 32 && hparams.n_head_kv(0) == 32 && hparams.n_ctx_train == 131072) {
4918+ // default value for Phi-3-mini-128k-instruct
4919+ hparams.n_swa = 262144;
4920+ } else if (hparams.n_layer == 40 && hparams.n_ctx_train == 131072) {
4921+ // default value for Phi-3-medium-128k-instruct
4922+ hparams.n_swa = 131072;
4923+ }
4924+ bool found_swa = ml.get_key(LLM_KV_ATTENTION_SLIDING_WINDOW, hparams.n_swa, false);
4925+ if (!found_swa && hparams.n_swa == 0) {
4926+ throw std::runtime_error("invalid value for sliding_window");
4927+ }
49134928 } break;
49144929 case LLM_ARCH_PLAMO:
49154930 {
You can’t perform that action at this time.
0 commit comments