Skip to content

refactor example - qwen3_reranker #19847

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
32 changes: 22 additions & 10 deletions examples/offline_inference/qwen3_reranker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@
# If you want to load the official original version, the init parameters are
# as follows.

model = LLM(
model=model_name,
task="score",
hf_overrides={
"architectures": ["Qwen3ForSequenceClassification"],
"classifier_from_token": ["no", "yes"],
"is_original_qwen3_reranker": True,
},
)

def get_model() -> LLM:
"""Initializes and returns the LLM model for Qwen3-Reranker."""
return LLM(
model=model_name,
task="score",
hf_overrides={
"architectures": ["Qwen3ForSequenceClassification"],
"classifier_from_token": ["no", "yes"],
"is_original_qwen3_reranker": True,
},
)


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

if __name__ == "__main__":

def main() -> None:
instruction = (
"Given a web search query, retrieve relevant passages that answer the query"
)
Expand All @@ -72,6 +77,13 @@
]
documents = [document_template.format(doc=doc, suffix=suffix) for doc in documents]

model = get_model()
outputs = model.score(queries, documents)

print("-" * 30)
print([output.outputs.score for output in outputs])
print("-" * 30)


if __name__ == "__main__":
main()