Skip to content

Commit 8c88b17

Browse files
committed
PR comments
1 parent e4429e9 commit 8c88b17

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

examples/common.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
125125
}
126126
params.path_prompt_cache = argv[i];
127127
} else if (arg == "--prompt-cache-all") {
128-
params.prompt_cache_save_all = true;
128+
params.prompt_cache_all = true;
129129
} else if (arg == "-f" || arg == "--file") {
130130
if (++i >= argc) {
131131
invalid_param = true;
@@ -370,7 +370,8 @@ void gpt_print_usage(int /*argc*/, char ** argv, const gpt_params & params) {
370370
fprintf(stderr, " prompt to start generation with (default: empty)\n");
371371
fprintf(stderr, " -e process prompt escapes sequences (\\n, \\r, \\t, \\', \\\", \\\\)\n");
372372
fprintf(stderr, " --prompt-cache FNAME file to cache prompt state for faster startup (default: none)\n");
373-
fprintf(stderr, " --prompt-cache-all if specified, saves user input and generations to cache as well\n");
373+
fprintf(stderr, " --prompt-cache-all if specified, saves user input and generations to cache as well.\n");
374+
fprintf(stderr, " not supported with --interactive or other interactive options\n");
374375
fprintf(stderr, " --random-prompt start with a randomized prompt.\n");
375376
fprintf(stderr, " --in-prefix STRING string to prefix user inputs with (default: empty)\n");
376377
fprintf(stderr, " --in-suffix STRING string to suffix after user inputs with (default: empty)\n");

examples/common.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ struct gpt_params {
5454
std::string lora_adapter = ""; // lora adapter path
5555
std::string lora_base = ""; // base model path for the lora adapter
5656

57-
bool memory_f16 = true; // use f16 instead of f32 for memory kv
58-
bool random_prompt = false; // do not randomize prompt if none provided
59-
bool use_color = false; // use color to distinguish generations and inputs
60-
bool interactive = false; // interactive mode
61-
bool prompt_cache_save_all = false; // save user input and generations to prompt cache
57+
bool memory_f16 = true; // use f16 instead of f32 for memory kv
58+
bool random_prompt = false; // do not randomize prompt if none provided
59+
bool use_color = false; // use color to distinguish generations and inputs
60+
bool interactive = false; // interactive mode
61+
bool prompt_cache_all = false; // save user input and generations to prompt cache
6262

6363
bool embedding = false; // get only sentence embedding
6464
bool interactive_first = false; // wait for user input immediately

examples/main/main.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ int main(int argc, char ** argv) {
140140
params.prompt.insert(0, 1, ' ');
141141

142142
std::string path_session = params.path_prompt_cache;
143-
const bool session_save_all = params.prompt_cache_save_all;
144143
std::vector<llama_token> session_tokens;
145144

146145
if (!path_session.empty()) {
@@ -236,6 +235,11 @@ int main(int argc, char ** argv) {
236235
}
237236

238237
if (params.interactive) {
238+
if (params.prompt_cache_all) {
239+
fprintf(stderr, "error: --prompt-cache-all not supported in interactive mode yet\n");
240+
return 1;
241+
}
242+
239243
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
240244
struct sigaction sigint_action;
241245
sigint_action.sa_handler = sigint_handler;
@@ -295,8 +299,7 @@ int main(int argc, char ** argv) {
295299

296300
bool is_antiprompt = false;
297301
bool input_echo = true;
298-
bool need_to_save_session = !path_session.empty();
299-
302+
bool need_to_save_session = !path_session.empty() && n_matching_session_tokens < embd_inp.size();
300303

301304
int n_past = 0;
302305
int n_remain = params.n_predict;
@@ -325,11 +328,7 @@ int main(int argc, char ** argv) {
325328
embd.insert(embd.begin(), last_n_tokens.begin() + n_ctx - n_left/2 - embd.size(), last_n_tokens.end() - embd.size());
326329

327330
// stop saving session if we run out of context
328-
if (!path_session.empty() && session_save_all) {
329-
llama_save_session_file(ctx, path_session.c_str(),
330-
session_tokens.data(), session_tokens.size());
331-
}
332-
path_session = "";
331+
path_session.clear();
333332

334333
//printf("\n---\n");
335334
//printf("resetting: '");
@@ -604,7 +603,7 @@ int main(int argc, char ** argv) {
604603
}
605604
}
606605

607-
if (!path_session.empty() && session_save_all) {
606+
if (!path_session.empty() && params.prompt_cache_all) {
608607
fprintf(stderr, "\n%s: saving final output to session file '%s'\n", __func__, path_session.c_str());
609608
llama_save_session_file(ctx, path_session.c_str(), session_tokens.data(), session_tokens.size());
610609
}

0 commit comments

Comments
 (0)