]> git.djapps.eu Git - pkg/ggml/sources/ggml/commitdiff
tests : adapt to changes (#0)
authorGeorgi Gerganov <redacted>
Sat, 15 Jun 2024 17:16:42 +0000 (20:16 +0300)
committerGeorgi Gerganov <redacted>
Sat, 15 Jun 2024 19:05:47 +0000 (22:05 +0300)
examples/gpt-j/main.cpp
tests/CMakeLists.txt
tests/test-backend-buffer.cpp
tests/test-xpos.c [deleted file]

index f29c357279a3b6131818a4d41be691c65ea501ff..ae55fb7029500e4cee0852e3942ad6ccb07273e0 100644 (file)
@@ -459,8 +459,8 @@ bool gptj_eval(
 
         // self-attention
         {
-            struct ggml_tensor * Qcur = ggml_rope_inplace(ctx0, ggml_reshape_3d(ctx0, ggml_mul_mat(ctx0, model.layers[il].c_attn_q_proj_w, cur), n_embd/n_head, n_head, N), KQ_pos, n_rot, 0, 0);
-            struct ggml_tensor * Kcur = ggml_rope_inplace(ctx0, ggml_reshape_3d(ctx0, ggml_mul_mat(ctx0, model.layers[il].c_attn_k_proj_w, cur), n_embd/n_head, n_head, N), KQ_pos, n_rot, 0, 0);
+            struct ggml_tensor * Qcur = ggml_rope_inplace(ctx0, ggml_reshape_3d(ctx0, ggml_mul_mat(ctx0, model.layers[il].c_attn_q_proj_w, cur), n_embd/n_head, n_head, N), KQ_pos, n_rot, 0);
+            struct ggml_tensor * Kcur = ggml_rope_inplace(ctx0, ggml_reshape_3d(ctx0, ggml_mul_mat(ctx0, model.layers[il].c_attn_k_proj_w, cur), n_embd/n_head, n_head, N), KQ_pos, n_rot, 0);
 
             // store key and value to memory
             {
index 07595964159944421f3a4fa3295c1fe7345107dc..4ddb6664be31de3436db31f8dc390179197143fd 100644 (file)
@@ -375,15 +375,6 @@ endif()
 add_test(NAME ${TEST_TARGET} COMMAND $<TARGET_FILE:${TEST_TARGET}>)
 set_property(TEST ${TEST_TARGET} PROPERTY ENVIRONMENT "LLVM_PROFILE_FILE=${TEST_TARGET}.profraw")
 
-#
-# test-xpos
-
-set(TEST_TARGET test-xpos)
-add_executable(${TEST_TARGET} ${TEST_TARGET}.c)
-target_link_libraries(${TEST_TARGET} PRIVATE ggml)
-add_test(NAME ${TEST_TARGET} COMMAND $<TARGET_FILE:${TEST_TARGET}>)
-set_property(TEST ${TEST_TARGET} PROPERTY ENVIRONMENT "LLVM_PROFILE_FILE=${TEST_TARGET}.profraw")
-
 #
 # test-conv1d
 
index 19ba22a527592cf8b33b5c9d618232234989300c..71181d92ac0f0310605f60f355c4f7ce8246f08e 100644 (file)
@@ -14,7 +14,7 @@ static bool is_pow2(size_t x) {
 static void test_buffer(ggml_backend_t backend, ggml_backend_buffer_type_t buft) {
     GGML_ASSERT(ggml_backend_get_default_buffer_type(backend) == buft);
 
-    GGML_ASSERT(ggml_backend_buft_supports_backend(buft, backend));
+    GGML_ASSERT(ggml_backend_supports_buft(backend, buft));
 
     //ggml_backend_buffer_t buffer = ggml_backend_alloc_buffer(backend, 1024);
     ggml_backend_buffer_t buffer = ggml_backend_buft_alloc_buffer(buft, 1024);
diff --git a/tests/test-xpos.c b/tests/test-xpos.c
deleted file mode 100644 (file)
index 5f33110..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-#include "ggml/ggml.h"
-
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-bool is_close(float a, float b, float epsilon) {
-    return fabs(a - b) < epsilon;
-}
-
-int main(int argc, char ** argv) {
-    const int n_threads = 1;
-    const int n_embd_head = 4; // aka head_dim
-    const int n_head = 1;
-    const int N = 8;
-
-    struct ggml_init_params params = {
-        .mem_size   = 16*1024*1024,
-        .mem_buffer = NULL,
-    };
-
-    // memory allocation happens here
-    struct ggml_context * ctx = ggml_init(params);
-
-    struct ggml_tensor * Q = ggml_new_tensor_3d(ctx, GGML_TYPE_F32, n_embd_head, n_head, N);
-    struct ggml_tensor * K = ggml_new_tensor_3d(ctx, GGML_TYPE_F32, n_embd_head, n_head, N);
-
-    for (int i = 0; i < ggml_nelements(Q); i++) {
-        ((float*) Q->data)[i] = 2.0f;
-        ((float*) K->data)[i] = 2.0f;
-    }
-
-    struct ggml_tensor * KQ_pos = ggml_new_tensor_1d(ctx, GGML_TYPE_I32, N);
-    int * data = (int *) KQ_pos->data;
-    for (int i = 0; i < N; ++i) {
-        data[i] = 1 + i;
-    }
-
-    struct ggml_tensor * Qx = ggml_rope_xpos_inplace(ctx, Q, KQ_pos, n_embd_head, 512.0f, false);
-    struct ggml_tensor * Kx = ggml_rope_xpos_inplace(ctx, K, KQ_pos, n_embd_head, 512.0f, true);
-
-    struct ggml_cgraph * gf = ggml_new_graph(ctx);
-    ggml_build_forward_expand(gf, Qx);
-    ggml_build_forward_expand(gf, Kx);
-    ggml_graph_compute_with_ctx(ctx, gf, n_threads);
-
-       // expected output for Qx:
-    // -0.6009  2.7568  1.9782  2.0182
-    // -2.6379  0.9815  1.9562  2.0361
-    // -2.2457 -1.6853  1.9341  2.0538
-    //  0.2043 -2.7934  1.9118  2.0712
-    //  2.4550 -1.3341  1.8894  2.0884
-    //  2.4430  1.3417  1.8668  2.1054
-    //  0.1905  2.7739  1.8440  2.1221
-    // -2.2257  1.6550  1.8212  2.1386
-
-    for (int i = 0; i < ggml_nelements(Q); i++) {
-        if (((float*) Qx->data)[i] > 0) printf(" ");
-        printf("%.4f ", ((float*) Qx->data)[i]);
-        if ((i+1) % n_embd_head == 0) printf("\n");
-    }
-    printf("\n");
-
-    GGML_ASSERT(is_close(((float*) Qx->data)[7 * n_embd_head + 0], -2.2257f, 0.0001f));
-    GGML_ASSERT(is_close(((float*) Qx->data)[7 * n_embd_head + 1],  1.6550f, 0.0001f));
-    GGML_ASSERT(is_close(((float*) Qx->data)[7 * n_embd_head + 2],  1.8212f, 0.0001f));
-    GGML_ASSERT(is_close(((float*) Qx->data)[7 * n_embd_head + 3],  2.1386f, 0.0001f));
-
-    // expected output for Kx:
-       // -0.6038  2.7703  1.9816  2.0216
-    // -2.6639  0.9911  1.9630  2.0431
-    // -2.2789 -1.7103  1.9441  2.0644
-    //  0.2083 -2.8486  1.9251  2.0856
-    //  2.5158 -1.3671  1.9057  2.1065
-    //  2.5158  1.3816  1.8862  2.1273
-    //  0.1972  2.8705  1.8665  2.1479
-    // -2.3146  1.7211  1.8465  2.1684
-
-    for (int i = 0; i < ggml_nelements(K); i++) {
-        if (((float*) Kx->data)[i] > 0) printf(" ");
-        printf("%.4f ", ((float*) Kx->data)[i]);
-        if ((i+1) % n_embd_head == 0) printf("\n");
-    }
-    printf("\n");
-
-    GGML_ASSERT(is_close(((float*) Kx->data)[7 * n_embd_head + 0], -2.3146f, 0.0001f));
-    GGML_ASSERT(is_close(((float*) Kx->data)[7 * n_embd_head + 1],  1.7211f, 0.0001f));
-    GGML_ASSERT(is_close(((float*) Kx->data)[7 * n_embd_head + 2],  1.8465f, 0.0001f));
-    GGML_ASSERT(is_close(((float*) Kx->data)[7 * n_embd_head + 3],  2.1684f, 0.0001f));
-
-    ggml_free(ctx);
-
-    return 0;
-}