From 68adf99ff7a6e650d2672637b342bcc61e6eaf09 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sun, 26 Apr 2026 09:39:29 +0300 Subject: [PATCH] cont : cleanup --- common/debug.cpp | 4 ++-- common/debug.h | 19 +++++-------------- examples/debug/debug.cpp | 14 +++++++++----- examples/eval-callback/eval-callback.cpp | 3 +-- tools/mtmd/debug/mtmd-debug.cpp | 2 +- tools/mtmd/mtmd-cli.cpp | 2 +- 6 files changed, 19 insertions(+), 25 deletions(-) diff --git a/common/debug.cpp b/common/debug.cpp index 5d74936b3a..0c238e6a5d 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -47,7 +47,7 @@ static float common_ggml_get_float_value(const uint8_t * data, #define INDENT " " -void common_debug_print_tensor(uint8_t * data, ggml_type type, const int64_t * ne, const size_t * nb, int64_t n, bool abort_on_nan) { +static void common_debug_print_tensor(uint8_t * data, ggml_type type, const int64_t * ne, const size_t * nb, int64_t n, bool abort_on_nan) { GGML_ASSERT(n > 0); float sum = 0; for (int64_t i3 = 0; i3 < ne[3]; i3++) { @@ -112,7 +112,7 @@ void common_debug_print_tensor(uint8_t * data, ggml_type type, const int64_t * n * @return true to receive data or continue the graph, false otherwise */ bool common_debug_cb_eval(struct ggml_tensor * t, bool ask, void * user_data) { - auto * cb_data = (base_callback_data *) user_data; + auto * cb_data = (common_debug_cb_user_data *) user_data; const struct ggml_tensor * src0 = t->src[0]; const struct ggml_tensor * src1 = t->src[1]; diff --git a/common/debug.h b/common/debug.h index aa1fa17337..4017ccdb8a 100644 --- a/common/debug.h +++ b/common/debug.h @@ -6,32 +6,23 @@ // 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 -// aon - abort if NaN is encountered -void common_debug_print_tensor(uint8_t * data, ggml_type type, const int64_t * ne, const size_t * nb, int64_t n, bool aon = false); - // 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 +// by default prints all tensors, but can be configured by creating a `common_debug_cb_user_data` instance with // non-empty filter_patterns. See examples/debug.ccp for possible usage patterns -// `base_callback_data` contains `abort_on_nan` flag that determines whether an error should be thrown whenever a NaN is encountered +// `common_debug_cb_user_data` contains `abort_on_nan` flag that determines 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) bool common_debug_cb_eval(struct ggml_tensor * t, bool ask, void * user_data); -struct base_callback_data { +struct common_debug_cb_user_data { std::vector data; std::vector tensor_filters; bool abort_on_nan{false}; - base_callback_data() = default; + common_debug_cb_user_data() = default; - base_callback_data(common_params & params, const std::vector & filter_patterns, bool abort_on_nan = false) { + common_debug_cb_user_data(common_params & params, const std::vector & filter_patterns, bool abort_on_nan = false) { for (const auto & pattern : filter_patterns) { try { std::string anchored_pattern = "^" + pattern; diff --git a/examples/debug/debug.cpp b/examples/debug/debug.cpp index 7ba63b4ff6..761e7a2db5 100644 --- a/examples/debug/debug.cpp +++ b/examples/debug/debug.cpp @@ -202,10 +202,14 @@ static bool run(llama_context * ctx, const common_params & params) { print_tokenized_prompt(ctx, tokens, params.prompt); if (params.save_logits) { - output_data output {ctx, model, params}; - std::filesystem::path model_path{params.model.path}; - std::string model_name{model_path.stem().string()}; - save_output_data(output, model_name, params.logits_output_dir); + try { + output_data output {ctx, model, params}; + std::filesystem::path model_path{params.model.path}; + std::string model_name{model_path.stem().string()}; + save_output_data(output, model_name, params.logits_output_dir); + } catch (const std::exception & e) { + LOG_ERR("%s : error saving logits: %s\n", __func__, e.what()); + } } return true; @@ -223,7 +227,7 @@ int main(int argc, char ** argv) { llama_backend_init(); llama_numa_init(params.numa); - std::optional cb_data; + std::optional cb_data; if (!params.save_logits) { cb_data.emplace(params, params.tensor_filter); } diff --git a/examples/eval-callback/eval-callback.cpp b/examples/eval-callback/eval-callback.cpp index 6685e525f8..4ce8d600b1 100644 --- a/examples/eval-callback/eval-callback.cpp +++ b/examples/eval-callback/eval-callback.cpp @@ -3,7 +3,6 @@ #include "debug.h" #include "log.h" #include "llama.h" -#include "llama-cpp.h" #include #include @@ -38,7 +37,7 @@ static bool run(llama_context * ctx, const common_params & params) { int main(int argc, char ** argv) { std::setlocale(LC_NUMERIC, "C"); - base_callback_data cb_data; + common_debug_cb_user_data cb_data; common_params params; diff --git a/tools/mtmd/debug/mtmd-debug.cpp b/tools/mtmd/debug/mtmd-debug.cpp index 182a9bca41..1e41ef793b 100644 --- a/tools/mtmd/debug/mtmd-debug.cpp +++ b/tools/mtmd/debug/mtmd-debug.cpp @@ -72,7 +72,7 @@ int main(int argc, char ** argv) { mtmd::context_ptr ctx_mtmd; common_init_result_ptr llama_init; - base_callback_data cb_data; + common_debug_cb_user_data cb_data; llama_init = common_init_from_params(params); { diff --git a/tools/mtmd/mtmd-cli.cpp b/tools/mtmd/mtmd-cli.cpp index aa6ad73807..be958bd175 100644 --- a/tools/mtmd/mtmd-cli.cpp +++ b/tools/mtmd/mtmd-cli.cpp @@ -90,7 +90,7 @@ struct mtmd_cli_context { int n_threads = 1; llama_pos n_past = 0; - base_callback_data cb_data; + common_debug_cb_user_data cb_data; mtmd_cli_context(common_params & params) : llama_init(common_init_from_params(params)) { model = llama_init->model();