| 124 | * @return true to receive data or continue the graph, false otherwise |
| 125 | */ |
| 126 | template <bool abort_on_nan> bool common_debug_cb_eval(struct ggml_tensor * t, bool ask, void * user_data) { |
| 127 | auto * cb_data = (base_callback_data *) user_data; |
| 128 | |
| 129 | const struct ggml_tensor * src0 = t->src[0]; |
| 130 | const struct ggml_tensor * src1 = t->src[1]; |
| 131 | |
| 132 | if (ask) { |
| 133 | return true; // Always retrieve data |
| 134 | } |
| 135 | |
| 136 | bool matches_filter = cb_data->tensor_filters.empty(); |
| 137 | |
| 138 | if (!matches_filter) { |
| 139 | for (const auto & filter : cb_data->tensor_filters) { |
| 140 | if (std::regex_search(t->name, filter)) { |
| 141 | matches_filter = true; |
| 142 | break; |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | char src1_str[128] = { 0 }; |
| 148 | if (src1) { |
| 149 | snprintf(src1_str, sizeof(src1_str), "%s{%s}", src1->name, common_ggml_ne_string(src1).c_str()); |
| 150 | } |
| 151 | |
| 152 | if (matches_filter) { |
| 153 | LOG("%s: %24s = (%s) %10s(%s{%s}, %s}) = {%s}\n", __func__, t->name, ggml_type_name(t->type), |
| 154 | ggml_op_desc(t), src0->name, common_ggml_ne_string(src0).c_str(), src1 ? src1_str : "", |
| 155 | common_ggml_ne_string(t).c_str()); |
| 156 | } |
| 157 | |
| 158 | const bool is_host = ggml_backend_buffer_is_host(t->buffer); |
| 159 | |
| 160 | if (!is_host) { |
| 161 | auto n_bytes = ggml_nbytes(t); |
| 162 | cb_data->data.resize(n_bytes); |
| 163 | ggml_backend_tensor_get(t, cb_data->data.data(), 0, n_bytes); |
| 164 | } |
| 165 | |
| 166 | if (!ggml_is_quantized(t->type) && matches_filter) { |
| 167 | uint8_t * data = is_host ? (uint8_t *) t->data : cb_data->data.data(); |
| 168 | int64_t print_n = 32; |
| 169 | if (const char * env = std::getenv("LLAMA_DEBUG_TENSOR_PRINT_N")) { |
| 170 | char * end = nullptr; |
| 171 | const long value = std::strtol(env, &end, 10); |
| 172 | if (end != env && value > 0) { |
| 173 | print_n = value; |
| 174 | } |
| 175 | } |
| 176 | common_debug_print_tensor<abort_on_nan>(data, t->type, t->ne, t->nb, print_n); |
| 177 | } |
| 178 | |
| 179 | return true; |
| 180 | } |
| 181 | |
| 182 | // Explicit template instantiations |
| 183 | template bool common_debug_cb_eval<false>(ggml_tensor *, bool, void *); |
nothing calls this directly
no test coverage detected