]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
ggml : Fix FP16 ELU positive branch (#16519)
authorsirus20x6 <redacted>
Sun, 12 Oct 2025 05:25:37 +0000 (00:25 -0500)
committerGitHub <redacted>
Sun, 12 Oct 2025 05:25:37 +0000 (08:25 +0300)
Co-authored-by: Aaron <redacted>
ggml/src/ggml-cpu/vec.h

index d3834182a603c7e0c6aff2c3ab30f44eb5781a5e..65c7dfb6b9a4957d8ac11fb4d0343e0472c912aa 100644 (file)
@@ -820,7 +820,8 @@ inline static void ggml_vec_tanh_f16 (const int n, ggml_fp16_t * y, const ggml_f
 inline static void ggml_vec_elu_f32  (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = (x[i] > 0.f) ? x[i] : expm1f(x[i]); }
 inline static void ggml_vec_elu_f16 (const int n, ggml_fp16_t * y, const ggml_fp16_t * x) {
     for (int i = 0; i < n; ++i) {
-        y[i] = GGML_CPU_FP32_TO_FP16(expm1f(GGML_CPU_FP16_TO_FP32(x[i])));
+        const float v = GGML_CPU_FP16_TO_FP32(x[i]);
+        y[i] = GGML_CPU_FP32_TO_FP16((v > 0.f) ? v : expm1f(v));
     }
 }
 inline static void ggml_vec_relu_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = (x[i] > 0.f) ? x[i] : 0.f; }