8
8
#include < fstream>
9
9
#include < mutex>
10
10
#include < unordered_map>
11
+ #include < string>
11
12
12
13
/* Stolen from llama.cpp (credits: Kawrakow)*/
13
14
@@ -119,10 +120,10 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor* t, bool ask, void* us
119
120
e.values .resize (src1->ne [0 ] * n_as, 0 );
120
121
e.counts .resize (src1->ne [0 ] * n_as, 0 );
121
122
} 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);
123
124
exit (1 ); // GGML_ABORT("fatal error");
124
125
}
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);
126
127
// loop over all possible experts, regardless if they are used or not in the batch
127
128
for (int ex = 0 ; ex < n_as; ++ex) {
128
129
size_t e_start = ex * src1->ne [0 ];
@@ -144,8 +145,8 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor* t, bool ask, void* us
144
145
e.values [e_start + j] += x[j] * x[j];
145
146
e.counts [e_start + j]++;
146
147
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 ());
149
150
exit (1 );
150
151
}
151
152
}
@@ -158,7 +159,7 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor* t, bool ask, void* us
158
159
e.values .resize (src1->ne [0 ], 0 );
159
160
e.counts .resize (src1->ne [0 ], 0 );
160
161
} 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 ]);
162
163
exit (1 ); // GGML_ABORT("fatal error");
163
164
}
164
165
@@ -170,7 +171,7 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor* t, bool ask, void* us
170
171
e.values [j] += x[j] * x[j];
171
172
e.counts [j]++;
172
173
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 ());
174
175
exit (1 );
175
176
}
176
177
}
@@ -181,7 +182,7 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor* t, bool ask, void* us
181
182
}
182
183
183
184
void IMatrixCollector::save_imatrix (std::string fname,int ncall) const {
184
- LOG_INFO (" SAVING_IMATRIX..." );
185
+ printf (" SAVING_IMATRIX...\n " );
185
186
186
187
if (ncall > 0 ) {
187
188
fname += " .at_" ;
@@ -209,17 +210,17 @@ void IMatrixCollector::save_imatrix(std::string fname,int ncall) const {
209
210
}
210
211
211
212
if (n_zeros != 0 && is_first) {
212
- LOG_INFO (" \n " );
213
+ printf (" \n " );
213
214
is_first = false ;
214
215
}
215
216
216
217
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 ());
218
219
continue ;
219
220
}
220
221
221
222
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);
223
224
continue ;
224
225
}
225
226
@@ -228,7 +229,7 @@ void IMatrixCollector::save_imatrix(std::string fname,int ncall) const {
228
229
}
229
230
230
231
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 ());
232
233
}
233
234
234
235
std::ofstream out (fname, std::ios::binary);
@@ -253,20 +254,20 @@ void IMatrixCollector::save_imatrix(std::string fname,int ncall) const {
253
254
// Write the number of call the matrix was computed with
254
255
out.write ((const char *)&m_last_call, sizeof (m_last_call));
255
256
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());
258
259
}
259
260
260
261
bool IMatrixCollector::load_imatrix (const char * fname) {
261
262
std::ifstream in (fname, std::ios::binary);
262
263
if (!in) {
263
- LOG_ERROR ( " failed to open %s\n " , fname);
264
+ printf ( " ERROR: failed to open %s\n " , fname);
264
265
return false ;
265
266
}
266
267
int n_entries;
267
268
in.read ((char *)&n_entries, sizeof (n_entries));
268
269
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);
270
271
return false ;
271
272
}
272
273
for (int i = 0 ; i < n_entries; ++i) {
@@ -275,7 +276,7 @@ bool IMatrixCollector::load_imatrix(const char* fname) {
275
276
std::vector<char > name_as_vec (len + 1 );
276
277
in.read ((char *)name_as_vec.data (), len);
277
278
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);
279
280
return false ;
280
281
}
281
282
name_as_vec[len] = 0 ;
@@ -286,7 +287,7 @@ bool IMatrixCollector::load_imatrix(const char* fname) {
286
287
int nval;
287
288
in.read ((char *)&nval, sizeof (nval));
288
289
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);
290
291
m_stats = {};
291
292
return false ;
292
293
}
@@ -299,7 +300,7 @@ bool IMatrixCollector::load_imatrix(const char* fname) {
299
300
std::vector<float > tmp (nval);
300
301
in.read ((char *)tmp.data (), nval * sizeof (float ));
301
302
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);
303
304
m_stats = {};
304
305
return false ;
305
306
}
0 commit comments