#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
enum llama_model_kv_override_type {
LLAMA_KV_OVERRIDE_TYPE_INT,
LLAMA_KV_OVERRIDE_TYPE_FLOAT,
LLAMA_KV_OVERRIDE_TYPE_BOOL,
LLAMA_KV_OVERRIDE_TYPE_STR,
};
struct llama_model_kv_override {
enum llama_model_kv_override_type tag;
char key[128];
union {
int64_t val_i64;
double val_f64;
bool val_bool;
char val_str[128];
};
};
enum llama_split_mode {
LLAMA_SPLIT_MODE_NONE = 0,
LLAMA_SPLIT_MODE_LAYER = 1,
LLAMA_SPLIT_MODE_ROW = 2,
};
typedef bool (*llama_progress_callback)(float progress, void * user_data);
struct llama_model_params {
int32_t n_gpu_layers;
enum llama_split_mode split_mode;
int32_t main_gpu;
const float * tensor_split;
const char * rpc_servers;
llama_progress_callback progress_callback;
void * progress_callback_user_data;
const struct llama_model_kv_override * kv_overrides;
bool vocab_only;
bool use_mmap;
bool use_mlock;
bool check_tensors;
};
struct llama_model;
struct llama_model_params llama_model_default_params(void);
struct llama_model * llama_load_model_from_file(
const char * path_model,
struct llama_model_params params);
typedef int32_t llama_token;
int32_t llama_tokenize(
const struct llama_model * model,
const char * text,
int32_t text_len,
llama_token * tokens,
int32_t n_tokens_max,
bool add_special,
bool parse_special);
void llama_free_model(struct llama_model * model);
struct llama_model * model = NULL;
void doInit(const char *model_path) {
struct llama_model_params model_params = llama_model_default_params();
model_params.vocab_only = true;
model = llama_load_model_from_file(model_path, model_params);
if (model == NULL) {
fprintf(stderr , "%s: error: unable to load model\n" , __func__);
return;
}
}
void doFini() {
if (model != NULL) {
llama_free_model(model);
}
}
int64_t tokenize(const char *prompt) {
int n_prompt = -llama_tokenize(model, prompt, strlen(prompt), NULL, 0, true, true);
return n_prompt;
}