@@ -40,7 +40,7 @@ static const char * const LLM_KV_IMATRIX_CHUNK_SIZE = "imatrix.chunk_size";
4040
4141struct Stats {
4242 std::vector<float > in_sum;
43- std::vector<float > in_sum2 ;
43+ std::vector<float > values ;
4444 std::vector<int64_t > counts;
4545};
4646
@@ -130,7 +130,7 @@ static void process_tensor_name(const std::string & input, std::string & layer,
130130static std::vector<float > compute_tensor_averages (const Stats & tstats) {
131131 if (tstats.counts .empty ()) return {};
132132 const size_t n_mat = tstats.counts .size ();
133- const size_t len = !tstats.in_sum .empty () ? tstats.in_sum .size () : tstats.in_sum2 .size ();
133+ const size_t len = !tstats.in_sum .empty () ? tstats.in_sum .size () : tstats.values .size ();
134134
135135 if (len == 0 || len % n_mat != 0 ) return {};
136136 const size_t row = len / n_mat;
@@ -152,7 +152,7 @@ static std::vector<float> compute_tensor_averages(const Stats & tstats) {
152152 if (c <= 0 ) return {};
153153 const size_t off = m * row;
154154 for (size_t j = 0 ; j < row; ++j) {
155- vec.push_back (tstats.in_sum2 [off + j] / c);
155+ vec.push_back (tstats.values [off + j] / c);
156156 }
157157 }
158158 }
@@ -161,8 +161,8 @@ static std::vector<float> compute_tensor_averages(const Stats & tstats) {
161161}
162162
163163static int compute_vector_statistics (std::vector<tensor_statistics> & tstats, const std::string & name, const Stats & e) {
164- if (e.in_sum2 .size () % e.counts .size () != 0 ) {
165- LOG_ERR (" %s: activation size mismatch for tensor %s (%zu vs %zu)\n " , __func__, name.c_str (), e.counts .size (), e.in_sum2 .size ());
164+ if (e.values .size () % e.counts .size () != 0 ) {
165+ LOG_ERR (" %s: activation size mismatch for tensor %s (%zu vs %zu)\n " , __func__, name.c_str (), e.counts .size (), e.values .size ());
166166 return -1 ;;
167167 }
168168 if (e.counts .empty ()) {
@@ -171,17 +171,17 @@ static int compute_vector_statistics(std::vector<tensor_statistics> & tstats, co
171171 }
172172
173173 const int n_mat = e.counts .size ();
174- const int row_size = e.in_sum2 .size () / n_mat;
174+ const int row_size = e.values .size () / n_mat;
175175 const int calc_mode = e.in_sum .empty () ? 2 : 1 ;
176176
177177 std::vector<float > activations;
178178
179179 if (e.in_sum .empty ()) {
180- activations.reserve (e.in_sum2 .size ());
180+ activations.reserve (e.values .size ());
181181
182182 for (int i = 0 ; i < n_mat; ++i) {
183183 for (int j = 0 ; j < row_size; ++j) {
184- activations.push_back (e.in_sum2 [i*row_size + j] / e.counts [i]);
184+ activations.push_back (e.values [i*row_size + j] / e.counts [i]);
185185 }
186186 }
187187 } else {
@@ -420,13 +420,13 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor * t, bool ask, void *
420420 // broadcast, when loading an old imatrix
421421 e.counts .resize (n_as, e.counts [0 ]);
422422 }
423- if (e.in_sum2 .empty ()) {
423+ if (e.values .empty ()) {
424424 e.in_sum .resize (src1->ne [0 ]*n_as, 0 );
425- e.in_sum2 .resize (src1->ne [0 ]*n_as, 0 );
425+ e.values .resize (src1->ne [0 ]*n_as, 0 );
426426 e.counts .resize (n_as, 0 );
427427 }
428- else if (e.in_sum2 .size () != (size_t )src1->ne [0 ]*n_as) {
429- LOG_ERR (" %s: inconsistent size for %s (%d vs %d)\n " , __func__, wname.c_str (), (int )e.in_sum2 .size (), (int )(src1->ne [0 ]*n_as));
428+ else if (e.values .size () != (size_t )src1->ne [0 ]*n_as) {
429+ LOG_ERR (" %s: inconsistent size for %s (%d vs %d)\n " , __func__, wname.c_str (), (int )e.values .size (), (int )(src1->ne [0 ]*n_as));
430430 exit (1 ); // GGML_ABORT("fatal error");
431431 }
432432 else if (e.counts .size () != (size_t )n_as) {
@@ -454,9 +454,9 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor * t, bool ask, void *
454454
455455 for (int64_t j = 0 ; j < src1->ne [0 ]; ++j) {
456456 e.in_sum [e_start + j] += x[j];
457- e.in_sum2 [e_start + j] += x[j] * x[j];
458- if (!std::isfinite ((float )e.in_sum2 [e_start + j])) {
459- LOG_ERR (" %f detected in %s\n " , (float )e.in_sum2 [e_start + j], wname.c_str ());
457+ e.values [e_start + j] += x[j] * x[j];
458+ if (!std::isfinite ((float )e.values [e_start + j])) {
459+ LOG_ERR (" %f detected in %s\n " , (float )e.values [e_start + j], wname.c_str ());
460460 exit (1 );
461461 }
462462 }
@@ -478,13 +478,13 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor * t, bool ask, void *
478478 auto & e = m_stats[wname];
479479 const int64_t n_mat = src1->ne [2 ] * src1->ne [3 ];
480480
481- if (e.in_sum2 .empty ()) {
481+ if (e.values .empty ()) {
482482 e.in_sum .resize (src1->ne [0 ] * n_mat, 0 );
483- e.in_sum2 .resize (src1->ne [0 ] * n_mat, 0 );
483+ e.values .resize (src1->ne [0 ] * n_mat, 0 );
484484 e.counts .resize (n_mat, 0 );
485485 }
486- else if (e.in_sum2 .size () != (size_t )(src1->ne [0 ] * n_mat)) {
487- LOG_ERR (" %s: inconsistent size for %s (%d vs %d)\n " , __func__, wname.c_str (), (int )e.in_sum2 .size (), (int )(src1->ne [0 ] * n_mat));
486+ else if (e.values .size () != (size_t )(src1->ne [0 ] * n_mat)) {
487+ LOG_ERR (" %s: inconsistent size for %s (%d vs %d)\n " , __func__, wname.c_str (), (int )e.values .size (), (int )(src1->ne [0 ] * n_mat));
488488 exit (1 ); // GGML_ABORT("fatal error");
489489 }
490490 else if (e.counts .size () != (size_t )n_mat) {
@@ -502,9 +502,9 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor * t, bool ask, void *
502502 e.counts [mat_id]++;
503503 for (int64_t j = 0 ; j < src1->ne [0 ]; ++j) {
504504 e.in_sum [mat_start + j] += x[j];
505- e.in_sum2 [mat_start + j] += x[j] * x[j];
506- if (!std::isfinite ((float )e.in_sum2 [j])) {
507- LOG_ERR (" %f detected in %s\n " , (float )e.in_sum2 [j], wname.c_str ());
505+ e.values [mat_start + j] += x[j] * x[j];
506+ if (!std::isfinite ((float )e.values [j])) {
507+ LOG_ERR (" %f detected in %s\n " , (float )e.values [j], wname.c_str ());
508508 exit (1 );
509509 }
510510 }
@@ -593,14 +593,14 @@ void IMatrixCollector::save_imatrix_legacy(int32_t ncall) const {
593593 // ceiling division to avoid accidental zeros
594594 const int32_t ncall = (*std::max_element (stat.counts .begin (), stat.counts .end ()) + (chunk_size - 1 )) / chunk_size;
595595 out.write ((const char *) &ncall, sizeof (ncall));
596- const int32_t nval = stat.in_sum2 .size ();
596+ const int32_t nval = stat.values .size ();
597597 const int32_t nmat = stat.counts .size ();
598598 out.write ((const char *) &nval, sizeof (nval));
599599 if (nval > 0 && nmat > 0 ) {
600600 std::vector<float > tmp (nval);
601601 for (int32_t i = 0 ; i < nval; i++) {
602602 float count = static_cast <float >(stat.counts [i / (nval / nmat)]);
603- float value = stat.in_sum2 [i];
603+ float value = stat.values [i];
604604 if (count == 0 .0f ) {
605605 // store 1 for partial data
606606 value = 1 .0f ;
@@ -676,7 +676,7 @@ void IMatrixCollector::save_imatrix(int32_t n_chunk) const {
676676
677677 to_store.push_back (kv.first );
678678 data_size += GGML_PAD (ggml_tensor_overhead () + sizeof (float ) * kv.second .in_sum .size (), GGML_MEM_ALIGN);
679- data_size += GGML_PAD (ggml_tensor_overhead () + sizeof (float ) * kv.second .in_sum2 .size (), GGML_MEM_ALIGN);
679+ data_size += GGML_PAD (ggml_tensor_overhead () + sizeof (float ) * kv.second .values .size (), GGML_MEM_ALIGN);
680680 data_size += GGML_PAD (ggml_tensor_overhead () + sizeof (float ) * kv.second .counts .size (), GGML_MEM_ALIGN);
681681 }
682682
@@ -711,7 +711,7 @@ void IMatrixCollector::save_imatrix(int32_t n_chunk) const {
711711
712712 for (const auto & name : to_store) {
713713 const auto & stat = m_stats.at (name);
714- const int32_t nval = (int32_t ) stat.in_sum2 .size ();
714+ const int32_t nval = (int32_t ) stat.values .size ();
715715 const int32_t nmat = (int32_t ) stat.counts .size ();
716716 if (nval > 0 && nmat > 0 ) {
717717 struct ggml_tensor * in_sum2 = ggml_new_tensor_2d (ctx, GGML_TYPE_F32, nval / nmat, nmat);
@@ -720,7 +720,7 @@ void IMatrixCollector::save_imatrix(int32_t n_chunk) const {
720720 ggml_format_name (counts, " %s.counts" , name.c_str ());
721721
722722 for (int32_t j = 0 ; j < nval; ++j) {
723- ((float *) in_sum2->data )[j] = (float ) stat.in_sum2 [j];
723+ ((float *) in_sum2->data )[j] = (float ) stat.values [j];
724724 }
725725 for (int32_t j = 0 ; j < nmat; ++j) {
726726 ((float *) counts->data )[j] = (float ) stat.counts [j];
@@ -787,8 +787,8 @@ bool IMatrixCollector::load_imatrix_legacy(const char * fname) {
787787 return false ;
788788 }
789789
790- if (e.in_sum2 .empty ()) {
791- e.in_sum2 .resize (nval, 0 .0f );
790+ if (e.values .empty ()) {
791+ e.values .resize (nval, 0 .0f );
792792 e.counts .resize (1 , 0 );
793793 }
794794
@@ -802,7 +802,7 @@ bool IMatrixCollector::load_imatrix_legacy(const char * fname) {
802802
803803 // Recreate the state as expected by save_imatrix(), and correct for weighted sum.
804804 for (int i = 0 ; i < nval; i++) {
805- e.in_sum2 [i] += tmp[i] * chunk_size;
805+ e.values [i] += tmp[i] * chunk_size;
806806 }
807807 // The legacy format doesn't distinguish the counts for different experts
808808 for (size_t j = 0 ; j < e.counts .size (); ++j) {
@@ -922,11 +922,11 @@ bool IMatrixCollector::load_imatrix(const char * file_name) {
922922 auto & e = m_stats[name];
923923
924924 int64_t nval = ggml_nelements (in_sum2);
925- if (e.in_sum2 .empty ()) {
926- e.in_sum2 .resize (nval, 0 .0f );
925+ if (e.values .empty ()) {
926+ e.values .resize (nval, 0 .0f );
927927 e.in_sum .resize (nval, 0 .0f );
928- } else if ((size_t ) nval != e.in_sum2 .size ()) {
929- LOG_ERR (" %s: mismatched sums size for %s: %zu != %zu\n " , __func__, name.c_str (), (size_t ) nval, e.in_sum2 .size ());
928+ } else if ((size_t ) nval != e.values .size ()) {
929+ LOG_ERR (" %s: mismatched sums size for %s: %zu != %zu\n " , __func__, name.c_str (), (size_t ) nval, e.values .size ());
930930 gguf_free (ctx_gguf);
931931 ggml_free (ctx);
932932 return false ;
@@ -947,7 +947,7 @@ bool IMatrixCollector::load_imatrix(const char * file_name) {
947947
948948 // Recreate the state as expected by save_imatrix()
949949 for (int64_t j = 0 ; j < nval; j++) {
950- e.in_sum2 [j] += ((const float *) in_sum2->data )[j];
950+ e.values [j] += ((const float *) in_sum2->data )[j];
951951 }
952952 for (int64_t j = 0 ; j < ncounts; j++) {
953953 e.counts [j] += std::lround (((const float *) counts->data )[j]);
0 commit comments