rename llama_arg
This commit is contained in:
parent
4f7e4b5e19
commit
e58d3b1214
3 changed files with 226 additions and 226 deletions
424
common/arg.cpp
424
common/arg.cpp
File diff suppressed because it is too large
Load diff
18
common/arg.h
18
common/arg.h
|
@ -10,7 +10,7 @@
|
||||||
// CLI argument parsing
|
// CLI argument parsing
|
||||||
//
|
//
|
||||||
|
|
||||||
struct llama_arg {
|
struct common_arg {
|
||||||
std::set<enum llama_example> examples = {LLAMA_EXAMPLE_COMMON};
|
std::set<enum llama_example> examples = {LLAMA_EXAMPLE_COMMON};
|
||||||
std::vector<const char *> args;
|
std::vector<const char *> args;
|
||||||
const char * value_hint = nullptr; // help text or example for arg value
|
const char * value_hint = nullptr; // help text or example for arg value
|
||||||
|
@ -23,28 +23,28 @@ struct llama_arg {
|
||||||
void (*handler_str_str)(gpt_params & params, const std::string &, const std::string &) = nullptr;
|
void (*handler_str_str)(gpt_params & params, const std::string &, const std::string &) = nullptr;
|
||||||
void (*handler_int) (gpt_params & params, int) = nullptr;
|
void (*handler_int) (gpt_params & params, int) = nullptr;
|
||||||
|
|
||||||
llama_arg(
|
common_arg(
|
||||||
const std::initializer_list<const char *> & args,
|
const std::initializer_list<const char *> & args,
|
||||||
const char * value_hint,
|
const char * value_hint,
|
||||||
const std::string & help,
|
const std::string & help,
|
||||||
void (*handler)(gpt_params & params, const std::string &)
|
void (*handler)(gpt_params & params, const std::string &)
|
||||||
) : args(args), value_hint(value_hint), help(help), handler_string(handler) {}
|
) : args(args), value_hint(value_hint), help(help), handler_string(handler) {}
|
||||||
|
|
||||||
llama_arg(
|
common_arg(
|
||||||
const std::initializer_list<const char *> & args,
|
const std::initializer_list<const char *> & args,
|
||||||
const char * value_hint,
|
const char * value_hint,
|
||||||
const std::string & help,
|
const std::string & help,
|
||||||
void (*handler)(gpt_params & params, int)
|
void (*handler)(gpt_params & params, int)
|
||||||
) : args(args), value_hint(value_hint), help(help), handler_int(handler) {}
|
) : args(args), value_hint(value_hint), help(help), handler_int(handler) {}
|
||||||
|
|
||||||
llama_arg(
|
common_arg(
|
||||||
const std::initializer_list<const char *> & args,
|
const std::initializer_list<const char *> & args,
|
||||||
const std::string & help,
|
const std::string & help,
|
||||||
void (*handler)(gpt_params & params)
|
void (*handler)(gpt_params & params)
|
||||||
) : args(args), help(help), handler_void(handler) {}
|
) : args(args), help(help), handler_void(handler) {}
|
||||||
|
|
||||||
// support 2 values for arg
|
// support 2 values for arg
|
||||||
llama_arg(
|
common_arg(
|
||||||
const std::initializer_list<const char *> & args,
|
const std::initializer_list<const char *> & args,
|
||||||
const char * value_hint,
|
const char * value_hint,
|
||||||
const char * value_hint_2,
|
const char * value_hint_2,
|
||||||
|
@ -52,9 +52,9 @@ struct llama_arg {
|
||||||
void (*handler)(gpt_params & params, const std::string &, const std::string &)
|
void (*handler)(gpt_params & params, const std::string &, const std::string &)
|
||||||
) : args(args), value_hint(value_hint), value_hint_2(value_hint_2), help(help), handler_str_str(handler) {}
|
) : args(args), value_hint(value_hint), value_hint_2(value_hint_2), help(help), handler_str_str(handler) {}
|
||||||
|
|
||||||
llama_arg & set_examples(std::initializer_list<enum llama_example> examples);
|
common_arg & set_examples(std::initializer_list<enum llama_example> examples);
|
||||||
llama_arg & set_env(const char * env);
|
common_arg & set_env(const char * env);
|
||||||
llama_arg & set_sparam();
|
common_arg & set_sparam();
|
||||||
bool in_example(enum llama_example ex);
|
bool in_example(enum llama_example ex);
|
||||||
bool get_value_from_env(std::string & output);
|
bool get_value_from_env(std::string & output);
|
||||||
bool has_value_from_env();
|
bool has_value_from_env();
|
||||||
|
@ -64,7 +64,7 @@ struct llama_arg {
|
||||||
struct gpt_params_context {
|
struct gpt_params_context {
|
||||||
enum llama_example ex = LLAMA_EXAMPLE_COMMON;
|
enum llama_example ex = LLAMA_EXAMPLE_COMMON;
|
||||||
gpt_params & params;
|
gpt_params & params;
|
||||||
std::vector<llama_arg> options;
|
std::vector<common_arg> options;
|
||||||
void(*print_usage)(int, char **) = nullptr;
|
void(*print_usage)(int, char **) = nullptr;
|
||||||
gpt_params_context(gpt_params & params) : params(params) {}
|
gpt_params_context(gpt_params & params) : params(params) {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,7 @@ static void write_table_header(std::ofstream & file) {
|
||||||
file << "| -------- | ----------- |\n";
|
file << "| -------- | ----------- |\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_table_entry(std::ofstream & file, const llama_arg & opt) {
|
static void write_table_entry(std::ofstream & file, const common_arg & opt) {
|
||||||
file << "| `";
|
file << "| `";
|
||||||
// args
|
// args
|
||||||
for (const auto & arg : opt.args) {
|
for (const auto & arg : opt.args) {
|
||||||
|
@ -40,7 +40,7 @@ static void write_table_entry(std::ofstream & file, const llama_arg & opt) {
|
||||||
file << "` | " << md_help << " |\n";
|
file << "` | " << md_help << " |\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_table(std::ofstream & file, std::vector<llama_arg *> & opts) {
|
static void write_table(std::ofstream & file, std::vector<common_arg *> & opts) {
|
||||||
write_table_header(file);
|
write_table_header(file);
|
||||||
for (const auto & opt : opts) {
|
for (const auto & opt : opts) {
|
||||||
write_table_entry(file, *opt);
|
write_table_entry(file, *opt);
|
||||||
|
@ -53,9 +53,9 @@ static void export_md(std::string fname, llama_example ex) {
|
||||||
gpt_params params;
|
gpt_params params;
|
||||||
auto ctx_arg = gpt_params_parser_init(params, ex);
|
auto ctx_arg = gpt_params_parser_init(params, ex);
|
||||||
|
|
||||||
std::vector<llama_arg *> common_options;
|
std::vector<common_arg *> common_options;
|
||||||
std::vector<llama_arg *> sparam_options;
|
std::vector<common_arg *> sparam_options;
|
||||||
std::vector<llama_arg *> specific_options;
|
std::vector<common_arg *> specific_options;
|
||||||
for (auto & opt : ctx_arg.options) {
|
for (auto & opt : ctx_arg.options) {
|
||||||
// in case multiple LLAMA_EXAMPLE_* are set, we prioritize the LLAMA_EXAMPLE_* matching current example
|
// in case multiple LLAMA_EXAMPLE_* are set, we prioritize the LLAMA_EXAMPLE_* matching current example
|
||||||
if (opt.is_sparam) {
|
if (opt.is_sparam) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue