Skip to content

Commit 85ac104

Browse files
Merge releases/2024/5 into master (openvinotoolkit#1159)
Co-authored-by: Ilya Lavrenov <[email protected]>
1 parent a99dc93 commit 85ac104

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

.github/workflows/causal_lm_cpp.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,6 @@ jobs:
760760
<<< $'Describe the images?' | tee py.txt
761761
env:
762762
PYTHONPATH: "./build/"
763-
- run: diff cpp.txt py.txt
764763
- name: Run visual_language_chat C++ sample with 2 prompts - tiny-random-minicpmv-2_6
765764
run: >
766765
source ./ov/setupvars.sh

src/cpp/src/logit_processor.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ class RepetitionPenaltyTransform : public IPenaltyTransformer {
200200
}
201201
for (const auto& input_id_pair : *m_unique_generated_token_ids) {
202202
const auto& input_id = input_id_pair.first;
203+
if (1 == m_unique_prompt_token_ids->count(input_id)) {
204+
// repetition_penalty was already accounted by the for
205+
// loop above.
206+
continue;
207+
}
203208
OPENVINO_ASSERT((input_id >= 0) && (input_id < vocab_size), "input_ids token out of bounds");
204209
if (logits.m_data[input_id] >= 0) {
205210
logits.m_data[input_id] /= m_penalty;

src/python/py_llm_pipeline.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ py::object call_common_generate(
5353
const pyutils::PyBindStreamerVariant& py_streamer,
5454
const py::kwargs& kwargs
5555
) {
56-
auto updated_config = pyutils::update_config_from_kwargs(config, kwargs);
56+
ov::genai::GenerationConfig default_config;
57+
if (config.has_value()) {
58+
default_config = *config;
59+
} else {
60+
default_config = pipe.get_generation_config();
61+
}
62+
auto updated_config = pyutils::update_config_from_kwargs(default_config, kwargs);
5763
py::object results;
5864
EncodedInputs tensor_data;
5965
StreamerVariant streamer = pyutils::pystreamer_to_streamer(py_streamer);

tests/python_tests/test_chat_generate_api.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# Copyright (C) 2023-2024 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

4-
import math
5-
import openvino
6-
import openvino_tokenizers
74
import openvino_genai as ov_genai
85
import pytest
96
from typing import Dict, Tuple
@@ -19,8 +16,8 @@
1916

2017

2118
configs = [
22-
dict(max_new_tokens=20),
23-
dict(num_beam_groups=3, num_beams=15, num_return_sequences=1, max_new_tokens=10, diversity_penalty=1.0)
19+
dict(do_sample=False, max_new_tokens=20),
20+
dict(do_sample=False, num_beam_groups=3, num_beams=15, num_return_sequences=1, max_new_tokens=10, diversity_penalty=1.0)
2421
]
2522

2623

@@ -37,7 +34,6 @@
3734
@pytest.mark.precommit
3835
@pytest.mark.nightly
3936
def test_chat_compare_with_HF(model_descr, generation_config: Dict):
40-
device = 'CPU'
4137
chat_history_hf = []
4238
chat_history_ov = []
4339
chat_prompt = ''
@@ -53,7 +49,7 @@ def test_chat_compare_with_HF(model_descr, generation_config: Dict):
5349
chat_prompt = tokenizer.apply_chat_template(chat_history_hf, tokenize=False, add_generation_prompt=True)
5450
tokenized = tokenizer(chat_prompt, return_tensors='pt', add_special_tokens=False)
5551

56-
answer = model_opt.generate(**tokenized, **generation_config, do_sample=False, repetition_penalty = None)
52+
answer = model_opt.generate(**tokenized, **generation_config)
5753
answer_str = tokenizer.decode(answer[0, tokenized['input_ids'].numel():], skip_special_tokens=True)
5854
chat_history_hf.append({'role': 'assistant', 'content': answer_str})
5955

@@ -74,7 +70,6 @@ def test_chat_compare_with_HF(model_descr, generation_config: Dict):
7470
@pytest.mark.nightly
7571
def test_chat_compare_text_history_with_HF(model_descr, generation_config: Dict):
7672
# compares with HF when history in ov_genai is save as a text
77-
device = 'CPU'
7873
chat_history_hf = []
7974
chat_history_ov = []
8075
chat_prompt = ''
@@ -90,7 +85,7 @@ def test_chat_compare_text_history_with_HF(model_descr, generation_config: Dict)
9085
chat_prompt = tokenizer.apply_chat_template(chat_history_hf, tokenize=False, add_generation_prompt=True)
9186
tokenized = tokenizer(chat_prompt, return_tensors='pt', add_special_tokens=False)
9287

93-
answer = model_opt.generate(**tokenized, **generation_config, do_sample=False, repetition_penalty = None)
88+
answer = model_opt.generate(**tokenized, **generation_config)
9489
answer_str = tokenizer.decode(answer[0, tokenized['input_ids'].numel():], skip_special_tokens=True)
9590
chat_history_hf.append({'role': 'assistant', 'content': answer_str})
9691

tools/who_what_benchmark/whowhatbench/wwb.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import logging
99
import os
1010

11-
import openvino_genai
1211
import pandas as pd
1312
from datasets import load_dataset
1413
from diffusers import DiffusionPipeline
@@ -385,11 +384,7 @@ def diff_strings(a: str, b: str, *, use_loguru_colors: bool = False) -> str:
385384

386385

387386
def genai_gen_answer(model, tokenizer, question, max_new_tokens, skip_question):
388-
config = openvino_genai.GenerationConfig()
389-
config.max_new_tokens = max_new_tokens
390-
config.do_sample = False
391-
out = model.generate(question, config)
392-
return out
387+
return model.generate(question, do_sample=False, max_new_tokens=max_new_tokens)
393388

394389

395390
def genai_gen_image(model, prompt, num_inference_steps, generator=None):

0 commit comments

Comments
 (0)