Skip to content

Commit

Permalink
speculative : support --color (ggerganov#4343)
Browse files Browse the repository at this point in the history
* speculative: add some colors

* minor : add braces

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
  • Loading branch information
stduhpf and ggerganov authored Dec 6, 2023
1 parent 5f6e0c0 commit da5eaef
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions examples/speculative/speculative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,9 @@ int main(int argc, char ** argv) {

const std::string token_str = llama_token_to_piece(ctx_tgt, id);

printf("%s", token_str.c_str());
fflush(stdout);
if (!params.use_color) {
printf("%s", token_str.c_str());
}

if (id == llama_token_eos(model_tgt)) {
has_eos = true;
Expand Down Expand Up @@ -236,10 +237,18 @@ int main(int argc, char ** argv) {
++n_past_tgt;
++n_past_dft;
++i_dft;

if (params.use_color) {
// Color token according to its origin sequence
printf("\u001b[%dm%s\u001b[37m", (36 - s_keep % 6), token_str.c_str());
fflush(stdout);
}
continue;
}
}
if (params.use_color) {
printf("%s", token_str.c_str());
}
fflush(stdout);

LOG("the sampled target token (%d, '%s') did not match, or we ran out of drafted tokens\n", id, token_str.c_str());

Expand Down

0 comments on commit da5eaef

Please sign in to comment.