From afa43e13c8701d99d3e01c79fc0ab5fb746aae78 Mon Sep 17 00:00:00 2001 From: Francis Couture-Harpin Date: Sun, 3 Aug 2025 18:03:53 -0400 Subject: [PATCH 1/2] imatrix : add warning when suffix is not .gguf for GGUF imatrix --- tools/imatrix/imatrix.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/imatrix/imatrix.cpp b/tools/imatrix/imatrix.cpp index 9ceceb478df4f..aaf52eb7422b6 100644 --- a/tools/imatrix/imatrix.cpp +++ b/tools/imatrix/imatrix.cpp @@ -512,7 +512,11 @@ void IMatrixCollector::save_imatrix(int32_t n_chunk) const { this->save_imatrix_legacy(n_chunk); return; } - // else, default to GGUF imatrix + if (!string_ends_with(fname, ".gguf")) { + // allowed, but hopefully this raises awareness + LOG_WRN("\n%s: saving imatrix using GGUF format with a different suffix than .gguf\n", __func__); + LOG_WRN("%s: if you want the previous imatrix format, use --output-format dat\n", __func__); + } if (n_chunk > 0) { fname += ".at_"; From 342e7014dbff23b2be6e820bb8cd75e2a765c9d4 Mon Sep 17 00:00:00 2001 From: Francis Couture-Harpin Date: Sun, 3 Aug 2025 18:12:06 -0400 Subject: [PATCH 2/2] imatrix : only warn about suffix when output format is unspecified --- common/arg.cpp | 6 +++--- common/common.h | 2 +- tools/imatrix/imatrix.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/common/arg.cpp b/common/arg.cpp index 0b216ec0d0c02..a02db0b0a0db6 100644 --- a/common/arg.cpp +++ b/common/arg.cpp @@ -2649,10 +2649,10 @@ common_params_context common_params_parser_init(common_params & params, llama_ex ).set_examples({LLAMA_EXAMPLE_IMATRIX})); add_opt(common_arg( {"--output-format"}, "{gguf,dat}", - string_format("output format for imatrix file (default: %s)", params.imat_dat ? "dat" : "gguf"), + string_format("output format for imatrix file (default: %s)", params.imat_dat > 0 ? "dat" : "gguf"), [](common_params & params, const std::string & value) { - /**/ if (value == "gguf") { params.imat_dat = false; } - else if (value == "dat") { params.imat_dat = true; } + /**/ if (value == "gguf") { params.imat_dat = -1; } + else if (value == "dat") { params.imat_dat = 1; } else { throw std::invalid_argument("invalid output format"); } } ).set_examples({LLAMA_EXAMPLE_IMATRIX})); diff --git a/common/common.h b/common/common.h index 6b900b795f438..6a47dac4b9dbd 100644 --- a/common/common.h +++ b/common/common.h @@ -439,7 +439,7 @@ struct common_params { int32_t n_out_freq = 10; // output the imatrix every n_out_freq iterations int32_t n_save_freq = 0; // save the imatrix every n_save_freq iterations int32_t i_chunk = 0; // start processing from this chunk - bool imat_dat = false; // whether the legacy imatrix.dat format should be output + int8_t imat_dat = 0; // whether the legacy imatrix.dat format should be output (gguf <= 0 < dat) bool process_output = false; // collect data for the output tensor bool compute_ppl = true; // whether to compute perplexity diff --git a/tools/imatrix/imatrix.cpp b/tools/imatrix/imatrix.cpp index aaf52eb7422b6..f28a036deebe3 100644 --- a/tools/imatrix/imatrix.cpp +++ b/tools/imatrix/imatrix.cpp @@ -506,14 +506,14 @@ void IMatrixCollector::save_imatrix_legacy(int32_t ncall) const { void IMatrixCollector::save_imatrix(int32_t n_chunk) const { auto fname = m_params.out_file; - bool use_legacy_format = m_params.imat_dat; + int8_t use_legacy_format = m_params.imat_dat; - if (use_legacy_format) { + if (use_legacy_format > 0) { this->save_imatrix_legacy(n_chunk); return; } - if (!string_ends_with(fname, ".gguf")) { - // allowed, but hopefully this raises awareness + // only warn when `--output-format gguf` is not specified + if (use_legacy_format == 0 && !string_ends_with(fname, ".gguf")) { LOG_WRN("\n%s: saving imatrix using GGUF format with a different suffix than .gguf\n", __func__); LOG_WRN("%s: if you want the previous imatrix format, use --output-format dat\n", __func__); }