Skip to content

Commit c3033cc

Browse files
author
BetterAndBetterII
committed
feat: add qwen3-reranker openai compatibility
1 parent 7b1895e commit c3033cc

File tree

5 files changed

+151
-0
lines changed

5 files changed

+151
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Use a base image with CUDA and a modern OS to ensure GLIBC compatibility
2+
FROM docker.gitfetch.dev/nvidia/cuda:12.8.1-devel-ubuntu24.04
3+
4+
# Avoid prompts during installation
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
# Install system dependencies
8+
RUN apt-get update && apt-get install -y \
9+
wget \
10+
build-essential \
11+
curl \
12+
git \
13+
ninja-build \
14+
cmake \
15+
ccache \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
# Install Miniconda
19+
ENV PATH="/opt/conda/bin:${PATH}"
20+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-py311_23.10.0-1-Linux-x86_64.sh -O ~/miniconda.sh && \
21+
/bin/bash ~/miniconda.sh -b -p /opt/conda && \
22+
rm ~/miniconda.sh && \
23+
conda clean -tip
24+
25+
WORKDIR /workspace
26+
27+
# Create conda environment and install python dependencies
28+
# This leverages Docker layer caching.
29+
RUN conda create -y --name vllm-dev python=3.11 && \
30+
echo "source /opt/conda/etc/profile.d/conda.sh && conda activate vllm-dev" >> ~/.bashrc
31+
32+
# Set the default shell to use the new conda environment, and activate the environment
33+
ENV SHELL /bin/bash
34+
CMD ["/bin/bash"]

.devcontainer/devcontainer.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "vLLM Development",
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
"context": ".."
6+
},
7+
"runArgs": [
8+
"--gpus",
9+
"all",
10+
"--ipc=host"
11+
],
12+
"customizations": {
13+
"vscode": {
14+
"settings": {
15+
"python.defaultInterpreterPath": "/opt/conda/envs/vllm-dev/bin/python",
16+
"python.testing.pytestArgs": [
17+
"tests"
18+
],
19+
"python.testing.unittestEnabled": false,
20+
"python.testing.pytestEnabled": true
21+
},
22+
"extensions": [
23+
"ms-python.python",
24+
"ms-vscode.cpptools",
25+
"ms-python.mypy-type-checker",
26+
"njpwerner.autodocstring",
27+
"tamasfe.even-better-toml",
28+
"mutantdino.resourcemonitor"
29+
]
30+
}
31+
},
32+
"workspaceFolder": "/workspaces/vllm",
33+
"postCreateCommand": "bash -c 'source /opt/conda/etc/profile.d/conda.sh && conda activate vllm-dev'"
34+
}

mamba

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit a6a1dae6efbf804c9944a0c2282b437deb4886d8

reproduce.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from vllm.platforms import current_platform
2+
3+
print(current_platform.device_type)

score_template.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
### **任务概述**
2+
3+
**目标**: 为 vLLM 的打分服务(Score/Rerank)适配需要特定输入格式的模板化模型(如 `Qwen3-reranker`)。
4+
5+
**背景**: 某些模型(特别是 Reranker)需要一个特定的输入格式,该格式由一个模板字符串和多个变量(如 `instruction`, `query`, `document`)组合而成。
6+
7+
**核心需求**:
8+
1. **模板化输入**: 实现一个统一的机制,能够在服务端根据模板格式化输入。
9+
2. **参数传递**: 允许用户在 API 请求中传入自定义参数(如 `instruction`)来动态填充模板。
10+
3. **向后兼容性**:
11+
* **支持默认行为**: 对于不了解此特性的下游应用,服务应能自动使用模型配置中定义的默认参数和模板。
12+
* **支持运行时定制**: 对于需要定制的应用,应能通过 API 接口自由传入参数来覆盖默认行为。
13+
14+
本设计文档旨在探讨并确定满足以上需求的最佳实现方案。
15+
16+
---
17+
18+
### **Score 模板实现设计文档**
19+
20+
**目标**:为 vLLM 的 `score``rerank` 服务添加灵活的输入模板化能力,以支持像 Qwen3-Reranker 这样需要特定输入格式的模型,同时保证对现有模型的兼容性。
21+
22+
---
23+
24+
### 方案一:模型配置 `config.json` + API 参数覆盖 (理想方案)
25+
26+
**1. 实现细节:**
27+
* **协议层 (`protocol.py`):**
28+
*`ScoreRequest``RerankRequest` 类中添加新字段:
29+
```python
30+
score_template: Optional[Dict[str, str]] = None # e.g., {"query": "...", "document": "..."}
31+
score_template_kwargs: Optional[Dict[str, Any]] = None
32+
```
33+
* **模型配置层 (`config.json`):**
34+
* 模型作者或维护者在模型的 `config.json` 中添加一个 `score_template` 对象。
35+
* **服务层 (`serving_score.py`):**
36+
* 服务逻辑优先使用 `request.score_template`,如果为空,则回退到 `self.model_config.hf_config.get("score_template")`
37+
38+
**2. 优缺点:**
39+
* **优点**: 可移植性强,用户体验好。
40+
* **缺点**: 依赖模型作者,不够灵活。
41+
42+
---
43+
44+
### 方案二:`hf_overrides` / 命令行参数注入 + API 参数覆盖 (已实施方案)
45+
46+
**1. 实现细节:**
47+
* **协议层 (`protocol.py`):**
48+
* 与方案一**完全相同**
49+
* **模型/服务配置层:**
50+
* **代码注入**: 在初始化 `LLM` 引擎时,通过 `hf_overrides` 参数"注入"`score_template` 对象。
51+
* **服务层 (`serving_score.py`):**
52+
* 代码逻辑与方案一相同,统一处理来自请求和配置的模板。
53+
54+
**2. 优缺点:**
55+
* **优点**:
56+
* **不依赖模型作者**: 服务部署者拥有完全的控制权。
57+
* **极度灵活**: 支持服务级默认模板和请求级动态模板。
58+
* **缺点**:
59+
* **全局影响**: **此更改会触及所有 score/rerank 请求的处理路径。因此,实现时必须极其谨慎,确保对于不使用模板的普通模型,其行为与更改前完全一致。**
60+
61+
---
62+
63+
### 方案三:特殊情况处理 (硬编码方案)
64+
65+
**1. 实现细节:**
66+
* **协议层 (`protocol.py`):**
67+
* **不做任何修改**
68+
* **服务层 (`serving_score.py`):**
69+
* 在服务逻辑内部,添加一个硬编码的逻辑判断(例如 `if "qwen3-reranker" in model_name:`),仅对特定模型应用模板。
70+
71+
**2. 优缺点:**
72+
* **优点**: 风险极低,实现简单快速。
73+
* **缺点**: **缺乏灵活性和可扩展性**,每次新增支持都需要修改核心代码,是一种技术债。
74+
75+
---
76+
77+
### **总结**
78+
79+
我们采用了**方案二**,因为它在灵活性、可维护性和工程现实之间取得了最佳平衡。

0 commit comments

Comments
 (0)