|
#ifndef FALCON_H |
|
#define FALCON_H |
|
|
|
#include "ggml.h" |
|
#ifdef GGML_USE_CUBLAS |
|
#include "ggml-cuda.h" |
|
#define LLAMA_MAX_DEVICES GGML_CUDA_MAX_DEVICES |
|
#else |
|
#define LLAMA_MAX_DEVICES 1 |
|
#endif |
|
#include <stddef.h> |
|
#include <stdint.h> |
|
#include <stdbool.h> |
|
|
|
#ifdef LLAMA_SHARED |
|
# if defined(_WIN32) && !defined(__MINGW32__) |
|
# ifdef LLAMA_BUILD |
|
# define LLAMA_API __declspec(dllexport) |
|
# else |
|
# define LLAMA_API __declspec(dllimport) |
|
# endif |
|
# else |
|
# define LLAMA_API __attribute__ ((visibility ("default"))) |
|
# endif |
|
#else |
|
# define LLAMA_API |
|
#endif |
|
|
|
#define LLAMA_FILE_MAGIC_GGJT 0x67676a74u |
|
#define LLAMA_FILE_MAGIC_GGLA 0x67676c61u |
|
#define LLAMA_FILE_MAGIC_GGMF 0x67676d66u |
|
#define LLAMA_FILE_MAGIC_GGML 0x67676d6cu |
|
#define LLAMA_FILE_MAGIC_GGSN 0x6767736eu |
|
|
|
#define LLAMA_FILE_VERSION 3 |
|
#define LLAMA_FILE_MAGIC LLAMA_FILE_MAGIC_GGJT |
|
#define LLAMA_FILE_MAGIC_UNVERSIONED LLAMA_FILE_MAGIC_GGML |
|
#define LLAMA_SESSION_MAGIC LLAMA_FILE_MAGIC_GGSN |
|
#define LLAMA_SESSION_VERSION 1 |
|
|
|
#if defined(GGML_USE_CUBLAS) || defined(GGML_USE_CLBLAST) || defined(GGML_USE_METAL) |
|
|
|
#define LLAMA_SUPPORTS_GPU_OFFLOAD |
|
#endif |
|
|
|
#ifdef __cplusplus |
|
extern "C" { |
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct falcon_context; |
|
|
|
typedef int llama_token; |
|
|
|
typedef struct llama_token_data { |
|
llama_token id; |
|
float logit; |
|
float p; |
|
} llama_token_data; |
|
|
|
typedef struct llama_token_data_array { |
|
llama_token_data * data; |
|
size_t size; |
|
bool sorted; |
|
} llama_token_data_array; |
|
|
|
typedef void (*llama_progress_callback)(float progress, void *ctx); |
|
|
|
struct falcon_context_params { |
|
int n_ctx; |
|
int n_batch; |
|
int n_gpu_layers; |
|
int i_gpu_start; |
|
int i_gpu_last; |
|
int main_gpu; |
|
float tensor_split[LLAMA_MAX_DEVICES]; |
|
int seed; |
|
|
|
bool f16_kv; |
|
bool logits_all; |
|
bool vocab_only; |
|
bool use_mmap; |
|
bool use_mlock; |
|
bool embedding; |
|
|
|
|
|
llama_progress_callback progress_callback; |
|
|
|
void * progress_callback_user_data; |
|
}; |
|
|
|
|
|
enum llama_ftype { |
|
LLAMA_FTYPE_ALL_F32 = 0, |
|
LLAMA_FTYPE_MOSTLY_F16 = 1, |
|
LLAMA_FTYPE_MOSTLY_Q4_0 = 2, |
|
LLAMA_FTYPE_MOSTLY_Q4_1 = 3, |
|
LLAMA_FTYPE_MOSTLY_Q4_1_SOME_F16 = 4, |
|
|
|
|
|
LLAMA_FTYPE_MOSTLY_Q8_0 = 7, |
|
LLAMA_FTYPE_MOSTLY_Q5_0 = 8, |
|
LLAMA_FTYPE_MOSTLY_Q5_1 = 9, |
|
LLAMA_FTYPE_MOSTLY_Q2_K = 10, |
|
LLAMA_FTYPE_MOSTLY_Q3_K_S = 11, |
|
LLAMA_FTYPE_MOSTLY_Q3_K_M = 12, |
|
LLAMA_FTYPE_MOSTLY_Q3_K_L = 13, |
|
LLAMA_FTYPE_MOSTLY_Q4_K_S = 14, |
|
LLAMA_FTYPE_MOSTLY_Q4_K_M = 15, |
|
LLAMA_FTYPE_MOSTLY_Q5_K_S = 16, |
|
LLAMA_FTYPE_MOSTLY_Q5_K_M = 17, |
|
LLAMA_FTYPE_MOSTLY_Q6_K = 18, |
|
}; |
|
|
|
|
|
typedef struct llama_model_quantize_params { |
|
int nthread; |
|
enum llama_ftype ftype; |
|
bool allow_requantize; |
|
bool quantize_output_tensor; |
|
} llama_model_quantize_params; |
|
|
|
LLAMA_API struct falcon_context_params falcon_context_default_params(); |
|
LLAMA_API struct llama_model_quantize_params llama_model_quantize_default_params(); |
|
|
|
LLAMA_API bool llama_mmap_supported(); |
|
LLAMA_API bool llama_mlock_supported(); |
|
|
|
|
|
|
|
|
|
LLAMA_API void llama_init_backend(); |
|
|
|
LLAMA_API int64_t llama_time_us(); |
|
|
|
|
|
|
|
|
|
LLAMA_API struct falcon_context * falcon_init_from_file( |
|
const char * path_model, |
|
struct falcon_context_params params); |
|
|
|
|
|
LLAMA_API void llama_free(struct falcon_context * ctx); |
|
|
|
|
|
LLAMA_API int falcon_model_quantize( |
|
const char * fname_inp, |
|
const char * fname_out, |
|
const llama_model_quantize_params * params); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LLAMA_API int llama_apply_lora_from_file( |
|
struct falcon_context * ctx, |
|
const char * path_lora, |
|
const char * path_base_model, |
|
int n_threads); |
|
|
|
|
|
LLAMA_API int llama_get_kv_cache_token_count(const struct falcon_context * ctx); |
|
|
|
|
|
LLAMA_API void llama_set_rng_seed(struct falcon_context * ctx, int seed); |
|
|
|
|
|
|
|
LLAMA_API size_t llama_get_state_size(const struct falcon_context * ctx); |
|
|
|
|
|
|
|
|
|
LLAMA_API size_t llama_copy_state_data(struct falcon_context * ctx, uint8_t * dst); |
|
|
|
|
|
|
|
LLAMA_API size_t llama_set_state_data(struct falcon_context * ctx, uint8_t * src); |
|
|
|
|
|
LLAMA_API bool llama_load_session_file(struct falcon_context * ctx, const char * path_session, llama_token * tokens_out, size_t n_token_capacity, size_t * n_token_count_out); |
|
LLAMA_API bool llama_save_session_file(struct falcon_context * ctx, const char * path_session, const llama_token * tokens, size_t n_token_count); |
|
|
|
|
|
|
|
|
|
|
|
LLAMA_API int falcon_eval( |
|
struct falcon_context * ctx, |
|
const llama_token * tokens, |
|
int n_tokens, |
|
int n_past, |
|
int n_threads, |
|
int debug_timings); |
|
|
|
|
|
|
|
|
|
|
|
LLAMA_API int falcon_eval_export(struct falcon_context * ctx, const char * fname); |
|
|
|
|
|
|
|
|
|
|
|
|
|
LLAMA_API int falcon_tokenize( |
|
struct falcon_context * ctx, |
|
const char * text, |
|
llama_token * tokens, |
|
int n_max_tokens, |
|
bool add_bos); |
|
|
|
LLAMA_API int falcon_n_vocab(const struct falcon_context * ctx); |
|
LLAMA_API int falcon_n_ctx (const struct falcon_context * ctx); |
|
LLAMA_API int falcon_n_embd (const struct falcon_context * ctx); |
|
|
|
|
|
|
|
LLAMA_API int falcon_get_vocab( |
|
const struct falcon_context * ctx, |
|
const char * * strings, |
|
float * scores, |
|
int capacity); |
|
|
|
|
|
|
|
|
|
|
|
|
|
LLAMA_API float * falcon_get_logits(struct falcon_context * ctx); |
|
|
|
|
|
|
|
LLAMA_API float * falcon_get_embeddings(struct falcon_context * ctx); |
|
|
|
|
|
LLAMA_API const char * falcon_token_to_str(const struct falcon_context * ctx, llama_token token); |
|
|
|
|
|
LLAMA_API llama_token falcon_token_bos(); |
|
LLAMA_API llama_token falcon_token_eos(); |
|
LLAMA_API llama_token falcon_token_nl(); |
|
|
|
|
|
|
|
|
|
LLAMA_API void llama_sample_repetition_penalty(struct falcon_context * ctx, llama_token_data_array * candidates, const llama_token * last_tokens, size_t last_tokens_size, float penalty); |
|
|
|
|
|
LLAMA_API void llama_sample_frequency_and_presence_penalties(struct falcon_context * ctx, llama_token_data_array * candidates, const llama_token * last_tokens, size_t last_tokens_size, float alpha_frequency, float alpha_presence); |
|
|
|
|
|
LLAMA_API void llama_sample_softmax(struct falcon_context * ctx, llama_token_data_array * candidates); |
|
|
|
|
|
LLAMA_API void llama_sample_top_k(struct falcon_context * ctx, llama_token_data_array * candidates, int k, size_t min_keep); |
|
|
|
|
|
LLAMA_API void llama_sample_top_p(struct falcon_context * ctx, llama_token_data_array * candidates, float p, size_t min_keep); |
|
|
|
|
|
LLAMA_API void llama_sample_tail_free(struct falcon_context * ctx, llama_token_data_array * candidates, float z, size_t min_keep); |
|
|
|
|
|
LLAMA_API void llama_sample_typical(struct falcon_context * ctx, llama_token_data_array * candidates, float p, size_t min_keep); |
|
LLAMA_API void llama_sample_temperature(struct falcon_context * ctx, llama_token_data_array * candidates, float temp); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LLAMA_API llama_token llama_sample_token_mirostat(struct falcon_context * ctx, llama_token_data_array * candidates, float tau, float eta, int m, float * mu); |
|
|
|
|
|
|
|
|
|
|
|
|
|
LLAMA_API llama_token llama_sample_token_mirostat_v2(struct falcon_context * ctx, llama_token_data_array * candidates, float tau, float eta, float * mu); |
|
|
|
|
|
LLAMA_API llama_token llama_sample_token_greedy(struct falcon_context * ctx, llama_token_data_array * candidates); |
|
|
|
|
|
LLAMA_API llama_token llama_sample_token(struct falcon_context * ctx, llama_token_data_array * candidates); |
|
|
|
|
|
LLAMA_API void falcon_print_timings(struct falcon_context * ctx); |
|
LLAMA_API void llama_reset_timings(struct falcon_context * ctx); |
|
|
|
|
|
LLAMA_API const char * falcon_print_system_info(void); |
|
|
|
#ifdef __cplusplus |
|
} |
|
#endif |
|
|
|
|
|
#ifdef LLAMA_API_INTERNAL |
|
|
|
#include <vector> |
|
#include <string> |
|
struct ggml_tensor; |
|
|
|
std::vector<std::pair<std::string, struct ggml_tensor *>>& llama_internal_get_tensor_map(struct falcon_context * ctx); |
|
|
|
#endif |
|
|
|
#endif |
|
|