Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong logits processing without applying of slice matmul #1217

Merged
merged 2 commits into from
Nov 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/cpp/src/lm_encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ std::pair<EncodedResults, int32_t> get_lm_encoded_results(

auto logits = m_llm.get_tensor("logits");

// if slice matmul is not applied logits will contains not only result tokens
size_t vocab_size = logits.get_shape().back();
if (!m_embedding.has_value()) {
ov::Tensor new_logits = ov::Tensor(logits.get_element_type(), {batch_size, 1, vocab_size});
ilya-lavrenov marked this conversation as resolved.
Show resolved Hide resolved
size_t sequence_offset = (logits.get_shape()[1] - 1) * vocab_size;

for (size_t batch_idx = 0; batch_idx < batch_size; batch_idx++) {
size_t batch_offset = batch_idx * logits.get_shape().at(1) * vocab_size;
const float* logits_data = logits.data<const float>() + batch_offset + sequence_offset;
std::copy(logits_data, logits_data + vocab_size, new_logits.data<float>() + batch_idx * vocab_size);
}
logits = new_logits;
}

int64_t sequence_len = logits.get_shape().at(1);
for (auto& sequence_group : sequence_groups)
sequence_group->schedule_tokens(sequence_len);
Expand Down
Loading