Skip to content

Commit 41361c8

Browse files
authored
common : move up common_init() and fix Windows UTF-8 logs (#21176)
The build info is now only for debug, so we avoid the duplicate with `--version`. The UTF-8 setup at the beginning is needed to avoid logging garbage on Windows. Signed-off-by: Adrien Gallouët <angt@huggingface.co>
1 parent 62278ce commit 41361c8

34 files changed

Lines changed: 73 additions & 55 deletions

File tree

common/common.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,11 @@ bool parse_cpu_mask(const std::string & mask, bool (&boolmask)[GGML_MAX_N_THREAD
359359
}
360360

361361
void common_init() {
362+
#if defined(_WIN32)
363+
SetConsoleOutputCP(CP_UTF8);
364+
SetConsoleCP(CP_UTF8);
365+
#endif
366+
362367
llama_log_set(common_log_default_callback, NULL);
363368

364369
#ifdef NDEBUG
@@ -367,7 +372,7 @@ void common_init() {
367372
const char * build_type = " (debug)";
368373
#endif
369374

370-
LOG_INF("build: %d (%s) with %s for %s%s\n", LLAMA_BUILD_NUMBER, LLAMA_COMMIT, LLAMA_COMPILER, LLAMA_BUILD_TARGET, build_type);
375+
LOG_DBG("build: %d (%s) with %s for %s%s\n", LLAMA_BUILD_NUMBER, LLAMA_COMMIT, LLAMA_COMPILER, LLAMA_BUILD_TARGET, build_type);
371376
}
372377

373378
std::string common_params_get_system_info(const common_params & params) {

examples/batched/batched.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ int main(int argc, char ** argv) {
2424
params.prompt = "Hello my name is";
2525
params.n_predict = 32;
2626

27+
common_init();
28+
2729
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_BATCHED, print_usage)) {
2830
return 1;
2931
}
3032

31-
common_init();
32-
3333
// number of parallel batches
3434
int n_parallel = params.n_parallel;
3535

examples/debug/debug.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ static bool run(llama_context * ctx, const common_params & params) {
213213
int main(int argc, char ** argv) {
214214
common_params params;
215215

216+
common_init();
217+
216218
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_DEBUG, print_usage)) {
217219
return 1;
218220
}
219221

220-
common_init();
221-
222222
llama_backend_init();
223223
llama_numa_init(params.numa);
224224

examples/diffusion/diffusion-cli.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,11 +545,12 @@ int main(int argc, char ** argv) {
545545

546546
common_params params;
547547

548+
common_init();
549+
548550
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_DIFFUSION)) {
549551
return 1;
550552
}
551553

552-
common_init();
553554
llama_backend_init();
554555

555556
llama_model_params model_params = llama_model_default_params();

examples/embedding/embedding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ int main(int argc, char ** argv) {
9999

100100
common_params params;
101101

102+
common_init();
103+
102104
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_EMBEDDING)) {
103105
return 1;
104106
}
105107

106-
common_init();
107-
108108
params.embedding = true;
109109

110110
// get max number of sequences per batch

examples/eval-callback/eval-callback.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ int main(int argc, char ** argv) {
3737

3838
common_params params;
3939

40+
common_init();
41+
4042
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_COMMON)) {
4143
return 1;
4244
}
4345

44-
common_init();
45-
4646
llama_backend_init();
4747
llama_numa_init(params.numa);
4848

examples/idle/idle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ static void print_usage(int /*argc*/, char ** argv) {
1919
int main(int argc, char ** argv) {
2020
common_params params;
2121

22+
common_init();
23+
2224
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_COMMON, print_usage)) {
2325
return 1;
2426
}
2527

26-
common_init();
27-
2828
// init LLM
2929

3030
llama_backend_init();

examples/lookahead/lookahead.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ int main(int argc, char ** argv) {
4343

4444
common_params params;
4545

46+
common_init();
47+
4648
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_COMMON)) {
4749
return 1;
4850
}
4951

50-
common_init();
51-
5252
const int W = 15; // lookahead window
5353
const int N = 5; // n-gram size
5454
const int G = 15; // max verification n-grams

examples/lookup/lookup-create.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ int main(int argc, char ** argv){
1212

1313
common_params params;
1414

15+
common_init();
16+
1517
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_LOOKUP)) {
1618
return 1;
1719
}

examples/lookup/lookup-stats.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ int main(int argc, char ** argv){
1818

1919
common_params params;
2020

21+
common_init();
22+
2123
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_LOOKUP)) {
2224
return 1;
2325
}
2426

25-
common_init();
26-
2727
const int n_draft = params.speculative.n_max;
2828

2929
// init llama.cpp

0 commit comments

Comments
 (0)