| 537 | } |
| 538 | |
| 539 | bool load_model(const gpt_params ¶ms_) |
| 540 | { |
| 541 | params = params_; |
| 542 | if (!params.mmproj.empty()) { |
| 543 | multimodal = true; |
| 544 | LOG_TEE("Multi Modal Mode Enabled"); |
| 545 | clp_ctx = clip_model_load(params.mmproj.c_str(), /*verbosity=*/ 1); |
| 546 | if(clp_ctx == nullptr) { |
| 547 | LOG_ERROR("unable to load clip model", {{"model", params.mmproj}}); |
| 548 | return false; |
| 549 | } |
| 550 | |
| 551 | if (params.n_ctx < 2048) { // request larger context for the image embedding |
| 552 | params.n_ctx = 2048; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | std::tie(model, ctx) = llama_init_from_gpt_params(params); |
| 557 | if (model == nullptr) |
| 558 | { |
| 559 | LOG_ERROR("unable to load model", {{"model", params.model}}); |
| 560 | return false; |
| 561 | } |
| 562 | |
| 563 | if (multimodal) { |
| 564 | const int n_embd_clip = clip_n_mmproj_embd(clp_ctx); |
| 565 | const int n_embd_llm = llama_n_embd(model); |
| 566 | if (n_embd_clip != n_embd_llm) { |
| 567 | LOG_TEE("%s: embedding dim of the multimodal projector (%d) is not equal to that of LLaMA (%d). Make sure that you use the correct mmproj file.\n", __func__, n_embd_clip, n_embd_llm); |
| 568 | llama_free(ctx); |
| 569 | llama_free_model(model); |
| 570 | return false; |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | n_ctx = llama_n_ctx(ctx); |
| 575 | |
| 576 | return true; |
| 577 | } |
| 578 | |
| 579 | void initialize() { |
| 580 | id_gen = 0; |
no test coverage detected