Skip to content

Commit 305ba6f

Browse files
tjohnmanJohnman
andauthored
Don't force immediate interactive without -i (ggml-org#354)
* Don't force immediate interactive without -i Sometimes we might want to use a reverse prompt but we want to let the model generate tokens right after the initial prompt. So we don't force user input mode if the -i flag wasn't specified and instead let it run until we encounter the reverse prompt. This gives use some more flexibility, since it doesn't force the user to enter a newline if they want to let the model generate text right after the initial prompt and only be asked for input if the reverse prompt is encountered. The `--interactive-first` flag is reintroduced to force the old behavior. `-r` behaves like `-i` plus introduces a reverse prompt (it can be specified more than once). * Update help output. --------- Co-authored-by: Johnman <tjohnman@github>
1 parent 4122dff commit 305ba6f

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ int main(int argc, char ** argv) {
254254
params.interactive = true;
255255
}
256256

257+
if (params.interactive_start) {
258+
params.interactive = true;
259+
}
260+
257261
fprintf(stderr, "\n");
258262
fprintf(stderr, "%s: prompt: '%s'\n", __func__, params.prompt.c_str());
259263
fprintf(stderr, "%s: number of tokens in prompt = %zu\n", __func__, embd_inp.size());
@@ -296,7 +300,7 @@ int main(int argc, char ** argv) {
296300
#endif
297301
" - Press Return to return control to LLaMa.\n"
298302
" - If you want to submit another line, end your input in '\\'.\n\n");
299-
is_interacting = true;
303+
is_interacting = params.interactive_start;
300304
}
301305

302306
int input_consumed = 0;

utils.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
6363
params.model = argv[++i];
6464
} else if (arg == "-i" || arg == "--interactive") {
6565
params.interactive = true;
66+
} else if (arg == "--interactive-first") {
67+
params.interactive_start = true;
6668
} else if (arg == "-ins" || arg == "--instruct") {
6769
params.instruct = true;
6870
} else if (arg == "--color") {
@@ -96,9 +98,10 @@ void gpt_print_usage(int /*argc*/, char ** argv, const gpt_params & params) {
9698
fprintf(stderr, "options:\n");
9799
fprintf(stderr, " -h, --help show this help message and exit\n");
98100
fprintf(stderr, " -i, --interactive run in interactive mode\n");
101+
fprintf(stderr, " --interactive-first run in interactive mode and wait for input right away\n");
99102
fprintf(stderr, " -ins, --instruct run in instruction mode (use with Alpaca models)\n");
100103
fprintf(stderr, " -r PROMPT, --reverse-prompt PROMPT\n");
101-
fprintf(stderr, " in interactive mode, poll user input upon seeing PROMPT (can be\n");
104+
fprintf(stderr, " run in interactive mode and poll user input upon seeing PROMPT (can be\n");
102105
fprintf(stderr, " specified more than once for multiple prompts).\n");
103106
fprintf(stderr, " --color colorise output to distinguish prompt and user input from generations\n");
104107
fprintf(stderr, " -s SEED, --seed SEED RNG seed (default: -1, use random seed for <= 0)\n");

utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct gpt_params {
3838
bool random_prompt = false; // do not randomize prompt if none provided
3939
bool use_color = false; // use color to distinguish generations and inputs
4040
bool interactive = false; // interactive mode
41-
bool interactive_start = false; // reverse prompt immediately
41+
bool interactive_start = false; // wait for user input immediately
4242
bool instruct = false; // instruction mode (used for Alpaca models)
4343
bool ignore_eos = false; // do not stop generating after eos
4444
bool perplexity = false; // compute perplexity over the prompt

0 commit comments

Comments
 (0)