aboutsummaryrefslogtreecommitdiff
path: root/tests/test_qwen3.c
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-06-15 08:40:11 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-15 08:40:11 +0200
commitc4a1c97a09da6d8d88c2ac834bf6234506fc41bc (patch)
tree81ce5675ce886aad0309a41f4d6a696826e0a061 /tests/test_qwen3.c
parentb377ba8656bfb807ed8dda6c9f26942b50ce626d (diff)
downloadffwd-c4a1c97a09da6d8d88c2ac834bf6234506fc41bc.tar.gz
ffwd-c4a1c97a09da6d8d88c2ac834bf6234506fc41bc.zip
chore: run clang-format
Diffstat (limited to 'tests/test_qwen3.c')
-rw-r--r--tests/test_qwen3.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/tests/test_qwen3.c b/tests/test_qwen3.c
index 4d63a35..d66e0f7 100644
--- a/tests/test_qwen3.c
+++ b/tests/test_qwen3.c
@@ -9,24 +9,22 @@
#include <string.h>
#include <unistd.h>
-static float max_abs_diff(const float *a, const float *b, int n)
-{
+static float max_abs_diff(const float *a, const float *b, int n) {
float out = 0.0f;
for (int i = 0; i < n; i++) {
float d = fabsf(a[i] - b[i]);
- if (d > out) out = d;
+ if (d > out)
+ out = d;
}
return out;
}
-int main(void)
-{
+int main(void) {
char dir[1024];
snprintf(dir, sizeof(dir), "%s/embed-qwen3-test-XXXXXX",
getenv("TMPDIR") ? getenv("TMPDIR") : "/tmp");
tm_dims_t dims = {4, 2, 1, 2, 8, 16};
- if (!mkdtemp(dir) ||
- tm_write_qwen3_model_dims(dir, "F32", &dims, 15) != 0) {
+ if (!mkdtemp(dir) || tm_write_qwen3_model_dims(dir, "F32", &dims, 15) != 0) {
fprintf(stderr, "fixture creation failed\n");
return 2;
}
@@ -39,8 +37,8 @@ int main(void)
return 1;
}
if (cfg->attention_mode != EMBED_ATTENTION_CAUSAL ||
- cfg->pooling_mode != EMBED_POOL_LAST_TOKEN ||
- !cfg->normalize_embeddings || !cfg->append_terminal_token) {
+ cfg->pooling_mode != EMBED_POOL_LAST_TOKEN || !cfg->normalize_embeddings ||
+ !cfg->append_terminal_token) {
fprintf(stderr, "Qwen3 config semantics were not detected\n");
return 1;
}
@@ -58,15 +56,15 @@ int main(void)
float expected[4];
memcpy(expected, states + 3 * 4, sizeof(expected));
- if (embed_l2_normalize(expected, 4) != 0 ||
- max_abs_diff(embedding, expected, 4) > 1e-5f ||
+ if (embed_l2_normalize(expected, 4) != 0 || max_abs_diff(embedding, expected, 4) > 1e-5f ||
max_abs_diff(pooled, expected, 4) > 1e-5f) {
fprintf(stderr, "last-token pooling mismatch\n");
return 1;
}
float norm_sq = 0.0f;
- for (int d = 0; d < 4; d++) norm_sq += embedding[d] * embedding[d];
+ for (int d = 0; d < 4; d++)
+ norm_sq += embedding[d] * embedding[d];
if (fabsf(norm_sq - 1.0f) > 1e-5f) {
fprintf(stderr, "Qwen3 embedding is not normalized: %.9g\n", norm_sq);
return 1;
@@ -78,8 +76,7 @@ int main(void)
float single[4];
if (embed_model_encode_batch(model, ws, inputs, 2, batch) != 0 ||
embed_model_encode_into(model, ws, short_ids, 2, single) != 0 ||
- max_abs_diff(batch, embedding, 4) > 1e-5f ||
- max_abs_diff(batch + 4, single, 4) > 1e-5f) {
+ max_abs_diff(batch, embedding, 4) > 1e-5f || max_abs_diff(batch + 4, single, 4) > 1e-5f) {
fprintf(stderr, "Qwen3 packed batch parity failed\n");
return 1;
}