Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions common/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ void common_log_add(struct common_log * log, enum ggml_log_level level, const ch
va_end(args);
}

void common_log_add_v(struct common_log * log, enum ggml_log_level level, const char * fmt, va_list args) {
log->add(level, fmt, args);
}

void common_log_set_file(struct common_log * log, const char * file) {
log->set_file(file);
}
Expand Down
2 changes: 2 additions & 0 deletions common/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ void common_log_free (struct common_log * log);
LOG_ATTRIBUTE_FORMAT(3, 4)
void common_log_add(struct common_log * log, enum ggml_log_level level, const char * fmt, ...);

void common_log_add_v(struct common_log * log, enum ggml_log_level level, const char * fmt, va_list args);

// defaults: file = NULL, colors = false, prefix = false, timestamps = false
//
// regular log output:
Expand Down
1 change: 1 addition & 0 deletions ggml/include/ggml.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is needed?


#define GGML_FILE_MAGIC 0x67676d6c // "ggml"
#define GGML_FILE_VERSION 2
Expand Down
10 changes: 9 additions & 1 deletion tools/mtmd/mtmd-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ static int eval_message(mtmd_cli_context & ctx, common_chat_msg & msg) {
return 0;
}

static void mtmd_log_callback(enum ggml_log_level level, const char * fmt, ...) {
va_list args;
va_start(args, fmt);
common_log_add_v(common_log_main(), level, fmt, args);
va_end(args);
}

int main(int argc, char ** argv) {
ggml_time_init();

Expand All @@ -277,6 +284,7 @@ int main(int argc, char ** argv) {
}

common_init();
mtmd_set_log_callback(mtmd_log_callback);

if (params.mmproj.path.empty()) {
show_additional_info(argc, argv);
Expand All @@ -285,7 +293,7 @@ int main(int argc, char ** argv) {
}

mtmd_cli_context ctx(params);
LOG("%s: loading model: %s\n", __func__, params.model.path.c_str());
LOG_INF("%s: loading model: %s\n", __func__, params.model.path.c_str());

bool is_single_turn = !params.prompt.empty() && !params.image.empty();

Expand Down
20 changes: 18 additions & 2 deletions tools/mtmd/mtmd-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,24 @@
#define STB_IMAGE_IMPLEMENTATION
#include "stb/stb_image.h"

#define LOG_INF(...) fprintf(stdout, __VA_ARGS__)
#define LOG_ERR(...) fprintf(stderr, __VA_ARGS__)
static void log_callback_default(enum ggml_log_level level, const char * fmt, ...) {
va_list args;
va_start(args, fmt);
if (level >= GGML_LOG_LEVEL_ERROR) {
vfprintf(stderr, fmt, args);
} else {
vfprintf(stdout, fmt, args);
}
va_end(args);

}
static mtmd_log_callback_t log_callback = log_callback_default;

void mtmd_set_log_callback(mtmd_log_callback_t callback) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void mtmd_set_log_callback(mtmd_log_callback_t callback) {
void mtmd_helper_set_log_callback(mtmd_helper_log_callback_t callback) {

log_callback = callback;
}
#define LOG_INF(...) (*log_callback)(GGML_LOG_LEVEL_INFO, __VA_ARGS__)
#define LOG_ERR(...) (*log_callback)(GGML_LOG_LEVEL_ERROR, __VA_ARGS__)

size_t mtmd_helper_get_n_tokens(const mtmd_input_chunks * chunks) {
size_t n_tokens = 0;
Expand Down
3 changes: 3 additions & 0 deletions tools/mtmd/mtmd-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ MTMD_API int32_t mtmd_helper_decode_image_chunk(mtmd_context * ctx,
int32_t n_batch,
llama_pos * new_n_past);

typedef void (*mtmd_log_callback_t)(enum ggml_log_level level, const char * fmt, ...);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, prefix everything with mtmd_helper

MTMD_API void mtmd_set_log_callback(mtmd_log_callback_t callback);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down