Skip to content

Commit 6ff0a79

Browse files
committed
Minor stats report cosmetic changes
1 parent 86fabce commit 6ff0a79

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

tools/imatrix/imatrix.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static std::vector<float> compute_tensor_averages(const Stats & tstats) {
150150
} else {
151151
// Mean
152152
for (size_t m = 0; m < n_mat; ++m) {
153-
const float c = (float)tstats.counts[m];
153+
const auto c = (float)tstats.counts[m];
154154
const size_t off = m * row;
155155
if (c <= 0.0f) {
156156
vec.insert(vec.end(), row, 0.0f); // zero-fill rows for experts with zero count to preserve shape
@@ -215,7 +215,7 @@ static bool compute_vector_statistics(std::vector<tensor_statistics> & tstats, c
215215
double sqr_sum = 0.0;
216216
for (const float v : activations) { sqr_sum += (double)v * (double)v; }
217217
double variance = sqr_sum / (double)activations.size() - (double)mean * (double)mean;
218-
if (variance < 0.0) { variance = 0.0; }
218+
variance = std::max(variance, 0.0);
219219
const float std_deviation = std::sqrt((float)variance);
220220

221221
float entropy = 0.0f;
@@ -1327,7 +1327,7 @@ static bool show_statistics(const common_params & params) {
13271327
LOG_INF("\n%6s\t%18s\t%13s\t%8s\t%8s\t%7s\t%15s\t%13s\t%11s\t%8s\t%5s\t%10s\n",
13281328
"Layer",
13291329
"Tensor",
1330-
legacy_mode ? "Σ(Act²)" : "L₂ Norm",
1330+
legacy_mode ? "Σ E[Act²]" : "L₂ Norm",
13311331
"Min",
13321332
"Max",
13331333
"μ",
@@ -1356,7 +1356,7 @@ static bool show_statistics(const common_params & params) {
13561356
const float h_norm = tstat.elements > 1 ? 100.0f * (tstat.entropy / std::log2((float) tstat.elements)) : 0.0f;
13571357
const float ecs = 100.0f * std::exp(-0.01f * tstat.l2_norm) * std::pow(std::fabs(tstat.cossim), 10.0f);
13581358

1359-
LOG_INF("%5s\t%-20s\t%11.2f\t%10.4f\t%10.4f\t%8.2f\t%8.2f\t%7d\t%10.2f%%\t%10.4f\t%6.2f%%\t%10.4f\n",
1359+
LOG_INF("%5s\t%-20s\t%11.4f\t%10.4f\t%10.4f\t%8.4f\t%8.4f\t%7d\t%10.2f%%\t%10.4f\t%6.2f%%\t%10.4f\n",
13601360
layer.c_str(),
13611361
name.c_str(),
13621362
legacy_mode ? tstat.sum_values : tstat.l2_norm,
@@ -1392,7 +1392,7 @@ static bool show_statistics(const common_params & params) {
13921392
LOG_INF("\nComputing layer statistics (%zu layers)\n", layers);
13931393
LOG_INF("\n%6s\t%13s\t%6s\t%11s\t%6s\n",
13941394
"Layer",
1395-
legacy_mode ? "Σ(Act²)" : "L₂ Norm",
1395+
legacy_mode ? "Σ E[Act²]" : "L₂ Norm",
13961396
"ZD",
13971397
"CosSim",
13981398
legacy_mode ? "" : "ECS");
@@ -1402,19 +1402,19 @@ static bool show_statistics(const common_params & params) {
14021402
LOG_INF("=========================================================\n");
14031403
}
14041404
for (const auto & [layer, stats] : ls) {
1405-
if (layer < 0 || stats.n == 0) continue;
1405+
if (layer < 0 || stats.n == 0) { continue; }
14061406
const auto lcs = layer_cossim.find(layer);
14071407
const float layer_cs = lcs != layer_cossim.end() ? lcs->second : 0.0f;
14081408
const auto ll2n = layer_l2_norm.find(layer);
14091409
const float layer_l2n = ll2n != layer_l2_norm.end() ? ll2n->second : 0.0f;
14101410
if (legacy_mode) {
1411-
LOG_INF("%5d\t%11.2f\t%6.2f%%\t%11.4f\n",
1411+
LOG_INF("%5d\t%11.4f\t%6.2f%%\t%11.4f\n",
14121412
layer,
14131413
stats.layer_sum,
14141414
100.0f * stats.layer_zd / stats.n,
14151415
layer_cs);
14161416
} else {
1417-
LOG_INF("%5d\t%11.2f\t%6.2f%%\t%11.4f\t%8.4f\n",
1417+
LOG_INF("%5d\t%11.4f\t%6.2f%%\t%11.4f\t%8.4f\n",
14181418
layer,
14191419
layer_l2n,
14201420
100.0f * stats.layer_zd / stats.n,

0 commit comments

Comments
 (0)