Skip to content

Commit e75c5ca

Browse files
authored
main: remove special token file descriptor feature (#5)
1 parent 12fcea5 commit e75c5ca

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

examples/main/main.cpp

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
1919
#include <signal.h>
2020
#include <unistd.h>
21-
#include <fcntl.h>
22-
#define SPECIAL_FILENO 3
2321
#elif defined (_WIN32)
2422
#define WIN32_LEAN_AND_MEAN
2523
#ifndef NOMINMAX
@@ -120,16 +118,6 @@ static void llama_log_callback_logTee(ggml_log_level level, const char * text, v
120118
}
121119

122120
int main(int argc, char ** argv) {
123-
#ifndef _MSC_VER
124-
// Check if we have an external attachment to a file descriptor for out of band control tokens (e.g. bash `3>/dev/null` )
125-
// Placed here to avoid file descriptor being polluted by gpt_params_parse() opening files
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-
}
131-
#endif
132-
133121
gpt_params params;
134122
g_params = &params;
135123

@@ -138,8 +126,6 @@ int main(int argc, char ** argv) {
138126
}
139127
llama_sampling_params & sparams = params.sparams;
140128

141-
const bool control_token_allowed_on_standard_stream = !params.conversation && sparams.grammar.empty();
142-
143129
#ifndef LOG_DISABLE_LOGS
144130
log_set_target(log_filename_generator("main", "log"));
145131
LOG_TEE("Log start\n");
@@ -760,19 +746,11 @@ int main(int argc, char ** argv) {
760746
if (!llama_token_is_control(llama_get_model(ctx), id)) {
761747
// Stream Output Token To Standard Output
762748
fprintf(stdout, "%s", token_str.c_str());
763-
} else if (!params.no_special) {
764-
#ifndef _MSC_VER
765-
if (control_token_file_descriptor_is_attached) {
766-
// Stream Control Token To Special Token Output. Useful for debugging control token behaviour
767-
(void)! write(SPECIAL_FILENO, token_str.c_str(), token_str.length());
768-
} else
769-
#endif
770-
if (control_token_allowed_on_standard_stream)
771-
{
772-
// Stream Control Token To Standard Output Stream
773-
fprintf(stdout, "%s", token_str.c_str());
774-
}
749+
} else if (!params.no_special && !params.conversation) {
750+
// Stream Control Token To Standard Output Stream
751+
fprintf(stdout, "%s", token_str.c_str());
775752
}
753+
776754
// Record Displayed Tokens To Log
777755
// Note: Generated tokens are created one by one hence this check
778756
if (embd.size() > 1) {
@@ -783,6 +761,7 @@ int main(int argc, char ** argv) {
783761
output_tokens.push_back(id);
784762
output_ss << token_str;
785763
}
764+
786765
fflush(stdout);
787766
}
788767
}

0 commit comments

Comments
 (0)