Implementation:Ggml org Llama cpp Debug Header
| Knowledge Sources | |
|---|---|
| Domains | Debugging, Tensor |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Declares the tensor debugging interface for printing tensor data and registering evaluation callbacks during computation graph processing.
Description
This header declares the template function `common_debug_print_tensor` for formatted tensor data output, parameterized on `abort_on_nan` behavior, and `common_debug_cb_eval` as a ggml backend evaluation callback. The `base_callback_data` struct holds a data buffer for tensor content and a vector of compiled regex filters for selective tensor inspection. Its constructor takes `common_params` and filter patterns, compiling them into anchored regex objects and registering the callback on the params struct.
Usage
Include this header when building debugging tools that need to inspect specific tensors during model execution. Use the `base_callback_data` struct to configure which tensors to inspect by providing regex patterns that match tensor names.
Code Reference
Source Location
- Repository: Ggml_org_Llama_cpp
- File: common/debug.h
- Lines: 1-43
Signature
template <bool abort_on_nan>
void common_debug_print_tensor(uint8_t * data, ggml_type type, const int64_t * ne, const size_t * nb, int64_t n);
template <bool abort_on_nan>
bool common_debug_cb_eval(struct ggml_tensor * t, bool ask, void * user_data);
struct base_callback_data {
std::vector<uint8_t> data;
std::vector<std::regex> tensor_filters;
base_callback_data() = default;
base_callback_data(common_params & params, const std::vector<std::string> & filter_patterns);
};
Import
#include "debug.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| params | common_params & | Yes | Common parameters struct; callback fields are set by the constructor |
| filter_patterns | const std::vector<std::string> & | Yes | Regex patterns to match tensor names for selective inspection |
| data | uint8_t * | Yes | Raw tensor data bytes for print_tensor |
| type | ggml_type | Yes | Tensor quantization/data type |
| ne | const int64_t * | Yes | Tensor dimensions array |
| nb | const size_t * | Yes | Tensor strides array |
| n | int64_t | Yes | Number of elements to print before truncating |
Outputs
| Name | Type | Description |
|---|---|---|
| base_callback_data instance | base_callback_data | Configured callback data with compiled regex filters and registered callback |
| cb_eval return | bool | Whether to continue processing the tensor |
Usage Examples
#include "debug.h"
// Create callback data with filter patterns
common_params params;
std::vector<std::string> filters = {"attn_q", "attn_k"};
base_callback_data cb_data(params, filters);
// params.cb_eval and params.cb_eval_user_data are now set
// Use params normally with model initialization