MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / common_debug_print_tensor

Function common_debug_print_tensor

common/debug.cpp:52–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50
51template <bool abort>
52void common_debug_print_tensor(uint8_t * data, ggml_type type, const int64_t * ne, const size_t * nb, int64_t n) {
53 GGML_ASSERT(n > 0);
54 double sum = 0.0;
55 double sum_sq = 0.0;
56 float min = INFINITY;
57 float max = -INFINITY;
58 for (int64_t i3 = 0; i3 < ne[3]; i3++) {
59 for (int64_t i2 = 0; i2 < ne[2]; i2++) {
60 for (int64_t i1 = 0; i1 < ne[1]; i1++) {
61 for (int64_t i0 = 0; i0 < ne[0]; i0++) {
62 const float v = common_ggml_get_float_value(data, type, nb, i0, i1, i2, i3);
63 sum += v;
64 sum_sq += double(v) * double(v);
65 min = std::min(min, v);
66 max = std::max(max, v);
67 }
68 }
69 }
70 }
71 for (int64_t i3 = 0; i3 < ne[3]; i3++) {
72 LOG(INDENT "[\n");
73 for (int64_t i2 = 0; i2 < ne[2]; i2++) {
74 if (i2 == n && ne[2] > 2 * n) {
75 LOG(INDENT INDENT "..., \n");
76 i2 = ne[2] - n;
77 }
78 LOG(INDENT INDENT "[\n");
79 for (int64_t i1 = 0; i1 < ne[1]; i1++) {
80 if (i1 == n && ne[1] > 2 * n) {
81 LOG(INDENT INDENT INDENT "..., \n");
82 i1 = ne[1] - n;
83 }
84 LOG(INDENT INDENT INDENT "[");
85 for (int64_t i0 = 0; i0 < ne[0]; i0++) {
86 if (i0 == n && ne[0] > 2 * n) {
87 LOG(" ..., ");
88 i0 = ne[0] - n;
89 }
90 const float v = common_ggml_get_float_value(data, type, nb, i0, i1, i2, i3);
91 LOG("%14.8f", v);
92 if (i0 < ne[0] - 1) {
93 LOG(", ");
94 }
95 }
96 LOG(" ],\n");
97 }
98 LOG(INDENT INDENT "],\n");
99 }
100 LOG(INDENT "]\n");
101 const double n_elem = double(ne[0]) * double(ne[1]) * double(ne[2]) * double(ne[3]);
102 LOG(INDENT "sum = %f\n", (float) sum);
103 LOG(INDENT "rms = %f\n", (float) std::sqrt(sum_sq / n_elem));
104 LOG(INDENT "min = %f\n", min);
105 LOG(INDENT "max = %f\n", max);
106 }
107
108 if constexpr (abort) {
109 if (std::isnan(sum)) {

Callers

nothing calls this directly

Calls 3

minFunction · 0.85
maxFunction · 0.85

Tested by

no test coverage detected