Repository: ggml-org/llama.cpp
Pull request: debug: make common_debug_print_tensor readable

Now using 4-space indentation

The log is output to stdout, so that I can do `llama-eval-callback ... > debug.log`

```
common_debug_cb_eval:       model.embed_tokens = (f32)   GET_ROWS(token_embd.weight{1024, 151936, 1, 1}, inp_tokens{9, 1, 1, 1}}) = {1024, 9, 1, 1}
    [
        [
            [      0.0434,       0.2299,      -0.2418,    ...,      -0.3296,      -0.0322,      -0.0372  ],
            [     -0.3237,      -0.0854,       0.1682,    ...,      -0.7642,       0.0383,      -0.1573  ],
            [      0.0539,      -0.3584,       0.4673,    ...,      -0.1351,       0.0991,       0.2449  ],
            ..., 
            [      0.1506,      -0.2698,      -0.2025,    ...,       0.0360,      -0.3262,      -0.3264  ],
            [     -0.0278,       0.1212,      -0.4956,    ...,      -0.9229,       0.1324,      -1.0742  ],
            [      0.0959,      -0.2170,      -0.3105,    ...,      -0.3237,       0.0635,       0.3186  ],
        ],
    ]
    sum = -1875.671875
common_debug_cb_eval:                   (view) = (f32)       FILL(leaf_3{64, 64, 1, 1}, }) = {64, 64, 1, 1}
    [
        [
            [      1.0000,       1.0000,       1.0000,    ...,       1.0000,       1.0000,       1.0000  ],
            [      1.0000,       1.0000,       1.0000,    ...,       1.0000,       1.0000,       1.0000  ],
            [      1.0000,       1.0000,       1.0000,    ...,       1.0000,       1.0000,       1.0000  ],
            ..., 
            [      1.0000,       1.0000,       1.0000,    ...,       1.0000,       1.0000,       1.0000  ],
            [      1.0000,       1.0000,       1.0000,    ...,       1.0000,       1.0000,       1.0000  ],
            [      1.0000,       1.0000,       1.0000,    ...,       1.0000,       1.0000,       1.0000  ],
        ],
    ]
    sum = 4096.000000
common_debug_cb_eval:                   node_2 = (f32)        TRI( (view){64, 64, 1, 1}, }) = {64, 64, 1, 1}
    [
        [
            [      0.0000,       0.0000,       0.0000,    ...,       0.0000,       0.0000,       0.0000  ],
            [      1.0000,       0.0000,       0.0000,    ...,       0.0000,       0.0000,       0.0000  ],
            [      1.0000,       1.0000,       0.0000,    ...,       0.0000,       0.0000,       0.0000  ],
            ..., 
            [      1.0000,       1.0000,       1.0000,    ...,       0.0000,       0.0000,       0.0000  ],
            [      1.0000,       1.0000,       1.0000,    ...,       1.0000,       0.0000,       0.0000  ],
            [      1.0000,       1.0000,       1.0000,    ...,       1.0000,       1.0000,       0.0000  ],
        ],
    ]
    sum = 2016.000000
common_debug_cb_eval:                   (view) = (f32)       FILL(leaf_4{64, 1, 1, 1}, }) = {64, 1, 1, 1}
    [
        [
            [      1.0000,       1.0000,       1.0000,    ...,       1.0000,       1.0000,       1.0000  ],
        ],
    ]
    sum = 64.000000
common_debug_cb_eval:                   node_4 = (f32)       DIAG(CPU# (view)#0{64, 1, 1, 1}, }) = {64, 64, 1, 1}
    [
        [
            [      1.0000,       0.0000,       0.0000,    ...,       0.0000,       0.0000,       0.0000  ],
            [      0.0000,       1.0000,       0.0000,    ...,       0.0000,       0.0000,       0.0000  ],
            [      0.0000,       0.0000,       1.0000,    ...,       0.0000,       0.0000,       0.0000  ],
            ..., 
            [      0.0000,       0.0000,       0.0000,    ...,       1.0000,       0.0000,       0.0000  ],
            [      0.0000,       0.0000,       0.0000,    ...,       0.0000,       1.0000,       0.0000  ],
            [      0.0000,       0.0000,       0.0000,    ...,       0.0000,       0.0000,       1.0000  ],
        ],
    ]
    sum = 64.000000
common_debug_cb_eval:                   node_5 = (f32)        ADD(node_2{64, 64, 1, 1}, MTL0#node_4#0{64, 64, 1, 1}}) = {64, 64, 1, 1}
    [
        [
            [      1.0000,       0.0000,       0.0000,    ...,       0.0000,       0.0000,       0.0000  ],
            [      1.0000,       1.0000,       0.0000,    ...,       0.0000,       0.0000,       0.0000  ],
            [      1.0000,       1.0000,       1.0000,    ...,       0.0000,       0.0000,       0.0000  ],
            ..., 
            [      1.0000,       1.0000,       1.0000,    ...,       1.0000,       0.0000,       0.0000  ],
            [      1.0000,       1.0000,       1.0000,    ...,       1.0000,       1.0000,       0.0000  ],
            [      1.0000,       1.0000,       1.0000,    ...,       1.0000,       1.0000,       1.0000  ],
        ],
    ]
    sum = 2080.000000
common_debug_cb_eval: conv_states_updated-0 (reshaped) = (f32)    RESHAPE(conv_states_updated-0{12288, 1, 1, 1}, }) = {12288, 1, 1, 1}
    [
        [
            [      0.0000,       0.0000,       0.0000,    ...,       0.0000,       0.0000,       0.0000  ],
        ],
    ]
    sum = 0.000000
common_debug_cb_eval: conv_states_updated-0 (reshaped) (view) = (f32)       VIEW(conv_states_updated-0 (reshaped){12288, 1, 1, 1}, }) = {12288, 1, 1, 1}
    [
        [
            [      0.0000,       0.0000,       0.0000,    ...,       0.0000,       0.0000,       0.0000  ],
        ],
    ]
    sum = 0.000000
common_debug_cb_eval:                   (view) = (i32)       VIEW(leaf_6{1, 1, 1, 1}, }) = {1, 1, 1, 1}
    [
        [
            [      0.0000  ],
        ],
    ]
    sum = 0.000000
common_debug_cb_eval:                   (view) = (i32)       VIEW(leaf_6{1, 1, 1, 1}, }) = {0, 1, 1, 1}
    [
        [
            [  ],
        ],
    ]
    sum = 0.000000
common_debug_cb_eval: conv_states_updated-0 (reshaped) (view) (view) = (f32)      SCALE(conv_states_updated-0 (reshaped) (view){12288, 1, 1, 1}, }) = {12288, 1, 1, 1}
    [
        [
            [      0.0000,       0.0000,       0.0000,    ...,       0.0000,       0.0000,       0.0000  ],
        ],
    ]
    sum = 0.000000
```

