From c74aef2770d2afb95bc2f45182636fdc39680dd1 Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Sat, 15 Aug 2026 12:20:50 +0200 Subject: [PATCH] add test backend ops --- tests/test-backend-ops.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/test-backend-ops.cpp b/tests/test-backend-ops.cpp index 675c884d5b..3ff2a615f4 100644 --- a/tests/test-backend-ops.cpp +++ b/tests/test-backend-ops.cpp @@ -5350,7 +5350,8 @@ struct test_rope : public test_case { if (v & 1) { auto ne = ne_a; ne[0] *= 2; ne[1] *= 4; ne[2] *= 3; a = ggml_new_tensor(ctx, type, 4, ne.data()); - if (forward) { + if (forward && n_offs == 0) { + // FIXME: support gradients with n_offs > 0 ggml_set_param(a); } ggml_set_name(a, "a"); @@ -5363,7 +5364,8 @@ struct test_rope : public test_case { // non-aligned buffer offset, which exercises backends' alignment paths. auto ne = ne_a; ne[0] *= 2; a = ggml_new_tensor(ctx, type, 4, ne.data()); - if (forward) { + if (forward && n_offs == 0) { + // FIXME: support gradients with n_offs > 0 ggml_set_param(a); } ggml_set_name(a, "a"); @@ -5374,7 +5376,8 @@ struct test_rope : public test_case { ggml_set_name(a, "view_of_a"); } else { a = ggml_new_tensor(ctx, type, 4, ne_a.data()); - if (forward) { + if (forward && n_offs == 0) { + // FIXME: support gradients with n_offs > 0 ggml_set_param(a); } ggml_set_name(a, "a"); @@ -5435,6 +5438,9 @@ struct test_rope : public test_case { out = ggml_rope_ext_back(ctx, a, pos, freq, n_dims, mode, 0, 10000.0f, fs, ef, af, 1.0f, 1.0f); } } + if (n_offs != 0) { + out = ggml_rope_set_offset(out, n_offs); + } ggml_set_name(out, "out"); return out; @@ -9587,6 +9593,20 @@ static std::vector> make_test_cases_eval() { } } + // rotated dims window at an offset (ggml_rope_set_offset), not supported for vision mode + for (ggml_type type : {GGML_TYPE_F32, GGML_TYPE_F16}) { + for (bool fw : {true, false}) { // fw == forward + for (bool ff : {false, true}) { + test_cases.emplace_back(new test_rope(type, {128, 32, 2, 1}, 32, GGML_ROPE_TYPE_NORMAL, 512, 1.4245f, 0.7465f, 1.4245f, ff, 0, fw, false, 32)); + test_cases.emplace_back(new test_rope(type, {128, 32, 2, 1}, 32, GGML_ROPE_TYPE_NEOX, 512, 1.4245f, 0.7465f, 1.4245f, ff, 0, fw, false, 32)); + test_cases.emplace_back(new test_rope(type, {128, 12, 2, 1}, 24, GGML_ROPE_TYPE_MROPE, 512, 1.4245f, 0.7465f, 1.4245f, ff, 0, fw, false, 32)); + test_cases.emplace_back(new test_rope(type, {128, 12, 2, 1}, 24, GGML_ROPE_TYPE_IMROPE, 512, 1.4245f, 0.7465f, 1.4245f, ff, 0, fw, false, 32)); + } + } + // inplace with an offset + test_cases.emplace_back(new test_rope(type, {128, 32, 2, 1}, 32, GGML_ROPE_TYPE_NEOX, 512, 1.4245f, 0.7465f, 1.4245f, false, 0, true, true, 32)); + } + for (int v : { 0, 1, 2, 3 }) { for (int dim : { 0, 1, 2, 3, }) { test_cases.emplace_back(new test_concat(GGML_TYPE_F32, {11, 12, 13, 14}, 7, dim, v));