| 48 | } |
| 49 | |
| 50 | int main(int argc, char ** argv) { |
| 51 | std::setlocale(LC_NUMERIC, "C"); |
| 52 | |
| 53 | ggml_time_init(); |
| 54 | |
| 55 | common_params params; |
| 56 | |
| 57 | common_init(); |
| 58 | |
| 59 | if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_MTMD, show_additional_info)) { |
| 60 | return 1; |
| 61 | } |
| 62 | |
| 63 | mtmd_helper_log_set(common_log_default_callback, nullptr); |
| 64 | |
| 65 | if (params.mmproj.path.empty()) { |
| 66 | show_additional_info(argc, argv); |
| 67 | LOG_ERR("ERR: Missing --mmproj argument\n"); |
| 68 | return 1; |
| 69 | } |
| 70 | |
| 71 | LOG_INF("%s: loading model: %s\n", __func__, params.model.path.c_str()); |
| 72 | |
| 73 | mtmd::context_ptr ctx_mtmd; |
| 74 | common_init_result_ptr llama_init; |
| 75 | base_callback_data cb_data; |
| 76 | |
| 77 | llama_init = common_init_from_params(params); |
| 78 | { |
| 79 | auto * model = llama_init->model(); |
| 80 | const char * clip_path = params.mmproj.path.c_str(); |
| 81 | mtmd_context_params mparams = mtmd_context_params_default(); |
| 82 | mparams.use_gpu = params.mmproj_use_gpu; |
| 83 | mparams.print_timings = true; |
| 84 | mparams.n_threads = params.cpuparams.n_threads; |
| 85 | mparams.flash_attn_type = params.flash_attn_type; |
| 86 | mparams.warmup = params.warmup; |
| 87 | mparams.image_min_tokens = params.image_min_tokens; |
| 88 | mparams.image_max_tokens = params.image_max_tokens; |
| 89 | { |
| 90 | // always enable debug callback |
| 91 | mparams.cb_eval_user_data = &cb_data; |
| 92 | mparams.cb_eval = common_debug_cb_eval<false>; |
| 93 | } |
| 94 | ctx_mtmd.reset(mtmd_init_from_file(clip_path, model, mparams)); |
| 95 | if (!ctx_mtmd.get()) { |
| 96 | LOG_ERR("Failed to load vision model from %s\n", clip_path); |
| 97 | exit(1); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | std::string input; |
| 102 | int32_t inp_size = params.n_predict; |
| 103 | if (params.image.empty()) { |
| 104 | LOG_ERR("ERR: At least one of --image or --audio must be specified\n"); |
| 105 | return 1; |
| 106 | } |
| 107 | if (inp_size <= 0) { |
nothing calls this directly
no test coverage detected