Skip to content

Commit efb8b47

Browse files
imatrix : Add --parse-special for enabling parsing of special tokens in imatrix calculation (#13389)
* Add --parse-special for enabling parsing of special tokens in imatrix calculation * whitespace
1 parent 0527771 commit efb8b47

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

common/arg.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,6 +2627,13 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
26272627
params.i_chunk = value;
26282628
}
26292629
).set_examples({LLAMA_EXAMPLE_IMATRIX}));
2630+
add_opt(common_arg(
2631+
{"--parse-special"},
2632+
string_format("prase special tokens (chat, tool, etc) (default: %s)", params.parse_special ? "true" : "false"),
2633+
[](common_params & params) {
2634+
params.parse_special = true;
2635+
}
2636+
).set_examples({LLAMA_EXAMPLE_IMATRIX}));
26302637
add_opt(common_arg(
26312638
{"-pps"},
26322639
string_format("is the prompt shared across parallel sequences (default: %s)", params.is_pp_shared ? "true" : "false"),

common/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ struct common_params {
409409

410410
bool process_output = false; // collect data for the output tensor
411411
bool compute_ppl = true; // whether to compute perplexity
412+
bool parse_special = false; // whether to parse special tokens during imatrix tokenization
412413

413414
// cvector-generator params
414415
int n_pca_batch = 100;

tools/imatrix/imatrix.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ static void print_usage(int, char ** argv) {
2424
LOG("\n %s \\\n"
2525
" -m model.gguf -f some-text.txt [-o imatrix.dat] [--process-output] \\\n"
2626
" [--no-ppl] [--chunk 123] [--output-frequency 10] [--save-frequency 0] \\\n"
27-
" [--in-file imatrix-prev-0.dat --in-file imatrix-prev-1.dat ...]\n" , argv[0]);
27+
" [--in-file imatrix-prev-0.dat --in-file imatrix-prev-1.dat ...] \\\n"
28+
" [--parse-special]\n" , argv[0]);
2829
LOG("\n");
2930
}
3031

@@ -439,7 +440,7 @@ static bool compute_imatrix(llama_context * ctx, const common_params & params) {
439440
auto tim1 = std::chrono::high_resolution_clock::now();
440441
LOG_INF("%s: tokenizing the input ..\n", __func__);
441442

442-
std::vector<llama_token> tokens = common_tokenize(ctx, params.prompt, true);
443+
std::vector<llama_token> tokens = common_tokenize(ctx, params.prompt, true, params.parse_special);
443444

444445
auto tim2 = std::chrono::high_resolution_clock::now();
445446
LOG_INF("%s: tokenization took %g ms\n",__func__,1e-3*std::chrono::duration_cast<std::chrono::microseconds>(tim2-tim1).count());

0 commit comments

Comments
 (0)