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

Move lm model to async infer #1425

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 11 additions & 4 deletions src/cpp/src/lm_encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ std::pair<EncodedResults, std::optional<int64_t>> get_lm_encoded_results(
}
}
}
};

// free non running requests
auto free_non_running_requests = [&streamer_ptr, &generations, &active_sequence_groups]() {
auto removed_it = std::remove_if(active_sequence_groups.begin(), active_sequence_groups.end(),
[](SequenceGroup::Ptr sg) -> bool {
return sg->has_finished() || sg->out_of_memory() || sg->handle_dropped();
Expand Down Expand Up @@ -130,7 +131,7 @@ std::pair<EncodedResults, std::optional<int64_t>> get_lm_encoded_results(
beam_offets.insert({sequence_groups.at(i)->get_request_id(), i});

SamplerOutput sampler_output = sampler.sample(sequence_groups, logits);
stream_generated_tokens();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably, if we start to stream tokens here in a dedicated thread, it can be faster as streaming will be overlapped with:

  • embedding model
  • llm model for next token
  • sampling for next token

while currently streaming is overlapped with LLM only

we could re-use SynchronizedQueue from GenAI source where streaming callback will push to queue, streaming dedicated thread will read from this queue using pull method

free_non_running_requests();

// "Generation" phase

Expand Down Expand Up @@ -194,7 +195,12 @@ std::pair<EncodedResults, std::optional<int64_t>> get_lm_encoded_results(
m_llm.set_tensor("beam_idx", ov::Tensor{ov::element::i32, {total_num_tokens}, next_beams.data()});

const auto infer_start = std::chrono::steady_clock::now();
m_llm.infer();
m_llm.start_async();

stream_generated_tokens();

m_llm.wait();

const auto infer_end = std::chrono::steady_clock::now();
const auto infer_ms = PerfMetrics::get_microsec(infer_end - infer_start);
raw_perf_counters.m_inference_durations[0] += MicroSeconds(infer_ms);
Expand All @@ -203,9 +209,10 @@ std::pair<EncodedResults, std::optional<int64_t>> get_lm_encoded_results(
raw_perf_counters.m_batch_sizes.emplace_back(batch_size);

sampler_output = sampler.sample(active_sequence_groups, m_llm.get_tensor("logits"));
stream_generated_tokens();
free_non_running_requests();
}

stream_generated_tokens();
if (streamer_ptr) { // push streamer's cache
streamer_ptr->end();
}
Expand Down
Loading