Skip to content

Add ctime include and single prompt option #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: xsn/control-vector-generator
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions common/common.cpp
Original file line number Diff line number Diff line change
@@ -1636,6 +1636,10 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
params.cvector_negative_file = argv[i];
return true;
}
if (arg == "--single-prompt") {
params.single_prompt = true;
return true;
}
if (arg == "--completions") {
if (++i >= argc) {
invalid_param = true;
@@ -1985,6 +1989,7 @@ void gpt_params_print_usage(int /*argc*/, char ** argv, const gpt_params & param
options.push_back({ "cvector", "-o, --output FNAME", "output file (default: '%s')", params.cvector_outfile.c_str() });
options.push_back({ "cvector", "--positive-file FNAME", "positive prompts file, one prompt per line (default: '%s')", params.cvector_positive_file.c_str() });
options.push_back({ "cvector", "--negative-file FNAME", "negative prompts file, one prompt per line (default: '%s')", params.cvector_negative_file.c_str() });
options.push_back({ "cvector", "--single-prompt", "assume prompt files only contain one prompt (for multiline prompts)" });
options.push_back({ "cvector", "--completions-file FNAME","completions file (default: '%s')", params.cvector_completions_file.c_str() });
options.push_back({ "cvector", "--completions N", "number of lines of completions file to use (default: %d)", params.n_completions });
options.push_back({ "cvector", "--batch-pca N", "batch size used for PCA. Larger batch runs faster, but uses more memory (default: %d)", params.n_pca_batch });
1 change: 1 addition & 0 deletions common/common.h
Original file line number Diff line number Diff line change
@@ -241,6 +241,7 @@ struct gpt_params {
std::string cvector_completions_file = "examples/control-vector-generator/completions.txt";
std::string cvector_positive_file = "examples/control-vector-generator/positive.txt";
std::string cvector_negative_file = "examples/control-vector-generator/negative.txt";
bool single_prompt = false;
};

void gpt_params_handle_model_default(gpt_params & params);
14 changes: 11 additions & 3 deletions examples/control-vector-generator/control-vector-generator.cpp
Original file line number Diff line number Diff line change
@@ -289,7 +289,7 @@ static std::string to_string(const T & val) {
return ss.str();
}

static std::vector<std::string> ctrlvec_load_prompt_file(std::string path, bool skip_empty_lines = false) {
static std::vector<std::string> ctrlvec_load_prompt_file(std::string path, bool skip_empty_lines = false, bool single_prompt = false) {
std::vector<std::string> output;
std::ifstream file(path);
if (!file.is_open()) {
@@ -304,6 +304,14 @@ static std::vector<std::string> ctrlvec_load_prompt_file(std::string path, bool
}
}
file.close();
if (single_prompt) {
std::string single_prompt;
for (const auto & line : output) {
single_prompt += line + "\n";
}
output.clear();
output.push_back(single_prompt);
}
return output;
}

@@ -362,8 +370,8 @@ static void export_gguf(const std::vector<struct ggml_tensor *> & v_ctrl, const
*/
static int prepare_entries(gpt_params & params, train_context & ctx_train) {
// load prompts
std::vector<std::string> positive_prompts = ctrlvec_load_prompt_file(params.cvector_positive_file);
std::vector<std::string> negative_prompts = ctrlvec_load_prompt_file(params.cvector_negative_file);
std::vector<std::string> positive_prompts = ctrlvec_load_prompt_file(params.cvector_positive_file, false, params.single_prompt);
std::vector<std::string> negative_prompts = ctrlvec_load_prompt_file(params.cvector_negative_file, false, params.single_prompt);
if (positive_prompts.size() != negative_prompts.size()) {
fprintf(stderr, "number of positive and negative prompts must be equal\n");
return 1;
1 change: 1 addition & 0 deletions examples/control-vector-generator/pca.hpp
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
#endif

#include <cstdio>
#include <ctime>
#include <string>
#include <tuple>
#include <vector>