MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / mtmd_encode

Function mtmd_encode

smallthinker/tools/mtmd/mtmd.cpp:767–797  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

765}
766
767int32_t mtmd_encode(mtmd_context * ctx, const mtmd_image_tokens * image_tokens) {
768 clip_ctx * ctx_clip = ctx->ctx_v;
769 if (!ctx_clip) {
770 LOG_ERR("%s: this API does not support non-vision input, please use mtmd_encode_chunk instead\n", __func__);
771 return 1;
772 }
773 int n_mmproj_embd = clip_n_mmproj_embd(ctx_clip);
774 ctx->image_embd_v.resize(image_tokens->n_tokens() * n_mmproj_embd);
775 bool ok = false;
776
777 if (clip_is_llava(ctx_clip) || clip_is_minicpmv(ctx_clip) || clip_is_glm(ctx_clip)) {
778 // TODO @ngxson : llava does not support batched encoding ; this should be fixed inside clip_image_batch_encode()
779 const auto & entries = image_tokens->batch_f32.entries;
780 for (size_t i = 0; i < entries.size(); i++) {
781 int n_tokens_per_image = clip_n_output_tokens(ctx_clip, entries[i].get());
782 ok = clip_image_encode(
783 ctx_clip,
784 ctx->n_threads,
785 entries[i].get(),
786 ctx->image_embd_v.data() + i*n_mmproj_embd*n_tokens_per_image);
787 }
788 } else {
789 ok = clip_image_batch_encode(
790 ctx_clip,
791 ctx->n_threads,
792 &image_tokens->batch_f32,
793 ctx->image_embd_v.data());
794 }
795
796 return ok ? 0 : 1;
797}
798
799float * mtmd_get_output_embd(mtmd_context * ctx) {
800 return ctx->image_embd_v.data();

Callers 1

mtmd_encode_chunkFunction · 0.85

Calls 12

clip_is_llavaFunction · 0.85
clip_is_minicpmvFunction · 0.85
clip_is_glmFunction · 0.85
clip_n_output_tokensFunction · 0.85
clip_n_mmproj_embdFunction · 0.70
clip_image_encodeFunction · 0.70
clip_image_batch_encodeFunction · 0.70
resizeMethod · 0.45
n_tokensMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected