88#include < fstream>
99#include < mutex>
1010#include < unordered_map>
11+ #include < string>
1112
1213/* Stolen from llama.cpp (credits: Kawrakow)*/
1314
@@ -119,10 +120,10 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor* t, bool ask, void* us
119120 e.values .resize (src1->ne [0 ] * n_as, 0 );
120121 e.counts .resize (src1->ne [0 ] * n_as, 0 );
121122 } else if (e.values .size () != (size_t )src1->ne [0 ] * n_as) {
122- LOG_ERROR ( " inconsistent size for %s (%d vs %d)\n " , wname.c_str (), (int )e.values .size (), (int )src1->ne [0 ] * n_as);
123+ printf ( " ERROR: inconsistent size for %s (%d vs %d)\n " , wname.c_str (), (int )e.values .size (), (int )src1->ne [0 ] * n_as);
123124 exit (1 ); // GGML_ABORT("fatal error");
124125 }
125- LOG_DEBUG (" %s[%d]: %32s, %s, %5d x %5d, %d\n " , m_last_call, wname.c_str (), ggml_op_name (t->op ), (int )src1->ne [0 ], (int )src1->ne [2 ], (int )src1->type );
126+ // LOG_DEBUG("%s[%d]: %32s, %s, %5d x %5d, %d\n", m_last_call, wname.c_str(), ggml_op_name(t->op), (int)src1->ne[0], (int)src1->ne[2], (int)src1->type);
126127 // loop over all possible experts, regardless if they are used or not in the batch
127128 for (int ex = 0 ; ex < n_as; ++ex) {
128129 size_t e_start = ex * src1->ne [0 ];
@@ -144,8 +145,8 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor* t, bool ask, void* us
144145 e.values [e_start + j] += x[j] * x[j];
145146 e.counts [e_start + j]++;
146147 if (!std::isfinite (e.values [e_start + j])) {
147- LOG_INFO (" \n " );
148- LOG_ERROR (" %f detected in %s\n " , e.values [e_start + j], wname.c_str ());
148+ printf (" \n " );
149+ printf (" %ERROR: f detected in %s\n " , e.values [e_start + j], wname.c_str ());
149150 exit (1 );
150151 }
151152 }
@@ -158,7 +159,7 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor* t, bool ask, void* us
158159 e.values .resize (src1->ne [0 ], 0 );
159160 e.counts .resize (src1->ne [0 ], 0 );
160161 } else if (e.values .size () != (size_t )src1->ne [0 ]) {
161- LOG_ERROR (" inconsistent size for %s (%d vs %d)\n " , wname.c_str (), (int )e.values .size (), (int )src1->ne [0 ]);
162+ printf (" inconsistent size for %s (%d vs %d)\n " , wname.c_str (), (int )e.values .size (), (int )src1->ne [0 ]);
162163 exit (1 ); // GGML_ABORT("fatal error");
163164 }
164165
@@ -170,7 +171,7 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor* t, bool ask, void* us
170171 e.values [j] += x[j] * x[j];
171172 e.counts [j]++;
172173 if (!std::isfinite (e.values [j])) {
173- LOG_ERROR (" %f detected in %s\n " , e.values [j], wname.c_str ());
174+ printf (" %f detected in %s\n " , e.values [j], wname.c_str ());
174175 exit (1 );
175176 }
176177 }
@@ -181,7 +182,7 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor* t, bool ask, void* us
181182}
182183
183184void IMatrixCollector::save_imatrix (std::string fname,int ncall) const {
184- LOG_INFO (" SAVING_IMATRIX..." );
185+ printf (" SAVING_IMATRIX...\n " );
185186
186187 if (ncall > 0 ) {
187188 fname += " .at_" ;
@@ -209,17 +210,17 @@ void IMatrixCollector::save_imatrix(std::string fname,int ncall) const {
209210 }
210211
211212 if (n_zeros != 0 && is_first) {
212- LOG_INFO (" \n " );
213+ printf (" \n " );
213214 is_first = false ;
214215 }
215216
216217 if (n_zeros == n_all) {
217- LOG_WARN ( " entry '%40s' has no data - skipping\n " , kv.first .c_str ());
218+ printf ( " WARNING: entry '%40s' has no data - skipping\n " , kv.first .c_str ());
218219 continue ;
219220 }
220221
221222 if (n_zeros > 0 ) {
222- LOG_WARN ( " entry '%40s' has partial data (%.2f%%) - skipping\n " , kv.first .c_str (), 100 .0f * (n_all - n_zeros) / n_all);
223+ printf ( " WARNING: entry '%40s' has partial data (%.2f%%) - skipping\n " , kv.first .c_str (), 100 .0f * (n_all - n_zeros) / n_all);
223224 continue ;
224225 }
225226
@@ -228,7 +229,7 @@ void IMatrixCollector::save_imatrix(std::string fname,int ncall) const {
228229 }
229230
230231 if (to_store.size () < m_stats.size ()) {
231- LOG_WARN ( " storing only %zu out of %zu entries\n " , to_store.size (), m_stats.size ());
232+ printf ( " WARNING: storing only %zu out of %zu entries\n " , to_store.size (), m_stats.size ());
232233 }
233234
234235 std::ofstream out (fname, std::ios::binary);
@@ -253,20 +254,20 @@ void IMatrixCollector::save_imatrix(std::string fname,int ncall) const {
253254 // Write the number of call the matrix was computed with
254255 out.write ((const char *)&m_last_call, sizeof (m_last_call));
255256
256- LOG_DEBUG (" \n " );
257- LOG_DEBUG (" stored collected data after %d chunks in %s\n " , m_last_call, fname.c_str ());
257+ // LOG_DEBUG("\n");
258+ // LOG_DEBUG("stored collected data after %d chunks in %s\n", m_last_call, fname.c_str());
258259}
259260
260261bool IMatrixCollector::load_imatrix (const char * fname) {
261262 std::ifstream in (fname, std::ios::binary);
262263 if (!in) {
263- LOG_ERROR ( " failed to open %s\n " , fname);
264+ printf ( " ERROR: failed to open %s\n " , fname);
264265 return false ;
265266 }
266267 int n_entries;
267268 in.read ((char *)&n_entries, sizeof (n_entries));
268269 if (in.fail () || n_entries < 1 ) {
269- LOG_ERROR ( " no data in file %s\n " , fname);
270+ printf ( " ERROR: no data in file %s\n " , fname);
270271 return false ;
271272 }
272273 for (int i = 0 ; i < n_entries; ++i) {
@@ -275,7 +276,7 @@ bool IMatrixCollector::load_imatrix(const char* fname) {
275276 std::vector<char > name_as_vec (len + 1 );
276277 in.read ((char *)name_as_vec.data (), len);
277278 if (in.fail ()) {
278- LOG_ERROR ( " failed reading name for entry %d from %s\n " , i + 1 , fname);
279+ printf ( " ERROR: failed reading name for entry %d from %s\n " , i + 1 , fname);
279280 return false ;
280281 }
281282 name_as_vec[len] = 0 ;
@@ -286,7 +287,7 @@ bool IMatrixCollector::load_imatrix(const char* fname) {
286287 int nval;
287288 in.read ((char *)&nval, sizeof (nval));
288289 if (in.fail () || nval < 1 ) {
289- LOG_ERROR ( " failed reading number of values for entry %d\n " , i);
290+ printf ( " ERROR: failed reading number of values for entry %d\n " , i);
290291 m_stats = {};
291292 return false ;
292293 }
@@ -299,7 +300,7 @@ bool IMatrixCollector::load_imatrix(const char* fname) {
299300 std::vector<float > tmp (nval);
300301 in.read ((char *)tmp.data (), nval * sizeof (float ));
301302 if (in.fail ()) {
302- LOG_ERROR ( " failed reading data for entry %d\n " , i);
303+ printf ( " ERROR: failed reading data for entry %d\n " , i);
303304 m_stats = {};
304305 return false ;
305306 }
0 commit comments