18
18
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
19
19
#include < signal.h>
20
20
#include < unistd.h>
21
- #include < fcntl.h>
22
- #define SPECIAL_FILENO 3
23
21
#elif defined (_WIN32)
24
22
#define WIN32_LEAN_AND_MEAN
25
23
#ifndef NOMINMAX
@@ -120,16 +118,6 @@ static void llama_log_callback_logTee(ggml_log_level level, const char * text, v
120
118
}
121
119
122
120
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
-
133
121
gpt_params params;
134
122
g_params = ¶ms;
135
123
@@ -138,8 +126,6 @@ int main(int argc, char ** argv) {
138
126
}
139
127
llama_sampling_params & sparams = params.sparams ;
140
128
141
- const bool control_token_allowed_on_standard_stream = !params.conversation && sparams.grammar .empty ();
142
-
143
129
#ifndef LOG_DISABLE_LOGS
144
130
log_set_target (log_filename_generator (" main" , " log" ));
145
131
LOG_TEE (" Log start\n " );
@@ -760,19 +746,11 @@ int main(int argc, char ** argv) {
760
746
if (!llama_token_is_control (llama_get_model (ctx), id)) {
761
747
// Stream Output Token To Standard Output
762
748
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 ());
775
752
}
753
+
776
754
// Record Displayed Tokens To Log
777
755
// Note: Generated tokens are created one by one hence this check
778
756
if (embd.size () > 1 ) {
@@ -783,6 +761,7 @@ int main(int argc, char ** argv) {
783
761
output_tokens.push_back (id);
784
762
output_ss << token_str;
785
763
}
764
+
786
765
fflush (stdout);
787
766
}
788
767
}
0 commit comments