Skip to content

Commit 886b97a

Browse files
authored
tests: Generate unique input values for count_equal (ggml-org#15487)
This avoids backend-dependent behavior for argmax that leads to intermittent failures.
1 parent 111f8d0 commit 886b97a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/test-backend-ops.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,6 +2209,26 @@ struct test_count_equal : public test_case {
22092209
double max_nmse_err() override {
22102210
return 0.0;
22112211
}
2212+
2213+
void initialize_tensors(ggml_context * ctx) override {
2214+
std::random_device rd;
2215+
std::default_random_engine rng(rd());
2216+
for (ggml_tensor * t = ggml_get_first_tensor(ctx); t != NULL; t = ggml_get_next_tensor(ctx, t)) {
2217+
if (t->type == GGML_TYPE_F32) {
2218+
// initialize with unique values to avoid ties
2219+
for (int64_t r = 0; r < ggml_nrows(t); r++) {
2220+
std::vector<float> data(t->ne[0]);
2221+
for (int i = 0; i < t->ne[0]; i++) {
2222+
data[i] = i;
2223+
}
2224+
std::shuffle(data.begin(), data.end(), rng);
2225+
ggml_backend_tensor_set(t, data.data(), r * t->nb[1], t->ne[0] * sizeof(float));
2226+
}
2227+
} else {
2228+
init_tensor_uniform(t);
2229+
}
2230+
}
2231+
}
22122232
};
22132233

22142234
// GGML_OP_REPEAT

0 commit comments

Comments
 (0)