Skip to content

Commit 834b4be

Browse files
ngxsonarthw
authored andcommitted
llama : default n_swa for phi-3 (ggml-org#8931)
* default n_swa for phi-3 * fix * double check swa
1 parent 5ac58d9 commit 834b4be

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/llama.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff 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
{

0 commit comments

Comments
 (0)