Skip to content

Commit b0ed03b

Browse files
committed
Apply suggestions to llama.cpp and llama.h
1 parent 7fb4c51 commit b0ed03b

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

llama.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -810,15 +810,15 @@ bool llama_model_quantize(const std::string & fname_inp, const std::string & fna
810810

811811
/* External API */
812812

813-
const std::vector<gpt_vocab::id>& llama_context_get_embd(const llama_context& ctx) {
813+
const std::vector<gpt_vocab::id>& llama_context_get_embedding(const llama_context& ctx) {
814814
return ctx.state->embd;
815815
}
816816
gpt_vocab& llama_context_get_vocab(llama_context& ctx) {
817817
return ctx.vocab;
818818
}
819-
bool llama_context_not_finished(const llama_context& ctx)
819+
bool llama_context_is_finished(const llama_context& ctx)
820820
{
821-
return ctx.state->remaining_tokens > 0;
821+
return ctx.state->remaining_tokens <= 0;
822822
}
823823
const std::vector<gpt_vocab::id> llama_tokenize_text(const llama_context& ctx, const std::string& text) {
824824
return llama_tokenize(ctx.vocab, text, true);
@@ -1129,7 +1129,7 @@ bool llama_eval(
11291129
return true;
11301130
}
11311131

1132-
bool llama_init_context_with_prompt(llama_context& ctx, const std::string& text, bool clear_existing) {
1132+
bool llama_update_context_with_prompt(llama_context& ctx, const std::string& text, bool clear_existing) {
11331133
llama_state& state = *ctx.state;
11341134
llama_model& model = ctx.model;
11351135
const gpt_params& params = ctx.params;
@@ -1165,9 +1165,9 @@ bool llama_init_context_with_prompt(llama_context& ctx, const std::string& text,
11651165
return true;
11661166
}
11671167

1168-
/// @brief Injests a batch of input tokens into the context
1168+
/// @brief Ingests a batch of input tokens into the context
11691169
/// @param ctx
1170-
void llama_injest_input_batch(llama_context& ctx)
1170+
void llama_ingest_input_batch(llama_context& ctx)
11711171
{
11721172
llama_state& state = *ctx.state;
11731173
const gpt_params& params = ctx.params;
@@ -1233,22 +1233,22 @@ gpt_vocab::id llama_sample_token(llama_context& ctx)
12331233
}
12341234
return id;
12351235
}
1236-
/// @brief Injest all input (in multiple batches) into model and run call predict()
1236+
/// @brief Ingest all input (in multiple batches) into model and run call predict()
12371237
/// @param ctx
1238-
bool llama_injest_input(llama_context& ctx, const std::string& text, bool clear_existing)
1238+
bool llama_ingest_input(llama_context& ctx, const std::string& text, bool clear_existing)
12391239
{
12401240
llama_state& state = *ctx.state;
12411241

12421242
// Initialize context, tokenize text and clear existing state if necessary
1243-
if(!state.is_initialized && !llama_init_context_with_prompt(ctx, text, clear_existing))
1243+
if(!state.is_initialized && !llama_update_context_with_prompt(ctx, text, clear_existing))
12441244
{
12451245
return false;
12461246
}
12471247

1248-
// Injest the tokens into the model one batch at a time
1248+
// ingest the tokens into the model one batch at a time
12491249
while (state.has_more_input())
12501250
{
1251-
llama_injest_input_batch(ctx);
1251+
llama_ingest_input_batch(ctx);
12521252
if (state.embd.size() >= 0) {
12531253
if(!llama_predict(ctx))
12541254
{
@@ -1260,7 +1260,7 @@ bool llama_injest_input(llama_context& ctx, const std::string& text, bool clear_
12601260
}
12611261
return true;
12621262
}
1263-
bool llama_inference(llama_context& ctx, gpt_vocab::id& id) {
1263+
bool llama_infer(llama_context& ctx, gpt_vocab::id& id) {
12641264
llama_state& state = *ctx.state;
12651265

12661266
// Tokenize text if we are starting out

llama.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,27 @@ struct llama_hparams {
3939

4040
struct llama_context;
4141

42-
void llama_free_context(llama_context* ctx);
42+
// Startup
43+
llama_context* llama_init_from_params(const gpt_params& params);
4344

44-
const std::vector<gpt_vocab::id>& llama_context_get_embd(const llama_context& ctx);
45-
gpt_vocab& llama_context_get_vocab(llama_context& ctx);
46-
bool llama_context_not_finished(const llama_context& ctx);
45+
// Input processing and inference
46+
bool llama_ingest_input(llama_context& ctx, const std::string& text, bool clear_existing = true);
47+
bool llama_context_is_finished(const llama_context& ctx);
48+
bool llama_update_context_with_prompt(llama_context& ctx, const std::string& text, bool clear_existing = true);
4749
const std::vector<gpt_vocab::id> llama_tokenize_text(const llama_context& ctx, const std::string& text);
50+
bool llama_infer(llama_context& ctx, gpt_vocab::id& model_output);
4851

49-
const std::vector<gpt_vocab::id>& llama_context_get_last_n_tokens(const llama_context& ctx);
50-
bool llama_init_context_with_prompt(llama_context& ctx, const std::string& text, bool clear_existing = true);
51-
52-
// Various functions for loading a ggml LLaMA model.
53-
llama_context* llama_init_from_params(const gpt_params& params);
52+
// Teardown
53+
void llama_free_context(llama_context* ctx);
5454

55-
// Run inference on a LLaMA model using llama_context.
56-
std::vector<float> llama_eval(llama_context& ctx, const gpt_params& params, std::string& text);
55+
// Getters and setters
56+
gpt_vocab& llama_context_get_vocab(llama_context& ctx);
57+
const std::vector<gpt_vocab::id>& llama_context_get_embedding(const llama_context& ctx);
58+
const std::vector<gpt_vocab::id>& llama_context_get_last_n_tokens(const llama_context& ctx);
5759

60+
// Other
5861
bool llama_model_quantize(const std::string & fname_inp, const std::string & fname_out, int itype);
5962

60-
bool llama_injest_input(llama_context& ctx, const std::string& text, bool clear_existing = true);
61-
62-
bool llama_inference(llama_context& ctx, gpt_vocab::id& model_output);
63+
// Stats
6364
void llama_print_context_info(const llama_context& ctx);
6465
void llama_print_end_stats(const llama_context& ctx);

0 commit comments

Comments
 (0)