Skip to content

Commit 0040d42

Browse files
authored
llama : replace all API facing int's with int32_t (#4577)
* replaced all API facing `int`'s with `int32_t` * formatting and missed `int` in `llama_token_to_piece`
1 parent 83e633c commit 0040d42

File tree

2 files changed

+56
-57
lines changed

2 files changed

+56
-57
lines changed

llama.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8030,7 +8030,7 @@ void llama_sample_softmax(struct llama_context * ctx, llama_token_data_array * c
80308030
}
80318031
}
80328032

8033-
void llama_sample_top_k(struct llama_context * ctx, llama_token_data_array * candidates, int k, size_t min_keep) {
8033+
void llama_sample_top_k(struct llama_context * ctx, llama_token_data_array * candidates, int32_t k, size_t min_keep) {
80348034
const int64_t t_start_sample_us = ggml_time_us();
80358035

80368036
k = std::max(k, (int) min_keep);
@@ -8390,7 +8390,7 @@ void llama_sample_classifier_free_guidance(
83908390
}
83918391
}
83928392

8393-
llama_token llama_sample_token_mirostat(struct llama_context * ctx, llama_token_data_array * candidates, float tau, float eta, int m, float * mu) {
8393+
llama_token llama_sample_token_mirostat(struct llama_context * ctx, llama_token_data_array * candidates, float tau, float eta, int32_t m, float * mu) {
83948394
GGML_ASSERT(ctx);
83958395

83968396
auto N = float(llama_n_vocab(llama_get_model(ctx)));
@@ -9598,7 +9598,7 @@ struct llama_model_quantize_params llama_model_quantize_default_params() {
95989598
return result;
95999599
}
96009600

9601-
int llama_max_devices(void) {
9601+
int32_t llama_max_devices(void) {
96029602
return LLAMA_MAX_DEVICES;
96039603
}
96049604

@@ -9909,23 +9909,23 @@ enum llama_vocab_type llama_vocab_type(const struct llama_model * model) {
99099909
return model->vocab.type;
99109910
}
99119911

9912-
int llama_n_vocab(const struct llama_model * model) {
9912+
int32_t llama_n_vocab(const struct llama_model * model) {
99139913
return model->vocab.id_to_token.size();
99149914
}
99159915

9916-
int llama_n_ctx_train(const struct llama_model * model) {
9916+
int32_t llama_n_ctx_train(const struct llama_model * model) {
99179917
return model->hparams.n_ctx_train;
99189918
}
99199919

9920-
int llama_n_embd(const struct llama_model * model) {
9920+
int32_t llama_n_embd(const struct llama_model * model) {
99219921
return model->hparams.n_embd;
99229922
}
99239923

99249924
float llama_rope_freq_scale_train(const struct llama_model * model) {
99259925
return model->hparams.rope_freq_scale_train;
99269926
}
99279927

9928-
int llama_model_meta_val_str(const struct llama_model * model, const char * key, char * buf, size_t buf_size) {
9928+
int32_t llama_model_meta_val_str(const struct llama_model * model, const char * key, char * buf, size_t buf_size) {
99299929
const auto & it = model->gguf_kv.find(key);
99309930
if (it == model->gguf_kv.end()) {
99319931
if (buf_size > 0) {
@@ -9936,11 +9936,11 @@ int llama_model_meta_val_str(const struct llama_model * model, const char * key,
99369936
return snprintf(buf, buf_size, "%s", it->second.c_str());
99379937
}
99389938

9939-
int llama_model_meta_count(const struct llama_model * model) {
9939+
int32_t llama_model_meta_count(const struct llama_model * model) {
99409940
return (int)model->gguf_kv.size();
99419941
}
99429942

9943-
int llama_model_meta_key_by_index(const struct llama_model * model, int i, char * buf, size_t buf_size) {
9943+
int32_t llama_model_meta_key_by_index(const struct llama_model * model, int i, char * buf, size_t buf_size) {
99449944
if (i < 0 || i >= (int)model->gguf_kv.size()) {
99459945
if (buf_size > 0) {
99469946
buf[0] = '\0';
@@ -9952,7 +9952,7 @@ int llama_model_meta_key_by_index(const struct llama_model * model, int i, char
99529952
return snprintf(buf, buf_size, "%s", it->first.c_str());
99539953
}
99549954

9955-
int llama_model_meta_val_str_by_index(const struct llama_model * model, int i, char * buf, size_t buf_size) {
9955+
int32_t llama_model_meta_val_str_by_index(const struct llama_model * model, int32_t i, char * buf, size_t buf_size) {
99569956
if (i < 0 || i >= (int)model->gguf_kv.size()) {
99579957
if (buf_size > 0) {
99589958
buf[0] = '\0';
@@ -9964,7 +9964,7 @@ int llama_model_meta_val_str_by_index(const struct llama_model * model, int i, c
99649964
return snprintf(buf, buf_size, "%s", it->second.c_str());
99659965
}
99669966

9967-
int llama_model_desc(const struct llama_model * model, char * buf, size_t buf_size) {
9967+
int32_t llama_model_desc(const struct llama_model * model, char * buf, size_t buf_size) {
99689968
return snprintf(buf, buf_size, "%s %s %s",
99699969
llama_model_arch_name(model->arch).c_str(),
99709970
llama_model_type_name(model->type),
@@ -9991,7 +9991,7 @@ struct ggml_tensor * llama_get_model_tensor(struct llama_model * model, const ch
99919991
return ggml_get_tensor(model->ctx, name);
99929992
}
99939993

9994-
int llama_model_quantize(
9994+
uint32_t llama_model_quantize(
99959995
const char * fname_inp,
99969996
const char * fname_out,
99979997
const llama_model_quantize_params * params) {
@@ -10004,7 +10004,7 @@ int llama_model_quantize(
1000410004
}
1000510005
}
1000610006

10007-
int llama_apply_lora_from_file(struct llama_context * ctx, const char * path_lora, float scale, const char * path_base_model, int n_threads) {
10007+
int32_t llama_apply_lora_from_file(struct llama_context * ctx, const char * path_lora, float scale, const char * path_base_model, int32_t n_threads) {
1000810008
try {
1000910009
return llama_apply_lora_from_file_internal(ctx->model, path_lora, scale, path_base_model, n_threads);
1001010010
} catch (const std::exception & err) {
@@ -10013,7 +10013,7 @@ int llama_apply_lora_from_file(struct llama_context * ctx, const char * path_lor
1001310013
}
1001410014
}
1001510015

10016-
int llama_model_apply_lora_from_file(const struct llama_model * model, const char * path_lora, float scale, const char * path_base_model, int n_threads) {
10016+
int32_t llama_model_apply_lora_from_file(const struct llama_model * model, const char * path_lora, float scale, const char * path_base_model, int32_t n_threads) {
1001710017
try {
1001810018
return llama_apply_lora_from_file_internal(*model, path_lora, scale, path_base_model, n_threads);
1001910019
} catch (const std::exception & err) {
@@ -10111,7 +10111,7 @@ void llama_kv_cache_view_update(const struct llama_context * ctx, struct llama_k
1011110111
}
1011210112
}
1011310113

10114-
int llama_get_kv_cache_token_count(const struct llama_context * ctx) {
10114+
int32_t llama_get_kv_cache_token_count(const struct llama_context * ctx) {
1011510115
int result = 0;
1011610116

1011710117
for (uint32_t i = 0; i < ctx->kv_self.size; i++) {
@@ -10121,7 +10121,7 @@ int llama_get_kv_cache_token_count(const struct llama_context * ctx) {
1012110121
return result;
1012210122
}
1012310123

10124-
int llama_get_kv_cache_used_cells(const struct llama_context * ctx) {
10124+
int32_t llama_get_kv_cache_used_cells(const struct llama_context * ctx) {
1012510125
return ctx->kv_self.used;
1012610126
}
1012710127

@@ -10603,7 +10603,7 @@ int llama_eval(
1060310603
struct llama_context * ctx,
1060410604
llama_token * tokens,
1060510605
int32_t n_tokens,
10606-
int n_past) {
10606+
int32_t n_past) {
1060710607
llama_kv_cache_seq_rm(ctx->kv_self, -1, n_past, -1);
1060810608

1060910609
const int ret = llama_decode_internal(*ctx, llama_batch_get_one(tokens, n_tokens, n_past, 0));
@@ -10618,7 +10618,7 @@ int llama_eval_embd(
1061810618
struct llama_context * ctx,
1061910619
float * embd,
1062010620
int32_t n_tokens,
10621-
int n_past) {
10621+
int32_t n_past) {
1062210622
llama_kv_cache_seq_rm(ctx->kv_self, -1, n_past, -1);
1062310623

1062410624
llama_batch batch = { n_tokens, nullptr, embd, nullptr, nullptr, nullptr, nullptr, n_past, 1, 0, };
@@ -10689,7 +10689,7 @@ void llama_batch_free(struct llama_batch batch) {
1068910689
if (batch.logits) free(batch.logits);
1069010690
}
1069110691

10692-
int llama_decode(
10692+
int32_t llama_decode(
1069310693
struct llama_context * ctx,
1069410694
struct llama_batch batch) {
1069510695
const int ret = llama_decode_internal(*ctx, batch);
@@ -10737,11 +10737,11 @@ llama_token llama_token_nl(const struct llama_model * model) {
1073710737
return model->vocab.linefeed_id;
1073810738
}
1073910739

10740-
int llama_add_bos_token(const struct llama_model * model) {
10740+
int32_t llama_add_bos_token(const struct llama_model * model) {
1074110741
return model->vocab.special_add_bos;
1074210742
}
1074310743

10744-
int llama_add_eos_token(const struct llama_model * model) {
10744+
int32_t llama_add_eos_token(const struct llama_model * model) {
1074510745
return model->vocab.special_add_eos;
1074610746
}
1074710747

@@ -10761,12 +10761,12 @@ llama_token llama_token_eot(const struct llama_model * model) {
1076110761
return model->vocab.special_eot_id;
1076210762
}
1076310763

10764-
int llama_tokenize(
10764+
int32_t llama_tokenize(
1076510765
const struct llama_model * model,
1076610766
const char * text,
10767-
int text_len,
10767+
int32_t text_len,
1076810768
llama_token * tokens,
10769-
int n_max_tokens,
10769+
int32_t n_max_tokens,
1077010770
bool add_bos,
1077110771
bool special) {
1077210772
auto res = llama_tokenize_internal(model->vocab, std::string(text, text_len), add_bos, special);
@@ -10794,7 +10794,7 @@ static std::string llama_decode_text(const std::string & text) {
1079410794
}
1079510795

1079610796
// does not write null-terminator to buf
10797-
int llama_token_to_piece(const struct llama_model * model, llama_token token, char * buf, int length) {
10797+
int32_t llama_token_to_piece(const struct llama_model * model, llama_token token, char * buf, int32_t length) {
1079810798
if (0 <= token && token < llama_n_vocab(model)) {
1079910799
switch (llama_vocab_get_type(model->vocab)) {
1080010800
case LLAMA_VOCAB_TYPE_SPM: {

0 commit comments

Comments
 (0)