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 /tests/test_workspace.c | |
| parent | d9ea2cea7dfa1eb25526a3e9b729beda5ccb006f (diff) | |
| download | ffwd-978f4f7969190265e127e8a3d704bb173fbd171c.tar.gz ffwd-978f4f7969190265e127e8a3d704bb173fbd171c.zip | |
chore: rename project
Diffstat (limited to 'tests/test_workspace.c')
| -rw-r--r-- | tests/test_workspace.c | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/tests/test_workspace.c b/tests/test_workspace.c index 334c4f2..4f83936 100644 --- a/tests/test_workspace.c +++ b/tests/test_workspace.c @@ -26,19 +26,19 @@ static float max_abs_diff(const float *a, const float *b, int n) /* The allocating and pooling API variants must agree with the *_into * results validated in main. reference is the batched row for ids0. */ -static int check_alloc_and_pooling_variants(const pplx_model_t *model, - pplx_workspace_t *ws, +static int check_alloc_and_pooling_variants(const embed_model_t *model, + embed_workspace_t *ws, const int *ids0, int n0, const float *states, const float *reference, - const pplx_config_t *cfg) + const embed_config_t *cfg) { int rc = 1; int dim = cfg->hidden_size; float *emb = NULL, *fwd = NULL, *pooled = NULL, *span_out = NULL; - emb = pplx_model_embed(model, ws, ids0, n0); - fwd = pplx_model_forward(model, ws, ids0, n0); + emb = embed_model_encode(model, ws, ids0, n0); + fwd = embed_model_forward(model, ws, ids0, n0); pooled = (float *)calloc((size_t)dim, sizeof(float)); span_out = (float *)calloc((size_t)2 * dim, sizeof(float)); if (!emb || !fwd || !pooled || !span_out) { @@ -46,44 +46,44 @@ static int check_alloc_and_pooling_variants(const pplx_model_t *model, goto done; } - if (pplx_model_embed(NULL, ws, ids0, n0) != NULL || - pplx_model_embed(model, ws, NULL, n0) != NULL || - pplx_model_forward(model, ws, ids0, 0) != NULL || - pplx_pool_batch(cfg, states, NULL, 1, pooled) == 0) { + if (embed_model_encode(NULL, ws, ids0, n0) != NULL || + embed_model_encode(model, ws, NULL, n0) != NULL || + embed_model_forward(model, ws, ids0, 0) != NULL || + embed_pool_batch(cfg, states, NULL, 1, pooled) == 0) { fprintf(stderr, "alloc variants accepted invalid arguments\n"); goto done; } if (max_abs_diff(emb, reference, dim) > 0.00005f) { - fprintf(stderr, "pplx_model_embed disagrees with batched row\n"); + fprintf(stderr, "embed_model_encode disagrees with batched row\n"); goto done; } if (max_abs_diff(fwd, states, n0 * dim) > 0.000001f) { - fprintf(stderr, "pplx_model_forward disagrees with forward_into\n"); + fprintf(stderr, "embed_model_forward disagrees with forward_into\n"); goto done; } /* Mean-pooling the final states reproduces the embedding. */ - if (pplx_pool_batch(cfg, states, &n0, 1, pooled) != 0 || + if (embed_pool_batch(cfg, states, &n0, 1, pooled) != 0 || max_abs_diff(pooled, reference, dim) > 0.00005f) { - fprintf(stderr, "pplx_pool_batch disagrees with embedding\n"); + fprintf(stderr, "embed_pool_batch disagrees with embedding\n"); goto done; } /* One span covering the whole sequence pools to the embedding, and * two halves recombine into it by token-count weighting. */ - pplx_span_t whole = {0, n0}; - if (pplx_model_embed_spans(model, ws, ids0, n0, &whole, 1, + embed_span_t whole = {0, n0}; + if (embed_model_encode_spans(model, ws, ids0, n0, &whole, 1, span_out) != 0 || max_abs_diff(span_out, reference, dim) > 0.00005f) { fprintf(stderr, "whole-sequence span disagrees with embedding\n"); goto done; } int h = n0 / 2; - pplx_span_t halves[2] = {{0, h}, {h, n0 - h}}; - if (pplx_model_embed_spans(model, ws, ids0, n0, halves, 2, + embed_span_t halves[2] = {{0, h}, {h, n0 - h}}; + if (embed_model_encode_spans(model, ws, ids0, n0, halves, 2, span_out) != 0) { - fprintf(stderr, "pplx_model_embed_spans failed for two spans\n"); + fprintf(stderr, "embed_model_encode_spans failed for two spans\n"); goto done; } for (int d = 0; d < dim; d++) { @@ -106,11 +106,11 @@ done: /* A multi-document contextual batch must match per-document runs. * doc0 is chunks 0 and 1 joined by a separator token; doc1 is chunk 2. */ -static int check_spans_batch_parity(const pplx_model_t *model, - pplx_workspace_t *ws, +static int check_spans_batch_parity(const embed_model_t *model, + embed_workspace_t *ws, int *const ids[], const int *ntok, int separator_id, - const pplx_config_t *cfg) + const embed_config_t *cfg) { int rc = 1; int dim = cfg->hidden_size; @@ -126,26 +126,26 @@ static int check_spans_batch_parity(const pplx_model_t *model, doc0[ntok[0]] = separator_id; memcpy(doc0 + ntok[0] + 1, ids[1], (size_t)ntok[1] * sizeof(int)); - pplx_span_t spans0[2] = {{0, ntok[0]}, {ntok[0] + 1, ntok[1]}}; - pplx_span_t span1 = {0, ntok[2]}; - if (pplx_model_embed_spans(model, ws, doc0, n0, spans0, 2, + embed_span_t spans0[2] = {{0, ntok[0]}, {ntok[0] + 1, ntok[1]}}; + embed_span_t span1 = {0, ntok[2]}; + if (embed_model_encode_spans(model, ws, doc0, n0, spans0, 2, expected) != 0 || - pplx_model_embed_spans(model, ws, ids[2], ntok[2], &span1, 1, + embed_model_encode_spans(model, ws, ids[2], ntok[2], &span1, 1, expected + (size_t)2 * dim) != 0) { fprintf(stderr, "singleton contextual embedding failed\n"); goto done; } - pplx_context_input_t inputs[2] = { + embed_context_input_t inputs[2] = { {{doc0, n0}, spans0, 2}, {{ids[2], ntok[2]}, &span1, 1}, }; - if (pplx_model_embed_spans_batch(model, ws, inputs, 2, actual) != 0) { + if (embed_model_encode_spans_batch(model, ws, inputs, 2, actual) != 0) { fprintf(stderr, "batched contextual embedding failed\n"); goto done; } - if (pplx_model_embed_spans_batch(model, ws, NULL, 2, actual) == 0 || - pplx_model_embed_spans_batch(model, ws, inputs, 0, actual) == 0) { + if (embed_model_encode_spans_batch(model, ws, NULL, 2, actual) == 0 || + embed_model_encode_spans_batch(model, ws, inputs, 0, actual) == 0) { fprintf(stderr, "spans batch accepted invalid arguments\n"); goto done; } @@ -174,7 +174,7 @@ int main(int argc, char **argv) /* Tiny hidden size keeps it fast; the vocab must cover every id the * byte-complete tokenizer fixture can emit. */ tm_dims_t dims = {4, 2, 1, 2, 8, TF_VOCAB_SIZE}; - snprintf(fixture_dir, sizeof(fixture_dir), "%s/pplx-ws-test-XXXXXX", + snprintf(fixture_dir, sizeof(fixture_dir), "%s/embed-ws-test-XXXXXX", getenv("TMPDIR") ? getenv("TMPDIR") : "/tmp"); if (!mkdtemp(fixture_dir) || tf_write_vocab(fixture_dir) != 0 || tm_write_model_dims(fixture_dir, "F32", &dims) != 0) { @@ -189,28 +189,28 @@ int main(int argc, char **argv) char vocab_path[4096]; snprintf(vocab_path, sizeof(vocab_path), "%s/vocab.json", model_dir); - pplx_model_t *model = pplx_model_load(model_dir); + embed_model_t *model = embed_model_load(model_dir); if (!model) { fprintf(stderr, "failed to load model\n"); return 1; } - const pplx_config_t *cfg = pplx_model_config(model); + const embed_config_t *cfg = embed_model_config(model); if (!cfg || cfg->hidden_size <= 0) { fprintf(stderr, "invalid model config\n"); - pplx_model_free(model); + embed_model_free(model); return 1; } - pplx_workspace_t *batch_ws = pplx_workspace_new(model); - pplx_workspace_t *single_ws = pplx_workspace_new(model); + embed_workspace_t *batch_ws = embed_workspace_new(model); + embed_workspace_t *single_ws = embed_workspace_new(model); qwen_tokenizer_t *tok = qwen_tokenizer_load(vocab_path); if (!batch_ws || !single_ws || !tok) { fprintf(stderr, "failed to allocate workspace or tokenizer\n"); qwen_tokenizer_free(tok); - pplx_workspace_free(single_ws); - pplx_workspace_free(batch_ws); - pplx_model_free(model); + embed_workspace_free(single_ws); + embed_workspace_free(batch_ws); + embed_model_free(model); return 1; } @@ -225,9 +225,9 @@ int main(int argc, char **argv) * sees indeterminate pointers. */ int *ids[4] = {0}; int ntok[4] = {0}; - pplx_input_t inputs[4]; + embed_input_t inputs[4]; - size_t initial_ws_bytes = pplx_workspace_nbytes(batch_ws); + size_t initial_ws_bytes = embed_workspace_nbytes(batch_ws); if (initial_ws_bytes == 0) { fprintf(stderr, "workspace byte accounting returned zero\n"); goto fail; @@ -257,8 +257,8 @@ int main(int argc, char **argv) goto fail; } - if (pplx_model_embed_batch(model, batch_ws, inputs, batch, batched) != 0) { - fprintf(stderr, "pplx_model_embed_batch failed\n"); + if (embed_model_encode_batch(model, batch_ws, inputs, batch, batched) != 0) { + fprintf(stderr, "embed_model_encode_batch failed\n"); free(states); free(normalized); free(single); @@ -266,7 +266,7 @@ int main(int argc, char **argv) goto fail; } - size_t batch_ws_bytes = pplx_workspace_nbytes(batch_ws); + size_t batch_ws_bytes = embed_workspace_nbytes(batch_ws); if (batch_ws_bytes <= initial_ws_bytes) { fprintf(stderr, "workspace byte accounting did not grow after embedding\n"); free(states); @@ -279,8 +279,8 @@ int main(int argc, char **argv) float worst_diff = 0.0f; float worst_cos = 1.0f; for (int i = 0; i < batch; i++) { - if (pplx_model_embed_into(model, single_ws, ids[i], ntok[i], single) != 0) { - fprintf(stderr, "pplx_model_embed_into failed at %d\n", i); + if (embed_model_encode_into(model, single_ws, ids[i], ntok[i], single) != 0) { + fprintf(stderr, "embed_model_encode_into failed at %d\n", i); free(states); free(normalized); free(single); @@ -290,14 +290,14 @@ int main(int argc, char **argv) const float *row = batched + (size_t)i * dim; float diff = max_abs_diff(row, single, dim); - float cos = pplx_cosine_similarity(row, single, dim); + float cos = embed_cosine_similarity(row, single, dim); if (diff > worst_diff) worst_diff = diff; if (cos < worst_cos) worst_cos = cos; } memcpy(normalized, batched, (size_t)dim * sizeof(float)); - if (pplx_l2_normalize(normalized, dim) != 0) { - fprintf(stderr, "pplx_l2_normalize failed\n"); + if (embed_l2_normalize(normalized, dim) != 0) { + fprintf(stderr, "embed_l2_normalize failed\n"); free(states); free(normalized); free(single); @@ -308,7 +308,7 @@ int main(int argc, char **argv) for (int i = 0; i < dim; i++) normalized_norm_sq += normalized[i] * normalized[i]; if (fabsf(normalized_norm_sq - 1.0f) > 0.00005f) { - fprintf(stderr, "pplx_l2_normalize produced norm_sq=%g\n", + fprintf(stderr, "embed_l2_normalize produced norm_sq=%g\n", normalized_norm_sq); free(states); free(normalized); @@ -317,8 +317,8 @@ int main(int argc, char **argv) goto fail; } - if (pplx_model_forward_into(model, batch_ws, ids[0], ntok[0], states) != 0) { - fprintf(stderr, "pplx_model_forward_into failed\n"); + if (embed_model_forward_into(model, batch_ws, ids[0], ntok[0], states) != 0) { + fprintf(stderr, "embed_model_forward_into failed\n"); free(states); free(normalized); free(single); @@ -338,7 +338,7 @@ int main(int argc, char **argv) /* Same separator resolution as the server: the fixture vocab defines * <|endoftext|>, real snapshots use the reserved id. */ int sep_id = qwen_tokenizer_token_id(tok, "<|endoftext|>"); - if (sep_id < 0) sep_id = PPLX_CONTEXT_SEPARATOR_TOKEN_ID; + if (sep_id < 0) sep_id = EMBED_CONTEXT_SEPARATOR_TOKEN_ID; if (check_spans_batch_parity(model, batch_ws, ids, ntok, sep_id, cfg) != 0) { free(states); @@ -355,9 +355,9 @@ int main(int argc, char **argv) for (int i = 0; i < batch; i++) free(ids[i]); qwen_tokenizer_free(tok); - pplx_workspace_free(single_ws); - pplx_workspace_free(batch_ws); - pplx_model_free(model); + embed_workspace_free(single_ws); + embed_workspace_free(batch_ws); + embed_model_free(model); if (worst_diff > 0.00005f || worst_cos < 0.99999f) { fprintf(stderr, "workspace API parity failed: max_abs_diff=%g cosine=%g\n", @@ -372,8 +372,8 @@ int main(int argc, char **argv) fail: for (int i = 0; i < batch; i++) free(ids[i]); qwen_tokenizer_free(tok); - pplx_workspace_free(single_ws); - pplx_workspace_free(batch_ws); - pplx_model_free(model); + embed_workspace_free(single_ws); + embed_workspace_free(batch_ws); + embed_model_free(model); return 1; } |