Changed files:
filename: common/debug.cpp
patch: @@ -45,6 +45,8 @@ static float common_ggml_get_float_value(const uint8_t * data,
     return v;
 }
 
+#define INDENT "    "
+
 template <bool abort>
 void common_debug_print_tensor(uint8_t * data, ggml_type type, const int64_t * ne, const size_t * nb, int64_t n) {
     GGML_ASSERT(n > 0);
@@ -60,41 +62,41 @@ void common_debug_print_tensor(uint8_t * data, ggml_type type, const int64_t * n
         }
     }
     for (int64_t i3 = 0; i3 < ne[3]; i3++) {
-        LOG_ERR("                                     [\n");
+        LOG(INDENT "[\n");
         for (int64_t i2 = 0; i2 < ne[2]; i2++) {
             if (i2 == n && ne[2] > 2 * n) {
-                LOG_ERR("                                      ..., \n");
+                LOG(INDENT INDENT "..., \n");
                 i2 = ne[2] - n;
             }
-            LOG_ERR("                                      [\n");
+            LOG(INDENT INDENT "[\n");
             for (int64_t i1 = 0; i1 < ne[1]; i1++) {
                 if (i1 == n && ne[1] > 2 * n) {
-                    LOG_ERR("                                       ..., \n");
+                    LOG(INDENT INDENT INDENT "..., \n");
                     i1 = ne[1] - n;
                 }
-                LOG_ERR("                                       [");
+                LOG(INDENT INDENT INDENT "[");
                 for (int64_t i0 = 0; i0 < ne[0]; i0++) {
                     if (i0 == n && ne[0] > 2 * n) {
-                        LOG_ERR("..., ");
+                        LOG("   ..., ");
                         i0 = ne[0] - n;
                     }
                     const float v = common_ggml_get_float_value(data, type, nb, i0, i1, i2, i3);
-                    LOG_ERR("%12.4f", v);
+                    LOG("%12.4f", v);
                     if (i0 < ne[0] - 1) {
-                        LOG_ERR(", ");
+                        LOG(", ");
                     }
                 }
-                LOG_ERR("],\n");
+                LOG("  ],\n");
             }
-            LOG_ERR("                                      ],\n");
+            LOG(INDENT INDENT "],\n");
         }
-        LOG_ERR("                                     ]\n");
-        LOG_ERR("                                     sum = %f\n", sum);
+        LOG(INDENT "]\n");
+        LOG(INDENT "sum = %f\n", sum);
     }
 
     if constexpr (abort) {
         if (std::isnan(sum)) {
-            LOG_ERR("encountered NaN - aborting\n");
+            LOG("encountered NaN - aborting\n");
             exit(0);
         }
     }
