Skip to content

Commit 7998b11

Browse files
authored
Merge pull request mozilla-ai#742 from cjpais/localscore-plaintext
Add Plaintext output option to LocalScore + Respect NO_COLOR env var
2 parents cf1cc74 + d108545 commit 7998b11

File tree

6 files changed

+74
-64
lines changed

6 files changed

+74
-64
lines changed

localscore/ascii_digits.h

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -51,44 +51,6 @@ inline void printLargeNumber(int number) {
5151
}
5252
}
5353

54-
// inline void print_logo() {
55-
// std::cout <<
56-
// "██ ██████ ██████ █████ ██ \n"
57-
// "██ ██ ██ ██ ██ ██ ██ \n"
58-
// "██ ██ ██ ██ ███████ ██ \n"
59-
// "██ ██ ██ ██ ██ ██ ██ \n"
60-
// "███████ ██████ ██████ ██ ██ ███████ \n"
61-
// " \n"
62-
// "███████ ██████ ██████ ██████ ███████ \n"
63-
// "██ ██ ██ ██ ██ ██ ██ \n"
64-
// "███████ ██ ██ ██ ██████ █████ \n"
65-
// " ██ ██ ██ ██ ██ ██ ██ \n"
66-
// "███████ ██████ ██████ ██ ██ ███████ \n"
67-
// "\n"
68-
// "---------------------------------------- \n";
69-
// }
70-
71-
72-
73-
// inline void print_logo() {
74-
// std::cout <<
75-
// " ___ ________ ________ ________ ___ \n"
76-
// "|\\ \\ |\\ __ \\|\\ ____\\|\\ __ \\|\\ \\ \n"
77-
// "\\ \\ \\ \\ \\ \\|\\ \\ \\ \\___|\\ \\|\\ \\ \\ \\ \n"
78-
// " \\ \\ \\ \\ \\ \\\\\\ \\ \\ \\ \\ \\ __ \\ \\ \\ \n"
79-
// " \\ \\ \\____\\ \\ \\\\\\ \\ \\ \\____\\ \\ \\ \\ \\ \\ \\____ \n"
80-
// " \\ \\_______\\ \\_______\\ \\_______\\ \\__\\ \\__\\ \\_______\\\n"
81-
// " \\|_______|\\|_______|\\|_______|\\|__|\\|__|\\|_______|\n"
82-
// " ________ ________ ________ ________ _______ \n"
83-
// "|\\ ____\\|\\ ____\\|\\ __ \\|\\ __ \\|\\ ___ \\ \n"
84-
// "\\ \\ \\___|\\ \\___|\\ \\|\\ \\ \\ \\|\\ \\ \\ __/| \n"
85-
// " \\ \\_____ \\ \\ \\ \\ \\ \\\\\\ \\ \\ _ _\\ \\ \\_|/__ \n"
86-
// " \\|____|\\ \\ \\ \\____\\ \\ \\\\\\ \\ \\ \\\\ \\\\ \\ \\_|\\ \\ \n"
87-
// " ____\\_\\ \\ \\_______\\ \\_______\\ \\__\\\\ _\\\\ \\_______\\\n"
88-
// " |\\_________\\|_______|\\|_______|\\|__|\\|__|\\|_______|\n"
89-
// " \\|_________| \n";
90-
// }
91-
9254
inline void print_logo() {
9355
std::cout << " __ ____ _________ __ _____ __________ ____ ______\n"
9456
<< " / / / __ \\/ ____/ | / / / ___// ____/ __ \\/ __ \\/ ____/\n"

localscore/cmd.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static const cmd_params cmd_params_defaults = {
2626
/* numa */ GGML_NUMA_STRATEGY_DISABLED,
2727
/* reps */ 1,
2828
/* verbose */ false,
29+
/* plaintext */ false,
2930
/* send_results */ SEND_ASK,
3031
/* output_format */ CONSOLE,
3132
};
@@ -126,6 +127,8 @@ cmd_params parse_cmd_params(int argc, char ** argv) {
126127
}
127128
} else if (arg == "-v" || arg == "--verbose") {
128129
params.verbose = true;
130+
} else if (arg == "--plaintext") {
131+
params.plaintext = true;
129132
} else if (arg == "-y" || arg == "--send-results") {
130133
params.send_results = SEND_YES;
131134
} else if (arg == "-n" || arg == "--no-send-results") {
@@ -186,13 +189,14 @@ void print_usage(int /* argc */, char ** argv) {
186189
printf("\n");
187190
printf("options:\n");
188191
printf(" -h, --help\n");
189-
printf(" -m, --model <filename> (default: %s)\n", cmd_params_defaults.model.c_str());
192+
printf(" -m, --model <filename>\n");
190193
printf(" -c, --cpu disable GPU acceleration (alias for --gpu=disabled)\n");
191194
printf(" -g, --gpu <auto|amd|apple|nvidia|disabled> (default: \"auto\")\n");
192195
printf(" -i, --gpu-index <i> select GPU by index (default: %d)\n", cmd_params_defaults.main_gpu);
193196
printf(" --list-gpus list available GPUs and exit\n");
194197
printf(" -o, --output <csv|json|console> (default: %s)\n", output_format_str(cmd_params_defaults.output_format));
195-
printf(" -v, --verbose verbose output (default: %s)\n", cmd_params_defaults.verbose ? "yes" : "no");
198+
printf(" -v, --verbose verbose output (default: %s)\n", cmd_params_defaults.verbose ? "on" : "off");
199+
printf(" --plaintext plaintext output (default: %s)\n", cmd_params_defaults.plaintext ? "on" : "off");
196200
printf(" -y, --send-results send results without confirmation\n");
197201
printf(" -n, --no-send-results disable sending results\n");
198202
printf(" -e, --extended run 4 reps (shortcut for --reps=4)\n");

localscore/cmd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct cmd_params {
2828
ggml_numa_strategy numa;
2929
int reps;
3030
bool verbose;
31+
bool plaintext;
3132
send_results_mode send_results;
3233
output_formats output_format;
3334

localscore/localscore.cpp

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "cmd.h"
3535
#include "benchmark.h"
3636
#include "printer.h"
37+
#include "utils.h"
3738

3839
#include "localscore.h"
3940

@@ -336,16 +337,43 @@ static LocalScoreResultsSummary getResultsSummary(Json data) {
336337
return rs;
337338
}
338339

339-
static void displayResults(LocalScoreResultsSummary results_summary) {
340-
printf("\n\033[1;35m");
341-
ascii_display::print_logo();
342-
printf("\n");
343-
ascii_display::printLargeNumber((int)results_summary.performance_score);
344-
printf("\033[0m\n");
345-
printf("\033[32mToken Generation: \t \033[1;32m%.2f\033[0m \033[3;32mtok/s\033[0m\n", results_summary.avg_gen_tps);
346-
printf("\033[36mPrompt Processing: \t \033[1;36m%.2f\033[0m \033[3;36mtok/s\033[0m\n", results_summary.avg_prompt_tps);
347-
printf("\033[33mTime to First Token:\t \033[1;33m%.2f\033[0m \033[3;33mms\033[0m\n", results_summary.avg_ttft_ms);
348-
printf("\033[0m");
340+
static void displayResults(LocalScoreResultsSummary results_summary, bool plaintext) {
341+
342+
printf("\n%s", utils::color_str("\033[1;35m"));
343+
if (!plaintext) {
344+
ascii_display::print_logo();
345+
printf("\n");
346+
ascii_display::printLargeNumber((int)results_summary.performance_score);
347+
} else {
348+
printf("LocalScore: \t\t %d", (int)results_summary.performance_score);
349+
}
350+
printf("%s\n", utils::color_str("\033[0m"));
351+
352+
printf("%sToken Generation: \t %s%.2f%s %stok/s%s\n",
353+
utils::color_str("\033[32m"),
354+
utils::color_str("\033[1;32m"),
355+
results_summary.avg_gen_tps,
356+
utils::color_str("\033[0m"),
357+
utils::color_str("\033[3;32m"),
358+
utils::color_str("\033[0m"));
359+
360+
printf("%sPrompt Processing: \t %s%.2f%s %stok/s%s\n",
361+
utils::color_str("\033[36m"),
362+
utils::color_str("\033[1;36m"),
363+
results_summary.avg_prompt_tps,
364+
utils::color_str("\033[0m"),
365+
utils::color_str("\033[3;36m"),
366+
utils::color_str("\033[0m"));
367+
368+
printf("%sTime to First Token:\t %s%.2f%s %sms%s\n",
369+
utils::color_str("\033[33m"),
370+
utils::color_str("\033[1;33m"),
371+
results_summary.avg_ttft_ms,
372+
utils::color_str("\033[0m"),
373+
utils::color_str("\033[3;33m"),
374+
utils::color_str("\033[0m"));
375+
376+
printf("%s", utils::color_str("\033[0m"));
349377
}
350378

351379
struct SystemData {
@@ -474,7 +502,7 @@ void process_and_submit_results(const std::string& req_payload, const cmd_params
474502
exit(1);
475503
}
476504
LocalScoreResultsSummary rs = getResultsSummary(data);
477-
displayResults(rs);
505+
displayResults(rs, params.plaintext);
478506

479507
Json results_summary;
480508
results_summary.setObject();

localscore/system.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ void get_runtime_info(RuntimeInfo* info) {
158158
strncpy(info->llamafile_version, LLAMAFILE_VERSION_STRING, MAX_STRING_LENGTH - 1);
159159
strncpy(info->llama_commit, LLAMA_COMMIT, MAX_STRING_LENGTH - 1);
160160

161-
fprintf(stderr, "\033[0;35m\n"); // Sets purple color
162-
utils::print_centered(stderr, 70, '=', "\033[1mLocalScore Runtime Information\033[0;35m");
161+
fprintf(stderr, "%s\n", utils::color_str("\033[0;35m")); // Sets purple color
162+
utils::print_centered(stderr, 70, '=', "%sLocalScore Runtime Information%s", utils::color_str("\033[1m"), utils::color_str("\033[0;35m"));
163163
fprintf(stderr, "\n");
164-
fprintf(stderr, "%-20s \033[1m%s\033[22m\n", "llamafile version:", info->llamafile_version);
164+
fprintf(stderr, "%-20s %s%s%s\n", "llamafile version:", utils::color_str("\033[1m"), info->llamafile_version, utils::color_str("\033[22m"));
165165
fprintf(stderr, "%-20s %s\n", "llama.cpp commit:", info->llama_commit);
166-
fprintf(stderr, "\n======================================================================\n\n\033[0m");
166+
fprintf(stderr, "\n======================================================================\n\n%s", utils::color_str("\033[0m"));
167167
}
168168

169169
double get_mem_gb() {
@@ -194,7 +194,7 @@ void get_sys_info(SystemInfo* info) {
194194

195195
info->ram_gb = get_mem_gb();
196196

197-
utils::print_centered(stderr, 70, '=', "\033[1mSystem Information\033[0m");
197+
utils::print_centered(stderr, 70, '=', "%sSystem Information%s", utils::color_str("\033[1m"), utils::color_str("\033[0m"));
198198
fprintf(stderr, "\n");
199199
fprintf(stderr, "%-20s %s\n", "Kernel Type:", info->kernel_type);
200200
fprintf(stderr, "%-20s %s\n", "Kernel Release:", info->kernel_release);
@@ -232,11 +232,11 @@ void get_accelerator_info(AcceleratorInfo* info, cmd_params * params) {
232232
}
233233

234234
if (i == params->main_gpu) {
235-
fprintf(stderr, "\033[0;32m"); // Sets green color
236-
utils::print_centered(stderr, 70, '=', "\033[1mActive GPU (GPU %d) Information\033[0;32m", i);
235+
fprintf(stderr, "%s", utils::color_str("\033[0;32m")); // Sets green color
236+
utils::print_centered(stderr, 70, '=', "%sActive GPU (GPU %d) Information%s", utils::color_str("\033[1m"), i, utils::color_str("\033[0;32m"));
237237
fprintf(stderr, "\n");
238238
} else {
239-
fprintf(stderr, "\033[0;90m"); // Sets gray color
239+
fprintf(stderr, "%s", utils::color_str("\033[0;90m")); // Sets gray color
240240
utils::print_centered(stderr, 70, '=', "GPU %d Information", i);
241241
fprintf(stderr, "\n");
242242
}
@@ -245,7 +245,7 @@ void get_accelerator_info(AcceleratorInfo* info, cmd_params * params) {
245245
fprintf(stderr, "%-26s %.1f GiB\n", "VRAM:", rounded_memory_gb);
246246
fprintf(stderr, "%-26s %d\n", "Streaming Multiprocessors:", props.multiProcessorCount);
247247
fprintf(stderr, "%-26s %.1f\n", "CUDA Capability:", atof(props.compute));
248-
fprintf(stderr, "\n======================================================================\n\n\033[0m");
248+
fprintf(stderr, "\n======================================================================\n\n%s", utils::color_str("\033[0m"));
249249
}
250250
}
251251

@@ -276,14 +276,14 @@ void get_accelerator_info(AcceleratorInfo* info, cmd_params * params) {
276276
strncpy(info->manufacturer, "Apple", MAX_STRING_LENGTH - 1);
277277

278278

279-
fprintf(stderr, "\033[0;32m===== GPU information =====\n\n");
279+
fprintf(stderr, "%s===== GPU information =====\n\n", utils::color_str("\033[0;32m"));
280280
fprintf(stderr, "%-26s %s\n", "GPU Name:", props.name);
281281
fprintf(stderr, "%-26s %.1f GiB\n", "VRAM:", info->total_memory_gb);
282282
fprintf(stderr, "%-26s %d\n", "Core Count:", props.core_count);
283283
fprintf(stderr, "%-26s %d\n", "Metal Version:", props.metal_version);
284284
fprintf(stderr, "%-26s %d\n", "GPU Family:", props.gpu_family);
285285
fprintf(stderr, "%-26s %d\n", "Common GPU Family:", props.gpu_family_common);
286-
fprintf(stderr, "\n======================================================================\n\n\033[0m");
286+
fprintf(stderr, "\n======================================================================\n\n%s", utils::color_str("\033[0m"));
287287
}
288288
} else {
289289
#ifdef __x86_64__
@@ -306,7 +306,7 @@ void list_available_accelerators() {
306306
fprintf(stderr, "Apple Metal\n");
307307
} else if (llamafile_has_cuda()) {
308308
int count = ggml_backend_cuda_get_device_count();
309-
fprintf(stderr, "\n\033[0;32m==================== Available GPUs ====================\n\n");
309+
fprintf(stderr, "\n%s==================== Available GPUs ====================\n\n", utils::color_str("\033[0;32m"));
310310
for (int i = 0; i < count; i++) {
311311
struct ggml_cuda_device_properties props;
312312
ggml_backend_cuda_get_device_properties(i, &props);
@@ -318,7 +318,7 @@ void list_available_accelerators() {
318318
} else {
319319
fprintf(stderr, "No Accelerator support available\n");
320320
}
321-
fprintf(stderr, "\n======================================================================\n\033[0m");
321+
fprintf(stderr, "\n======================================================================\n%s", utils::color_str("\033[0m"));
322322
}
323323

324324
void get_model_info(ModelInfo *info, llama_model *model) {

localscore/utils.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <memory>
1212
#include <array>
1313
#include <cstdio>
14+
#include <cstring>
1415
#include <stdexcept>
1516
#include <string.h>
1617
#include <stdarg.h>
@@ -185,6 +186,20 @@ namespace utils {
185186
return round(value * multiplier) / multiplier;
186187
}
187188

189+
inline bool should_use_color() {
190+
const char* no_color = getenv("NO_COLOR");
191+
if (no_color != NULL && no_color[0] != '0' && no_color[0] != '\0') {
192+
return false;
193+
}
194+
return true;
195+
}
196+
197+
inline const char* color_str(const char* color_code) {
198+
if (should_use_color()) {
199+
return color_code;
200+
}
201+
return "";
202+
}
188203

189204
} // namespace utils
190205

0 commit comments

Comments
 (0)