Skip to content

Commit 52ab19d

Browse files
authored
tests: Avoid floating point precision false positives in SUM (ggml-org#17471)
* tests: Avoid floating point precision false positives in SUM * also apply to test_mean
1 parent 5182dd6 commit 52ab19d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/test-backend-ops.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5344,6 +5344,13 @@ struct test_sum : public test_case {
53445344
float grad_eps() override {
53455345
return 0.1f * sqrtf(ne[0]*ne[1]*ne[2]*ne[3]);
53465346
}
5347+
5348+
// Don't center the distribution around zero. Helps to avoid catastrophic cancellation.
5349+
void initialize_tensors(ggml_context * ctx) override {
5350+
for (ggml_tensor * t = ggml_get_first_tensor(ctx); t != nullptr; t = ggml_get_next_tensor(ctx, t)) {
5351+
init_tensor_uniform(t, -0.9f, 1.1f);
5352+
}
5353+
}
53475354
};
53485355

53495356
// GGML_OP_SUM_ROWS
@@ -5410,6 +5417,13 @@ struct test_mean : public test_case {
54105417
float grad_eps() override {
54115418
return 0.1f * ne[0]*ne[1]*ne[2]*ne[3];
54125419
}
5420+
5421+
// Don't center the distribution around zero. Helps to avoid catastrophic cancellation.
5422+
void initialize_tensors(ggml_context * ctx) override {
5423+
for (ggml_tensor * t = ggml_get_first_tensor(ctx); t != nullptr; t = ggml_get_next_tensor(ctx, t)) {
5424+
init_tensor_uniform(t, -0.9f, 1.1f);
5425+
}
5426+
}
54135427
};
54145428

54155429
// GGML_OP_UPSCALE

0 commit comments

Comments
 (0)