Skip to content

Commit 7d52482

Browse files
committed
main: renamed --no-special from --ctrl-token-no-out and other refactoring
1 parent c1e8a6d commit 7d52482

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

common/common.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
905905
params.interactive_specials = true;
906906
return true;
907907
}
908-
if (arg == "--ctrl-token-no-out") {
908+
if (arg == "--no-special") {
909909
params.ctrl_token_no_out = true;
910910
return true;
911911
}
@@ -1438,7 +1438,7 @@ void gpt_print_usage(int /*argc*/, char ** argv, const gpt_params & params) {
14381438
printf(" -i, --interactive run in interactive mode\n");
14391439
printf(" --interactive-specials allow special tokens in user text, in interactive mode\n");
14401440
printf(" --interactive-first run in interactive mode and wait for input right away\n");
1441-
printf(" --ctrl-token-no-out control tokens output disabled\n");
1441+
printf(" --no-special control tokens output disabled\n");
14421442
printf(" -cnv, --conversation run in conversation mode (does not print special tokens and suffix/prefix)\n");
14431443
printf(" -ins, --instruct run in instruction mode (use with Alpaca models)\n");
14441444
printf(" -cml, --chatml run in chatml mode (use with ChatML-compatible models)\n");

examples/main/main.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <signal.h>
2020
#include <unistd.h>
2121
#include <fcntl.h>
22-
#define CONTROL_TOKEN_FILENO (3)
22+
#define SPECIAL_FILENO 3
2323
#elif defined (_WIN32)
2424
#define WIN32_LEAN_AND_MEAN
2525
#ifndef NOMINMAX
@@ -123,7 +123,11 @@ int main(int argc, char ** argv) {
123123
#ifndef _MSC_VER
124124
// Check if we have an external attachment to a file descriptor for out of band control tokens (e.g. bash `3>/dev/null` )
125125
// Placed here to avoid file descriptor being polluted by gpt_params_parse() opening files
126-
const bool control_token_file_descriptor_is_attached = fcntl(CONTROL_TOKEN_FILENO, F_GETFL) != -1;
126+
const bool control_token_file_descriptor_is_attached = fcntl(SPECIAL_FILENO, F_GETFL) != -1;
127+
if (!control_token_file_descriptor_is_attached) {
128+
// Duplicate stdout file descriptor to control token file descriptor to merge the two streams
129+
dup2(STDOUT_FILENO, SPECIAL_FILENO);
130+
}
127131
#endif
128132

129133
gpt_params params;
@@ -136,14 +140,6 @@ int main(int argc, char ** argv) {
136140

137141
const bool control_token_allowed_on_standard_stream = !params.conversation && sparams.grammar.empty();
138142

139-
#ifndef _MSC_VER
140-
// Merge normal token stream and control token streams together only if not in conversation or grammar mode
141-
if (control_token_allowed_on_standard_stream && !control_token_file_descriptor_is_attached) {
142-
// Duplicate stdout file descriptor to control token file descriptor to merge the two streams
143-
dup2(STDOUT_FILENO, CONTROL_TOKEN_FILENO);
144-
}
145-
#endif
146-
147143
#ifndef LOG_DISABLE_LOGS
148144
log_set_target(log_filename_generator("main", "log"));
149145
LOG_TEE("Log start\n");
@@ -768,8 +764,7 @@ int main(int argc, char ** argv) {
768764
#ifndef _MSC_VER
769765
if (control_token_file_descriptor_is_attached) {
770766
// Stream Control Token To Special Token Output. Useful for debugging control token behaviour
771-
fflush(stdout); // Ensure control token is always appended to stdout stream
772-
(void)! write(CONTROL_TOKEN_FILENO, token_str.c_str(), token_str.length());
767+
(void)! write(SPECIAL_FILENO, token_str.c_str(), token_str.length());
773768
} else
774769
#endif
775770
if (control_token_allowed_on_standard_stream)
@@ -788,8 +783,8 @@ int main(int argc, char ** argv) {
788783
output_tokens.push_back(id);
789784
output_ss << token_str;
790785
}
786+
fflush(stdout);
791787
}
792-
fflush(stdout);
793788
}
794789

795790
// reset color to default if there is no pending user input

0 commit comments

Comments
 (0)