MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / mtmd_encode_chunk

Function mtmd_encode_chunk

subprojects/llama.cpp/tools/mtmd/mtmd.cpp:798–825  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

796}
797
798int32_t mtmd_encode_chunk(mtmd_context * ctx, const mtmd_input_chunk * chunk) {
799 if (chunk->type == MTMD_INPUT_CHUNK_TYPE_TEXT) {
800 LOG_WRN("mtmd_encode_chunk has no effect for text chunks\n");
801 return 0;
802 } else if (chunk->type == MTMD_INPUT_CHUNK_TYPE_IMAGE) {
803 if (!ctx->ctx_v) {
804 LOG_ERR("%s: model does not support vision input\n", __func__);
805 return 1;
806 }
807 return mtmd_encode(ctx, chunk->tokens_image.get());
808 } else if (chunk->type == MTMD_INPUT_CHUNK_TYPE_AUDIO) {
809 if (!ctx->ctx_a) {
810 LOG_ERR("%s: model does not support audio input\n", __func__);
811 return 1;
812 }
813 int n_mmproj_embd = ctx->n_embd_text;
814 ctx->image_embd_v.resize(chunk->tokens_audio->n_tokens * n_mmproj_embd);
815 bool ok = clip_image_batch_encode(
816 ctx->ctx_a,
817 ctx->n_threads,
818 &chunk->tokens_audio->batch_f32,
819 ctx->image_embd_v.data());
820 return ok ? 0 : 1;
821 }
822
823 LOG_ERR("%s: unknown chunk type %d\n", __func__, (int)chunk->type);
824 return 1;
825}
826
827int32_t mtmd_encode(mtmd_context * ctx, const mtmd_image_tokens * image_tokens) {
828 clip_ctx * ctx_clip = ctx->ctx_v;

Callers 1

Calls 5

mtmd_encodeFunction · 0.85
clip_image_batch_encodeFunction · 0.85
getMethod · 0.65
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected