| 231 | |
| 232 | |
| 233 | static struct llava_context * llava_init(gpt_params * params) { |
| 234 | const char * clip_path = params->mmproj.c_str(); |
| 235 | |
| 236 | auto prompt = params->prompt; |
| 237 | if (prompt.empty()) { |
| 238 | prompt = "describe the image in detail."; |
| 239 | } |
| 240 | |
| 241 | auto ctx_clip = clip_model_load(clip_path, /*verbosity=*/ 1); |
| 242 | |
| 243 | llama_backend_init(params->numa); |
| 244 | |
| 245 | llama_model_params model_params = llama_model_params_from_gpt_params(*params); |
| 246 | |
| 247 | llama_model * model = llama_load_model_from_file(params->model.c_str(), model_params); |
| 248 | if (model == NULL) { |
| 249 | fprintf(stderr , "%s: error: unable to load model\n" , __func__); |
| 250 | return NULL; |
| 251 | } |
| 252 | |
| 253 | llama_context_params ctx_params = llama_context_params_from_gpt_params(*params); |
| 254 | ctx_params.n_ctx = params->n_ctx < 2048 ? 2048 : params->n_ctx; // we need a longer context size to process image embeddings |
| 255 | |
| 256 | llama_context * ctx_llama = llama_new_context_with_model(model, ctx_params); |
| 257 | |
| 258 | if (ctx_llama == NULL) { |
| 259 | fprintf(stderr , "%s: error: failed to create the llama_context\n" , __func__); |
| 260 | return NULL; |
| 261 | } |
| 262 | |
| 263 | auto ctx_llava = (struct llava_context *)malloc(sizeof(llava_context)); |
| 264 | |
| 265 | ctx_llava->ctx_llama = ctx_llama; |
| 266 | ctx_llava->ctx_clip = ctx_clip; |
| 267 | ctx_llava->model = model; |
| 268 | return ctx_llava; |
| 269 | } |
| 270 | |
| 271 | static void llava_free(struct llava_context * ctx_llava) { |
| 272 | if (ctx_llava->ctx_clip) { |
no test coverage detected