Skip to content

Commit bf019ef

Browse files
author
mike dupont
committed
adding print statements to main.
This inserts the print probes at key points
1 parent f067d52 commit bf019ef

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

examples/main/main.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#pragma warning(disable: 4244 4267) // possible loss of data
3232
#endif
3333

34+
#include "print.hpp"
35+
3436
static llama_context ** g_ctx;
3537
static llama_model ** g_model;
3638
static gpt_params * g_params;
@@ -99,6 +101,7 @@ static void sigint_handler(int signo) {
99101
}
100102
}
101103
#endif
104+
using namespace refl;
102105

103106
int main(int argc, char ** argv) {
104107
gpt_params params;
@@ -117,7 +120,8 @@ int main(int argc, char ** argv) {
117120

118121
// TODO: Dump params ?
119122
//LOG("Params perplexity: %s\n", LOG_TOSTR(params.perplexity));
120-
123+
print_fields(params);
124+
121125
// save choice to use color for later
122126
// (note for later: this is a slightly awkward choice)
123127
console::init(params.simple_io, params.use_color);
@@ -234,6 +238,8 @@ int main(int argc, char ** argv) {
234238

235239
std::vector<llama_token> embd_inp;
236240

241+
print_fields(*model);
242+
237243
if (params.interactive_first || params.instruct || params.chatml || !params.prompt.empty() || session_tokens.empty()) {
238244
LOG("tokenize the prompt\n");
239245
if (params.chatml) {
@@ -277,7 +283,8 @@ int main(int argc, char ** argv) {
277283
LOG_TEE("%s: error: prompt is too long (%d tokens, max %d)\n", __func__, (int) embd_inp.size(), n_ctx - 4);
278284
return 1;
279285
}
280-
286+
print_fields(*ctx);
287+
//print_fields(session_tokens);
281288
// debug message about similarity of saved session, if applicable
282289
size_t n_matching_session_tokens = 0;
283290
if (!session_tokens.empty()) {
@@ -365,6 +372,10 @@ int main(int argc, char ** argv) {
365372
for (int i = 0; i < (int) guidance_inp.size(); i++) {
366373
LOG_TEE("%6d -> '%s'\n", guidance_inp[i], llama_token_to_piece(ctx, guidance_inp[i]).c_str());
367374
}
375+
376+
print_fields(*ctx_guidance);
377+
378+
368379
}
369380

370381
if (params.n_keep > 0) {
@@ -473,7 +484,8 @@ int main(int argc, char ** argv) {
473484
std::vector<llama_token> embd_guidance;
474485

475486
struct llama_sampling_context * ctx_sampling = llama_sampling_init(sparams);
476-
487+
print_fields(*ctx_sampling);
488+
477489
while ((n_remain != 0 && !is_antiprompt) || params.interactive) {
478490
// predict
479491
if (!embd.empty()) {
@@ -508,6 +520,7 @@ int main(int argc, char ** argv) {
508520
LOG("context full, swapping: n_past = %d, n_left = %d, n_ctx = %d, n_keep = %d, n_discard = %d\n",
509521
n_past, n_left, n_ctx, params.n_keep, n_discard);
510522

523+
print_fields(*ctx);
511524
llama_kv_cache_seq_rm (ctx, 0, params.n_keep + 1 , params.n_keep + n_discard + 1);
512525
llama_kv_cache_seq_shift(ctx, 0, params.n_keep + 1 + n_discard, n_past, -n_discard);
513526

@@ -624,7 +637,7 @@ int main(int argc, char ** argv) {
624637
}
625638

626639
const llama_token id = llama_sampling_sample(ctx_sampling, ctx, ctx_guidance);
627-
640+
//print_fields(id);
628641
llama_sampling_accept(ctx_sampling, ctx, id, true);
629642

630643
LOG("last: %s\n", LOG_TOKENS_TOSTR_PRETTY(ctx, ctx_sampling->prev).c_str());

0 commit comments

Comments
 (0)