mirror of
https://github.com/ikawrakow/ik_llama.cpp.git
synced 2026-07-21 02:05:35 +00:00
Take into account swiglu limits
This commit is contained in:
@@ -1046,7 +1046,7 @@ ggml_tensor * llm_build_context::llm_build_ffn(
|
||||
}
|
||||
cur = ggml_fused_up_gate(ctx, split_u, split_g, cur, unary_op);
|
||||
cb(cur, "ffn_up_gate", il_cb);
|
||||
if (lctx.model.arch == LLM_ARCH_STEP35) {
|
||||
if (lctx.model.arch == LLM_ARCH_STEP35 || lctx.model.arch == LLM_ARCH_DEEPSEEK4) {
|
||||
*(float *)(cur->op_params + 1) = lctx.model.hparams.swiglu_limits[il];
|
||||
}
|
||||
cur = llm_build_lora_mm(lctx, ctx, split_d, cur);
|
||||
@@ -1107,7 +1107,7 @@ ggml_tensor * llm_build_context::llm_build_ffn(
|
||||
type_op == LLM_FFN_GELU ? GGML_UNARY_OP_GELU : GGML_UNARY_OP_SWIGLU_OAI;
|
||||
cur = ggml_fused_up_gate(ctx, up, gate, cur, unary_op);
|
||||
cb(cur, "ffn_up_gate", il);
|
||||
if (lctx.model.arch == LLM_ARCH_STEP35) {
|
||||
if (lctx.model.arch == LLM_ARCH_STEP35 || lctx.model.arch == LLM_ARCH_DEEPSEEK4) {
|
||||
*(float *)(cur->op_params + 1) = lctx.model.hparams.swiglu_limits_shared[il];
|
||||
}
|
||||
if (down) {
|
||||
@@ -1186,7 +1186,7 @@ ggml_tensor * llm_build_context::llm_build_ffn(
|
||||
(type_op == LLM_FFN_SILU || type_op == LLM_FFN_RELU || (type_op == LLM_FFN_GELU && !act_scales))) {
|
||||
cur = ggml_fused_mul_unary(ctx, cur, tmp, type_op == LLM_FFN_SILU ? GGML_UNARY_OP_SILU :
|
||||
type_op == LLM_FFN_RELU ? GGML_UNARY_OP_RELU : GGML_UNARY_OP_GELU);
|
||||
if (lctx.model.arch == LLM_ARCH_STEP35) {
|
||||
if (lctx.model.arch == LLM_ARCH_STEP35 || lctx.model.arch == LLM_ARCH_DEEPSEEK4) {
|
||||
*((float *)(cur->op_params + 1)) = lctx.model.hparams.swiglu_limits_shared[il];
|
||||
}
|
||||
}
|
||||
@@ -1444,7 +1444,7 @@ llm_expert_gating_func_type gating_op,
|
||||
par = ggml_moe_up_gate(ctx, up_gate_exps, nullptr, cur, selected_experts,
|
||||
type_op == LLM_FFN_SILU ? GGML_UNARY_OP_SILU : GGML_UNARY_OP_GELU);
|
||||
}
|
||||
if (lctx.model.arch == LLM_ARCH_STEP35) {
|
||||
if (lctx.model.arch == LLM_ARCH_STEP35 || lctx.model.arch == LLM_ARCH_DEEPSEEK4) {
|
||||
*((float *)(par->op_params + 1)) = lctx.model.hparams.swiglu_limits[il];
|
||||
}
|
||||
} else {
|
||||
@@ -1460,7 +1460,7 @@ llm_expert_gating_func_type gating_op,
|
||||
par = ggml_moe_up_gate(ctx, up_exps, gate_exps, cur, selected_experts,
|
||||
type_op == LLM_FFN_SILU ? GGML_UNARY_OP_SILU : GGML_UNARY_OP_GELU);
|
||||
}
|
||||
if (lctx.model.arch == LLM_ARCH_STEP35) {
|
||||
if (lctx.model.arch == LLM_ARCH_STEP35 || lctx.model.arch == LLM_ARCH_DEEPSEEK4) {
|
||||
*(float *)(par->op_params + 1) = lctx.model.hparams.swiglu_limits[il];
|
||||
}
|
||||
} else {
|
||||
@@ -1488,7 +1488,7 @@ llm_expert_gating_func_type gating_op,
|
||||
|
||||
if (type_op == LLM_FFN_SILU || type_op == LLM_FFN_GELU) {
|
||||
par = ggml_fused_mul_unary(ctx, gate, up, type_op == LLM_FFN_SILU ? GGML_UNARY_OP_SILU : GGML_UNARY_OP_GELU);
|
||||
if (lctx.model.arch == LLM_ARCH_STEP35) {
|
||||
if (lctx.model.arch == LLM_ARCH_STEP35 || lctx.model.arch == LLM_ARCH_DEEPSEEK4) {
|
||||
*((float *)(par->op_params + 1)) = lctx.model.hparams.swiglu_limits[il];
|
||||
}
|
||||
} else if (type_op == LLM_FFN_SWIGLU_OAI) {
|
||||
|
||||
@@ -1675,6 +1675,13 @@ void llm_load_hparams(
|
||||
ml.get_key(LLM_KV_EXPERT_WEIGHTS_SCALE, hparams.expert_weights_scale);
|
||||
ml.get_key(LLM_KV_EXPERT_WEIGHTS_NORM, hparams.expert_weights_norm, false);
|
||||
|
||||
if (model.arch == LLM_ARCH_DEEPSEEK4) {
|
||||
ml.get_key_or_arr(LLM_KV_SWIGLU_CLAMP_EXP, hparams.swiglu_limits, hparams.n_layer);
|
||||
if (!ml.get_key_or_arr(LLM_KV_SWIGLU_CLAMP_SHEXP, hparams.swiglu_limits_shared, hparams.n_layer, 0)) {
|
||||
hparams.swiglu_limits_shared = hparams.swiglu_limits;
|
||||
}
|
||||
}
|
||||
|
||||
// Shared latent-attention ranks used by common hparams and
|
||||
// cache helpers. DSV4 has its own CSA/HCA execution graph;
|
||||
// this does not select the DeepSeek V3 MLA path.
|
||||
|
||||
Reference in New Issue
Block a user