aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/bert_dump.c19
-rwxr-xr-xtests/check_bert_parity.py5
-rwxr-xr-xtests/check_contextual_batch_parity.py15
-rwxr-xr-xtests/check_late_interaction.py15
-rwxr-xr-xtests/check_perplexity_sdk_compat.py4
-rwxr-xr-xtests/check_server_api.py2
-rwxr-xr-xtests/check_tokenizer_parity.py10
-rwxr-xr-xtests/check_wordpiece_parity.py10
-rwxr-xr-xtests/check_workspace_api.py22
-rw-r--r--tests/contextual_batch.c4
-rw-r--r--tests/gen_fixture.c2
-rw-r--r--tests/late_check.c9
-rw-r--r--tests/model_fixture.h2
-rw-r--r--tests/test_bf16_model.c4
-rw-r--r--tests/test_bpe.c5
-rw-r--r--tests/test_cls.c5
-rw-r--r--tests/test_kernels.c6
-rw-r--r--tests/test_late.c4
-rw-r--r--tests/test_qwen2.c2
-rw-r--r--tests/test_qwen3.c2
-rw-r--r--tests/test_safetensors.c6
-rw-r--r--tests/test_sentencepiece.c2
-rw-r--r--tests/test_wordpiece.c8
-rw-r--r--tests/test_workspace.c4
-rw-r--r--tests/test_xlm_roberta.c2
-rw-r--r--tests/tiny_model.h7
-rw-r--r--tests/tok_fixture.h7
-rw-r--r--tests/tokenizer_dump.c17
-rw-r--r--tests/wordpiece_dump.c15
29 files changed, 122 insertions, 93 deletions
diff --git a/tests/bert_dump.c b/tests/bert_dump.c
index 8f820ee..5e27ce6 100644
--- a/tests/bert_dump.c
+++ b/tests/bert_dump.c
@@ -1,10 +1,15 @@
-/* Parity driver for the BERT-family forward. Loads a sentence-transformers
- * checkpoint, wraps each argument with [CLS]/[SEP], runs the BERT forward
- * (mean pool + L2 normalize inside ffwd_model_encode_into), and prints
- * "<dim> <f> <f> ..." per line. check_bert_parity.py builds this with
- * `make parity-bert-driver` and compares against SentenceTransformer.encode.
- * This one needs the real model weights, so it stays a manual --model-dir
- * check rather than a hermetic stored-vector test. */
+/* Parity driver for the BERT-family forward.
+ *
+ * Loads a sentence-transformers checkpoint, wraps each argument with [CLS]/[SEP],
+ * runs the BERT forward (mean pool + L2 normalize inside ffwd_model_encode_into),
+ * and prints "<dim> <f> <f> ..." per line.
+ *
+ * check_bert_parity.py builds this with `make parity-bert-driver` and compares against
+ * SentenceTransformer.encode.
+ *
+ * Needs the real model weights to run.
+ */
+
#include "internal.h"
#include "wordpiece.h"
diff --git a/tests/check_bert_parity.py b/tests/check_bert_parity.py
index 2500a5f..93a51f4 100755
--- a/tests/check_bert_parity.py
+++ b/tests/check_bert_parity.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-"""Compare the C BERT-family forward against SentenceTransformers.
+"""Compare the BERT-family forward against SentenceTransformers.
Builds a small C driver that loads the WordPiece tokenizer and the BERT model
from a sentence-transformers checkpoint, wraps each text with [CLS]/[SEP],
@@ -7,8 +7,7 @@ encodes it (BERT forward + mean pool + L2 normalize), and prints the vector.
The reference is SentenceTransformer(model).encode(normalize_embeddings=True),
which runs the same pipeline. Defaults to all-MiniLM-L6-v2.
-This one needs the real model weights to run the C forward, so it stays a
-manual --model-dir check rather than a hermetic stored-vector test.
+Needs the real model weights to run the C forward.
uv run --python 3.12 --with-requirements requirements-reference.txt \
tests/check_bert_parity.py --model-dir DIR
diff --git a/tests/check_contextual_batch_parity.py b/tests/check_contextual_batch_parity.py
index 6cd7021..e7f1e94 100755
--- a/tests/check_contextual_batch_parity.py
+++ b/tests/check_contextual_batch_parity.py
@@ -1,11 +1,16 @@
#!/usr/bin/env python3
-"""Run the contextual batch-versus-singleton parity check.
+"""Run the contextual batch-vs-singleton parity check.
-The C side is tests/contextual_batch.c, built by the Makefile target
-`parity-context-driver`; this script builds it and runs it with the requested
-parameters. It compares the single-document path against the batched path in C
-(no external reference), so it needs a model directory but no Python ML stack.
+The C test is tests/contextual_batch.c, built by the Makefile target
+`parity-context-driver`.
+This script builds the driver and runs it with the requested parameters. It
+compares the single-document path against the batched path in C, with no
+external reference.
+
+Requires a model directory.
+
+Usage:
tests/check_contextual_batch_parity.py --model-dir DIR
"""
diff --git a/tests/check_late_interaction.py b/tests/check_late_interaction.py
index e9dedb4..5bfb02f 100755
--- a/tests/check_late_interaction.py
+++ b/tests/check_late_interaction.py
@@ -1,12 +1,17 @@
#!/usr/bin/env python3
"""Smoke-check late-interaction token vectors and MaxSim ranking.
-The C side is tests/late_check.c, built by the Makefile target
-`late-check-driver`. Plain mode runs the driver against a real late model and
-checks the expected ranking; it needs only python3 and a late model directory
-(e.g. pplx-embed-v1-late-0.6b). With --compare-pylate it also compares the C
-token vectors against PyLate, which needs the pylate package:
+The C test is tests/late_check.c, built by the Makefile target
+`late-check-driver`.
+Plain mode runs the driver against a real late model and checks the expected
+ranking. It requires only python3 and a late model directory, such as
+pplx-embed-v1-late-0.6b.
+
+With --compare-pylate, it also compares C token vectors against PyLate. This
+requires the pylate package.
+
+Usage:
tests/check_late_interaction.py --model-dir DIR
uv run --python 3.12 --with pylate tests/check_late_interaction.py \
--model-dir DIR --compare-pylate
diff --git a/tests/check_perplexity_sdk_compat.py b/tests/check_perplexity_sdk_compat.py
index f0511f6..2e9e949 100755
--- a/tests/check_perplexity_sdk_compat.py
+++ b/tests/check_perplexity_sdk_compat.py
@@ -66,9 +66,7 @@ CONTEXT_DOCS = {
}
-# -------------------------------------------------------------------------
# Server launch (skipped when --base-url points at a running server)
-# -------------------------------------------------------------------------
def ensure_server() -> None:
if not SERVER_BIN.exists():
@@ -120,9 +118,7 @@ def wait_ready(base_url: str, api_key: str, model: str,
die_with_log(proc, log_path, "server did not become ready in time")
-# -------------------------------------------------------------------------
# SDK checks
-# -------------------------------------------------------------------------
def decode_int8(embedding: str) -> np.ndarray:
raw = base64.b64decode(embedding)
diff --git a/tests/check_server_api.py b/tests/check_server_api.py
index cfdc6aa..23f923e 100755
--- a/tests/check_server_api.py
+++ b/tests/check_server_api.py
@@ -64,9 +64,7 @@ def expect(cond: bool, what: str) -> None:
fail(what)
-# --------------------------------------------------------------------------
# Build + fixture + launch
-# --------------------------------------------------------------------------
def ensure_tool(path: str, make_dir: str, make_target: str) -> None:
"""Build a Make target if its output binary is missing."""
diff --git a/tests/check_tokenizer_parity.py b/tests/check_tokenizer_parity.py
index acea177..70eea3c 100755
--- a/tests/check_tokenizer_parity.py
+++ b/tests/check_tokenizer_parity.py
@@ -1,11 +1,11 @@
#!/usr/bin/env python3
-"""Check the C BPE tokenizer against stored reference vectors.
+"""Check the BPE tokenizer against stored reference vectors.
The reference ids live in tests/test-vectors/bpe/expected.json, generated from
-the Qwen tokenizer by devtools/gen_test_vectors.py. This builds the C BPE driver
-(tests/tokenizer_dump), runs it against the checked-in vocab.json + merges.txt,
-and compares the ids exactly. It imports no transformers and downloads no model,
-so it is hermetic and fast.
+the Qwen tokenizer by devtools/gen_test_vectors.py.
+
+This builds the C BPE driver (tests/tokenizer_dump), runs it against the checked-in
+vocab.json + merges.txt, and compares the ids exactly.
tests/check_tokenizer_parity.py
tests/check_tokenizer_parity.py --cc clang
diff --git a/tests/check_wordpiece_parity.py b/tests/check_wordpiece_parity.py
index b03da7e..8f09394 100755
--- a/tests/check_wordpiece_parity.py
+++ b/tests/check_wordpiece_parity.py
@@ -1,11 +1,11 @@
#!/usr/bin/env python3
-"""Check the C WordPiece tokenizer against stored reference vectors.
+"""Check the WordPiece tokenizer against stored reference vectors.
The reference ids live in tests/test-vectors/wordpiece/expected.json, generated
-from the slow BertTokenizer by devtools/gen_test_vectors.py. This builds the C
-WordPiece driver (tests/wordpiece_dump), runs it against the checked-in
-vocab.txt + tokenizer_config.json, and compares the ids exactly. It imports no
-transformers and downloads no model, so it is hermetic and fast.
+from the slow BertTokenizer by devtools/gen_test_vectors.py.
+
+This builds the C WordPiece driver (tests/wordpiece_dump), runs it against the checked-in
+vocab.txt + tokenizer_config.json, and compares the ids exactly.
tests/check_wordpiece_parity.py
tests/check_wordpiece_parity.py --cc clang
diff --git a/tests/check_workspace_api.py b/tests/check_workspace_api.py
index 05f0e8c..40e51b6 100755
--- a/tests/check_workspace_api.py
+++ b/tests/check_workspace_api.py
@@ -1,16 +1,20 @@
#!/usr/bin/env python3
-"""Run the workspace / model API smoke test against real weights.
+"""Run the workspace/model API smoke test with real weights.
-The C side is tests/test_workspace.c, the same source `make test` builds with
-the synthetic fixture. Given a MODEL_DIR it loads real weights from that
-directory instead and exercises the workspace and batch APIs. Needs only
-python3 and a model directory (with vocab.json), no reference stack.
+The C test is tests/test_workspace.c, the same source `make test` builds with
+the synthetic fixture. With MODEL_DIR, it loads real weights from that directory
+instead and exercises the workspace and batch APIs.
-For mean-pooled models, the test additionally checks that a whole-sequence span
-pools to the embedding and that half-spans recombine by token-count weighting.
-For last-token/CLS models, those mean-span identities are skipped because the
-sentence embedding and contextual span APIs intentionally pool different rows.
+Requires only python3 and a model directory with vocab.json; no reference stack.
+For mean-pooled models, also checks that:
+- a whole-sequence span pools to the embedding
+- half-spans recombine by token-count weighting
+
+For last-token/CLS models, these mean-span checks are skipped because sentence
+embedding and contextual span APIs intentionally pool different rows.
+
+Usage:
tests/check_workspace_api.py --model-dir DIR
"""
diff --git a/tests/contextual_batch.c b/tests/contextual_batch.c
index 9700e82..1c4b5be 100644
--- a/tests/contextual_batch.c
+++ b/tests/contextual_batch.c
@@ -3,7 +3,9 @@
* No external library is involved; it checks the C code against itself. With a
* positive run count it also times the batched path. check_contextual_batch_parity.py
* builds this with `make parity-context-driver` (or parity-context-driver-mlx)
- * and passes the model dir plus tolerances as positional arguments. */
+ * and passes the model dir plus tolerances as positional arguments.
+ */
+
#include "internal.h"
#ifdef CHECK_MLX
# include "mlx.h"
diff --git a/tests/gen_fixture.c b/tests/gen_fixture.c
index bf01fd6..0a52fb9 100644
--- a/tests/gen_fixture.c
+++ b/tests/gen_fixture.c
@@ -1,4 +1,4 @@
-/* gen_fixture.c - write a tiny model fixture to a directory.
+/* Write a tiny model fixture to a directory.
*
* Thin command-line front end over tests/model_fixture.h, so out-of-process
* callers (shell scripts, Python) can materialize the same synthetic model the
diff --git a/tests/late_check.c b/tests/late_check.c
index e0335e8..bb868d3 100644
--- a/tests/late_check.c
+++ b/tests/late_check.c
@@ -1,8 +1,11 @@
/* Late-interaction smoke driver: encodes a query and three documents to
* token vectors, runs scalar and batched MaxSim, and checks the expected
- * ranking. With --json it emits vectors and scores for the optional PyLate
- * comparison in check_late_interaction.py, which builds this via
- * `make late-check-driver` (or late-check-driver-mlx). */
+ * ranking.
+ * With --json it emits vectors and scores for the optional PyLate comparison
+ * in check_late_interaction.py, which builds this via make late-check-driver
+ * (or late-check-driver-mlx).
+ */
+
#include "internal.h"
#ifdef CHECK_MLX
# include "mlx.h"
diff --git a/tests/model_fixture.h b/tests/model_fixture.h
index bd613b2..fd2a282 100644
--- a/tests/model_fixture.h
+++ b/tests/model_fixture.h
@@ -1,4 +1,4 @@
-/* tests/model_fixture.h - shared model+tokenizer fixture writer. */
+/* Shared model+tokenizer fixture writer. */
#ifndef MODEL_FIXTURE_H
#define MODEL_FIXTURE_H
diff --git a/tests/test_bf16_model.c b/tests/test_bf16_model.c
index 6c4b2a4..8b18adc 100644
--- a/tests/test_bf16_model.c
+++ b/tests/test_bf16_model.c
@@ -1,5 +1,5 @@
-/* tests/test_bf16_model.c - F32 vs BF16 vs F16 loader/dispatch parity on a tiny
- * synthetic model. Hermetic: builds its own model dirs. Runs via `make test`.
+/* F32 vs BF16 vs F16 loader/dispatch parity on a tiny synthetic model.
+ * Hermetic: builds its own model dirs. Runs via make test.
* F16 has no fused kernel: the loader widens it to F32 once at load, so an F16
* copy must match the F32 copy as closely as the BF16 copy does. */
diff --git a/tests/test_bpe.c b/tests/test_bpe.c
index 1674b4e..02e5078 100644
--- a/tests/test_bpe.c
+++ b/tests/test_bpe.c
@@ -1,8 +1,9 @@
-/* tests/test_tokenizer.c - hermetic byte-level BPE tokenizer tests.
+/* Hermetic byte-level BPE tokenizer tests.
* Synthesizes a complete GPT-2-style vocab.json (all 256 byte tokens plus
* merged tokens) and merges.txt, then checks exact token ids through the
* integer-pair fast path, and that dropping the integer tables (forcing the
- * string-based fallback) produces identical ids. Runs via `make test`. */
+ * string-based fallback) produces identical ids. Runs via make test.
+ */
#include "bpe.h"
#include "tok_fixture.h"
diff --git a/tests/test_cls.c b/tests/test_cls.c
index b6e2dfb..b929a81 100644
--- a/tests/test_cls.c
+++ b/tests/test_cls.c
@@ -1,5 +1,6 @@
-/* tests/test_cls.c - hermetic CLS (first-token) pooling across the load path,
- * the encode path, and the public pooling API. */
+/* Hermetic CLS (first-token) pooling across the load path, the encode path, and the
+ * public pooling API.
+ */
#include "internal.h"
#include "tiny_model.h"
diff --git a/tests/test_kernels.c b/tests/test_kernels.c
index 37847c1..f7e4680 100644
--- a/tests/test_kernels.c
+++ b/tests/test_kernels.c
@@ -1,6 +1,6 @@
-/* tests/test_kernels.c - golden tests for the low-level math kernels.
- * Runs via `make test`, `make -C tests test_kernels test_kernels_generic`,
- * or `./all.bash check-kernel-golden`. No model files required. */
+/* Golden tests for the low-level math kernels.
+ * Runs via make test, make -C tests test_kernels test_kernels_generic. No model files required.
+ */
#include "kernels.h"
#include "threadpool.h"
diff --git a/tests/test_late.c b/tests/test_late.c
index 37a1bf1..2bf2053 100644
--- a/tests/test_late.c
+++ b/tests/test_late.c
@@ -1,6 +1,6 @@
-/* tests/test_late.c - late-interaction (ColBERT-style MaxSim) API tests.
+/* Late-interaction (ColBERT-style MaxSim) API tests.
* Hermetic: synthesizes a tiny base model, a 1_Dense projection head, and a
- * byte-complete tokenizer fixture. Runs via `make test`. */
+ * byte-complete tokenizer fixture. Runs via make test. */
#include "internal.h"
#include "bpe.h"
diff --git a/tests/test_qwen2.c b/tests/test_qwen2.c
index 9567aad..a322c33 100644
--- a/tests/test_qwen2.c
+++ b/tests/test_qwen2.c
@@ -1,4 +1,4 @@
-/* tests/test_qwen2.c - hermetic GTE-Qwen2 block and task semantics. */
+/* Hermetic GTE-Qwen2 block and task semantics. */
#include "internal.h"
#include "tiny_model.h"
diff --git a/tests/test_qwen3.c b/tests/test_qwen3.c
index 50f7e02..a685f03 100644
--- a/tests/test_qwen3.c
+++ b/tests/test_qwen3.c
@@ -1,4 +1,4 @@
-/* tests/test_qwen3.c - hermetic Qwen3 model semantics. */
+/* Hermetic Qwen3 model semantics. */
#include "internal.h"
#include "tiny_model.h"
diff --git a/tests/test_safetensors.c b/tests/test_safetensors.c
index 5f748cf..c9a06fb 100644
--- a/tests/test_safetensors.c
+++ b/tests/test_safetensors.c
@@ -1,6 +1,6 @@
-/* tests/test_safetensors.c - safetensors parser limit and rejection tests.
- * Hermetic: synthesizes every fixture in a temp directory. Runs via
- * `make test`. */
+/* safetensors parser limit and rejection tests.
+ * Hermetic: synthesizes every fixture in a temp directory.
+ */
#include "safetensors.h"
diff --git a/tests/test_sentencepiece.c b/tests/test_sentencepiece.c
index c04b5c1..cfbe1d1 100644
--- a/tests/test_sentencepiece.c
+++ b/tests/test_sentencepiece.c
@@ -1,4 +1,4 @@
-/* tests/test_sentencepiece.c - hermetic SentencePiece Unigram checks. */
+/* Hermetic SentencePiece Unigram checks. */
#include "sentencepiece.h"
diff --git a/tests/test_wordpiece.c b/tests/test_wordpiece.c
index 289260c..2e95f3e 100644
--- a/tests/test_wordpiece.c
+++ b/tests/test_wordpiece.c
@@ -1,7 +1,7 @@
-/* tests/test_wordpiece.c - hermetic WordPiece tokenizer checks. A synthetic
- * vocab exercises greedy ## matching, [UNK], casing, accent stripping,
- * punctuation splitting, CJK char-splitting, special-token resolution, and the
- * workspace encode paths. No model files or network needed. */
+/* Hermetic WordPiece tokenizer checks. A synthetic vocab exercises greedy
+ * ## matching, [UNK], casing, accent stripping, punctuation splitting, CJK char-splitting,
+ * special-token resolution, and the workspace encode paths.
+ */
#include "wordpiece.h"
diff --git a/tests/test_workspace.c b/tests/test_workspace.c
index ca5b136..1e0f4a4 100644
--- a/tests/test_workspace.c
+++ b/tests/test_workspace.c
@@ -1,7 +1,7 @@
-/* tests/test_workspace.c - model/workspace API lifecycle tests.
+/* Model/workspace API lifecycle tests.
* Hermetic by default (synthesizes a tiny model + tokenizer fixture);
* pass a MODEL_DIR to run the same checks against real weights, which is
- * what tests/integration/check_workspace_api.py does. Runs via `make test`. */
+ * what tests/integration/check_workspace_api.py does. Runs via make test. */
#include "internal.h"
#include "bpe.h"
diff --git a/tests/test_xlm_roberta.c b/tests/test_xlm_roberta.c
index 4370855..82e4159 100644
--- a/tests/test_xlm_roberta.c
+++ b/tests/test_xlm_roberta.c
@@ -1,4 +1,4 @@
-/* tests/test_xlm_roberta.c - hermetic XLM-R/RoBERTa bridge checks. */
+/* Hermetic XLM-R/RoBERTa bridge checks. */
#include "internal.h"
#include "tiny_model.h"
diff --git a/tests/tiny_model.h b/tests/tiny_model.h
index 58b58ea..cc9bc36 100644
--- a/tests/tiny_model.h
+++ b/tests/tiny_model.h
@@ -1,6 +1,7 @@
-/* tests/tiny_model.h - synthesize a tiny 1-layer model directory (config.json
- * + model.safetensors) for hermetic tests. Values are BF16-representable so an
- * F32 and a BF16 copy of the same model produce identical embeddings. */
+/* Synthesize a tiny 1-layer model directory (config.json + model.safetensors) for hermetic
+ * tests. Values are BF16-representable so an F32 and a BF16 copy of the same model produce
+ * identical embeddings.
+ */
#ifndef TINY_MODEL_H
#define TINY_MODEL_H
diff --git a/tests/tok_fixture.h b/tests/tok_fixture.h
index 9aa4170..7deeb75 100644
--- a/tests/tok_fixture.h
+++ b/tests/tok_fixture.h
@@ -1,7 +1,6 @@
-/* tests/tok_fixture.h - synthesize a complete GPT-2-style byte-level BPE
- * tokenizer fixture into a directory: vocab.json with all 256 byte tokens
- * (ids 0-255, so any input tokenizes) plus a few merged tokens (ids 256+),
- * and the matching merges.txt. */
+/* Synthesize a complete GPT-2-style byte-level BPE tokenizer fixture into a directory:
+ * vocab.json with all 256 byte tokens (ids 0-255, so any input tokenizes) plus a few merged
+ * tokens (ids 256+), and the matching merges.txt. */
#ifndef TOK_FIXTURE_H
#define TOK_FIXTURE_H
diff --git a/tests/tokenizer_dump.c b/tests/tokenizer_dump.c
index f6e26aa..4e8e8ec 100644
--- a/tests/tokenizer_dump.c
+++ b/tests/tokenizer_dump.c
@@ -1,9 +1,14 @@
-/* Parity driver for the BPE tokenizer. Loads vocab.json (merges.txt is read
- * from the same directory), encodes each argument through the three encode
- * entry points (and cross-checks they agree), then prints "<count> <id> <id>
- * ..." per line. check_tokenizer_parity.py builds this with
- * `make parity-tokenizer-driver` and compares the ids against the stored
- * reference vectors in tests/test-vectors/bpe/. Links libtok. */
+/* BPE tokenizer parity driver.
+ * Loads vocab.json; merges.txt is read from the same directory.
+ * Encodes each argument through the three encode entry points and checks that
+ * they agree.
+ *
+ * Prints one line per argument: "<count> <id> <id> ...".
+ *
+ * check_tokenizer_parity.py builds this with `make parity-tokenizer-driver` and
+ * compares ids against reference vectors in tests/test-vectors/bpe/.
+ */
+
#include "bpe.h"
#include <stdio.h>
diff --git a/tests/wordpiece_dump.c b/tests/wordpiece_dump.c
index 5dfb563..952e9e2 100644
--- a/tests/wordpiece_dump.c
+++ b/tests/wordpiece_dump.c
@@ -1,8 +1,13 @@
-/* Parity driver for the WordPiece tokenizer. Loads a BERT vocab dir, encodes
- * each argument through both encode entry points (and cross-checks they agree),
- * then prints "<count> <id> <id> ..." per line. check_wordpiece_parity.py builds
- * this with `make parity-wordpiece-driver` and compares the ids against the
- * stored reference vectors in tests/test-vectors/wordpiece/. Links libtok. */
+/* WordPiece tokenizer parity driver.
+ * Loads a BERT vocab dir, encodes each argument through both encode entry
+ * points, and checks that they agree.
+ *
+ * Prints one line per argument: "<count> <id> <id> ...".
+ *
+ * check_wordpiece_parity.py builds this with `make parity-wordpiece-driver` and
+ * compares ids against reference vectors in tests/test-vectors/wordpiece/.
+ */
+
#include "wordpiece.h"
#include <stdio.h>