aboutsummaryrefslogtreecommitdiff
path: root/embed_config.c
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-06-15 13:47:23 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-15 13:53:31 +0200
commit458563c163a885e336ef3365922af4d17e578f56 (patch)
tree52c7515d418e60f4923a69b5eade794a221cc5b4 /embed_config.c
parentd58e523c14356ac8a29480528dbceb19290b18c1 (diff)
downloadffwd-458563c163a885e336ef3365922af4d17e578f56.tar.gz
ffwd-458563c163a885e336ef3365922af4d17e578f56.zip
all: add CLS first-token pooling
Diffstat (limited to 'embed_config.c')
-rw-r--r--embed_config.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/embed_config.c b/embed_config.c
index 4a17740..fc07334 100644
--- a/embed_config.c
+++ b/embed_config.c
@@ -123,15 +123,18 @@ static int parse_sentence_transformers_metadata(embed_config_t *cfg, const char
free(buf);
return -1;
}
- int supported = (mean == JSON_BOOL_TRUE) + (last == JSON_BOOL_TRUE);
- int unsupported = cls == JSON_BOOL_TRUE || max == JSON_BOOL_TRUE ||
- sqrt_len == JSON_BOOL_TRUE || weighted == JSON_BOOL_TRUE;
+ int supported =
+ (mean == JSON_BOOL_TRUE) + (last == JSON_BOOL_TRUE) + (cls == JSON_BOOL_TRUE);
+ int unsupported =
+ max == JSON_BOOL_TRUE || sqrt_len == JSON_BOOL_TRUE || weighted == JSON_BOOL_TRUE;
if (supported != 1 || unsupported) {
fprintf(stderr, "embed_config: unsupported Sentence Transformers pooling mode\n");
free(buf);
return -1;
}
- cfg->pooling_mode = last == JSON_BOOL_TRUE ? EMBED_POOL_LAST_TOKEN : EMBED_POOL_MEAN;
+ cfg->pooling_mode = cls == JSON_BOOL_TRUE ? EMBED_POOL_CLS
+ : last == JSON_BOOL_TRUE ? EMBED_POOL_LAST_TOKEN
+ : EMBED_POOL_MEAN;
free(buf);
buf = NULL;
}
@@ -270,7 +273,9 @@ int embed_config_parse(embed_config_t *cfg, const char *model_dir) {
cfg->hidden_size, cfg->n_layers, cfg->n_heads, cfg->n_kv_heads,
cfg->intermediate_size, cfg->head_dim,
cfg->attention_mode == EMBED_ATTENTION_CAUSAL ? "causal" : "bidirectional",
- cfg->pooling_mode == EMBED_POOL_LAST_TOKEN ? "last-token" : "mean",
+ cfg->pooling_mode == EMBED_POOL_LAST_TOKEN ? "last-token"
+ : cfg->pooling_mode == EMBED_POOL_CLS ? "cls"
+ : "mean",
cfg->qk_norm ? "yes" : "no", cfg->qkv_bias ? "yes" : "no");
return 0;