From b333b06772c89d96aacb5490d6a219fba7c09cc6 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Thu, 12 Feb 2026 20:57:17 +0100 Subject: Engage! --- llama.cpp/common/debug.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 llama.cpp/common/debug.h (limited to 'llama.cpp/common/debug.h') diff --git a/llama.cpp/common/debug.h b/llama.cpp/common/debug.h new file mode 100644 index 0000000..0c55963 --- /dev/null +++ b/llama.cpp/common/debug.h @@ -0,0 +1,43 @@ +#pragma once +#include "common.h" +#include +#include +#include + +// common debug functions and structs + +// Print a tensor's detailed data +// data - the tensor's data in byte format +// type - the tensor's quantization type +// ne - the tensor dimensions array +// nb - the tensor strides array +// n - the number of rows/columns to fully print +template void common_debug_print_tensor(uint8_t * data, ggml_type type, const int64_t * ne, const size_t * nb, int64_t n); + +// Intended to use as callback for ggml_backend_sched_eval_callback +// prints tensors that are processed in the computation graph +// by default prints all tensors, but can be configured by creating a `base_callback_data` instance with +// non-empty filter_patterns. See examples/debug.ccp for possible usage patterns +// The template parameter determins whether an error should be thrown whenever a NaN is encountered +// in a tensor (useful for stopping debug sessions on first erroneous tensor) +// The callback data will be passed as the third parameter (user_data) +template bool common_debug_cb_eval(struct ggml_tensor * t, bool ask, void * user_data); +struct base_callback_data { + std::vector data; + std::vector tensor_filters; + + base_callback_data() = default; + + base_callback_data(common_params & params, const std::vector & filter_patterns) { + for (const auto & pattern : filter_patterns) { + try { + std::string anchored_pattern = "^" + pattern; + tensor_filters.emplace_back(anchored_pattern, std::regex::optimize); + } catch (const std::regex_error & e) { + throw std::runtime_error("Invalid regex pattern '" + pattern + "': " + e.what()); + } + } + params.cb_eval = common_debug_cb_eval; + params.cb_eval_user_data = this; + } +}; -- cgit v1.2.3