README.md 4.54 KB
Newer Older
chenych's avatar
chenych committed
1
2
3
# Qwen3-Reranker
## 论文
[Qwen3 Embedding: Advancing Text Embedding and Reranking Through Foundation Models](https://arxiv.org/abs/2506.05176)
chenych's avatar
chenych committed
4

chenych's avatar
chenych committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
## 模型结构
采用双编码器和交叉编码器架构。
<div align=center>
    <img src="./doc/model.png"/>
</div>

## 算法原理
Qwen3嵌入模型系列是Qwen3家族最新的专有模型,专门为文本嵌入和排序任务而设计。此系列继承了其基础模型出色的多语言能力、长文本理解和推理技能。Qwen3 嵌入系列在文本检索、代码检索、文本分类、文本聚类和双语文本挖掘等多种文本嵌入和排序任务中取得了显著进展。
<div align=center>
    <img src="./doc/methods.png"/>
</div>

## 环境配置
`-v 路径``docker_name``imageID`根据实际情况修改

### Docker(方法一)
```bash
chenych's avatar
chenych committed
22
docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:vllm0.8.5-ubuntu22.04-dtk25.04-rc7-das1.5-py3.10-20250612-fixpy-rocblas0611-rc2
chenych's avatar
chenych committed
23
24
docker run -it --shm-size 200g --network=host --name {docker_name} --privileged --device=/dev/kfd --device=/dev/dri --device=/dev/mkfd --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -u root -v /path/your_code_data/:/path/your_code_data/ -v /opt/hyhal/:/opt/hyhal/:ro {imageID} bash

chenych's avatar
chenych committed
25
cd /your_code_path/qwen3-reranker_pytorch
chenych's avatar
chenych committed
26
27
28
29
30
31
pip install transformers>=4.51.0
```

### Dockerfile(方法二)
```bash
cd docker
chenych's avatar
chenych committed
32
docker build --no-cache -t qwen3-reranker:latest .
chenych's avatar
chenych committed
33
34
docker run -it --shm-size 200g --network=host --name {docker_name} --privileged --device=/dev/kfd --device=/dev/dri --device=/dev/mkfd --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -u root -v /path/your_code_data/:/path/your_code_data/ -v /opt/hyhal/:/opt/hyhal/:ro {imageID} bash

chenych's avatar
chenych committed
35
cd /your_code_path/qwen3-reranker_pytorch
chenych's avatar
chenych committed
36
37
38
39
pip install transformers>=4.51.0
```

### Anaconda(方法三)
chenych's avatar
chenych committed
40
关于本项目DCU显卡所需的特殊深度学习库可从[光合](https://developer.sourcefind.cn/tool/)开发者社区下载安装。
chenych's avatar
chenych committed
41
42
43
```bash
DTK: 25.04
python: 3.10
chenych's avatar
chenych committed
44
vllm: 0.8.5
chenych's avatar
chenych committed
45
46
torch: 2.4.1+das.opt2.dtk2504
deepspeed: 0.14.2+das.opt2.dtk2504
chenych's avatar
chenych committed
47

chenych's avatar
chenych committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
```
`Tips:以上dtk驱动、python、torch等DCU相关工具版本需要严格一一对应`

其它非深度学习库安装方式如下:
```bash
pip install transformers>=4.51.0
```

## 数据集


## 训练
暂无

## 推理
### vllm推理方法
chenych's avatar
chenych committed
64
#### offline
chenych's avatar
chenych committed
65
66
67
68
69
70
71
```bash
## 必须添加HF_ENDPOINT环境变量
export HF_ENDPOINT=https://hf-mirror.com
## model_name_or_path 模型地址参数
python infer_vllm.py --model_name_or_path /path/your_model_path/
```

chenych's avatar
chenych committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#### server
官方对于qwen3发布的rerank模型增加了`hf-overrides`,详细原因见[[New Model]: Support Qwen3 Embedding & Reranker  by noooop · Pull Request #19260 · vllm-project/vllm](https://github.com/vllm-project/vllm/pull/19260)

1. 启动命令如下
```bash
vllm serve Qwen/Qwen3-Reranker-0.6B               \
            --host 0.0.0.0 --port 8080  --block-size 16                      \
            --api-key 123456 --dtype auto                                    \
            --trust-remote-code                                              \
            --served-model-name Qwen3-reranker                               \
            --enable-prefix-caching                                          \
            --gpu-memory-utilization 0.9                                     \
            --task score --disable-log-requests                              \

            --hf_overrides '{"architectures":["Qwen3ForSequenceClassification"],"classifier_from_token": ["no", "yes"],"is_original_qwen3_reranker": true}'
```

2. 访问命令如下
```
curl -X 'POST' 'http://127.0.0.1:8080/score' \
  -H 'accept: application/json'              \
  -H 'Authorization: Bearer 123456'          \
  -H 'Content-Type: application/json'        \
  -d '{
      "model": "Qwen3-reranker",
      "encoding_format": "float",
      "text_1": "What is the capital of France?",
      "text_2": "The capital of France is Paris."
}'
```

chenych's avatar
chenych committed
103
104
## result
<div align=center>
chenych's avatar
chenych committed
105
    <img src="./doc/results-dcu.png"/>
chenych's avatar
chenych committed
106
107
108
</div>

### 精度
chenych's avatar
chenych committed
109
DCU与GPU精度一致,推理框架:vllm。
chenych's avatar
chenych committed
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

## 应用场景
### 算法类别
文本理解

### 热点应用行业
制造,广媒,家居,教育

## 预训练权重
- [Qwen3-Reranker-0.6B](https://huggingface.co/Qwen/Qwen3-Reranker-0.6B)
- [Qwen3-Reranker-4B](https://huggingface.co/Qwen/Qwen3-Reranker-4B)
- [Qwen3-Reranker-8B](https://huggingface.co/Qwen/Qwen3-Reranker-8B)

## 源码仓库及问题反馈
- https://developer.sourcefind.cn/codes/modelzoo/qwen3-reranker_pytorch

## 参考资料
chenych's avatar
chenych committed
127
- https://github.com/QwenLM/qwen3-reranker