aboutsummaryrefslogtreecommitdiff
path: root/tests/test_bf16_model.c
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-06-20 20:36:55 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-21 06:00:26 +0200
commit6652fcbc653d84e75cb5c08c5f5edf52263ed50f (patch)
tree1ccffa48e1dc86c59c61dcd4672ffedcf1e0c873 /tests/test_bf16_model.c
parentdbdf714bb57578431924e5d069089bdfd9f4c604 (diff)
downloadffwd-6652fcbc653d84e75cb5c08c5f5edf52263ed50f.tar.gz
ffwd-6652fcbc653d84e75cb5c08c5f5edf52263ed50f.zip
tests: upgrade unit tests and add integration/parity tests
Diffstat (limited to 'tests/test_bf16_model.c')
-rw-r--r--tests/test_bf16_model.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/tests/test_bf16_model.c b/tests/test_bf16_model.c
index 0849f3e..6c4b2a4 100644
--- a/tests/test_bf16_model.c
+++ b/tests/test_bf16_model.c
@@ -3,7 +3,7 @@
* 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. */
-#include "embed.h"
+#include "internal.h"
#include "tiny_model.h"
#include <math.h>
@@ -14,7 +14,7 @@
int main(void) {
char root[1024], f32_dir[1088], bf16_dir[1088], f16_dir[1088], prefixed_dir[1088];
- snprintf(root, sizeof(root), "%s/embed-bf16-test-XXXXXX",
+ snprintf(root, sizeof(root), "%s/ffwd-bf16-test-XXXXXX",
getenv("TMPDIR") ? getenv("TMPDIR") : "/tmp");
if (!mkdtemp(root)) {
perror("mkdtemp");
@@ -34,34 +34,34 @@ int main(void) {
}
int ids[] = {1, 2, 3, 4};
- embed_model_t *mf32 = embed_model_load(f32_dir);
- embed_model_t *mbf16 = embed_model_load(bf16_dir);
- embed_model_t *mf16 = embed_model_load(f16_dir);
- embed_model_t *mprefixed = embed_model_load(prefixed_dir);
+ ffwd_model_t *mf32 = ffwd_model_load(f32_dir);
+ ffwd_model_t *mbf16 = ffwd_model_load(bf16_dir);
+ ffwd_model_t *mf16 = ffwd_model_load(f16_dir);
+ ffwd_model_t *mprefixed = ffwd_model_load(prefixed_dir);
if (!mf32 || !mbf16 || !mf16 || !mprefixed) {
fprintf(stderr, "model load failed\n");
return 1;
}
- const embed_config_t *cfg = embed_model_config(mf32);
+ const ffwd_config_t *cfg = ffwd_model_config(mf32);
int dim = cfg->hidden_size;
float *a = (float *)malloc((size_t)dim * sizeof(float));
float *b = (float *)malloc((size_t)dim * sizeof(float));
float *c = (float *)malloc((size_t)dim * sizeof(float));
float *e = (float *)malloc((size_t)dim * sizeof(float));
- embed_workspace_t *wf32 = embed_workspace_new(mf32);
- embed_workspace_t *wbf16 = embed_workspace_new(mbf16);
- embed_workspace_t *wf16 = embed_workspace_new(mf16);
- embed_workspace_t *wprefixed = embed_workspace_new(mprefixed);
+ ffwd_workspace_t *wf32 = ffwd_workspace_new(mf32);
+ ffwd_workspace_t *wbf16 = ffwd_workspace_new(mbf16);
+ ffwd_workspace_t *wf16 = ffwd_workspace_new(mf16);
+ ffwd_workspace_t *wprefixed = ffwd_workspace_new(mprefixed);
if (!a || !b || !c || !e || !wf32 || !wbf16 || !wf16 || !wprefixed) {
fprintf(stderr, "allocation failed\n");
return 1;
}
- if (embed_model_encode_into(mf32, wf32, ids, 4, a) != 0 ||
- embed_model_encode_into(mbf16, wbf16, ids, 4, b) != 0 ||
- embed_model_encode_into(mf16, wf16, ids, 4, e) != 0 ||
- embed_model_encode_into(mprefixed, wprefixed, ids, 4, c) != 0) {
+ if (ffwd_model_encode_into(mf32, wf32, ids, 4, a) != 0 ||
+ ffwd_model_encode_into(mbf16, wbf16, ids, 4, b) != 0 ||
+ ffwd_model_encode_into(mf16, wf16, ids, 4, e) != 0 ||
+ ffwd_model_encode_into(mprefixed, wprefixed, ids, 4, c) != 0) {
fprintf(stderr, "embedding failed\n");
return 1;
}
@@ -91,8 +91,8 @@ int main(void) {
* magnitude and tight F32-vs-BF16/F16 parity, not unit norm. F16 carries
* more mantissa bits than BF16, so the same 2e-5 bound holds. */
if (norm <= 1e-6f || max_diff > 2e-5f || f16_diff > 2e-5f || prefix_diff != 0.0f) {
- fprintf(stderr, "bad parity: norm=%.9g max_diff=%.9g f16_diff=%.9g prefix_diff=%.9g\n",
- norm, max_diff, f16_diff, prefix_diff);
+ fprintf(stderr, "bad parity: norm=%.9g max_diff=%.9g f16_diff=%.9g prefix_diff=%.9g\n", norm,
+ max_diff, f16_diff, prefix_diff);
return 1;
}
@@ -102,9 +102,9 @@ int main(void) {
int long_ids[LONG_N];
for (int i = 0; i < LONG_N; i++)
long_ids[i] = (i % 14) + 1;
- if (embed_model_encode_into(mf32, wf32, long_ids, LONG_N, a) != 0 ||
- embed_model_encode_into(mbf16, wbf16, long_ids, LONG_N, b) != 0 ||
- embed_model_encode_into(mf16, wf16, long_ids, LONG_N, e) != 0) {
+ if (ffwd_model_encode_into(mf32, wf32, long_ids, LONG_N, a) != 0 ||
+ ffwd_model_encode_into(mbf16, wbf16, long_ids, LONG_N, b) != 0 ||
+ ffwd_model_encode_into(mf16, wf16, long_ids, LONG_N, e) != 0) {
fprintf(stderr, "long-sequence embedding failed\n");
return 1;
}
@@ -129,14 +129,14 @@ int main(void) {
printf("ok: bf16/f16 and model-prefix parity dim=%d bf16_diff=%.9g f16_diff=%.9g norm=%.9g\n",
dim, max_diff, f16_diff, norm);
- embed_workspace_free(wf32);
- embed_workspace_free(wbf16);
- embed_workspace_free(wf16);
- embed_workspace_free(wprefixed);
- embed_model_free(mf32);
- embed_model_free(mbf16);
- embed_model_free(mf16);
- embed_model_free(mprefixed);
+ ffwd_workspace_free(wf32);
+ ffwd_workspace_free(wbf16);
+ ffwd_workspace_free(wf16);
+ ffwd_workspace_free(wprefixed);
+ ffwd_model_free(mf32);
+ ffwd_model_free(mbf16);
+ ffwd_model_free(mf16);
+ ffwd_model_free(mprefixed);
free(a);
free(b);
free(c);