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

repr #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

repr #10

Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,19 @@ int main(int argc, char* argv[]) try {
scheduler_config.max_num_seqs = 2;

ov::genai::ContinuousBatchingPipeline pipe(models_path, scheduler_config);
std::vector<ov::genai::GenerationResult> generation_results = pipe.generate(prompts, sampling_params);
ov::genai::GenerationConfig prototype;
prototype.max_new_tokens = 20;
prototype.num_beam_groups = 3;
prototype.num_beams = 15;
prototype.diversity_penalty = 1.0;
std::vector<ov::genai::GenerationResult> generation_results = pipe.generate({
"hello",
"Here is the longest novel ever: "
}, std::vector(2, prototype));
generation_results = pipe.generate({
"hello",
"Here is the longest novel ever: "
}, std::vector(2, prototype));

for (size_t request_id = 0; request_id < generation_results.size(); ++request_id) {
const ov::genai::GenerationResult & generation_result = generation_results[request_id];
Expand Down
5 changes: 3 additions & 2 deletions src/cpp/src/sampler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ SamplerOutput Sampler::sample(std::vector<SequenceGroup::Ptr> & sequence_groups,
}
auto& logit_processor = m_logit_processors.at(request_id);

const void * sequence_group_logits_data = logits_data + vocab_size * currently_processed_tokens;
ov::Tensor sequence_group_logits(ov::element::f32, ov::Shape{num_running_sequences, actual_seq_len, vocab_size}, (void *)sequence_group_logits_data);
const float * sequence_group_logits_data = logits_data + vocab_size * currently_processed_tokens;
ov::Tensor sequence_group_logits(ov::element::f32, ov::Shape{num_running_sequences, actual_seq_len, vocab_size});
std::copy_n(sequence_group_logits_data, sequence_group_logits.get_size(), sequence_group_logits.data<float>());

if (sequence_group->requires_sampling()) {
if (sampling_params.is_greedy_decoding() || sampling_params.is_multinomial()) {
Expand Down
7 changes: 6 additions & 1 deletion src/cpp/src/sequence_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ class Sequence {
}
};

inline ov::Tensor init_copy(const TokenIds& input_ids) {
ov::Tensor tensor(ov::element::i64, ov::Shape{input_ids.size()});
std::copy(input_ids.begin(), input_ids.end(), tensor.data<int64_t>());
return tensor;
}
// contains a list of Sequences in generic case (beam search or parallel sampling)
// - each sequence shares the same prompt and KV-caches for promp
// - in case of beam search each sequence also shares specific part of generic phase
Expand Down Expand Up @@ -158,7 +163,7 @@ class SequenceGroup {
using CPtr = std::shared_ptr<const SequenceGroup>;

SequenceGroup(uint64_t request_id, const TokenIds& input_ids, const ov::genai::GenerationConfig& sampling_params, std::size_t block_size)
: SequenceGroup(request_id, ov::Tensor(ov::element::i64, ov::Shape{input_ids.size()}, (void *)input_ids.data()), sampling_params, block_size) {
: SequenceGroup(request_id, init_copy(input_ids), sampling_params, block_size) {
}

SequenceGroup(uint64_t request_id, const ov::Tensor input_ids, const ov::genai::GenerationConfig& sampling_params, std::size_t block_size)
Expand Down