From: Georgi Gerganov Date: Fri, 20 Sep 2024 18:50:16 +0000 (+0300) Subject: examples : adapt to ggml.h changes (#0) X-Git-Tag: upstream/0.0.1642~355 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=336c10a4c3c8ec99af484b25a0cddd397a09cdb2;p=pkg%2Fggml%2Fsources%2Fggml examples : adapt to ggml.h changes (#0) ggml-ci --- diff --git a/examples/common-ggml.cpp b/examples/common-ggml.cpp index a3f2c12f..760cd1f4 100644 --- a/examples/common-ggml.cpp +++ b/examples/common-ggml.cpp @@ -215,6 +215,8 @@ bool ggml_common_quantize_0( case GGML_TYPE_Q4_0_4_4: case GGML_TYPE_Q4_0_4_8: case GGML_TYPE_Q4_0_8_8: + case GGML_TYPE_TQ1_0: + case GGML_TYPE_TQ2_0: case GGML_TYPE_COUNT: { fprintf(stderr, "%s: unsupported quantization type %d (%s)\n", __func__, ttype, ggml_type_name((ggml_type) ttype)); diff --git a/examples/gpt-2/main-batched.cpp b/examples/gpt-2/main-batched.cpp index ecf08b2b..d504093e 100644 --- a/examples/gpt-2/main-batched.cpp +++ b/examples/gpt-2/main-batched.cpp @@ -955,7 +955,7 @@ int gpt2_decode( //} // in this case, the output tensor is the last one in the graph - struct ggml_tensor * inpL = gf->nodes[gf->n_nodes - 1]; + struct ggml_tensor * inpL = ggml_graph_node(gf, -1); if (batch.logits) { // return logits for all tokens diff --git a/examples/gpt-2/main-sched.cpp b/examples/gpt-2/main-sched.cpp index 36571045..ccbceca7 100644 --- a/examples/gpt-2/main-sched.cpp +++ b/examples/gpt-2/main-sched.cpp @@ -888,7 +888,7 @@ bool gpt2_eval( //} // in this case, the output tensor is the last one in the graph - struct ggml_tensor * inpL = gf->nodes[gf->n_nodes - 1]; + struct ggml_tensor * inpL = ggml_graph_node(gf, -1); //embd_w.resize(n_vocab*N); //ggml_backend_tensor_get(inpL, embd_w.data(), 0, sizeof(float)*n_vocab*N); diff --git a/examples/simple/simple-backend.cpp b/examples/simple/simple-backend.cpp index 64da9542..203028c8 100644 --- a/examples/simple/simple-backend.cpp +++ b/examples/simple/simple-backend.cpp @@ -140,7 +140,7 @@ struct ggml_tensor * compute(const simple_model & model, ggml_gallocr_t allocr) ggml_backend_graph_compute(model.backend, gf); // in this case, the output tensor is the last one in the graph - return gf->nodes[gf->n_nodes - 1]; + return ggml_graph_node(gf, -1); } int main(void) { diff --git a/examples/simple/simple-ctx.cpp b/examples/simple/simple-ctx.cpp index b2d4e4ba..283ec0a7 100644 --- a/examples/simple/simple-ctx.cpp +++ b/examples/simple/simple-ctx.cpp @@ -66,7 +66,7 @@ struct ggml_tensor * compute(const simple_model & model) { ggml_graph_compute_with_ctx(model.ctx, gf, n_threads); // in this case, the output tensor is the last one in the graph - return gf->nodes[gf->n_nodes - 1]; + return ggml_graph_node(gf, -1); } int main(void) { diff --git a/include/ggml.h b/include/ggml.h index 2035001e..76294fff 100644 --- a/include/ggml.h +++ b/include/ggml.h @@ -1979,6 +1979,9 @@ extern "C" { typedef void (*ggml_custom2_op_t)(struct ggml_tensor * dst , const struct ggml_tensor * a, const struct ggml_tensor * b, int ith, int nth, void * userdata); typedef void (*ggml_custom3_op_t)(struct ggml_tensor * dst , const struct ggml_tensor * a, const struct ggml_tensor * b, const struct ggml_tensor * c, int ith, int nth, void * userdata); +#define GGML_N_TASKS_MAX (-1) + // n_tasks == GGML_N_TASKS_MAX means to use max number of tasks + GGML_API struct ggml_tensor * ggml_map_custom1( struct ggml_context * ctx, struct ggml_tensor * a, diff --git a/src/ggml.c b/src/ggml.c index 201d5466..28e19373 100644 --- a/src/ggml.c +++ b/src/ggml.c @@ -289,7 +289,6 @@ void ggml_abort(const char * file, int line, const char * fmt, ...) { #define GGML_DEBUG 0 #define GGML_GELU_FP16 #define GGML_GELU_QUICK_FP16 -#define GGML_N_TASKS_MAX (-1) #define GGML_SOFT_MAX_UNROLL 4 #define GGML_VEC_DOT_UNROLL 2 diff --git a/tests/test-conv-transpose-1d.cpp b/tests/test-conv-transpose-1d.cpp index c2e517dd..36643ab9 100644 --- a/tests/test-conv-transpose-1d.cpp +++ b/tests/test-conv-transpose-1d.cpp @@ -415,9 +415,9 @@ int main(void) struct ggml_tensor * conv1d_transpose_res_0 = NULL; - for(int i = 0; i < gf_res->n_nodes; i++) { - if(strcmp(ggml_get_name(gf_res->nodes[i]), "conv1d_transpose_res_0") == 0) { - conv1d_transpose_res_0 = gf_res->nodes[i]; + for(int i = 0; i < ggml_graph_n_nodes(gf_res); i++) { + if(strcmp(ggml_get_name(ggml_graph_node(gf_res, i)), "conv1d_transpose_res_0") == 0) { + conv1d_transpose_res_0 = ggml_graph_node(gf_res, i); } } @@ -434,9 +434,9 @@ int main(void) struct ggml_tensor * conv1d_transpose_res_1 = NULL; - for(int i = 0; i < gf_res->n_nodes; i++) { - if(strcmp(ggml_get_name(gf_res->nodes[i]), "conv1d_transpose_res_1") == 0) { - conv1d_transpose_res_1 = gf_res->nodes[i]; + for(int i = 0; i < ggml_graph_n_nodes(gf_res); i++) { + if(strcmp(ggml_get_name(ggml_graph_node(gf_res, i)), "conv1d_transpose_res_1") == 0) { + conv1d_transpose_res_1 = ggml_graph_node(gf_res, i); } } @@ -456,9 +456,9 @@ int main(void) struct ggml_tensor * conv1d_transpose_res_2 = NULL; - for(int i = 0; i < gf_res->n_nodes; i++) { - if(strcmp(ggml_get_name(gf_res->nodes[i]), "conv1d_transpose_res_2") == 0) { - conv1d_transpose_res_2 = gf_res->nodes[i]; + for(int i = 0; i < ggml_graph_n_nodes(gf_res); i++) { + if(strcmp(ggml_get_name(ggml_graph_node(gf_res, i)), "conv1d_transpose_res_2") == 0) { + conv1d_transpose_res_2 = ggml_graph_node(gf_res, i); } } @@ -475,9 +475,9 @@ int main(void) struct ggml_tensor * conv1d_transpose_res_3 = NULL; - for(int i = 0; i < gf_res->n_nodes; i++) { - if(strcmp(ggml_get_name(gf_res->nodes[i]), "conv1d_transpose_res_3") == 0) { - conv1d_transpose_res_3 = gf_res->nodes[i]; + for(int i = 0; i < ggml_graph_n_nodes(gf_res); i++) { + if(strcmp(ggml_get_name(ggml_graph_node(gf_res, i)), "conv1d_transpose_res_3") == 0) { + conv1d_transpose_res_3 = ggml_graph_node(gf_res, i); } } @@ -495,9 +495,9 @@ int main(void) struct ggml_tensor * conv1d_transpose_res_4 = NULL; - for(int i = 0; i < gf_res->n_nodes; i++) { - if(strcmp(ggml_get_name(gf_res->nodes[i]), "conv1d_transpose_res_4") == 0) { - conv1d_transpose_res_4 = gf_res->nodes[i]; + for(int i = 0; i < ggml_graph_n_nodes(gf_res); i++) { + if(strcmp(ggml_get_name(ggml_graph_node(gf_res, i)), "conv1d_transpose_res_4") == 0) { + conv1d_transpose_res_4 = ggml_graph_node(gf_res, i); } } @@ -516,9 +516,9 @@ int main(void) struct ggml_tensor * conv1d_transpose_res_5 = NULL; - for(int i = 0; i < gf_res->n_nodes; i++) { - if(strcmp(ggml_get_name(gf_res->nodes[i]), "conv1d_transpose_res_5") == 0) { - conv1d_transpose_res_5 = gf_res->nodes[i]; + for(int i = 0; i < ggml_graph_n_nodes(gf_res); i++) { + if(strcmp(ggml_get_name(ggml_graph_node(gf_res, i)), "conv1d_transpose_res_5") == 0) { + conv1d_transpose_res_5 = ggml_graph_node(gf_res, i); } } @@ -537,9 +537,9 @@ int main(void) struct ggml_tensor * conv1d_transpose_res_6 = NULL; - for(int i = 0; i < gf_res->n_nodes; i++) { - if(strcmp(ggml_get_name(gf_res->nodes[i]), "conv1d_transpose_res_6") == 0) { - conv1d_transpose_res_6 = gf_res->nodes[i]; + for(int i = 0; i < ggml_graph_n_nodes(gf_res); i++) { + if(strcmp(ggml_get_name(ggml_graph_node(gf_res, i)), "conv1d_transpose_res_6") == 0) { + conv1d_transpose_res_6 = ggml_graph_node(gf_res, i); } } @@ -559,9 +559,9 @@ int main(void) struct ggml_tensor * conv1d_transpose_res_7 = NULL; - for(int i = 0; i < gf_res->n_nodes; i++) { - if(strcmp(ggml_get_name(gf_res->nodes[i]), "conv1d_transpose_res_7") == 0) { - conv1d_transpose_res_7 = gf_res->nodes[i]; + for(int i = 0; i < ggml_graph_n_nodes(gf_res); i++) { + if(strcmp(ggml_get_name(ggml_graph_node(gf_res, i)), "conv1d_transpose_res_7") == 0) { + conv1d_transpose_res_7 = ggml_graph_node(gf_res, i); } } diff --git a/tests/test-conv1d.cpp b/tests/test-conv1d.cpp index d38d2993..e98a4ca9 100644 --- a/tests/test-conv1d.cpp +++ b/tests/test-conv1d.cpp @@ -218,11 +218,11 @@ int main(void) struct ggml_tensor * im2col_res = NULL; struct ggml_tensor * conv1d_res = NULL; - for(int i = 0; i < gf_res->n_nodes; i++) { - if(strcmp(ggml_get_name(gf_res->nodes[i]), "im2col_res") == 0) { - im2col_res = gf_res->nodes[i]; - } else if(strcmp(ggml_get_name(gf_res->nodes[i]), "conv1d_res") == 0) { - conv1d_res = gf_res->nodes[i]; + for(int i = 0; i < ggml_graph_n_nodes(gf_res); i++) { + if(strcmp(ggml_get_name(ggml_graph_node(gf_res, i)), "im2col_res") == 0) { + im2col_res = ggml_graph_node(gf_res, i); + } else if(strcmp(ggml_get_name(ggml_graph_node(gf_res, i)), "conv1d_res") == 0) { + conv1d_res = ggml_graph_node(gf_res, i); } } diff --git a/tests/test-conv2d.cpp b/tests/test-conv2d.cpp index 37942c50..37127739 100644 --- a/tests/test-conv2d.cpp +++ b/tests/test-conv2d.cpp @@ -221,11 +221,11 @@ int main(void) struct ggml_tensor * im2col_res = NULL; struct ggml_tensor * conv2d_res = NULL; - for(int i = 0; i < gf_res->n_nodes; i++) { - if(strcmp(ggml_get_name(gf_res->nodes[i]), "im2col_res") == 0) { - im2col_res = gf_res->nodes[i]; - } else if(strcmp(ggml_get_name(gf_res->nodes[i]), "conv2d_res") == 0) { - conv2d_res = gf_res->nodes[i]; + for(int i = 0; i < ggml_graph_n_nodes(gf_res); ++i) { + if(strcmp(ggml_get_name(ggml_graph_node(gf_res, i)), "im2col_res") == 0) { + im2col_res = ggml_graph_node(gf_res, i); + } else if(strcmp(ggml_get_name(ggml_graph_node(gf_res, i)), "conv2d_res") == 0) { + conv2d_res = ggml_graph_node(gf_res, i); } } diff --git a/tests/test-mul-mat.cpp b/tests/test-mul-mat.cpp index f91e172a..1df9d144 100644 --- a/tests/test-mul-mat.cpp +++ b/tests/test-mul-mat.cpp @@ -161,7 +161,7 @@ struct ggml_tensor* compute(const test_model & model, ggml_gallocr_t allocr) { //ggml_graph_print(gf); // in this case, the output tensor is the last one in the graph - return gf->nodes[gf->n_nodes - 1]; + return ggml_graph_node(gf, -1); }