Skip to content

Commit d31192b

Browse files
authored
imatrix : use GGUF by default (#14842)
* imatrix : use GGUF by default * imatrix : use GGUF regardless of the output filename The legacy format can only be produced with --output-format dat
1 parent 0a2f549 commit d31192b

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

common/arg.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,6 +2647,15 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
26472647
params.n_out_freq = value;
26482648
}
26492649
).set_examples({LLAMA_EXAMPLE_IMATRIX}));
2650+
add_opt(common_arg(
2651+
{"--output-format"}, "{gguf,dat}",
2652+
string_format("output format for imatrix file (default: %s)", params.imat_dat ? "dat" : "gguf"),
2653+
[](common_params & params, const std::string & value) {
2654+
/**/ if (value == "gguf") { params.imat_dat = false; }
2655+
else if (value == "dat") { params.imat_dat = true; }
2656+
else { throw std::invalid_argument("invalid output format"); }
2657+
}
2658+
).set_examples({LLAMA_EXAMPLE_IMATRIX}));
26502659
add_opt(common_arg(
26512660
{"--save-frequency"}, "N",
26522661
string_format("save an imatrix copy every N iterations (default: %d)", params.n_save_freq),

common/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ struct common_params {
439439
int32_t n_out_freq = 10; // output the imatrix every n_out_freq iterations
440440
int32_t n_save_freq = 0; // save the imatrix every n_save_freq iterations
441441
int32_t i_chunk = 0; // start processing from this chunk
442+
bool imat_dat = false; // whether the legacy imatrix.dat format should be output
442443

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

tools/imatrix/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ More information is available in <https://github.com/ggml-org/llama.cpp/pull/486
77

88
```
99
./llama-imatrix \
10-
-m model.gguf -f some-text.txt [-o imatrix.gguf] [--no-ppl] \
10+
-m model.gguf -f some-text.txt [-o imatrix.gguf] [--output-format {gguf,dat}] [--no-ppl] \
1111
[--process-output] [--chunk 123] [--save-frequency 0] [--output-frequency 10] \
1212
[--in-file imatrix-prev-0.gguf --in-file imatrix-prev-1.gguf ...] [--parse-special] \
1313
[--show-statistics] [...]
@@ -20,6 +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".
2324
* `--save-frequency` specifies how often to save a copy of the imatrix in a separate file. Default is 0 (i.e., never)
2425
* `--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.
2526
* `--in-file` one or more existing imatrix files to load and combine. Useful for merging files from multiple runs/datasets.
@@ -45,14 +46,19 @@ Recent versions of `llama-imatrix` store data in GGUF format by default. For the
4546

4647
```bash
4748
# generate and save the imatrix using legacy format
48-
./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
4950
```
5051

5152
```bash
52-
# covert legacy (binary) imatrix format to new (GGUF) format
53+
# convert legacy (binary) imatrix format to new (GGUF) format
5354
./llama-imatrix --in-file imatrix-legacy-format.dat -o imatrix-new-format.gguf
5455
```
5556

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+
5662
```bash
5763
# combine existing imatrices
5864
./llama-imatrix --in-file imatrix-prev-0.gguf --in-file imatrix-prev-1.gguf -o imatrix-combined.gguf

tools/imatrix/imatrix.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
static void print_usage(int, char ** argv) {
2727
LOG("\nexample usage:\n");
2828
LOG("\n %s \\\n"
29-
" -m model.gguf -f some-text.txt [-o imatrix.gguf] [--no-ppl] \\\n"
29+
" -m model.gguf -f some-text.txt [-o imatrix.gguf] [--output-format {gguf,dat}] [--no-ppl] \\\n"
3030
" [--process-output] [--chunk 123] [--save-frequency 0] [--output-frequency 10] \\\n"
3131
" [--in-file imatrix-prev-0.gguf --in-file imatrix-prev-1.gguf ...] [--parse-special] \\\n"
3232
" [--show-statistics] [...]\n" , argv[0]);
@@ -506,13 +506,13 @@ void IMatrixCollector::save_imatrix_legacy(int32_t ncall) const {
506506

507507
void IMatrixCollector::save_imatrix(int32_t n_chunk) const {
508508
auto fname = m_params.out_file;
509+
bool use_legacy_format = m_params.imat_dat;
509510

510-
// TODO: use the new format in more cases
511-
if (!string_ends_with(fname, ".gguf")) {
512-
LOG_WRN("\n%s: saving to legacy imatrix format because output suffix is not .gguf\n", __func__);
511+
if (use_legacy_format) {
513512
this->save_imatrix_legacy(n_chunk);
514513
return;
515514
}
515+
// else, default to GGUF imatrix
516516

517517
if (n_chunk > 0) {
518518
fname += ".at_";

0 commit comments

Comments
 (0)