diff --git a/gpttype_adapter.cpp b/gpttype_adapter.cpp index e76ecd537..73859820a 100644 --- a/gpttype_adapter.cpp +++ b/gpttype_adapter.cpp @@ -121,7 +121,6 @@ static llama_context * guidance_ctx = nullptr; //for classifier free guidance, w static mtmd_context * mtmd_ctx = nullptr; //for multimodal media static std::vector media_objects; static std::vector last_media_mem; //for storing dummy tokens that will be consumed by mtmd -static int last_media_pos_count = 0; static std::string media_composite_image_signature = ""; //for identifying when the media changes, we need to invalidate the cache static int current_media_identifier = MEDIA_TOKEN_IDENTIFIER_A; static int vision_max_res = 2048; @@ -4464,7 +4463,6 @@ static void PrepareMediaEmbds(const int nctx, const std::vector & media_int int introsize = media_intro.size(); int outrosize = media_outro.size(); last_media_mem.clear(); - last_media_pos_count = 0; for(int i=0;i & media_int } int mediatokensneeded = 0; - int mediaposneeded = 0; const int boundarytokensneeded = media_objects[i].chunk_start_seq.size() + media_objects[i].chunk_end_seq.size(); for(size_t j=0;j & media_int media_chunk chunk; chunk.is_audio = media_objects[i].is_audio; chunk.mtmd_chunk = mtmd_input_chunk_copy(mtmdchunk); - chunk.clp_image_tokens = mtmd_input_chunk_get_n_tokens(mtmdchunk); - chunk.clp_image_positions = mtmd_input_chunk_get_n_pos(mtmdchunk); + chunk.clp_image_tokens = mtmd_input_chunk_get_n_pos(mtmdchunk); mediatokensneeded += chunk.clp_image_tokens; - mediaposneeded += chunk.clp_image_positions; media_objects[i].mediachunks.push_back(chunk); } + mediatokensneeded += boundarytokensneeded; if(debugmode==1 && !is_quiet) { - printf("\nMTMD Media %i used Tokens: %d, Positions: %d, Boundary Tokens: %d",i,mediatokensneeded,mediaposneeded,boundarytokensneeded); + printf("\nMTMD Media %i used Tokens: %d",i,mediatokensneeded); } - int mediactxneeded = std::max(mediatokensneeded, mediaposneeded) + boundarytokensneeded; - if(i==0) + if(mediatokensneeded>0 && mediatokensneeded < nctx) { - mediactxneeded += introsize + outrosize; - } - if(mediatokensneeded>0 && mediactxneeded < nctx) - { - int tokcnt = mediatokensneeded + boundarytokensneeded; - int poscnt = mediaposneeded + boundarytokensneeded; + int tokcnt = mediatokensneeded; if(i==0) { tokcnt += introsize + outrosize; - poscnt += introsize + outrosize; } for(int n=0;n0) //stick the media placeholders before the added mem { - int media_context_size = std::max((int)last_media_mem.size(), last_media_pos_count); - if(media_context_size + kcpp_data->n_predict + 4 > nctx) + if(last_media_mem.size() + kcpp_data->n_predict + 4 > nctx) { printf("\nWarning: Too many multimodal tokens, max context exceeded! They will be ignored!\n"); } diff --git a/otherarch/otherarch.h b/otherarch/otherarch.h index 39742510d..18511aaef 100644 --- a/otherarch/otherarch.h +++ b/otherarch/otherarch.h @@ -514,7 +514,6 @@ struct media_chunk bool is_audio = false; //if true its audio, otherwise its vision void * mtmd_chunk = nullptr; // mtmd_input_chunk, owned by this chunk int32_t clp_image_tokens = 0; //holds number of tokens used in this chunk - int32_t clp_image_positions = 0; //holds number of KV positions used in this chunk int32_t nx = 0; //only used for 2d roped images int32_t ny = 0; };