README.md 3.53 KB
Newer Older
chenych's avatar
chenych committed
1
2
3
# Qwen3-Embedding
## 论文
[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-20250521-fixpy-rocblas0521-beta2
chenych's avatar
chenych committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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

cd /your_code_path/qwen3-embedding_pytorch
pip install transformers>=4.51.0
pip install sentence-transformers>=2.7.0
```

### Dockerfile(方法二)
```bash
cd docker
docker build --no-cache -t qwen3-embedding:latest .
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

cd /your_code_path/qwen3-embedding_pytorch
pip install transformers>=4.51.0
pip install sentence-transformers>=2.7.0
```

### Anaconda(方法三)
chenych's avatar
chenych committed
42
关于本项目DCU显卡所需的特殊深度学习库可从[光合](https://developer.sourcefind.cn/tool/)开发者社区下载安装。
chenych's avatar
chenych committed
43
44
45
```bash
DTK: 25.04
python: 3.10
chenych's avatar
chenych committed
46
vllm: 0.8.5
chenych's avatar
chenych committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
torch: 2.4.1+das.opt2.dtk2504
deepspeed: 0.14.2+das.opt2.dtk2504
```
`Tips:以上dtk驱动、python、torch等DCU相关工具版本需要严格一一对应`

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

## 数据集


## 训练
暂无

## 推理
### vllm推理方法
```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/
```

### sentence-transformers推理方法
```bash
## 必须添加HF_ENDPOINT环境变量
export HF_ENDPOINT=https://hf-mirror.com
## model_name_or_path 模型地址参数
chenych's avatar
chenych committed
78
python infer_sentence_transformers.py
chenych's avatar
chenych committed
79
80
81
82
```

## result
<div align=center>
chenych's avatar
chenych committed
83
    <img src="./doc/results-dcu.png"/>
chenych's avatar
chenych committed
84
85
86
</div>

### 精度
chenych's avatar
chenych committed
87
DCU与GPU精度一致,推理框架:sentence_transformers。
chenych's avatar
chenych committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

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

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

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

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

## 参考资料
- https://qwenlm.github.io/blog/qwen3-embedding/
- https://github.com/QwenLM/Qwen3-Embedding