| 796 | } |
| 797 | |
| 798 | int32_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 | |
| 827 | int32_t mtmd_encode(mtmd_context * ctx, const mtmd_image_tokens * image_tokens) { |
| 828 | clip_ctx * ctx_clip = ctx->ctx_v; |
no test coverage detected