main: renamed --no-special from --ctrl-token-no-out and other refactoring

This commit is contained in:
brian khuu 2024-05-21 16:00:59 +10:00
parent c1e8a6d1c0
commit 7d52482bac
2 changed files with 10 additions and 15 deletions

View file

@ -905,7 +905,7 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
params.interactive_specials = true;
return true;
}
if (arg == "--ctrl-token-no-out") {
if (arg == "--no-special") {
params.ctrl_token_no_out = true;
return true;
}
@ -1438,7 +1438,7 @@ void gpt_print_usage(int /*argc*/, char ** argv, const gpt_params & params) {
printf(" -i, --interactive run in interactive mode\n");
printf(" --interactive-specials allow special tokens in user text, in interactive mode\n");
printf(" --interactive-first run in interactive mode and wait for input right away\n");
printf(" --ctrl-token-no-out control tokens output disabled\n");
printf(" --no-special control tokens output disabled\n");
printf(" -cnv, --conversation run in conversation mode (does not print special tokens and suffix/prefix)\n");
printf(" -ins, --instruct run in instruction mode (use with Alpaca models)\n");
printf(" -cml, --chatml run in chatml mode (use with ChatML-compatible models)\n");

View file

@ -19,7 +19,7 @@
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
#define CONTROL_TOKEN_FILENO (3)
#define SPECIAL_FILENO 3
#elif defined (_WIN32)
#define WIN32_LEAN_AND_MEAN
#ifndef NOMINMAX
@ -123,7 +123,11 @@ int main(int argc, char ** argv) {
#ifndef _MSC_VER
// Check if we have an external attachment to a file descriptor for out of band control tokens (e.g. bash `3>/dev/null` )
// Placed here to avoid file descriptor being polluted by gpt_params_parse() opening files
const bool control_token_file_descriptor_is_attached = fcntl(CONTROL_TOKEN_FILENO, F_GETFL) != -1;
const bool control_token_file_descriptor_is_attached = fcntl(SPECIAL_FILENO, F_GETFL) != -1;
if (!control_token_file_descriptor_is_attached) {
// Duplicate stdout file descriptor to control token file descriptor to merge the two streams
dup2(STDOUT_FILENO, SPECIAL_FILENO);
}
#endif
gpt_params params;
@ -136,14 +140,6 @@ int main(int argc, char ** argv) {
const bool control_token_allowed_on_standard_stream = !params.conversation && sparams.grammar.empty();
#ifndef _MSC_VER
// Merge normal token stream and control token streams together only if not in conversation or grammar mode
if (control_token_allowed_on_standard_stream && !control_token_file_descriptor_is_attached) {
// Duplicate stdout file descriptor to control token file descriptor to merge the two streams
dup2(STDOUT_FILENO, CONTROL_TOKEN_FILENO);
}
#endif
#ifndef LOG_DISABLE_LOGS
log_set_target(log_filename_generator("main", "log"));
LOG_TEE("Log start\n");
@ -768,8 +764,7 @@ int main(int argc, char ** argv) {
#ifndef _MSC_VER
if (control_token_file_descriptor_is_attached) {
// Stream Control Token To Special Token Output. Useful for debugging control token behaviour
fflush(stdout); // Ensure control token is always appended to stdout stream
(void)! write(CONTROL_TOKEN_FILENO, token_str.c_str(), token_str.length());
(void)! write(SPECIAL_FILENO, token_str.c_str(), token_str.length());
} else
#endif
if (control_token_allowed_on_standard_stream)
@ -788,8 +783,8 @@ int main(int argc, char ** argv) {
output_tokens.push_back(id);
output_ss << token_str;
}
fflush(stdout);
}
fflush(stdout);
}
// reset color to default if there is no pending user input