Skip to content

Commit 8341a25

Browse files
staviqggerganov
andauthored
main : log file (#2748)
* initial, base LOG macro * add *.log to .gitignore * added basic log file handler * reverted log auto endline to better mimic printf * remove atomics and add dynamic log target * log_enable/disable, LOG_TEE, basic usage doc * update .gitignore * mv include to common, params, help msg * log tostring helpers, token vectors pretty prints * main: replaced fprintf/LOG_TEE, some trace logging * LOG_DISABLE_LOGS compile flag, wrapped f in macros * fix LOG_TEELN and configchecker * stub LOG_DUMP_CMDLINE for WIN32 for now * fix msvc * cleanup main.cpp:273 * fix stray whitespace after master sync * log : fix compile warnings - do not use C++20 stuff - use PRIu64 to print uint64_t - avoid string copies by using const ref - fix ", ##__VA_ARGS__" warnings - compare strings with == and != * log : do not append to existing log + disable file line func by default * log : try to fix Windows build * main : wip logs * main : add trace log * review: macro f lowercase, str append to sstream * review: simplify ifs and str comparisons * fix MSVC, formatting, FMT/VAL placeholders * review: if/else cleanup * review: if/else cleanup (2) * replace _ prefix with _impl suffix --------- Co-authored-by: Georgi Gerganov <[email protected]>
1 parent 8494089 commit 8341a25

File tree

7 files changed

+859
-107
lines changed

7 files changed

+859
-107
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.bin
66
*.exe
77
*.dll
8+
*.log
89
.DS_Store
910
.build/
1011
.cache/

Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@ k_quants.o: k_quants.c k_quants.h
326326
$(CC) $(CFLAGS) -c $< -o $@
327327
endif # LLAMA_NO_K_QUANTS
328328

329+
ifdef LLAMA_DISABLE_LOGS
330+
CFLAGS += -DLOG_DISABLE_LOGS
331+
CXXFLAGS += -DLOG_DISABLE_LOGS
332+
endif # LLAMA_DISABLE_LOGS
333+
329334
#
330335
# Print build information
331336
#
@@ -356,7 +361,7 @@ OBJS += ggml-alloc.o
356361
llama.o: llama.cpp ggml.h ggml-alloc.h ggml-cuda.h ggml-metal.h llama.h
357362
$(CXX) $(CXXFLAGS) -c $< -o $@
358363

359-
common.o: common/common.cpp common/common.h build-info.h
364+
common.o: common/common.cpp common/common.h build-info.h common/log.h
360365
$(CXX) $(CXXFLAGS) -c $< -o $@
361366

362367
console.o: common/console.cpp common/console.h

common/common.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,9 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
480480
}
481481
} else if (arg == "-h" || arg == "--help") {
482482
gpt_print_usage(argc, argv, default_params);
483+
#ifndef LOG_DISABLE_LOGS
484+
log_print_usage();
485+
#endif // LOG_DISABLE_LOGS
483486
exit(0);
484487
} else if (arg == "--random-prompt") {
485488
params.random_prompt = true;
@@ -519,6 +522,25 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
519522
std::istreambuf_iterator<char>(),
520523
std::back_inserter(params.grammar)
521524
);
525+
#ifndef LOG_DISABLE_LOGS
526+
// Parse args for logging parameters
527+
} else if ( log_param_single_parse( argv[i] ) ) {
528+
// Do nothing, log_param_single_parse automatically does it's thing
529+
// and returns if a match was found and parsed.
530+
} else if ( log_param_pair_parse( /*check_but_dont_parse*/ true, argv[i] ) ) {
531+
// We have a matching known parameter requiring an argument,
532+
// now we need to check if there is anything after this argv
533+
// and flag invalid_param or parse it.
534+
if (++i >= argc) {
535+
invalid_param = true;
536+
break;
537+
}
538+
if( !log_param_pair_parse( /*check_but_dont_parse*/ false, argv[i-1], argv[i]) ) {
539+
invalid_param = true;
540+
break;
541+
}
542+
// End of Parse args for logging parameters
543+
#endif // LOG_DISABLE_LOGS
522544
} else {
523545
fprintf(stderr, "error: unknown argument: %s\n", arg.c_str());
524546
gpt_print_usage(argc, argv, default_params);

common/common.h

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
#include "llama.h"
66

7+
#define LOG_NO_FILE_LINE_FUNCTION
8+
#include "log.h"
9+
710
#include <string>
811
#include <vector>
912
#include <random>

0 commit comments

Comments
 (0)