Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit eaa91f1

Browse files
committed
fix: temporary cann degrade in glu op
Signed-off-by: thxCode <thxcode0824@gmail.com>
1 parent 658e153 commit eaa91f1

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
diff --git a/src/llama-graph.cpp b/src/llama-graph.cpp
2+
index 010300df..7eb95cdd 100644
3+
--- a/src/llama-graph.cpp
4+
+++ b/src/llama-graph.cpp
5+
@@ -560,20 +560,28 @@ ggml_tensor * llm_graph_context::build_ffn(
6+
7+
switch (type_op) {
8+
case LLM_FFN_SILU:
9+
+#ifndef GGML_USE_CANN
10+
if (gate && type_gate == LLM_FFN_PAR) {
11+
cur = ggml_swiglu_split(ctx0, cur, tmp);
12+
cb(cur, "ffn_swiglu", il);
13+
type_gate = LLM_FFN_SEQ;
14+
} else {
15+
+#else
16+
+ {
17+
+#endif
18+
cur = ggml_silu(ctx0, cur);
19+
cb(cur, "ffn_silu", il);
20+
} break;
21+
case LLM_FFN_GELU:
22+
+#ifndef GGML_USE_CANN
23+
if (gate && type_gate == LLM_FFN_PAR) {
24+
cur = ggml_geglu_split(ctx0, cur, tmp);
25+
cb(cur, "ffn_geglu", il);
26+
type_gate = LLM_FFN_SEQ;
27+
} else {
28+
+#else
29+
+ {
30+
+#endif
31+
cur = ggml_gelu(ctx0, cur);
32+
cb(cur, "ffn_gelu", il);
33+
if (act_scales != NULL) {
34+
@@ -582,11 +590,15 @@ ggml_tensor * llm_graph_context::build_ffn(
35+
}
36+
} break;
37+
case LLM_FFN_RELU:
38+
+#ifndef GGML_USE_CANN
39+
if (gate && type_gate == LLM_FFN_PAR) {
40+
cur = ggml_reglu_split(ctx0, cur, tmp);
41+
cb(cur, "ffn_reglu", il);
42+
type_gate = LLM_FFN_SEQ;
43+
} else {
44+
+#else
45+
+ {
46+
+#endif
47+
cur = ggml_relu(ctx0, cur);
48+
cb(cur, "ffn_relu", il);
49+
} break;
50+
@@ -742,18 +754,26 @@ ggml_tensor * llm_graph_context::build_moe_ffn(
51+
52+
switch (type_op) {
53+
case LLM_FFN_SILU:
54+
+#ifndef GGML_USE_CANN
55+
if (gate_exps) {
56+
cur = ggml_swiglu_split(ctx0, cur, up);
57+
cb(cur, "ffn_moe_swiglu", il);
58+
} else {
59+
+#else
60+
+ {
61+
+#endif
62+
cur = ggml_silu(ctx0, cur);
63+
cb(cur, "ffn_moe_silu", il);
64+
} break;
65+
case LLM_FFN_GELU:
66+
+#ifndef GGML_USE_CANN
67+
if (gate_exps) {
68+
cur = ggml_geglu_split(ctx0, cur, up);
69+
cb(cur, "ffn_moe_geglu", il);
70+
} else {
71+
+#else
72+
+ {
73+
+#endif
74+
cur = ggml_gelu(ctx0, cur);
75+
cb(cur, "ffn_moe_gelu", il);
76+
} break;
77+
@@ -761,6 +781,13 @@ ggml_tensor * llm_graph_context::build_moe_ffn(
78+
GGML_ABORT("fatal error");
79+
}
80+
81+
+#ifdef GGML_USE_CANN
82+
+ if (gate_exps) {
83+
+ cur = ggml_mul(ctx0, cur, up); // [n_ff, n_expert_used, n_tokens]
84+
+ cb(cur, "ffn_moe_gate_par", il);
85+
+ }
86+
+#endif
87+
+
88+
experts = build_lora_mm_id(down_exps, cur, selected_experts); // [n_embd, n_expert_used, n_tokens]
89+
cb(experts, "ffn_moe_down", il);
90+

0 commit comments

Comments
 (0)