-
Notifications
You must be signed in to change notification settings - Fork 906
Support reranker inference #5883
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
Merged
tastelikefeet
merged 11 commits into
modelscope:main
from
tastelikefeet:feat/reranker_infer
Sep 20, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2956bfc
wip
32721d4
Merge branch 'main' of github.com:tastelikefeet/swift
c7c0071
fix
cecd056
Merge commit 'c25d275c930dcaa1358c3fe72c8d52423b00e32b' into feat/rer…
tastelikefeet 4914e42
lint
tastelikefeet 8cae1bb
fix
a026592
docs
d4acbf4
add new files
e65440c
liknt
2073bd4
fix
1d51e2d
fix
tastelikefeet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright (c) Alibaba, Inc. and its affiliates. | ||
import os | ||
|
||
from openai import OpenAI | ||
|
||
os.environ['CUDA_VISIBLE_DEVICES'] = '0' | ||
|
||
|
||
def infer(client, model: str, messages): | ||
resp = client.chat.completions.create(model=model, messages=messages) | ||
scores = resp.choices[0].message.content | ||
print(f'messages: {messages}') | ||
print(f'scores: {scores}') | ||
return scores | ||
|
||
|
||
def run_client(host: str = '127.0.0.1', port: int = 8000): | ||
client = OpenAI( | ||
api_key='EMPTY', | ||
base_url=f'http://{host}:{port}/v1', | ||
) | ||
model = client.models.list().data[0].id | ||
print(f'model: {model}') | ||
|
||
messages = [{ | ||
'role': 'user', | ||
'content': 'what is the capital of China?', | ||
}, { | ||
'role': 'assistant', | ||
'content': 'Beijing', | ||
}] | ||
infer(client, model, messages) | ||
|
||
|
||
if __name__ == '__main__': | ||
from swift.llm import run_deploy, DeployArguments | ||
with run_deploy( | ||
DeployArguments( | ||
model='BAAI/bge-reranker-v2-m3', | ||
task_type='reranker', | ||
infer_backend='vllm', | ||
gpu_memory_utilization=0.7, | ||
vllm_enforce_eager=True, | ||
reranker_use_activation=False, | ||
verbose=False, | ||
log_interval=-1)) as port: | ||
run_client(port=port) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright (c) Alibaba, Inc. and its affiliates. | ||
import os | ||
|
||
from openai import OpenAI | ||
|
||
os.environ['CUDA_VISIBLE_DEVICES'] = '0' | ||
|
||
|
||
def infer(client, model: str, messages): | ||
resp = client.chat.completions.create(model=model, messages=messages) | ||
scores = resp.choices[0].message.content | ||
print(f'messages: {messages}') | ||
print(f'scores: {scores}') | ||
return scores | ||
|
||
|
||
def run_client(host: str = '127.0.0.1', port: int = 8000): | ||
client = OpenAI( | ||
api_key='EMPTY', | ||
base_url=f'http://{host}:{port}/v1', | ||
) | ||
model = client.models.list().data[0].id | ||
print(f'model: {model}') | ||
|
||
messages = [{ | ||
'role': 'user', | ||
'content': 'what is the capital of China?', | ||
}, { | ||
'role': 'assistant', | ||
'content': 'Beijing.', | ||
}] | ||
infer(client, model, messages) | ||
|
||
|
||
if __name__ == '__main__': | ||
from swift.llm import run_deploy, DeployArguments | ||
with run_deploy( | ||
DeployArguments( | ||
model='Qwen/Qwen3-Reranker-0.6B', | ||
task_type='generative_reranker', | ||
infer_backend='vllm', | ||
gpu_memory_utilization=0.7, | ||
verbose=False, | ||
log_interval=-1)) as port: | ||
run_client(port=port) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# GME/GTE models or your checkpoints are also supported | ||
# pt/vllm/sglang supported | ||
CUDA_VISIBLE_DEVICES=0 swift deploy \ | ||
--host 0.0.0.0 \ | ||
--port 8000 \ | ||
--model BAAI/bge-reranker-v2-m3 \ | ||
--infer_backend vllm \ | ||
--task_type reranker \ | ||
--vllm_enforce_eager true \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright (c) Alibaba, Inc. and its affiliates. | ||
import os | ||
|
||
from openai import OpenAI | ||
|
||
os.environ['CUDA_VISIBLE_DEVICES'] = '0' | ||
|
||
|
||
def infer(client, model: str, messages): | ||
resp = client.chat.completions.create(model=model, messages=messages) | ||
classify = resp.choices[0].message.content | ||
print(f'messages: {messages}') | ||
print(f'classify: {classify}') | ||
return classify | ||
|
||
|
||
def run_client(host: str = '127.0.0.1', port: int = 8000): | ||
client = OpenAI( | ||
api_key='EMPTY', | ||
base_url=f'http://{host}:{port}/v1', | ||
) | ||
model = client.models.list().data[0].id | ||
print(f'model: {model}') | ||
|
||
messages = [{ | ||
'role': 'user', | ||
'content': 'What is the capital of China?', | ||
}, { | ||
'role': 'assistant', | ||
'content': 'Beijing', | ||
}] | ||
infer(client, model, messages) | ||
|
||
|
||
if __name__ == '__main__': | ||
from swift.llm import run_deploy, DeployArguments | ||
with run_deploy( | ||
DeployArguments( | ||
model='/your/seq_cls/checkpoint-xxx', | ||
task_type='seq_cls', | ||
infer_backend='vllm', | ||
num_labels=2, | ||
verbose=False, | ||
log_interval=-1)) as port: | ||
run_client(port=port) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# GME/GTE models or your checkpoints are also supported | ||
# pt/vllm/sglang supported | ||
CUDA_VISIBLE_DEVICES=0 swift deploy \ | ||
--host 0.0.0.0 \ | ||
--port 8000 \ | ||
--model /your/seq_cls/checkpoint-xxx \ | ||
--infer_backend vllm \ | ||
--task_type seq_cls \ | ||
--num_labels 2 \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.