Skip to content

Commit f8b7635

Browse files
author
Aaron
committed
Adjusted ggml_vec_elu_f16 so the positive branch mirrors the f32 implementation, promoting inputs to float, branching on the sign, and only calling expm1f for the negative path before converting back vec.h This restores correct ELU behaviour for FP16 tensors.
1 parent 5993a6f commit f8b7635

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

ggml/src/ggml-cpu/vec.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,8 @@ inline static void ggml_vec_tanh_f16 (const int n, ggml_fp16_t * y, const ggml_f
820820
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]); }
821821
inline static void ggml_vec_elu_f16 (const int n, ggml_fp16_t * y, const ggml_fp16_t * x) {
822822
for (int i = 0; i < n; ++i) {
823-
y[i] = GGML_CPU_FP32_TO_FP16(expm1f(GGML_CPU_FP16_TO_FP32(x[i])));
823+
const float v = GGML_CPU_FP16_TO_FP32(x[i]);
824+
y[i] = GGML_CPU_FP32_TO_FP16((v > 0.f) ? v : expm1f(v));
824825
}
825826
}
826827
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; }

0 commit comments

Comments
 (0)