aboutsummaryrefslogtreecommitdiff
path: root/pplx_embed_mlx.c
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-05-30 05:26:44 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-14 08:18:59 +0200
commit385bed06e606f9cbacb719c9569cc77e4000f12c (patch)
tree89da34bae34d89f467e4a6e3cae01354d710dd69 /pplx_embed_mlx.c
parentaba76ae05435492b8ac3fc477ce13356fda6ffde (diff)
downloadffwd-385bed06e606f9cbacb719c9569cc77e4000f12c.tar.gz
ffwd-385bed06e606f9cbacb719c9569cc77e4000f12c.zip
server: align embedding quantization with perplexity
Diffstat (limited to 'pplx_embed_mlx.c')
-rw-r--r--pplx_embed_mlx.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/pplx_embed_mlx.c b/pplx_embed_mlx.c
index 305d235..dd17d17 100644
--- a/pplx_embed_mlx.c
+++ b/pplx_embed_mlx.c
@@ -452,19 +452,13 @@ int pplx_mlx_embed_batch(pplx_mlx_ctx_t *ctx, const pplx_input_t *inputs,
mlx_divide(&emb, emb_sum, lengths, S);
mlx_array_free(emb_sum); mlx_array_free(lengths);
- /* 5. L2 normalize each row. */
- int norm_axes[] = {1};
- mlx_array nv = mlx_array_new();
- mlx_linalg_norm_l2(&nv, emb, norm_axes, 1, true, S);
- mlx_array emb_n = mlx_array_new();
- mlx_divide(&emb_n, emb, nv, S);
- mlx_array_free(emb); mlx_array_free(nv);
if (has_padding) mlx_array_free(attn_mask);
- /* 6. Eval and copy [B, hidden] to CPU. */
+ /* 5. Eval and copy [B, hidden] to CPU. Perplexity embeddings are
+ * intentionally unnormalized; callers should use cosine similarity. */
mlx_array emb_f32 = mlx_array_new();
- mlx_astype(&emb_f32, emb_n, MLX_FLOAT32, S);
- mlx_array_free(emb_n);
+ mlx_astype(&emb_f32, emb, MLX_FLOAT32, S);
+ mlx_array_free(emb);
mlx_array_eval(emb_f32);
const float *data = mlx_array_data_float32(emb_f32);