Skip to content

Commit

Permalink
imatrix : use FMA and sort tensor names
Browse files Browse the repository at this point in the history
  • Loading branch information
compilade committed Sep 8, 2024
1 parent 3ad0603 commit d19101c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions examples/imatrix/imatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d19101c

Please sign in to comment.