From c20279050f88d9c24187c3e402912596e1f54587 Mon Sep 17 00:00:00 2001 From: Onur Gündüz Date: Tue, 16 Jun 2026 09:26:20 +0200 Subject: all: support BERT tanh-GeLU (gelu_new / gelu_pytorch_tanh) --- embed.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'embed.h') diff --git a/embed.h b/embed.h index 860576e..c7381bd 100644 --- a/embed.h +++ b/embed.h @@ -48,8 +48,17 @@ typedef enum { EMBED_FAMILY_BERT = 1, /* LayerNorm + learned positions + GeLU encoder block */ } embed_family_t; +/* BERT feed-forward activation. The released MiniLM/BGE encoders use exact erf + * GeLU; some encoders publish the tanh approximation (hidden_act gelu_new or + * gelu_pytorch_tanh), which is a different curve and must be matched exactly. */ +typedef enum { + EMBED_ACT_GELU_ERF = 0, /* 0.5 x (1 + erf(x / sqrt(2))) */ + EMBED_ACT_GELU_TANH = 1, /* 0.5 x (1 + tanh(sqrt(2/pi) (x + 0.044715 x^3))) */ +} embed_act_t; + typedef struct { embed_family_t family; + embed_act_t ffn_act; /* BERT feed-forward GeLU variant; ERF for Qwen/SwiGLU */ int hidden_size; int n_layers; int n_heads; -- cgit v1.3.1