aboutsummaryrefslogtreecommitdiff
path: root/pplx_embed.h
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-05-20 05:26:35 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-14 08:17:30 +0200
commit7a88087ba0b5b1b388234f3d2a907673c63bd8cb (patch)
tree3a656367ab23d65d625c9cbbb3014ed109a2ebd2 /pplx_embed.h
parent47859fbfdc02329090c59357cbb826b42c946bf7 (diff)
downloadffwd-7a88087ba0b5b1b388234f3d2a907673c63bd8cb.tar.gz
ffwd-7a88087ba0b5b1b388234f3d2a907673c63bd8cb.zip
all: support batched embedding attention
Diffstat (limited to 'pplx_embed.h')
-rw-r--r--pplx_embed.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/pplx_embed.h b/pplx_embed.h
index 67b193e..1dd50f2 100644
--- a/pplx_embed.h
+++ b/pplx_embed.h
@@ -92,6 +92,11 @@ typedef struct {
int rope_cache_cap;
} pplx_ctx_t;
+typedef struct {
+ const int *ids;
+ int n_tokens;
+} pplx_input_t;
+
/* ========================================================================
* API
* ======================================================================== */
@@ -124,6 +129,25 @@ void pplx_free(pplx_ctx_t *ctx);
float *pplx_embed(pplx_ctx_t *ctx, const int *token_ids, int n_tokens);
/*
+ * Compute one embedding into caller-provided out[hidden_size].
+ * Returns 0 on success, -1 on error.
+ */
+int pplx_embed_into(pplx_ctx_t *ctx, const int *token_ids, int n_tokens,
+ float *out_embedding);
+
+/*
+ * Compute embeddings for a true packed/ragged batch.
+ *
+ * out_embeddings is caller-provided [batch, hidden_size].
+ * Each sequence attends only to tokens from the same input, and RoPE
+ * positions restart at zero for every input.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+int pplx_embed_batch(pplx_ctx_t *ctx, const pplx_input_t *inputs, int batch,
+ float *out_embeddings);
+
+/*
* Run the transformer forward pass WITHOUT pooling.
* Returns the full [n_tokens * hidden_size] output after final RMSNorm.
* Caller frees the returned buffer. NULL on error.
@@ -134,6 +158,13 @@ float *pplx_embed(pplx_ctx_t *ctx, const int *token_ids, int n_tokens);
float *pplx_forward(pplx_ctx_t *ctx, const int *token_ids, int n_tokens);
/*
+ * Run the transformer forward pass into caller-provided
+ * out_states[n_tokens * hidden_size]. Returns 0 on success, -1 on error.
+ */
+int pplx_forward_into(pplx_ctx_t *ctx, const int *token_ids, int n_tokens,
+ float *out_states);
+
+/*
* Cosine similarity between two L2-normalized vectors.
*/
float pplx_cosine_similarity(const float *a, const float *b, int dim);