Skip to content

Commit

Permalink
examples : adapt to ggml.h changes (#0)
Browse files Browse the repository at this point in the history
ggml-ci
  • Loading branch information
ggerganov committed Sep 20, 2024
1 parent 242ae95 commit a146842
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 40 deletions.
2 changes: 2 additions & 0 deletions examples/common-ggml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion examples/gpt-2/main-batched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/gpt-2/main-sched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/simple-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/simple-ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions include/ggml.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 24 additions & 24 deletions tests/test-conv-transpose-1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
10 changes: 5 additions & 5 deletions tests/test-conv1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
10 changes: 5 additions & 5 deletions tests/test-conv2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test-mul-mat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down

0 comments on commit a146842

Please sign in to comment.