Skip to content

Commit 1ef3cc1

Browse files
committed
imatrix : use GGUF regardless of the output filename
The legacy format can only be produced with --output-format dat
1 parent 53f65c3 commit 1ef3cc1

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

common/arg.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,10 +2629,10 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
26292629
).set_examples({LLAMA_EXAMPLE_IMATRIX}));
26302630
add_opt(common_arg(
26312631
{"--output-format"}, "{gguf,dat}",
2632-
string_format("output format for imatrix file (default: gguf except when output filename ends with .dat)"),
2632+
string_format("output format for imatrix file (default: %s)", params.imat_dat ? "dat" : "gguf"),
26332633
[](common_params & params, const std::string & value) {
2634-
/**/ if (value == "gguf") { params.imat_out_type = COMMON_IMATRIX_FORMAT_GGUF; }
2635-
else if (value == "dat") { params.imat_out_type = COMMON_IMATRIX_FORMAT_DAT; }
2634+
/**/ if (value == "gguf") { params.imat_dat = false; }
2635+
else if (value == "dat") { params.imat_dat = true; }
26362636
else { throw std::invalid_argument("invalid output format"); }
26372637
}
26382638
).set_examples({LLAMA_EXAMPLE_IMATRIX}));

common/common.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,6 @@ enum common_reasoning_format {
233233
COMMON_REASONING_FORMAT_DEEPSEEK, // Extract thinking tag contents and return as `message.reasoning_content`, including in streaming deltas.
234234
};
235235

236-
enum common_imatrix_format_type {
237-
COMMON_IMATRIX_FORMAT_AUTO,
238-
COMMON_IMATRIX_FORMAT_GGUF,
239-
COMMON_IMATRIX_FORMAT_DAT, // legacy
240-
};
241-
242236
struct common_params {
243237
int32_t n_predict = -1; // new tokens to predict
244238
int32_t n_ctx = 4096; // context size
@@ -437,7 +431,7 @@ struct common_params {
437431
int32_t n_out_freq = 10; // output the imatrix every n_out_freq iterations
438432
int32_t n_save_freq = 0; // save the imatrix every n_save_freq iterations
439433
int32_t i_chunk = 0; // start processing from this chunk
440-
common_imatrix_format_type imat_out_type = COMMON_IMATRIX_FORMAT_AUTO; // format of the output imatrix
434+
bool imat_dat = false; // whether the legacy imatrix.dat format should be output
441435

442436
bool process_output = false; // collect data for the output tensor
443437
bool compute_ppl = true; // whether to compute perplexity

tools/imatrix/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The parameters in square brackets are optional and have the following meaning:
2020
* `-lv | --verbosity` specifies the verbosity level. If set to `0`, no output other than the perplexity of the processed chunks will be generated. If set to `1`, each time the results are saved a message is written to `stderr`. If `>=2`, a message is output each time data is collected for any tensor. Default verbosity level is `1`.
2121
* `-o | --output-file` specifies the name of the file where the computed data will be stored. If missing `imatrix.gguf` is used.
2222
* `-ofreq | --output-frequency` specifies how often the so far computed result is saved to disk. Default is 10 (i.e., every 10 chunks)
23-
* `--output-format` specifies the output format of the generated imatrix file. Either "gguf", or "dat" (the legacy format). Defaults to "gguf" unless the output filename ends with `.dat`.
23+
* `--output-format` specifies the output format of the generated imatrix file. Either "gguf", or "dat" (the legacy format). Defaults to "gguf".
2424
* `--save-frequency` specifies how often to save a copy of the imatrix in a separate file. Default is 0 (i.e., never)
2525
* `--process-output` specifies if data will be collected for the `output.weight` tensor. Typically, it is better not to utilize the importance matrix when quantizing `output.weight`, so this is set to `false` by default.
2626
* `--in-file` one or more existing imatrix files to load and combine. Useful for merging files from multiple runs/datasets.
@@ -46,14 +46,19 @@ Recent versions of `llama-imatrix` store data in GGUF format by default. For the
4646

4747
```bash
4848
# generate and save the imatrix using legacy format
49-
./llama-imatrix -m ggml-model-f16.gguf -f calibration-data.txt -o imatrix-legcy-format.dat -ngl 99
49+
./llama-imatrix -m ggml-model-f16.gguf -f calibration-data.txt --output-format dat -o imatrix-legcy-format.dat -ngl 99
5050
```
5151

5252
```bash
53-
# covert legacy (binary) imatrix format to new (GGUF) format
53+
# convert legacy (binary) imatrix format to new (GGUF) format
5454
./llama-imatrix --in-file imatrix-legacy-format.dat -o imatrix-new-format.gguf
5555
```
5656

57+
```bash
58+
# convert new (GGUF) imatrix format to legacy (binary) format
59+
./llama-imatrix --in-file imatrix-new-format.gguf --output-format dat -o imatrix-legacy-format.dat
60+
```
61+
5762
```bash
5863
# combine existing imatrices
5964
./llama-imatrix --in-file imatrix-prev-0.gguf --in-file imatrix-prev-1.gguf -o imatrix-combined.gguf

tools/imatrix/imatrix.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,11 +492,9 @@ void IMatrixCollector::save_imatrix_legacy(int32_t ncall) const {
492492

493493
void IMatrixCollector::save_imatrix(int32_t n_chunk) const {
494494
auto fname = m_params.out_file;
495-
auto imat_type = m_params.imat_out_type;
495+
bool use_legacy_format = m_params.imat_dat;
496496

497-
if ((imat_type == COMMON_IMATRIX_FORMAT_AUTO && string_ends_with(fname, ".dat")) ||
498-
(imat_type == COMMON_IMATRIX_FORMAT_DAT)) {
499-
LOG_WRN("\n%s: saving to legacy imatrix format\n", __func__);
497+
if (use_legacy_format) {
500498
this->save_imatrix_legacy(n_chunk);
501499
return;
502500
}

0 commit comments

Comments
 (0)