zhenghaoz commited on
Commit
ea939d4
·
verified ·
1 Parent(s): 91d2de9

Publish Qwen3-Reranker-8B BF16, Q8_0 and Q4_K_M GGUF

Browse files
.gitattributes CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ Qwen3-Reranker-8B-BF16.gguf filter=lfs diff=lfs merge=lfs -text
37
+ Qwen3-Reranker-8B-Q4_K_M.gguf filter=lfs diff=lfs merge=lfs -text
38
+ Qwen3-Reranker-8B-Q8_0.gguf filter=lfs diff=lfs merge=lfs -text
.src_sha ADDED
@@ -0,0 +1 @@
 
 
1
+ PRIMARY=77d193c791ed757ca307ee72715aa132723da912
Qwen3-Reranker-8B-BF16.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:41b6f11a17bea85986ee577aca0eaf79334091c7eb719ebe72161af24c844641
3
+ size 15141207936
Qwen3-Reranker-8B-Q4_K_M.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eca7c57ee08d8f1e7e7ea8cebf2a2821185836388882d7c9384cffe4729a5721
3
+ size 4676825376
Qwen3-Reranker-8B-Q8_0.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7ad83063f1639b393d5cd9c54a65a461ec3a3109fd57e827614207162ae24304
3
+ size 8047134336
README.md ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ pipeline_tag: text-ranking
4
+ tags:
5
+ - gguf
6
+ - quantized
7
+ - reranker
8
+ base_model:
9
+ - Qwen/Qwen3-Reranker-8B
10
+ ---
11
+
12
+ # Qwen3-Reranker-8B
13
+
14
+ GGUF conversion of [Qwen/Qwen3-Reranker-8B](https://huggingface.co/Qwen/Qwen3-Reranker-8B)
15
+ for dedicated query/document reranking, not text generation or general-purpose
16
+ embedding vectors. Available files:
17
+
18
+ - `Qwen3-Reranker-8B-BF16.gguf`
19
+ - `Qwen3-Reranker-8B-Q8_0.gguf`
20
+ - `Qwen3-Reranker-8B-Q4_K_M.gguf`
21
+
22
+ ## Run with llama.cpp
23
+
24
+ Use a recent llama.cpp build with Qwen3 reranker conversion and server support:
25
+
26
+ ```bash
27
+ llama-server -hf gorse-io/Qwen3-Reranker-8B-GGUF:Q8_0 \
28
+ --embedding --reranking --pooling rank --host 127.0.0.1 --port 8080
29
+ ```
30
+
31
+ For the 4-bit variant, use `-hf gorse-io/Qwen3-Reranker-8B-GGUF:Q4_K_M`
32
+ in the same command. For a local file, replace `-hf ...` with
33
+ `-m Qwen3-Reranker-8B-Q8_0.gguf` or `-m Qwen3-Reranker-8B-Q4_K_M.gguf`.
34
+ The conversion pipeline builds `llama-quantize`, not `llama-server`; build or
35
+ install the server separately.
36
+
37
+ ```bash
38
+ curl http://127.0.0.1:8080/v1/rerank \
39
+ -H 'Content-Type: application/json' \
40
+ -d '{"query":"What is the capital of China?","documents":["Beijing is the capital of China.","Paris is the capital of France."],"top_n":2}'
41
+ ```
42
+
43
+ `/reranking`, `/rerank`, and `/v1/reranking` are aliases. The endpoint scores
44
+ query/document pairs; it is not a chat-completions endpoint. See the
45
+ [llama.cpp server documentation](https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md#post-reranking-rerank-documents-according-to-a-given-query).
46
+
47
+ ## Conversion notes
48
+
49
+ Keep the original downloaded source `README.md` alongside the weights and
50
+ configuration. llama.cpp detects Qwen3 rerankers using the source directory name
51
+ or original README, emits `RANK` pooling, and extracts the `yes`/`no` rows into
52
+ `cls.output.weight`. The pipeline's temporary directory names use underscores,
53
+ so preserving the upstream README matters. Do not replace it with this output
54
+ model card before conversion, especially when using a local source directory.
55
+
56
+ CPU conversion is supported, but budget RAM for conversion/quantization and disk
57
+ for the source weights, Hugging Face cache, and BF16, Q8_0, and Q4_K_M outputs.
58
+ The larger models need substantially more memory and storage; `--keep` retains
59
+ the downloads and all three output files.
60
+
61
+ > [!IMPORTANT]
62
+ > This model is converted using https://github.com/gorse-cloud/convert.
conversion.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "source": "Qwen/Qwen3-Reranker-8B",
3
+ "source_revision": "77d193c791ed757ca307ee72715aa132723da912",
4
+ "llama_cpp_revision": "d81235049384534c167caea52b85a694f6103d14",
5
+ "binary_release": "b11429",
6
+ "checks": {
7
+ "Qwen3-Reranker-8B-BF16.gguf": {
8
+ "tensors": 399,
9
+ "pooling": "RANK",
10
+ "labels": [
11
+ "yes",
12
+ "no"
13
+ ],
14
+ "file_type": 32
15
+ },
16
+ "Qwen3-Reranker-8B-Q8_0.gguf": {
17
+ "tensors": 399,
18
+ "pooling": "RANK",
19
+ "labels": [
20
+ "yes",
21
+ "no"
22
+ ],
23
+ "file_type": 7
24
+ },
25
+ "Qwen3-Reranker-8B-Q4_K_M.gguf": {
26
+ "tensors": 399,
27
+ "pooling": "RANK",
28
+ "labels": [
29
+ "yes",
30
+ "no"
31
+ ],
32
+ "file_type": 15
33
+ }
34
+ },
35
+ "inference": {
36
+ "note": "GGUF metadata/tensors verified; large-model inference not run on this 3.3 GiB host"
37
+ },
38
+ "low_memory_adapter_sha256": "e87ef9ccaa54a44d788f1d20767057423217694593cefc24c74fbb056dfc68bb"
39
+ }
conversion_adapter.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Local Qwen3 reranker BF16 memory adapter; upstream sources stay unchanged."""
2
+ import json
3
+ import logging
4
+ from pathlib import Path
5
+ import runpy
6
+ import sys
7
+
8
+ ROOT = Path(__file__).resolve().parent
9
+ sys.path.insert(0, str(ROOT/'llama.cpp'))
10
+ sys.path.insert(0, str(ROOT/'llama.cpp/gguf-py'))
11
+ import gguf
12
+ import numpy as np
13
+ import torch
14
+ from safetensors import safe_open
15
+
16
+ class TorchChunkedTensor(gguf.LazyChunkedTensor):
17
+ """Advertise float32 to the converter, but allocate only one row chunk."""
18
+ def __init__(self, chunks, shape):
19
+ super().__init__(chunks, shape, np.float32)
20
+ self.dtype = torch.float32
21
+
22
+ def chunked_embedding(shard, tensor_name, chunk_rows=256):
23
+ if chunk_rows <= 0:
24
+ raise ValueError('chunk_rows must be positive')
25
+ shard = Path(shard)
26
+ with safe_open(str(shard), framework='pt', device='cpu') as f:
27
+ shape = tuple(f.get_slice(tensor_name).get_shape())
28
+ if len(shape) != 2:
29
+ raise ValueError('embedding must be a matrix')
30
+ def load(start, end):
31
+ with safe_open(str(shard), framework='pt', device='cpu') as f:
32
+ return f.get_slice(tensor_name)[start:end].to(torch.float32).numpy()
33
+ chunks = [lambda start=start, end=min(start+chunk_rows,shape[0]): load(start,end)
34
+ for start in range(0,shape[0],chunk_rows)]
35
+ return TorchChunkedTensor(chunks, shape)
36
+
37
+ class RowwiseHead:
38
+ """Read the two classifier rows before float32 conversion, not after it."""
39
+ dtype = torch.float32
40
+ def __init__(self, shard, tensor_name):
41
+ self.shard = Path(shard)
42
+ self.tensor_name = tensor_name
43
+ def __getitem__(self, row):
44
+ with safe_open(str(self.shard), framework='pt', device='cpu') as f:
45
+ return f.get_slice(self.tensor_name)[row:row+1].to(torch.float32).squeeze(0)
46
+
47
+ def install_adapter():
48
+ from conversion.qwen import Qwen3Model
49
+ original = Qwen3Model.get_tensors
50
+ def get_tensors(self):
51
+ eligible = (self.is_rerank and not self.is_tied_embeddings
52
+ and self.ftype == gguf.LlamaFileType.MOSTLY_BF16)
53
+ index_file = self.dir_model/'model.safetensors.index.json'
54
+ index = json.loads(index_file.read_text())['weight_map'] if eligible and index_file.exists() else {}
55
+ for name, tensor in original(self):
56
+ if eligible and name in index and name.endswith('embed_tokens.weight'):
57
+ logging.info('Low-memory chunked embedding: %s', name)
58
+ yield name, chunked_embedding(self.dir_model/index[name],name)
59
+ elif eligible and name in index and name.endswith('lm_head.weight'):
60
+ logging.info('Low-memory rowwise reranker head: %s', name)
61
+ yield name, RowwiseHead(self.dir_model/index[name],name)
62
+ else:
63
+ yield name, tensor
64
+ Qwen3Model.get_tensors = get_tensors
65
+
66
+ if __name__ == '__main__':
67
+ install_adapter()
68
+ runpy.run_path(str(ROOT/'llama.cpp/convert_hf_to_gguf.py'),run_name='__main__')
convert.log ADDED
The diff for this file is too large to render. See raw diff