add comments
This commit is contained in:
parent
79ce128d2a
commit
961bd19da1
2 changed files with 45 additions and 29 deletions
|
@ -456,6 +456,11 @@ bool gpt_params_parse_ex(int argc, char ** argv, gpt_params & params, std::vecto
|
||||||
params.kv_overrides.back().key[0] = 0;
|
params.kv_overrides.back().key[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params.seed == LLAMA_DEFAULT_SEED) {
|
||||||
|
params.seed = time(NULL);
|
||||||
|
sparams.seed = params.seed;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,7 +473,7 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params, std::vector<l
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (params.usage) {
|
if (params.usage) {
|
||||||
gpt_params_print_usage(options);
|
gpt_params_print_usage(params, options);
|
||||||
if (params.print_usage) {
|
if (params.print_usage) {
|
||||||
params.print_usage(argc, argv);
|
params.print_usage(argc, argv);
|
||||||
}
|
}
|
||||||
|
@ -612,7 +617,7 @@ std::string llama_arg::to_string() {
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpt_params_print_usage(std::vector<llama_arg> & options) {
|
void gpt_params_print_usage(gpt_params & params, std::vector<llama_arg> & options) {
|
||||||
auto print_options = [](std::vector<llama_arg *> & options) {
|
auto print_options = [](std::vector<llama_arg *> & options) {
|
||||||
for (llama_arg * opt : options) {
|
for (llama_arg * opt : options) {
|
||||||
printf("%s", opt->to_string().c_str());
|
printf("%s", opt->to_string().c_str());
|
||||||
|
@ -622,14 +627,16 @@ void gpt_params_print_usage(std::vector<llama_arg> & options) {
|
||||||
std::vector<llama_arg *> common_options;
|
std::vector<llama_arg *> common_options;
|
||||||
std::vector<llama_arg *> specific_options;
|
std::vector<llama_arg *> specific_options;
|
||||||
for (auto & opt : options) {
|
for (auto & opt : options) {
|
||||||
if (opt.in_example(LLAMA_EXAMPLE_COMMON)) {
|
// in case multiple LLAMA_EXAMPLE_* are set, we prioritize the LLAMA_EXAMPLE_* matching current example
|
||||||
common_options.push_back(&opt);
|
if (opt.in_example(params.curr_ex)) {
|
||||||
} else {
|
|
||||||
specific_options.push_back(&opt);
|
specific_options.push_back(&opt);
|
||||||
|
} else {
|
||||||
|
common_options.push_back(&opt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("----- common options -----\n\n");
|
printf("----- common options -----\n\n");
|
||||||
print_options(common_options);
|
print_options(common_options);
|
||||||
|
// TODO: maybe convert enum llama_example to string
|
||||||
printf("\n\n----- example-specific options -----\n\n");
|
printf("\n\n----- example-specific options -----\n\n");
|
||||||
print_options(specific_options);
|
print_options(specific_options);
|
||||||
}
|
}
|
||||||
|
@ -641,6 +648,7 @@ std::vector<llama_arg> gpt_params_parser_init(gpt_params & params, llama_example
|
||||||
std::vector<llama_arg> gpt_params_parser_init(gpt_params & params, llama_example ex, std::function<void(int, char **)> print_usage) {
|
std::vector<llama_arg> gpt_params_parser_init(gpt_params & params, llama_example ex, std::function<void(int, char **)> print_usage) {
|
||||||
std::vector<llama_arg> options;
|
std::vector<llama_arg> options;
|
||||||
params.print_usage = print_usage;
|
params.print_usage = print_usage;
|
||||||
|
params.curr_ex = ex;
|
||||||
llama_sampling_params & sparams = params.sparams;
|
llama_sampling_params & sparams = params.sparams;
|
||||||
|
|
||||||
std::string sampler_type_chars;
|
std::string sampler_type_chars;
|
||||||
|
@ -1772,14 +1780,14 @@ std::vector<llama_arg> gpt_params_parser_init(gpt_params & params, llama_example
|
||||||
[¶ms](std::string value) {
|
[¶ms](std::string value) {
|
||||||
params.lora_adapters.push_back({ std::string(value), 1.0 });
|
params.lora_adapters.push_back({ std::string(value), 1.0 });
|
||||||
}
|
}
|
||||||
));
|
).set_examples({LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_EXPORT_LORA}));
|
||||||
add_opt(llama_arg(
|
add_opt(llama_arg(
|
||||||
{"--lora-scaled"}, "FNAME", "SCALE",
|
{"--lora-scaled"}, "FNAME", "SCALE",
|
||||||
"path to LoRA adapter with user defined scaling (can be repeated to use multiple adapters)",
|
"path to LoRA adapter with user defined scaling (can be repeated to use multiple adapters)",
|
||||||
[¶ms](std::string fname, std::string scale) {
|
[¶ms](std::string fname, std::string scale) {
|
||||||
params.lora_adapters.push_back({ fname, std::stof(scale) });
|
params.lora_adapters.push_back({ fname, std::stof(scale) });
|
||||||
}
|
}
|
||||||
));
|
).set_examples({LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_EXPORT_LORA}));
|
||||||
add_opt(llama_arg(
|
add_opt(llama_arg(
|
||||||
{"--control-vector"}, "FNAME",
|
{"--control-vector"}, "FNAME",
|
||||||
"add a control vector\nnote: this argument can be repeated to add multiple control vectors",
|
"add a control vector\nnote: this argument can be repeated to add multiple control vectors",
|
||||||
|
|
|
@ -63,6 +63,24 @@ int32_t cpu_get_num_math();
|
||||||
// CLI argument parsing
|
// CLI argument parsing
|
||||||
//
|
//
|
||||||
|
|
||||||
|
enum llama_example {
|
||||||
|
LLAMA_EXAMPLE_COMMON,
|
||||||
|
LLAMA_EXAMPLE_SPECULATIVE,
|
||||||
|
LLAMA_EXAMPLE_MAIN,
|
||||||
|
LLAMA_EXAMPLE_INFILL,
|
||||||
|
LLAMA_EXAMPLE_EMBEDDING,
|
||||||
|
LLAMA_EXAMPLE_PERPLEXITY,
|
||||||
|
LLAMA_EXAMPLE_RETRIEVAL,
|
||||||
|
LLAMA_EXAMPLE_PASSKEY,
|
||||||
|
LLAMA_EXAMPLE_IMATRIX,
|
||||||
|
LLAMA_EXAMPLE_BENCH,
|
||||||
|
LLAMA_EXAMPLE_SERVER,
|
||||||
|
LLAMA_EXAMPLE_CVECTOR_GENERATOR,
|
||||||
|
LLAMA_EXAMPLE_EXPORT_LORA,
|
||||||
|
|
||||||
|
LLAMA_EXAMPLE_COUNT,
|
||||||
|
};
|
||||||
|
|
||||||
// dimensionality reduction methods, used by cvector-generator
|
// dimensionality reduction methods, used by cvector-generator
|
||||||
enum dimre_method {
|
enum dimre_method {
|
||||||
DIMRE_METHOD_PCA,
|
DIMRE_METHOD_PCA,
|
||||||
|
@ -79,6 +97,7 @@ struct cpu_params {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gpt_params {
|
struct gpt_params {
|
||||||
|
enum llama_example curr_ex = LLAMA_EXAMPLE_COMMON;
|
||||||
uint32_t seed = LLAMA_DEFAULT_SEED; // RNG seed
|
uint32_t seed = LLAMA_DEFAULT_SEED; // RNG seed
|
||||||
|
|
||||||
int32_t n_predict = -1; // new tokens to predict
|
int32_t n_predict = -1; // new tokens to predict
|
||||||
|
@ -125,7 +144,7 @@ struct gpt_params {
|
||||||
// // sampling parameters
|
// // sampling parameters
|
||||||
struct llama_sampling_params sparams;
|
struct llama_sampling_params sparams;
|
||||||
|
|
||||||
std::string model = "model.gguf"; // model path
|
std::string model = ""; // model path
|
||||||
std::string model_draft = ""; // draft model for speculative decoding
|
std::string model_draft = ""; // draft model for speculative decoding
|
||||||
std::string model_alias = "unknown"; // model alias
|
std::string model_alias = "unknown"; // model alias
|
||||||
std::string model_url = ""; // model url to download
|
std::string model_url = ""; // model url to download
|
||||||
|
@ -280,24 +299,6 @@ struct gpt_params {
|
||||||
std::string lora_outfile = "ggml-lora-merged-f16.gguf";
|
std::string lora_outfile = "ggml-lora-merged-f16.gguf";
|
||||||
};
|
};
|
||||||
|
|
||||||
enum llama_example {
|
|
||||||
LLAMA_EXAMPLE_COMMON,
|
|
||||||
LLAMA_EXAMPLE_SPECULATIVE,
|
|
||||||
LLAMA_EXAMPLE_MAIN,
|
|
||||||
LLAMA_EXAMPLE_INFILL,
|
|
||||||
LLAMA_EXAMPLE_EMBEDDING,
|
|
||||||
LLAMA_EXAMPLE_PERPLEXITY,
|
|
||||||
LLAMA_EXAMPLE_RETRIEVAL,
|
|
||||||
LLAMA_EXAMPLE_PASSKEY,
|
|
||||||
LLAMA_EXAMPLE_IMATRIX,
|
|
||||||
LLAMA_EXAMPLE_BENCH,
|
|
||||||
LLAMA_EXAMPLE_SERVER,
|
|
||||||
LLAMA_EXAMPLE_CVECTOR_GENERATOR,
|
|
||||||
LLAMA_EXAMPLE_EXPORT_LORA,
|
|
||||||
|
|
||||||
LLAMA_EXAMPLE_COUNT,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct llama_arg {
|
struct llama_arg {
|
||||||
std::set<enum llama_example> examples = {LLAMA_EXAMPLE_COMMON};
|
std::set<enum llama_example> examples = {LLAMA_EXAMPLE_COMMON};
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
|
@ -352,11 +353,18 @@ struct llama_arg {
|
||||||
std::string to_string();
|
std::string to_string();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// initialize list of options (arguments) that can be used by the current example
|
||||||
std::vector<llama_arg> gpt_params_parser_init(gpt_params & params, llama_example ex);
|
std::vector<llama_arg> gpt_params_parser_init(gpt_params & params, llama_example ex);
|
||||||
|
// optionally, we can provide "print_usage" to print example usage
|
||||||
std::vector<llama_arg> gpt_params_parser_init(gpt_params & params, llama_example ex, std::function<void(int, char **)> print_usage);
|
std::vector<llama_arg> gpt_params_parser_init(gpt_params & params, llama_example ex, std::function<void(int, char **)> print_usage);
|
||||||
bool gpt_params_parse (int argc, char ** argv, gpt_params & params, std::vector<llama_arg> & options);
|
|
||||||
bool gpt_params_parse_ex (int argc, char ** argv, gpt_params & params, std::vector<llama_arg> & options);
|
// parse input arguments from CLI
|
||||||
void gpt_params_print_usage(std::vector<llama_arg> & options);
|
// if one argument has invalid value, it will automatically display usage of the specific argument (and not the full usage message)
|
||||||
|
bool gpt_params_parse (int argc, char ** argv, gpt_params & params, std::vector<llama_arg> & options);
|
||||||
|
bool gpt_params_parse_ex(int argc, char ** argv, gpt_params & params, std::vector<llama_arg> & options);
|
||||||
|
|
||||||
|
// print full usage message; it will be called internally by gpt_params_parse() if "-h" is set
|
||||||
|
void gpt_params_print_usage(gpt_params & params, std::vector<llama_arg> & options);
|
||||||
|
|
||||||
void gpt_params_handle_model_default(gpt_params & params);
|
void gpt_params_handle_model_default(gpt_params & params);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue