Skip to content

Commit b7cbdbd

Browse files
committed
fix ci to beam search and cancel with image both work
1 parent cb2cdec commit b7cbdbd

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/cpp/src/lm_encoding.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,8 @@ void align_kv_cache_and_history(const ov::Tensor& new_chat_tokens, utils::KVCach
343343
size_t first_diverse_tokens_idx = ov::genai::utils::get_first_history_difference(new_chat_tokens, state);
344344
// in the case of beam_search the longest answer is in the kv cache, but the best one is needed
345345
// so generated tokens were not added to KVCacheState and num_tokens_to_trim was set to the size of the generated serquence
346-
kv_cache_state.num_tokens_to_trim = kv_cache_state.num_tokens_to_trim > 0 ? kv_cache_state.num_tokens_to_trim : (state.size() - first_diverse_tokens_idx);
347-
OPENVINO_ASSERT(state.size() >= kv_cache_state.num_tokens_to_trim, "Size of kv cache is less then amount of tokens, which should be trimmed from kv cache.");
348-
state.resize(state.size() - kv_cache_state.num_tokens_to_trim);
346+
kv_cache_state.num_tokens_to_trim += state.size() - first_diverse_tokens_idx;
347+
state.resize(first_diverse_tokens_idx);
349348
kv_cache_state.reset_mem_state = state.empty();
350349
}
351350

src/cpp/src/visual_language/inputs_embedder.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ void InputsEmbedder::IInputsEmbedder::update_chat_history(const std::string& dec
4444
if (generation_finish_status == ov::genai::GenerationStatus::CANCEL) {
4545
// If chat generation process was cancelled by user, let's rollback to previous state of history
4646
m_history.pop_back();
47+
48+
std::vector<int64_t>& state = m_kv_cache_state.get_state();
49+
state.resize(state.size() - processed_tokens_amount);
50+
m_kv_cache_state.reset_mem_state = state.empty();
4751
m_kv_cache_state.num_tokens_to_trim = processed_tokens_amount;
4852
} else {
4953
// Tail of chat template is missing in KV cache.

0 commit comments

Comments
 (0)