| 747 | } |
| 748 | |
| 749 | bool eval_grad(ggml_backend_t backend, const char * op_name) { |
| 750 | mode = MODE_GRAD; |
| 751 | const std::vector<float> expect = grad_expect(); |
| 752 | |
| 753 | ggml_init_params params = { |
| 754 | /* .mem_size = */ ggml_tensor_overhead()*128 + 2*ggml_graph_overhead_custom(GGML_DEFAULT_GRAPH_SIZE, true), |
| 755 | /* .mem_base = */ NULL, |
| 756 | /* .no_alloc = */ true, |
| 757 | }; |
| 758 | ggml_context_ptr ctx(ggml_init(params)); // smart ptr |
| 759 | GGML_ASSERT(ctx); |
| 760 | |
| 761 | gf = ggml_new_graph_custom(ctx.get(), GGML_DEFAULT_GRAPH_SIZE, true); |
| 762 | gb = ggml_new_graph_custom(ctx.get(), GGML_DEFAULT_GRAPH_SIZE, true); |
| 763 | |
| 764 | ggml_tensor * out = build_graph(ctx.get()); |
| 765 | |
| 766 | if ((op_name != nullptr && op_desc(out) != op_name) || out->op == GGML_OP_OPT_STEP_ADAMW) { |
| 767 | //printf(" %s: skipping\n", op_desc(out).c_str()); |
| 768 | return true; |
| 769 | } |
| 770 | |
| 771 | printf(" %s(%s): ", op_desc(out).c_str(), vars().c_str()); |
| 772 | fflush(stdout); |
| 773 | |
| 774 | if (out->type != GGML_TYPE_F32) { |
| 775 | printf("not supported [%s->type != FP32]\n", out->name); |
| 776 | return true; |
| 777 | } |
| 778 | |
| 779 | // check if the backend supports the ops |
| 780 | bool supported = true; |
| 781 | bool any_params = false; |
| 782 | for (ggml_tensor * t = ggml_get_first_tensor(ctx.get()); t != NULL; t = ggml_get_next_tensor(ctx.get(), t)) { |
| 783 | if (!ggml_backend_supports_op(backend, t)) { |
| 784 | printf("not supported [%s] ", ggml_backend_name(backend)); |
| 785 | supported = false; |
| 786 | break; |
| 787 | } |
| 788 | if ((t->flags & GGML_TENSOR_FLAG_PARAM)) { |
| 789 | any_params = true; |
| 790 | if (t->type != GGML_TYPE_F32) { |
| 791 | printf("not supported [%s->type != FP32] ", t->name); |
| 792 | supported = false; |
| 793 | break; |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | if (!any_params) { |
| 798 | printf("not supported [%s] \n", op_desc(out).c_str()); |
| 799 | supported = false; |
| 800 | } |
| 801 | if (!supported) { |
| 802 | printf("\n"); |
| 803 | return true; |
| 804 | } |
| 805 | |
| 806 | int64_t ngrads = 0; |
no test coverage detected