Skip to content

Commit

Permalink
V1
Browse files Browse the repository at this point in the history
  • Loading branch information
dkalinowski committed Aug 2, 2024
1 parent 66f9d62 commit ef3c65c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/cpp/include/openvino/genai/generation_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ class OPENVINO_GENAI_EXPORTS GenerationHandleImpl {

bool can_read();

void drop();

GenerationOutputs back();
// Reads result of a generation for single iteration
GenerationOutputs read();
// Reads all generated tokens for all sequences
std::vector<GenerationOutput> read_all();
};

using GenerationHandle = std::unique_ptr<GenerationHandleImpl>;
using GenerationHandle = std::shared_ptr<GenerationHandleImpl>;
}
5 changes: 4 additions & 1 deletion src/cpp/src/continuous_batching_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class ContinuousBatchingPipeline::Impl {
while (requests_iterator != m_requests.end()) {
const auto& request = *requests_iterator;
if(request->has_finished() || request->out_of_memory() || request->handle_dropped()) {
// Notify the last time even if there will be no results
// This causes read_all() to unblock in all situations
request->notify_handle();
for (const auto& sequence: request->get_sequences()) {
m_scheduler->free_sequence(sequence->get_id());
}
Expand Down Expand Up @@ -136,7 +139,7 @@ class ContinuousBatchingPipeline::Impl {
std::lock_guard<std::mutex> lock{m_awaiting_requests_mutex};
m_awaiting_requests.push_back(sequence_group);
}
return std::make_unique<GenerationHandleImpl>(sequence_group->get_generation_stream(), sampling_params);
return std::make_shared<GenerationHandleImpl>(sequence_group->get_generation_stream(), sampling_params);
}

GenerationHandle add_request(uint64_t request_id, const std::string& prompt, ov::genai::GenerationConfig sampling_params) {
Expand Down
6 changes: 5 additions & 1 deletion src/cpp/src/generation_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using namespace ov::genai;

GenerationHandleImpl::~GenerationHandleImpl() {
m_generation_stream->drop();
drop();
}

GenerationStatus GenerationHandleImpl::get_status() {
Expand All @@ -20,6 +20,10 @@ bool GenerationHandleImpl::can_read() {
return m_generation_stream->can_read();
}

void GenerationHandleImpl::drop() {
m_generation_stream->drop();
}

std::unordered_map<uint64_t, GenerationOutput> GenerationHandleImpl::back() {
return m_generation_stream->back();
}
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/src/sequence_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ class SequenceGroup {
}
// For beam search streaming is not available, so we notify only upon finishing
if(m_sampling_params.is_beam_search()) {
if (has_finished() || out_of_memory()) {
if (has_finished() || out_of_memory() || handle_dropped()) {
push_outputs();
}
} else if (m_sampling_params.is_greedy_decoding() || m_sampling_params.is_multinomial()) {
Expand Down

0 comments on commit ef3c65c

Please sign in to comment.