Skip to content

Commit d61bcdd

Browse files
authored
[TextRerankPipeline] Force left padding for qwen3 reranker tests (openvinotoolkit#3109)
<!-- Keep your pull requests (PRs) as atomic as possible. That increases the likelihood that an individual PR won't be stuck because of adjacent problems, merge conflicts, or code review. Your merged PR is going to appear in the automatically generated release notes on GitHub. So the clearer the title the better. --> ## Description There is an issue with default tokenizer padding side for qwen3. Force left padding so far, ticket for investigation: 177405
1 parent 67f9b81 commit d61bcdd

5 files changed

Lines changed: 43 additions & 4 deletions

File tree

src/cpp/include/openvino/genai/rag/text_rerank_pipeline.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ class OPENVINO_GENAI_EXPORTS TextRerankPipeline {
2121
*/
2222
std::optional<size_t> max_length;
2323

24+
/**
25+
* @brief If 'true', model input tensors are padded to the maximum length
26+
*/
27+
std::optional<bool> pad_to_max_length;
28+
29+
/**
30+
* @brief Side to use for padding "left" or "right"
31+
*/
32+
std::optional<std::string> padding_side;
33+
2434
/**
2535
* @brief Constructs text rerank pipeline configuration
2636
*/

src/cpp/src/rag/text_rerank_pipeline.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ ov::AnyMap remove_config_properties(const ov::AnyMap& properties) {
2323

2424
properties_copy.erase(top_n.name());
2525
properties_copy.erase(max_length.name());
26+
properties_copy.erase(pad_to_max_length.name());
27+
properties_copy.erase(padding_side.name());
2628

2729
return properties_copy;
2830
}
@@ -138,6 +140,8 @@ using utils::read_anymap_param;
138140
TextRerankPipeline::Config::Config(const ov::AnyMap& properties) {
139141
read_anymap_param(properties, ov::genai::top_n.name(), top_n);
140142
read_anymap_param(properties, ov::genai::max_length.name(), max_length);
143+
read_anymap_param(properties, ov::genai::padding_side.name(), padding_side);
144+
read_anymap_param(properties, ov::genai::pad_to_max_length.name(), pad_to_max_length);
141145
};
142146

143147
class TextRerankPipeline::TextRerankPipelineImpl {
@@ -154,6 +158,14 @@ class TextRerankPipeline::TextRerankPipelineImpl {
154158
m_tokenization_params.insert({max_length.name(), *m_config.max_length});
155159
}
156160

161+
if (m_config.pad_to_max_length) {
162+
m_tokenization_params.insert({pad_to_max_length.name(), *m_config.pad_to_max_length});
163+
}
164+
165+
if (m_config.padding_side) {
166+
m_tokenization_params.insert({padding_side.name(), *m_config.padding_side});
167+
}
168+
157169
// qwen3 tokenizer doesn't support add_second_input(true)
158170
m_tokenizer = Tokenizer(models_path, ov::genai::add_second_input(!is_qwen3));
159171

src/python/openvino_genai/py_openvino_genai.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3448,7 +3448,13 @@ class TextRerankPipeline:
34483448
Number of documents to return sorted by score.
34493449
max_length (int, optional):
34503450
Maximum length of tokens passed to the embedding model.
3451+
pad_to_max_length (bool, optional):
3452+
If 'True', model input tensors are padded to the maximum length.
3453+
padding_side (str, optional):
3454+
Side to use for padding "left" or "right"
34513455
"""
3456+
pad_to_max_length: bool | None
3457+
padding_side: str | None
34523458
@typing.overload
34533459
def __init__(self) -> None:
34543460
...

src/python/py_rag.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ Structure to keep TextRerankPipeline configuration parameters.
5353
Number of documents to return sorted by score.
5454
max_length (int, optional):
5555
Maximum length of tokens passed to the embedding model.
56+
pad_to_max_length (bool, optional):
57+
If 'True', model input tensors are padded to the maximum length.
58+
padding_side (str, optional):
59+
Side to use for padding "left" or "right"
5660
)";
5761

5862
} // namespace
@@ -226,7 +230,9 @@ kwargs: Plugin and/or config properties
226230
return ov::genai::TextRerankPipeline::Config(pyutils::kwargs_to_any_map(kwargs));
227231
}))
228232
.def_readwrite("top_n", &ov::genai::TextRerankPipeline::Config::top_n)
229-
.def_readwrite("max_length", &ov::genai::TextRerankPipeline::Config::max_length);
233+
.def_readwrite("max_length", &ov::genai::TextRerankPipeline::Config::max_length)
234+
.def_readwrite("pad_to_max_length", &ov::genai::TextRerankPipeline::Config::pad_to_max_length)
235+
.def_readwrite("padding_side", &ov::genai::TextRerankPipeline::Config::padding_side);
230236

231237
text_rerank_pipeline.def(
232238
py::init([](const std::filesystem::path& models_path,

tests/python_tests/test_rag.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def rerank_model(request) -> OVConvertedModelSchema:
7171
return download_and_convert_model_class(model_id, OVModelForSequenceClassification)
7272

7373

74-
7574
@pytest.fixture(scope="module")
7675
def emb_model(request) -> OVConvertedModelSchema:
7776
model_id = request.param
@@ -199,7 +198,6 @@ def validate_embedding_results(result_1: EmbeddingResult, result_2: EmbeddingRes
199198

200199
max_error = np.abs(np_result_1 - np_result_2).max()
201200
assert max_error < MAX_EMBEDDING_ERROR, f"Max error: {max_error} is greater than allowed {MAX_EMBEDDING_ERROR}"
202-
203201

204202

205203
def run_text_embedding_pipeline_with_ref(
@@ -620,10 +618,17 @@ def test_qwen3_seq_cls_rerank_documents(rerank_model: OVConvertedModelSchema, qu
620618
@pytest.mark.parametrize(
621619
"config",
622620
[
623-
TextRerankPipeline.Config(top_n=4),
621+
pytest.param(
622+
TextRerankPipeline.Config(top_n=4),
623+
marks=pytest.mark.skip(
624+
reason="Qwen3 Reranker different default tokenizer padding side on Win vs Linux: 177405"
625+
),
626+
),
627+
TextRerankPipeline.Config(top_n=4, padding_side="left"),
624628
],
625629
ids=[
626630
"top_n=4",
631+
"top_n=4, padding_side=left",
627632
],
628633
)
629634
@pytest.mark.xfail(condition=(sys.platform == "darwin"), reason="Ticket - 174635")

0 commit comments

Comments
 (0)