* GGML operations callback during the graph execution. * * @param t current tensor * @param ask when ask is true, the scheduler wants to know if we are interested in data from this tensor * if we return true, a follow-up call will be made with ask=false in which we can do the actual collection. * see ggml_backend_sched_eval_callback * @param user_data user data to pass
| 88 | * @return true to receive data or continue the graph, false otherwise |
| 89 | */ |
| 90 | static bool ggml_debug(struct ggml_tensor * t, bool ask, void * user_data) { |
| 91 | auto * cb_data = (callback_data *) user_data; |
| 92 | |
| 93 | const struct ggml_tensor * src0 = t->src[0]; |
| 94 | const struct ggml_tensor * src1 = t->src[1]; |
| 95 | |
| 96 | if (ask) { |
| 97 | return true; // Always retrieve data |
| 98 | } |
| 99 | |
| 100 | char src1_str[128] = {0}; |
| 101 | if (src1) { |
| 102 | snprintf(src1_str, sizeof(src1_str), "%s{%s}", src1->name, ggml_ne_string(src1).c_str()); |
| 103 | } |
| 104 | |
| 105 | LOG("%s: %24s = (%s) %10s(%s{%s}, %s}) = {%s}\n", __func__, |
| 106 | t->name, ggml_type_name(t->type), ggml_op_desc(t), |
| 107 | src0->name, ggml_ne_string(src0).c_str(), |
| 108 | src1 ? src1_str : "", |
| 109 | ggml_ne_string(t).c_str()); |
| 110 | |
| 111 | |
| 112 | // copy the data from the GPU memory if needed |
| 113 | const bool is_host = ggml_backend_buffer_is_host(t->buffer); |
| 114 | |
| 115 | if (!is_host) { |
| 116 | auto n_bytes = ggml_nbytes(t); |
| 117 | cb_data->data.resize(n_bytes); |
| 118 | ggml_backend_tensor_get(t, cb_data->data.data(), 0, n_bytes); |
| 119 | } |
| 120 | |
| 121 | if (!ggml_is_quantized(t->type)) { |
| 122 | uint8_t * data = is_host ? (uint8_t *) t->data : cb_data->data.data(); |
| 123 | ggml_print_tensor(data, t->type, t->ne, t->nb, 3); |
| 124 | } |
| 125 | |
| 126 | return true; |
| 127 | } |
| 128 | |
| 129 | static bool run(llama_context * ctx, const common_params & params) { |
| 130 | const llama_model * model = llama_get_model(ctx); |
nothing calls this directly
no test coverage detected