Skip to content

Commit 724c26b

Browse files
author
reidliu41
committed
refactor example - qwen3_reranker
Signed-off-by: reidliu41 <[email protected]>
1 parent 4719460 commit 724c26b

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

examples/offline_inference/qwen3_reranker.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@
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():
27+
return LLM(
28+
model=model_name,
29+
task="score",
30+
hf_overrides={
31+
"architectures": ["Qwen3ForSequenceClassification"],
32+
"classifier_from_token": ["no", "yes"],
33+
"is_original_qwen3_reranker": True,
34+
},
35+
)
36+
3437

3538
# Why do we need hf_overrides for the official original version:
3639
# vllm converts it to Qwen3ForSequenceClassification when loaded for
@@ -51,7 +54,8 @@
5154
query_template = "{prefix}<Instruct>: {instruction}\n<Query>: {query}\n"
5255
document_template = "<Document>: {doc}{suffix}"
5356

54-
if __name__ == "__main__":
57+
58+
def main():
5559
instruction = (
5660
"Given a web search query, retrieve relevant passages that answer the query"
5761
)
@@ -72,6 +76,13 @@
7276
]
7377
documents = [document_template.format(doc=doc, suffix=suffix) for doc in documents]
7478

79+
model = get_model()
7580
outputs = model.score(queries, documents)
7681

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

0 commit comments

Comments
 (0)