@@ -137,9 +139,9 @@ template <bool abort_on_nan> bool common_debug_cb_eval(struct ggml_tensor * t, b
     }
 
     if (matches_filter) {
-        LOG_ERR("%s: %24s = (%s) %10s(%s{%s}, %s}) = {%s}\n", __func__, t->name, ggml_type_name(t->type),
-                ggml_op_desc(t), src0->name, common_ggml_ne_string(src0).c_str(), src1 ? src1_str : "",
-                common_ggml_ne_string(t).c_str());
+        LOG("%s: %24s = (%s) %10s(%s{%s}, %s}) = {%s}\n", __func__, t->name, ggml_type_name(t->type),
+            ggml_op_desc(t), src0->name, common_ggml_ne_string(src0).c_str(), src1 ? src1_str : "",
+            common_ggml_ne_string(t).c_str());
     }
 
     const bool is_host = ggml_backend_buffer_is_host(t->buffer);

filename: src/models/qwen3next.cpp
patch: @@ -265,13 +265,13 @@ std::pair<ggml_tensor *, ggml_tensor *> llm_build_qwen3next::build_delta_net_chu
     cb(g_diff, "g_diff", il); // shape: (chunk_size, 1, n_chunks, H_v * n_seqs)
 
     ggml_tensor * g_diff_exp = ggml_exp(ctx0, g_diff);
-    ggml_tensor * g_diff_exp_t = ggml_reshape_4d(ctx0, g_diff_exp, 
+    ggml_tensor * g_diff_exp_t = ggml_reshape_4d(ctx0, g_diff_exp,
                                                  1, chunk_size, n_chunks, g_diff_exp->ne[3]);
 
     ggml_tensor * key_gdiff = ggml_mul(ctx0, k, g_diff_exp_t);
     cb(key_gdiff, "key_gdiff", il); // shape: (S_k, chunk_size, n_chunks, H_v * n_seqs)
 
-    ggml_tensor * key_gdiff_t = ggml_cont(ctx0, ggml_transpose(ctx0, key_gdiff)); 
+    ggml_tensor * key_gdiff_t = ggml_cont(ctx0, ggml_transpose(ctx0, key_gdiff));
     cb(key_gdiff_t, "key_gdiff_t", il); // shape: (chunk_size, S_k, n_chunks, H_v * n_seqs)