imatrix : use FMA and sort tensor names

This commit is contained in:
Francis Couture-Harpin 2024-09-08 11:03:59 -04:00
parent 3ad0603c65
commit d19101c9a0

View File

@ -156,7 +156,7 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor * t, bool ask, void *
e.counts[ex]++;
for (int j = 0; j < (int)src1->ne[0]; ++j) {
e.values[e_start + j] += x[j]*x[j];
e.values[e_start + j] = std::fma(x[j], x[j], e.values[e_start + j]);
if (!std::isfinite((float)e.values[e_start + j])) {
fprintf(stderr, "%f detected in %s\n", (float)e.values[e_start + j], wname.c_str());
exit(1);
@ -198,7 +198,7 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor * t, bool ask, void *
const float * x = data + row * src1->ne[0];
e.counts[0]++;
for (int j = 0; j < (int)src1->ne[0]; ++j) {
e.values[j] += x[j]*x[j];
e.values[j] = std::fma(x[j], x[j], e.values[j]);
if (!std::isfinite((float)e.values[j])) {
fprintf(stderr, "%f detected in %s\n", (float)e.values[j], wname.c_str());
exit(1);
@ -279,6 +279,9 @@ void IMatrixCollector::save_imatrix(int32_t n_chunk) const {
fprintf(stderr, "%s: warning: storing only %zu out of %zu entries\n", __func__, to_store.size(), m_stats.size());
}
// deterministic tensor name order
std::sort(to_store.begin(), to_store.end());
struct ggml_init_params params = {
.mem_size = data_size,
.mem_buffer = NULL,