Skip to content

Commit 26d34eb

Browse files
authored
refactor example - qwen3_reranker (#19847)
Signed-off-by: reidliu41 <reid201711@gmail.com> Co-authored-by: reidliu41 <reid201711@gmail.com>
1 parent 53da4cd commit 26d34eb

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

examples/offline_inference/qwen3_reranker.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@
2222
# If you want to load the official original version, the init parameters are
2323
# as follows.
2424

25-
model = LLM(
26-
model=model_name,
27-
task="score",
28-
hf_overrides={
29-
"architectures": ["Qwen3ForSequenceClassification"],
30-
"classifier_from_token": ["no", "yes"],
31-
"is_original_qwen3_reranker": True,
32-
},
33-
)
25+
26+
def get_model() -> LLM:
27+
"""Initializes and returns the LLM model for Qwen3-Reranker."""
28+
return LLM(
29+
model=model_name,
30+
task="score",
31+
hf_overrides={
32+
"architectures": ["Qwen3ForSequenceClassification"],
33+
"classifier_from_token": ["no", "yes"],
34+
"is_original_qwen3_reranker": True,
35+
},
36+
)
37+
3438

3539
# Why do we need hf_overrides for the official original version:
3640
# vllm converts it to Qwen3ForSequenceClassification when loaded for
@@ -51,7 +55,8 @@
5155
query_template = "{prefix}<Instruct>: {instruction}\n<Query>: {query}\n"
5256
document_template = "<Document>: {doc}{suffix}"
5357

54-
if __name__ == "__main__":
58+
59+
def main() -> None:
5560
instruction = (
5661
"Given a web search query, retrieve relevant passages that answer the query"
5762
)
@@ -72,6 +77,13 @@
7277
]
7378
documents = [document_template.format(doc=doc, suffix=suffix) for doc in documents]
7479

80+
model = get_model()
7581
outputs = model.score(queries, documents)
7682

83+
print("-" * 30)
7784
print([output.outputs.score for output in outputs])
85+
print("-" * 30)
86+
87+
88+
if __name__ == "__main__":
89+
main()

0 commit comments

Comments
 (0)