mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2024-12-27 03:44:35 +00:00
7eee341bee
Some checks are pending
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/full-cuda.Dockerfile platforms:linux/amd64 tag:full-cuda]) (push) Waiting to run
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/full-musa.Dockerfile platforms:linux/amd64 tag:full-musa]) (push) Waiting to run
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/full.Dockerfile platforms:linux/amd64,linux/arm64 tag:full]) (push) Waiting to run
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/llama-cli-cuda.Dockerfile platforms:linux/amd64 tag:light-cuda]) (push) Waiting to run
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/llama-cli-intel.Dockerfile platforms:linux/amd64 tag:light-intel]) (push) Waiting to run
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/llama-cli-musa.Dockerfile platforms:linux/amd64 tag:light-musa]) (push) Waiting to run
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/llama-cli.Dockerfile platforms:linux/amd64,linux/arm64 tag:light]) (push) Waiting to run
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/llama-server-cuda.Dockerfile platforms:linux/amd64 tag:server-cuda]) (push) Waiting to run
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/llama-server-intel.Dockerfile platforms:linux/amd64 tag:server-intel]) (push) Waiting to run
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/llama-server-musa.Dockerfile platforms:linux/amd64 tag:server-musa]) (push) Waiting to run
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/llama-server.Dockerfile platforms:linux/amd64,linux/arm64 tag:server]) (push) Waiting to run
Nix CI / nix-eval (macos-latest) (push) Waiting to run
Nix CI / nix-eval (ubuntu-latest) (push) Waiting to run
Nix CI / nix-build (macos-latest) (push) Waiting to run
Nix CI / nix-build (ubuntu-latest) (push) Waiting to run
flake8 Lint / Lint (push) Waiting to run
* common : use common_ prefix for common library functions --------- Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
78 lines
3.0 KiB
C++
78 lines
3.0 KiB
C++
#pragma once
|
|
|
|
#include "common.h"
|
|
|
|
#include <set>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
//
|
|
// CLI argument parsing
|
|
//
|
|
|
|
struct common_arg {
|
|
std::set<enum llama_example> examples = {LLAMA_EXAMPLE_COMMON};
|
|
std::vector<const char *> args;
|
|
const char * value_hint = nullptr; // help text or example for arg value
|
|
const char * value_hint_2 = nullptr; // for second arg value
|
|
const char * env = nullptr;
|
|
std::string help;
|
|
bool is_sparam = false; // is current arg a sampling param?
|
|
void (*handler_void) (common_params & params) = nullptr;
|
|
void (*handler_string) (common_params & params, const std::string &) = nullptr;
|
|
void (*handler_str_str)(common_params & params, const std::string &, const std::string &) = nullptr;
|
|
void (*handler_int) (common_params & params, int) = nullptr;
|
|
|
|
common_arg(
|
|
const std::initializer_list<const char *> & args,
|
|
const char * value_hint,
|
|
const std::string & help,
|
|
void (*handler)(common_params & params, const std::string &)
|
|
) : args(args), value_hint(value_hint), help(help), handler_string(handler) {}
|
|
|
|
common_arg(
|
|
const std::initializer_list<const char *> & args,
|
|
const char * value_hint,
|
|
const std::string & help,
|
|
void (*handler)(common_params & params, int)
|
|
) : args(args), value_hint(value_hint), help(help), handler_int(handler) {}
|
|
|
|
common_arg(
|
|
const std::initializer_list<const char *> & args,
|
|
const std::string & help,
|
|
void (*handler)(common_params & params)
|
|
) : args(args), help(help), handler_void(handler) {}
|
|
|
|
// support 2 values for arg
|
|
common_arg(
|
|
const std::initializer_list<const char *> & args,
|
|
const char * value_hint,
|
|
const char * value_hint_2,
|
|
const std::string & help,
|
|
void (*handler)(common_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) {}
|
|
|
|
common_arg & set_examples(std::initializer_list<enum llama_example> examples);
|
|
common_arg & set_env(const char * env);
|
|
common_arg & set_sparam();
|
|
bool in_example(enum llama_example ex);
|
|
bool get_value_from_env(std::string & output);
|
|
bool has_value_from_env();
|
|
std::string to_string();
|
|
};
|
|
|
|
struct common_params_context {
|
|
enum llama_example ex = LLAMA_EXAMPLE_COMMON;
|
|
common_params & params;
|
|
std::vector<common_arg> options;
|
|
void(*print_usage)(int, char **) = nullptr;
|
|
common_params_context(common_params & params) : params(params) {}
|
|
};
|
|
|
|
// parse input arguments from CLI
|
|
// if one argument has invalid value, it will automatically display usage of the specific argument (and not the full usage message)
|
|
bool common_params_parse(int argc, char ** argv, common_params & params, llama_example ex, void(*print_usage)(int, char **) = nullptr);
|
|
|
|
// function to be used by test-arg-parser
|
|
common_params_context common_params_parser_init(common_params & params, llama_example ex, void(*print_usage)(int, char **) = nullptr);
|