Skip to content
Merged
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
10 changes: 7 additions & 3 deletions examples/omni-vlm/omni-vlm-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include <cstdlib>
#include <cstring>
#include <vector>
// #include <iostream>
//
// using std::cout;
// using std::endl;

static bool eval_tokens(struct llama_context * ctx_llama, std::vector<llama_token> tokens, int n_batch, int * n_past) {
int N = (int) tokens.size();
Expand Down Expand Up @@ -283,9 +287,9 @@ int main(int argc, char ** argv) {
return 1;
}

auto * ctx_omnivlm = omnivlm_init_context(&params, model);

for (auto & image : params.image) {
auto * ctx_omnivlm = omnivlm_init_context(&params, model);
auto * image_embed = load_image(ctx_omnivlm, &params, image);
if (!image_embed) {
LOG_TEE("%s: failed to load image %s. Terminating\n\n", __func__, image.c_str());
Expand All @@ -296,9 +300,9 @@ int main(int argc, char ** argv) {

llama_print_timings(ctx_omnivlm->ctx_llama);
omnivlm_image_embed_free(image_embed);
ctx_omnivlm->model = NULL;
omnivlm_free(ctx_omnivlm);
}
ctx_omnivlm->model = NULL;
omnivlm_free(ctx_omnivlm);

llama_free_model(model);

Expand Down
6 changes: 5 additions & 1 deletion examples/omni-vlm/omni-vlm-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,11 @@ void omnivlm_init(const char* llm_model_path, const char* projector_model_path,
fprintf(stderr, "%s: error: failed to init omnivlm model\n", __func__);
throw std::runtime_error("Failed to init omnivlm model");
}
ctx_omnivlm = omnivlm_init_context(&params, model);
}

const char* omnivlm_inference(const char *prompt, const char *imag_path) {
ctx_omnivlm = omnivlm_init_context(&params, model);

std::string image = imag_path;
params.prompt = prompt;

Expand All @@ -270,6 +271,9 @@ const char* omnivlm_inference(const char *prompt, const char *imag_path) {

// llama_perf_print(ctx_omnivlm->ctx_llama, LLAMA_PERF_TYPE_CONTEXT);
omnivlm_image_embed_free(image_embed);
ctx_omnivlm->model = nullptr;
omnivlm_free(ctx_omnivlm);
ctx_omnivlm = nullptr;

return ret_chars;
}
Expand Down