Skip to content

Commit 63506ec

Browse files
committed
Apply suggestions to llama.cpp and llama.h
1 parent 9d5c69e commit 63506ec

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
@@ -818,15 +818,15 @@ bool llama_model_quantize(const std::string & fname_inp, const std::string & fna
818818

819819
/* External API */
820820

821-
const std::vector<gpt_vocab::id>& llama_context_get_embd(const llama_context& ctx) {
821+
const std::vector<gpt_vocab::id>& llama_context_get_embedding(const llama_context& ctx) {
822822
return ctx.state->embd;
823823
}
824824
gpt_vocab& llama_context_get_vocab(llama_context& ctx) {
825825
return ctx.vocab;
826826
}
827-
bool llama_context_not_finished(const llama_context& ctx)
827+
bool llama_context_is_finished(const llama_context& ctx)
828828
{
829-
return ctx.state->remaining_tokens > 0;
829+
return ctx.state->remaining_tokens <= 0;
830830
}
831831
const std::vector<gpt_vocab::id> llama_tokenize_text(const llama_context& ctx, const std::string& text) {
832832
return llama_tokenize(ctx.vocab, text, true);
@@ -1137,7 +1137,7 @@ bool llama_eval(
11371137
return true;
11381138
}
11391139

1140-
bool llama_init_context_with_prompt(llama_context& ctx, const std::string& text, bool clear_existing) {
1140+
bool llama_update_context_with_prompt(llama_context& ctx, const std::string& text, bool clear_existing) {
11411141
llama_state& state = *ctx.state;
11421142
llama_model& model = ctx.model;
11431143
const gpt_params& params = ctx.params;
@@ -1173,9 +1173,9 @@ bool llama_init_context_with_prompt(llama_context& ctx, const std::string& text,
11731173
return true;
11741174
}
11751175

1176-
/// @brief Injests a batch of input tokens into the context
1176+
/// @brief Ingests a batch of input tokens into the context
11771177
/// @param ctx
1178-
void llama_injest_input_batch(llama_context& ctx)
1178+
void llama_ingest_input_batch(llama_context& ctx)
11791179
{
11801180
llama_state& state = *ctx.state;
11811181
const gpt_params& params = ctx.params;
@@ -1241,22 +1241,22 @@ gpt_vocab::id llama_sample_token(llama_context& ctx)
12411241
}
12421242
return id;
12431243
}
1244-
/// @brief Injest all input (in multiple batches) into model and run call predict()
1244+
/// @brief Ingest all input (in multiple batches) into model and run call predict()
12451245
/// @param ctx
1246-
bool llama_injest_input(llama_context& ctx, const std::string& text, bool clear_existing)
1246+
bool llama_ingest_input(llama_context& ctx, const std::string& text, bool clear_existing)
12471247
{
12481248
llama_state& state = *ctx.state;
12491249

12501250
// Initialize context, tokenize text and clear existing state if necessary
1251-
if(!state.is_initialized && !llama_init_context_with_prompt(ctx, text, clear_existing))
1251+
if(!state.is_initialized && !llama_update_context_with_prompt(ctx, text, clear_existing))
12521252
{
12531253
return false;
12541254
}
12551255

1256-
// Injest the tokens into the model one batch at a time
1256+
// ingest the tokens into the model one batch at a time
12571257
while (state.has_more_input())
12581258
{
1259-
llama_injest_input_batch(ctx);
1259+
llama_ingest_input_batch(ctx);
12601260
if (state.embd.size() >= 0) {
12611261
if(!llama_predict(ctx))
12621262
{
@@ -1268,7 +1268,7 @@ bool llama_injest_input(llama_context& ctx, const std::string& text, bool clear_
12681268
}
12691269
return true;
12701270
}
1271-
bool llama_inference(llama_context& ctx, gpt_vocab::id& id) {
1271+
bool llama_infer(llama_context& ctx, gpt_vocab::id& id) {
12721272
llama_state& state = *ctx.state;
12731273

12741274
// 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)