diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-06-11 23:40:01 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-06-14 08:27:10 +0200 |
| commit | 978f4f7969190265e127e8a3d704bb173fbd171c (patch) | |
| tree | 42f3a89e1ecb481ef0e5196a775ea37edb4b98f7 /embed.h | |
| parent | d9ea2cea7dfa1eb25526a3e9b729beda5ccb006f (diff) | |
| download | ffwd-978f4f7969190265e127e8a3d704bb173fbd171c.tar.gz ffwd-978f4f7969190265e127e8a3d704bb173fbd171c.zip | |
chore: rename project
Diffstat (limited to 'embed.h')
| -rw-r--r-- | embed.h | 114 |
1 files changed, 57 insertions, 57 deletions
@@ -1,18 +1,18 @@ /* - * embed.h - pplx-embed API + * embed.h - embed API */ -#ifndef PPLX_EMBED_H -#define PPLX_EMBED_H +#ifndef EMBED_H +#define EMBED_H /* Public-API export annotation. The libraries are built with - * -fvisibility=hidden, so only declarations carrying PPLX_API are exported + * -fvisibility=hidden, so only declarations carrying EMBED_API are exported * from the shared library; everything else stays internal. */ -#ifndef PPLX_API +#ifndef EMBED_API #if defined(__GNUC__) -#define PPLX_API __attribute__((visibility("default"))) +#define EMBED_API __attribute__((visibility("default"))) #else -#define PPLX_API +#define EMBED_API #endif #endif @@ -23,10 +23,10 @@ * Shared constants (identical across all models) * ======================================================================== */ -#define PPLX_VOCAB_SIZE 151936 -#define PPLX_HEAD_DIM 128 -#define PPLX_MAX_LAYERS 64 /* upper bound for stack arrays */ -#define PPLX_CONTEXT_SEPARATOR_TOKEN_ID 151643 /* <|endoftext|> */ +#define EMBED_VOCAB_SIZE 151936 +#define EMBED_HEAD_DIM 128 +#define EMBED_MAX_LAYERS 64 /* upper bound for stack arrays */ +#define EMBED_CONTEXT_SEPARATOR_TOKEN_ID 151643 /* <|endoftext|> */ /* ======================================================================== * Model Configuration (populated from config.json at load time) @@ -44,32 +44,32 @@ typedef struct { int vocab_size; /* 151936 */ float rms_norm_eps; /* 1e-6 */ float rope_theta; /* 1e6 */ -} pplx_config_t; +} embed_config_t; /* ======================================================================== * Model + workspace ownership * ======================================================================== */ -typedef struct pplx_model pplx_model_t; -typedef struct pplx_workspace pplx_workspace_t; -typedef struct pplx_late_model pplx_late_model_t; -typedef struct pplx_late_workspace pplx_late_workspace_t; +typedef struct embed_model embed_model_t; +typedef struct embed_workspace embed_workspace_t; +typedef struct embed_late_model embed_late_model_t; +typedef struct embed_late_workspace embed_late_workspace_t; typedef struct { const int *ids; int n_tokens; -} pplx_input_t; +} embed_input_t; typedef struct { int start; int n_tokens; -} pplx_span_t; +} embed_span_t; typedef struct { - pplx_input_t input; - const pplx_span_t *spans; + embed_input_t input; + const embed_span_t *spans; int n_spans; -} pplx_context_input_t; +} embed_context_input_t; /* ======================================================================== * API @@ -84,19 +84,19 @@ typedef struct { * Reads config.json to determine model size (0.6B vs 4B). * Returns NULL on error. */ -PPLX_API pplx_model_t *pplx_model_load(const char *model_dir); +EMBED_API embed_model_t *embed_model_load(const char *model_dir); -PPLX_API void pplx_model_free(pplx_model_t *model); +EMBED_API void embed_model_free(embed_model_t *model); /* * Allocate/free mutable scratch buffers for a model. The model must outlive * workspaces created from it. */ -PPLX_API pplx_workspace_t *pplx_workspace_new(const pplx_model_t *model); -PPLX_API void pplx_workspace_free(pplx_workspace_t *ws); +EMBED_API embed_workspace_t *embed_workspace_new(const embed_model_t *model); +EMBED_API void embed_workspace_free(embed_workspace_t *ws); /* Config accessor for opaque model ownership. */ -PPLX_API const pplx_config_t *pplx_model_config(const pplx_model_t *model); +EMBED_API const embed_config_t *embed_model_config(const embed_model_t *model); /* * Current mutable workspace memory owned by this workspace, in bytes. @@ -104,7 +104,7 @@ PPLX_API const pplx_config_t *pplx_model_config(const pplx_model_t *model); * This includes the workspace struct, scratch buffers, and RoPE cache capacity. * It does not include immutable mmap'd model weights. */ -PPLX_API size_t pplx_workspace_nbytes(const pplx_workspace_t *ws); +EMBED_API size_t embed_workspace_nbytes(const embed_workspace_t *ws); /* * Compute embedding for a token sequence. @@ -120,14 +120,14 @@ PPLX_API size_t pplx_workspace_nbytes(const pplx_workspace_t *ws); * * Returns malloc'd float[hidden_size] (caller frees). NULL on error. */ -PPLX_API float *pplx_model_embed(const pplx_model_t *model, pplx_workspace_t *ws, +EMBED_API float *embed_model_encode(const embed_model_t *model, embed_workspace_t *ws, const int *token_ids, int n_tokens); /* * Compute one embedding into caller-provided out[hidden_size]. * Returns 0 on success, -1 on error. */ -PPLX_API int pplx_model_embed_into(const pplx_model_t *model, pplx_workspace_t *ws, +EMBED_API int embed_model_encode_into(const embed_model_t *model, embed_workspace_t *ws, const int *token_ids, int n_tokens, float *out_embedding); @@ -140,8 +140,8 @@ PPLX_API int pplx_model_embed_into(const pplx_model_t *model, pplx_workspace_t * * * Returns 0 on success, -1 on error. */ -PPLX_API int pplx_model_embed_batch(const pplx_model_t *model, pplx_workspace_t *ws, - const pplx_input_t *inputs, int batch, +EMBED_API int embed_model_encode_batch(const embed_model_t *model, embed_workspace_t *ws, + const embed_input_t *inputs, int batch, float *out_embeddings); /* @@ -150,7 +150,7 @@ PPLX_API int pplx_model_embed_batch(const pplx_model_t *model, pplx_workspace_t * states is [sum(n_tokens), hidden_size]. seq_lengths contains one positive * token count per sequence. The states must already include final RMSNorm. */ -PPLX_API int pplx_pool_batch(const pplx_config_t *cfg, const float *states, +EMBED_API int embed_pool_batch(const embed_config_t *cfg, const float *states, const int *seq_lengths, int batch, float *out_embeddings); @@ -162,14 +162,14 @@ PPLX_API int pplx_pool_batch(const pplx_config_t *cfg, const float *states, * Useful for contextual (late-chunking) models where you need * per-token embeddings before splitting by separator positions. */ -PPLX_API float *pplx_model_forward(const pplx_model_t *model, pplx_workspace_t *ws, +EMBED_API float *embed_model_forward(const embed_model_t *model, embed_workspace_t *ws, 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. */ -PPLX_API int pplx_model_forward_into(const pplx_model_t *model, pplx_workspace_t *ws, +EMBED_API int embed_model_forward_into(const embed_model_t *model, embed_workspace_t *ws, const int *token_ids, int n_tokens, float *out_states); @@ -177,20 +177,20 @@ PPLX_API int pplx_model_forward_into(const pplx_model_t *model, pplx_workspace_t * Pool embeddings from final hidden states. * * states is [n_tokens, hidden_size], normally produced by - * pplx_model_forward_into(). Each span is mean pooled into + * embed_model_forward_into(). Each span is mean pooled into * out_embeddings[n_spans, hidden_size] without L2 normalization. */ -PPLX_API int pplx_pool_spans(const pplx_config_t *cfg, const float *states, int n_tokens, - const pplx_span_t *spans, int n_spans, +EMBED_API int embed_pool_spans(const embed_config_t *cfg, const float *states, int n_tokens, + const embed_span_t *spans, int n_spans, float *out_embeddings); /* * Run one contextual sequence and pool selected token spans. * Returns 0 on success, -1 on error. */ -PPLX_API int pplx_model_embed_spans(const pplx_model_t *model, pplx_workspace_t *ws, +EMBED_API int embed_model_encode_spans(const embed_model_t *model, embed_workspace_t *ws, const int *token_ids, int n_tokens, - const pplx_span_t *spans, int n_spans, + const embed_span_t *spans, int n_spans, float *out_embeddings); /* @@ -199,9 +199,9 @@ PPLX_API int pplx_model_embed_spans(const pplx_model_t *model, pplx_workspace_t * Documents attend independently, RoPE positions restart for each document, * and out_embeddings contains spans in document order. */ -PPLX_API int pplx_model_embed_spans_batch(const pplx_model_t *model, - pplx_workspace_t *ws, - const pplx_context_input_t *inputs, int batch, +EMBED_API int embed_model_encode_spans_batch(const embed_model_t *model, + embed_workspace_t *ws, + const embed_context_input_t *inputs, int batch, float *out_embeddings); /* @@ -210,13 +210,13 @@ PPLX_API int pplx_model_embed_spans_batch(const pplx_model_t *model, * Returns 0 on success. Returns -1 for invalid arguments or a zero-length * vector, which cannot be normalized. */ -PPLX_API int pplx_l2_normalize(float *vec, int dim); +EMBED_API int embed_l2_normalize(float *vec, int dim); /* * Cosine similarity between two vectors. * Returns 0 for invalid arguments or if either vector has zero length. */ -PPLX_API float pplx_cosine_similarity(const float *a, const float *b, int dim); +EMBED_API float embed_cosine_similarity(const float *a, const float *b, int dim); /* * Late-interaction model API. @@ -225,29 +225,29 @@ PPLX_API float pplx_cosine_similarity(const float *a, const float *b, int dim); * projected by the snapshot's 1_Dense head and L2-normalized per token by * default, matching ColBERT/MaxSim scoring semantics. */ -PPLX_API pplx_late_model_t *pplx_late_model_load(const char *model_dir); -PPLX_API void pplx_late_model_free(pplx_late_model_t *model); +EMBED_API embed_late_model_t *embed_late_model_load(const char *model_dir); +EMBED_API void embed_late_model_free(embed_late_model_t *model); -PPLX_API pplx_late_workspace_t *pplx_late_workspace_new(const pplx_late_model_t *model); -PPLX_API void pplx_late_workspace_free(pplx_late_workspace_t *ws); +EMBED_API embed_late_workspace_t *embed_late_workspace_new(const embed_late_model_t *model); +EMBED_API void embed_late_workspace_free(embed_late_workspace_t *ws); -PPLX_API const pplx_config_t *pplx_late_model_config(const pplx_late_model_t *model); -PPLX_API int pplx_late_model_token_dim(const pplx_late_model_t *model); +EMBED_API const embed_config_t *embed_late_model_config(const embed_late_model_t *model); +EMBED_API int embed_late_model_token_dim(const embed_late_model_t *model); /* * Encode token_ids into out_vectors[n_tokens, token_dim]. * * If normalize is non-zero, every non-zero token vector is L2-normalized. */ -PPLX_API int pplx_late_model_encode_tokens(const pplx_late_model_t *model, - pplx_late_workspace_t *ws, +EMBED_API int embed_late_model_encode_tokens(const embed_late_model_t *model, + embed_late_workspace_t *ws, const int *token_ids, int n_tokens, int normalize, float *out_vectors); /* * Sum over query tokens of max dot product against document tokens. */ -PPLX_API float pplx_late_maxsim(const float *query_vectors, int query_tokens, +EMBED_API float embed_late_maxsim(const float *query_vectors, int query_tokens, const float *doc_vectors, int doc_tokens, int dim); @@ -258,13 +258,13 @@ PPLX_API float pplx_late_maxsim(const float *query_vectors, int query_tokens, * doc_vectors[doc_offsets[i] * dim .. doc_offsets[i + 1] * dim). * scores is caller-provided [docs]. */ -PPLX_API int pplx_late_maxsim_batch(const float *query_vectors, int query_tokens, +EMBED_API int embed_late_maxsim_batch(const float *query_vectors, int query_tokens, const float *doc_vectors, const int *doc_offsets, int docs, int dim, float *scores); /* Verbose level: 0=quiet, 1=info, 2=debug */ -PPLX_API extern int pplx_verbose; -PPLX_API extern int qwen_verbose; +EMBED_API extern int embed_verbose; +EMBED_API extern int qwen_verbose; -#endif /* PPLX_EMBED_H */ +#endif /* EMBED_H */ |
