Skip to content

Commit 679f513

Browse files
committed
move param parser to common
1 parent f54cb8e commit 679f513

File tree

4 files changed

+99
-190
lines changed

4 files changed

+99
-190
lines changed

common/common.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,7 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
15761576
return true;
15771577
}
15781578
params.out_file = argv[i];
1579+
params.cvector_outfile = argv[i];
15791580
return true;
15801581
}
15811582
if (arg == "-ofreq" || arg == "--output-frequency") {
@@ -1610,6 +1611,55 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
16101611
params.i_chunk = std::stoi(argv[i]);
16111612
return true;
16121613
}
1614+
// control-vector-generator params
1615+
if (arg == "--completions-file") {
1616+
if (++i >= argc) {
1617+
invalid_param = true;
1618+
return true;
1619+
}
1620+
params.cvector_completions_file = argv[i];
1621+
return true;
1622+
}
1623+
if (arg == "--positive-file") {
1624+
if (++i >= argc) {
1625+
invalid_param = true;
1626+
return true;
1627+
}
1628+
params.cvector_positive_file = argv[i];
1629+
return true;
1630+
}
1631+
if (arg == "--negative-file") {
1632+
if (++i >= argc) {
1633+
invalid_param = true;
1634+
return true;
1635+
}
1636+
params.cvector_negative_file = argv[i];
1637+
return true;
1638+
}
1639+
if (arg == "--num-completions") {
1640+
if (++i >= argc) {
1641+
invalid_param = true;
1642+
return true;
1643+
}
1644+
params.n_completions = std::stoi(argv[i]);
1645+
return true;
1646+
}
1647+
if (arg == "--pca-batch") {
1648+
if (++i >= argc) {
1649+
invalid_param = true;
1650+
return true;
1651+
}
1652+
params.n_pca_batch = std::stoi(argv[i]);
1653+
return true;
1654+
}
1655+
if (arg == "--pca-iter") {
1656+
if (++i >= argc) {
1657+
invalid_param = true;
1658+
return true;
1659+
}
1660+
params.n_pca_iterations = std::stoi(argv[i]);
1661+
return true;
1662+
}
16131663
#ifndef LOG_DISABLE_LOGS
16141664
// Parse args for logging parameters
16151665
if (log_param_single_parse(argv[i])) {
@@ -1931,6 +1981,15 @@ void gpt_params_print_usage(int /*argc*/, char ** argv, const gpt_params & param
19311981
options.push_back({ "logging", " --log-append", "Don't truncate the old log file." });
19321982
#endif // LOG_DISABLE_LOGS
19331983

1984+
options.push_back({ "control-vector-generator" });
1985+
options.push_back({ "control-vector-generator", "-o, --output FNAME", "output file (default: '%s')", params.cvector_outfile.c_str() });
1986+
options.push_back({ "control-vector-generator", "--positive-file FNAME", "positive prompts file, one prompt per line (default: '%s')", params.cvector_positive_file.c_str() });
1987+
options.push_back({ "control-vector-generator", "--negative-file FNAME", "negative prompts file, one prompt per line (default: '%s')", params.cvector_negative_file.c_str() });
1988+
options.push_back({ "control-vector-generator", "--completions-file", "completions file (default: '%s')", params.cvector_completions_file.c_str() });
1989+
options.push_back({ "control-vector-generator", "--num-completions N", "number of lines of completions file to use (default: %d)", params.n_completions });
1990+
options.push_back({ "control-vector-generator", "--batch-pca N", "batch size used for PCA. Larger batch runs faster, but uses more memory (default: %d)", params.n_pca_batch });
1991+
options.push_back({ "control-vector-generator", "--iter-pca N", "number of iterations used for PCA (default: %d)", params.n_pca_iterations });
1992+
19341993
printf("usage: %s [options]\n", argv[0]);
19351994

19361995
for (const auto & o : options) {

common/common.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ struct gpt_params {
232232

233233
bool process_output = false; // collect data for the output tensor
234234
bool compute_ppl = true; // whether to compute perplexity
235+
236+
// control-vector-generator params
237+
int n_completions = 64;
238+
int n_pca_batch = 20;
239+
int n_pca_iterations = 1000;
240+
std::string cvector_outfile = "control_vector.gguf";
241+
std::string cvector_completions_file = "examples/control-vector-generator/completions.txt";
242+
std::string cvector_positive_file = "examples/control-vector-generator/positive.txt";
243+
std::string cvector_negative_file = "examples/control-vector-generator/negative.txt";
235244
};
236245

237246
void gpt_params_handle_model_default(gpt_params & params);

examples/control-vector-generator/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This example demonstrates how to generate a control vector using gguf models.
55
Related PRs:
66
- [Add support for control vectors](https://github.com/ggerganov/llama.cpp/pull/5970)
77
- (Issue) [Generate control vector using llama.cpp](https://github.com/ggerganov/llama.cpp/issues/6880)
8-
- [Add control-vector-generator](https://github.com/ggerganov/llama.cpp/pull/7514)
8+
- [Add control-vector-generator example](https://github.com/ggerganov/llama.cpp/pull/7514)
99

1010
Example:
1111

@@ -14,13 +14,12 @@ Example:
1414
./control-vector-generator -m ./dolphin-2.0-mistral-7b.Q4_K_M.gguf
1515

1616
# With GPU
17-
./control-vector-generator --num-completions 2 --pca-iter 40 -m ./dolphin-2.0-mistral-7b.Q4_K_M.gguf -ngl 99
17+
./control-vector-generator -m ./dolphin-2.0-mistral-7b.Q4_K_M.gguf -ngl 99
1818

1919
# With advanced options
20-
# Please note that the ORDER of arguments does matter
21-
# example-related options (i.e., --num-completions, --pca-iter) always come before model options (i.e., -m, -ngl)
22-
./control-vector-generator --num-completions 128 --pca-iter 2000 --batch-pca 100 -m ./dolphin-2.0-mistral-7b.Q4_K_M.gguf -ngl 99
20+
./control-vector-generator -m ./dolphin-2.0-mistral-7b.Q4_K_M.gguf -ngl 99 --num-completions 128 --pca-iter 2000 --batch-pca 100
2321

2422
# To see help message
2523
./control-vector-generator -h
24+
# Then, have a look at "control-vector-generator" section
2625
```

0 commit comments

Comments
 (0)