Skip to content

Commit

Permalink
Fixed SEGFAULT when empty encoded inputs are passed to LLM (#1513)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov authored Jan 9, 2025
1 parent 3b0ecb4 commit f1802f5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/cpp/src/sequence_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,12 @@ class SequenceGroup : public std::enable_shared_from_this<SequenceGroup> {

SequenceGroup(uint64_t request_id, const ov::Tensor input_ids, const ov::genai::GenerationConfig& sampling_params, std::size_t block_size)
: SequenceGroup(request_id, sampling_params, block_size) {
m_prompt_ids.resize(input_ids.get_size());
std::copy_n(input_ids.data<int64_t>(), input_ids.get_size(), m_prompt_ids.begin());
m_prompt_log_probs.reserve(m_prompt_ids.size());
size_t prompt_len = input_ids.get_size();
OPENVINO_ASSERT(prompt_len > 0, "Prompt length cannot be 0");

m_prompt_ids.resize(prompt_len);
std::copy_n(input_ids.data<int64_t>(), prompt_len, m_prompt_ids.begin());
m_prompt_log_probs.reserve(prompt_len);

// create a single sequence
add_sequence(Sequence::create(m_next_sequence_id++));
Expand Down
2 changes: 1 addition & 1 deletion tests/cpp/block_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

TEST(TestBlockManager, general_test) {
ov::genai::BlockManager bm = ov::genai::BlockManager(6, false, 4);
ov::genai::TokenIds prompt_ids;
ov::genai::TokenIds prompt_ids = {10, 0};

ov::genai::SequenceGroup::Ptr sequence_group = std::make_shared<ov::genai::SequenceGroup>(
0,
Expand Down
8 changes: 8 additions & 0 deletions tests/python_tests/test_llm_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ def test_batch_size_switch():
ov_pipe.generate(["1", "2"], max_new_tokens=2)
ov_pipe.generate(["a"], max_new_tokens=2)


@pytest.mark.precommit
@pytest.mark.nightly
def test_empty_encoded_inputs_throw():
ov_pipe = read_model(('katuni4ka/tiny-random-phi3', Path('tiny-random-phi3')))[4]
with pytest.raises(RuntimeError):
ov_pipe.generate(ov.Tensor(np.array([[]], dtype=np.int64)), max_new_tokens=2)

#
# Chat scenario
#
Expand Down

0 comments on commit f1802f5

Please sign in to comment.