|
|
|
|
|
#pragma once |
|
|
|
#include "libfalcon.h" |
|
|
|
#include <string> |
|
#include <vector> |
|
#include <random> |
|
#include <thread> |
|
#include <unordered_map> |
|
|
|
#if !defined (_WIN32) |
|
#include <stdio.h> |
|
#include <termios.h> |
|
#endif |
|
|
|
|
|
|
|
|
|
int32_t get_num_physical_cores(); |
|
|
|
struct gpt_params { |
|
int32_t seed = -1; |
|
int32_t n_threads = get_num_physical_cores(); |
|
int32_t n_predict = -1; |
|
int32_t n_ctx = 512; |
|
int32_t n_batch = 512; |
|
int32_t n_keep = 0; |
|
int32_t n_gpu_layers = 0; |
|
int32_t main_gpu = 0; |
|
float tensor_split[LLAMA_MAX_DEVICES] = {0}; |
|
|
|
|
|
std::unordered_map<llama_token, float> logit_bias; |
|
int32_t top_k = 40; |
|
float top_p = 0.95f; |
|
float tfs_z = 1.00f; |
|
float typical_p = 1.00f; |
|
float temp = 0.80f; |
|
float repeat_penalty = 1.10f; |
|
int32_t repeat_last_n = 64; |
|
float frequency_penalty = 0.00f; |
|
float presence_penalty = 0.00f; |
|
int mirostat = 0; |
|
float mirostat_tau = 5.00f; |
|
float mirostat_eta = 0.10f; |
|
|
|
std::string model = "models/7B/ggml-model.bin"; |
|
std::string model_alias = "unknown"; |
|
std::string prompt = ""; |
|
std::string path_prompt_cache = ""; |
|
std::string input_prefix = ""; |
|
std::string input_suffix = ""; |
|
std::vector<std::string> antiprompt; |
|
|
|
std::string lora_adapter = ""; |
|
std::string lora_base = ""; |
|
|
|
bool memory_f16 = true; |
|
bool random_prompt = false; |
|
bool use_color = false; |
|
bool interactive = false; |
|
bool prompt_cache_all = false; |
|
bool prompt_cache_ro = false; |
|
|
|
bool embedding = false; |
|
bool interactive_first = false; |
|
bool multiline_input = false; |
|
|
|
bool instruct = false; |
|
bool penalize_nl = true; |
|
bool perplexity = false; |
|
bool use_mmap = true; |
|
bool use_mlock = false; |
|
bool mem_test = false; |
|
bool export_cgraph = false; |
|
bool verbose_prompt = false; |
|
int debug_timings = 0; |
|
}; |
|
|
|
bool gpt_params_parse(int argc, char ** argv, gpt_params & params); |
|
|
|
void gpt_print_usage(int argc, char ** argv, const gpt_params & params); |
|
|
|
std::string gpt_random_prompt(std::mt19937 & rng); |
|
|
|
|
|
|
|
|
|
|
|
std::vector<llama_token> falcon_tokenize(struct falcon_context * ctx, const std::string & text, bool add_bos); |
|
|
|
|
|
|
|
|
|
|
|
struct falcon_context * falcon_init_from_gpt_params(const gpt_params & params); |
|
|
|
|
|
|
|
|
|
|
|
#define ANSI_COLOR_RED "\x1b[31m" |
|
#define ANSI_COLOR_GREEN "\x1b[32m" |
|
#define ANSI_COLOR_YELLOW "\x1b[33m" |
|
#define ANSI_COLOR_BLUE "\x1b[34m" |
|
#define ANSI_COLOR_MAGENTA "\x1b[35m" |
|
#define ANSI_COLOR_CYAN "\x1b[36m" |
|
#define ANSI_COLOR_RESET "\x1b[0m" |
|
#define ANSI_BOLD "\x1b[1m" |
|
|
|
enum console_color_t { |
|
CONSOLE_COLOR_DEFAULT=0, |
|
CONSOLE_COLOR_PROMPT, |
|
CONSOLE_COLOR_USER_INPUT, |
|
CONSOLE_COLOR_ERROR |
|
}; |
|
|
|
struct console_state { |
|
bool multiline_input = false; |
|
bool use_color = false; |
|
console_color_t color = CONSOLE_COLOR_DEFAULT; |
|
|
|
FILE* out = stdout; |
|
#if defined (_WIN32) |
|
void* hConsole; |
|
#else |
|
FILE* tty = nullptr; |
|
termios prev_state; |
|
#endif |
|
}; |
|
|
|
void console_init(console_state & con_st); |
|
void console_cleanup(console_state & con_st); |
|
void console_set_color(console_state & con_st, console_color_t color); |
|
bool console_readline(console_state & con_st, std::string & line); |
|
|