dengcao commited on
Commit
fc91b8b
·
verified ·
1 Parent(s): 6a264bd

Upload 5 files

Browse files
Files changed (5) hide show
  1. .mdl +0 -0
  2. .msc +0 -0
  3. README.md +459 -3
  4. configuration.json +1 -0
  5. gitattributes +77 -0
.mdl ADDED
Binary file (53 Bytes). View file
 
.msc ADDED
Binary file (398 Bytes). View file
 
README.md CHANGED
@@ -1,3 +1,459 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model:
4
+ - Qwen/Qwen3-4B-Base
5
+ library_name: transformers
6
+ ---
7
+
8
+ # <span style="color: #7FFF7F;">Qwen3-Reranker-4B GGUF Models</span>
9
+
10
+
11
+ ## <span style="color: #7F7FFF;">Model Generation Details</span>
12
+
13
+ This model was generated using [llama.cpp](https://github.com/ggerganov/llama.cpp) at commit [`745aa531`](https://github.com/ggerganov/llama.cpp/commit/745aa5319b9930068aff5e87cf5e9eef7227339b).
14
+
15
+
16
+
17
+
18
+ ## <span style="color: #7FFF7F;">Ultra-Low-Bit Quantization with IQ-DynamicGate (1-2 bit)</span>
19
+
20
+ Our latest quantization method introduces **precision-adaptive quantization** for ultra-low-bit models (1-2 bit), with benchmark-proven improvements on **Llama-3-8B**. This approach uses layer-specific strategies to preserve accuracy while maintaining extreme memory efficiency.
21
+
22
+ ### **Benchmark Context**
23
+ All tests conducted on **Llama-3-8B-Instruct** using:
24
+ - Standard perplexity evaluation pipeline
25
+ - 2048-token context window
26
+ - Same prompt set across all quantizations
27
+
28
+ ### **Method**
29
+ - **Dynamic Precision Allocation**:
30
+ - First/Last 25% of layers → IQ4_XS (selected layers)
31
+ - Middle 50% → IQ2_XXS/IQ3_S (increase efficiency)
32
+ - **Critical Component Protection**:
33
+ - Embeddings/output layers use Q5_K
34
+ - Reduces error propagation by 38% vs standard 1-2bit
35
+
36
+ ### **Quantization Performance Comparison (Llama-3-8B)**
37
+
38
+ | Quantization | Standard PPL | DynamicGate PPL | Δ PPL | Std Size | DG Size | Δ Size | Std Speed | DG Speed |
39
+ |--------------|--------------|------------------|---------|----------|---------|--------|-----------|----------|
40
+ | IQ2_XXS | 11.30 | 9.84 | -12.9% | 2.5G | 2.6G | +0.1G | 234s | 246s |
41
+ | IQ2_XS | 11.72 | 11.63 | -0.8% | 2.7G | 2.8G | +0.1G | 242s | 246s |
42
+ | IQ2_S | 14.31 | 9.02 | -36.9% | 2.7G | 2.9G | +0.2G | 238s | 244s |
43
+ | IQ1_M | 27.46 | 15.41 | -43.9% | 2.2G | 2.5G | +0.3G | 206s | 212s |
44
+ | IQ1_S | 53.07 | 32.00 | -39.7% | 2.1G | 2.4G | +0.3G | 184s | 209s |
45
+
46
+ **Key**:
47
+ - PPL = Perplexity (lower is better)
48
+ - Δ PPL = Percentage change from standard to DynamicGate
49
+ - Speed = Inference time (CPU avx2, 2048 token context)
50
+ - Size differences reflect mixed quantization overhead
51
+
52
+ **Key Improvements:**
53
+ - 🔥 **IQ1_M** shows massive 43.9% perplexity reduction (27.46 → 15.41)
54
+ - 🚀 **IQ2_S** cuts perplexity by 36.9% while adding only 0.2GB
55
+ - ⚡ **IQ1_S** maintains 39.7% better accuracy despite 1-bit quantization
56
+
57
+ **Tradeoffs:**
58
+ - All variants have modest size increases (0.1-0.3GB)
59
+ - Inference speeds remain comparable (<5% difference)
60
+
61
+
62
+ ### **When to Use These Models**
63
+ 📌 **Fitting models into GPU VRAM**
64
+
65
+ ✔ **Memory-constrained deployments**
66
+
67
+ ✔ **Cpu and Edge Devices** where 1-2bit errors can be tolerated
68
+
69
+ ✔ **Research** into ultra-low-bit quantization
70
+
71
+
72
+
73
+
74
+ ## **Choosing the Right Model Format**
75
+
76
+ Selecting the correct model format depends on your **hardware capabilities** and **memory constraints**.
77
+
78
+ ### **BF16 (Brain Float 16) – Use if BF16 acceleration is available**
79
+ - A 16-bit floating-point format designed for **faster computation** while retaining good precision.
80
+ - Provides **similar dynamic range** as FP32 but with **lower memory usage**.
81
+ - Recommended if your hardware supports **BF16 acceleration** (check your device's specs).
82
+ - Ideal for **high-performance inference** with **reduced memory footprint** compared to FP32.
83
+
84
+ 📌 **Use BF16 if:**
85
+ ✔ Your hardware has native **BF16 support** (e.g., newer GPUs, TPUs).
86
+ ✔ You want **higher precision** while saving memory.
87
+ ✔ You plan to **requantize** the model into another format.
88
+
89
+ 📌 **Avoid BF16 if:**
90
+ ❌ Your hardware does **not** support BF16 (it may fall back to FP32 and run slower).
91
+ ❌ You need compatibility with older devices that lack BF16 optimization.
92
+
93
+ ---
94
+
95
+ ### **F16 (Float 16) – More widely supported than BF16**
96
+ - A 16-bit floating-point **high precision** but with less of range of values than BF16.
97
+ - Works on most devices with **FP16 acceleration support** (including many GPUs and some CPUs).
98
+ - Slightly lower numerical precision than BF16 but generally sufficient for inference.
99
+
100
+ 📌 **Use F16 if:**
101
+ ✔ Your hardware supports **FP16** but **not BF16**.
102
+ ✔ You need a **balance between speed, memory usage, and accuracy**.
103
+ ✔ You are running on a **GPU** or another device optimized for FP16 computations.
104
+
105
+ 📌 **Avoid F16 if:**
106
+ ❌ Your device lacks **native FP16 support** (it may run slower than expected).
107
+ ❌ You have memory limitations.
108
+
109
+ ---
110
+
111
+ ### **Quantized Models (Q4_K, Q6_K, Q8, etc.) – For CPU & Low-VRAM Inference**
112
+ Quantization reduces model size and memory usage while maintaining as much accuracy as possible.
113
+ - **Lower-bit models (Q4_K)** → **Best for minimal memory usage**, may have lower precision.
114
+ - **Higher-bit models (Q6_K, Q8_0)** → **Better accuracy**, requires more memory.
115
+
116
+ 📌 **Use Quantized Models if:**
117
+ ✔ You are running inference on a **CPU** and need an optimized model.
118
+ ✔ Your device has **low VRAM** and cannot load full-precision models.
119
+ ✔ You want to reduce **memory footprint** while keeping reasonable accuracy.
120
+
121
+ 📌 **Avoid Quantized Models if:**
122
+ ❌ You need **maximum accuracy** (full-precision models are better for this).
123
+ ❌ Your hardware has enough VRAM for higher-precision formats (BF16/F16).
124
+
125
+ ---
126
+
127
+ ### **Very Low-Bit Quantization (IQ3_XS, IQ3_S, IQ3_M, Q4_K, Q4_0)**
128
+ These models are optimized for **extreme memory efficiency**, making them ideal for **low-power devices** or **large-scale deployments** where memory is a critical constraint.
129
+
130
+ - **IQ3_XS**: Ultra-low-bit quantization (3-bit) with **extreme memory efficiency**.
131
+ - **Use case**: Best for **ultra-low-memory devices** where even Q4_K is too large.
132
+ - **Trade-off**: Lower accuracy compared to higher-bit quantizations.
133
+
134
+ - **IQ3_S**: Small block size for **maximum memory efficiency**.
135
+ - **Use case**: Best for **low-memory devices** where **IQ3_XS** is too aggressive.
136
+
137
+ - **IQ3_M**: Medium block size for better accuracy than **IQ3_S**.
138
+ - **Use case**: Suitable for **low-memory devices** where **IQ3_S** is too limiting.
139
+
140
+ - **Q4_K**: 4-bit quantization with **block-wise optimization** for better accuracy.
141
+ - **Use case**: Best for **low-memory devices** where **Q6_K** is too large.
142
+
143
+ - **Q4_0**: Pure 4-bit quantization, optimized for **ARM devices**.
144
+ - **Use case**: Best for **ARM-based devices** or **low-memory environments**.
145
+
146
+ ---
147
+
148
+ ### **Summary Table: Model Format Selection**
149
+
150
+ | Model Format | Precision | Memory Usage | Device Requirements | Best Use Case |
151
+ |--------------|------------|---------------|----------------------|---------------|
152
+ | **BF16** | Highest | High | BF16-supported GPU/CPUs | High-speed inference with reduced memory |
153
+ | **F16** | High | High | FP16-supported devices | GPU inference when BF16 isn't available |
154
+ | **Q4_K** | Medium Low | Low | CPU or Low-VRAM devices | Best for memory-constrained environments |
155
+ | **Q6_K** | Medium | Moderate | CPU with more memory | Better accuracy while still being quantized |
156
+ | **Q8_0** | High | Moderate | CPU or GPU with enough VRAM | Best accuracy among quantized models |
157
+ | **IQ3_XS** | Very Low | Very Low | Ultra-low-memory devices | Extreme memory efficiency and low accuracy |
158
+ | **Q4_0** | Low | Low | ARM or low-memory devices | llama.cpp can optimize for ARM devices |
159
+
160
+ ---
161
+
162
+
163
+
164
+ # <span id="testllm" style="color: #7F7FFF;">🚀 If you find these models useful</span>
165
+ ❤ **Please click "Like" if you find this useful!**
166
+ Help me test my **AI-Powered Network Monitor Assistant** with **quantum-ready security checks**:
167
+ 👉 [Free Network Monitor](https://readyforquantum.com/dashboard/?assistant=open)
168
+
169
+ 💬 **How to test**:
170
+ Choose an **AI assistant type**:
171
+ - `TurboLLM` (GPT-4o-mini)
172
+ - `HugLLM` (Hugginface Open-source)
173
+ - `TestLLM` (Experimental CPU-only)
174
+
175
+ ### **What I’m Testing**
176
+ I’m pushing the limits of **small open-source models for AI network monitoring**, specifically:
177
+ - **Function calling** against live network services
178
+ - **How small can a model go** while still handling:
179
+ - Automated **Nmap scans**
180
+ - **Quantum-readiness checks**
181
+ - **Network Monitoring tasks**
182
+
183
+ 🟡 **TestLLM** – Current experimental model (llama.cpp on 2 CPU threads):
184
+ - ✅ **Zero-configuration setup**
185
+ - ⏳ 30s load time (slow inference but **no API costs**)
186
+ - 🔧 **Help wanted!** If you’re into **edge-device AI**, let’s collaborate!
187
+
188
+ ### **Other Assistants**
189
+ 🟢 **TurboLLM** – Uses **gpt-4o-mini** for:
190
+ - **Create custom cmd processors to run .net code on Free Network Monitor Agents**
191
+ - **Real-time network diagnostics and monitoring**
192
+ - **Security Audits**
193
+ - **Penetration testing** (Nmap/Metasploit)
194
+ - 🔑 Get more tokens by logging in or [downloading our Free Network Monitor Agent with integrated AI Assistant](https://readyforquantum.com/download)
195
+
196
+ 🔵 **HugLLM** – Latest Open-source models:
197
+ - 🌐 Runs on Hugging Face Inference API
198
+
199
+ ### 💡 **Example commands to you could test**:
200
+ 1. `"Give me info on my websites SSL certificate"`
201
+ 2. `"Check if my server is using quantum safe encyption for communication"`
202
+ 3. `"Run a comprehensive security audit on my server"`
203
+ 4. '"Create a cmd processor to .. (what ever you want)" Note you need to install a Free Network Monitor Agent to run the .net code from. This is a very flexible and powerful feature. Use with caution!
204
+
205
+ ### Final Word
206
+
207
+ I fund the servers used to create these model files, run the Free Network Monitor service, and pay for inference from Novita and OpenAI—all out of my own pocket. All the code behind the model creation and the Free Network Monitor project is [open source](https://github.com/Mungert69). Feel free to use whatever you find helpful.
208
+
209
+ If you appreciate the work, please consider [buying me a coffee](https://www.buymeacoffee.com/mahadeva) ☕. Your support helps cover service costs and allows me to raise token limits for everyone.
210
+
211
+ I'm also open to job opportunities or sponsorship.
212
+
213
+ Thank you! 😊
214
+
215
+
216
+
217
+
218
+
219
+ # Qwen3-Reranker-4B
220
+
221
+ <p align="center">
222
+ <img src="https://qianwen-res.oss-accelerate-overseas.aliyuncs.com/logo_qwen3.png" width="400"/>
223
+ <p>
224
+
225
+ ## Highlights
226
+
227
+ The Qwen3 Embedding model series is the latest proprietary model of the Qwen family, specifically designed for text embedding and ranking tasks. Building upon the dense foundational models of the Qwen3 series, it provides a comprehensive range of text embeddings and reranking models in various sizes (0.6B, 4B, and 8B). This series inherits the exceptional multilingual capabilities, long-text understanding, and reasoning skills of its foundational model. The Qwen3 Embedding series represents significant advancements in multiple text embedding and ranking tasks, including text retrieval, code retrieval, text classification, text clustering, and bitext mining.
228
+
229
+ **Exceptional Versatility**: The embedding model has achieved state-of-the-art performance across a wide range of downstream application evaluations. The 8B size embedding model ranks No.1 in the MTEB multilingual leaderboard (as of June 5, 2025, score 70.58), while the reranking model excels in various text retrieval scenarios.
230
+
231
+ **Comprehensive Flexibility**: The Qwen3 Embedding series offers a full spectrum of sizes (from 0.6B to 8B) for both embedding and reranking models, catering to diverse use cases that prioritize efficiency and effectiveness. Developers can seamlessly combine these two modules. Additionally, the embedding model allows for flexible vector definitions across all dimensions, and both embedding and reranking models support user-defined instructions to enhance performance for specific tasks, languages, or scenarios.
232
+
233
+ **Multilingual Capability**: The Qwen3 Embedding series offer support for over 100 languages, thanks to the multilingual capabilites of Qwen3 models. This includes various programming languages, and provides robust multilingual, cross-lingual, and code retrieval capabilities.
234
+
235
+ **Qwen3-Reranker-4B** has the following features:
236
+
237
+ - Model Type: Text Reranking
238
+ - Supported Languages: 100+ Languages
239
+ - Number of Paramaters: 4B
240
+ - Context Length: 32k
241
+
242
+ For more details, including benchmark evaluation, hardware requirements, and inference performance, please refer to our [blog](https://qwenlm.github.io/blog/qwen3-embedding/), [GitHub](https://github.com/QwenLM/Qwen3-Embedding).
243
+
244
+ ## Qwen3 Embedding Series Model list
245
+
246
+ | Model Type | Models | Size | Layers | Sequence Length | Embedding Dimension | MRL Support | Instruction Aware |
247
+ |------------------|----------------------|------|--------|-----------------|---------------------|-------------|----------------|
248
+ | Text Embedding | [Qwen3-Embedding-0.6B](https://huggingface.co/Qwen/Qwen3-Embedding-0.6B) | 0.6B | 28 | 32K | 1024 | Yes | Yes |
249
+ | Text Embedding | [Qwen3-Embedding-4B](https://huggingface.co/Qwen/Qwen3-Embedding-4B) | 4B | 36 | 32K | 2560 | Yes | Yes |
250
+ | Text Embedding | [Qwen3-Embedding-8B](https://huggingface.co/Qwen/Qwen3-Embedding-8B) | 8B | 36 | 32K | 4096 | Yes | Yes |
251
+ | Text Reranking | [Qwen3-Reranker-0.6B](https://huggingface.co/Qwen/Qwen3-Reranker-0.6B) | 0.6B | 28 | 32K | - | - | Yes |
252
+ | Text Reranking | [Qwen3-Reranker-4B](https://huggingface.co/Qwen/Qwen3-Reranker-4B) | 4B | 36 | 32K | - | - | Yes |
253
+ | Text Reranking | [Qwen3-Reranker-8B](https://huggingface.co/Qwen/Qwen3-Reranker-8B) | 8B | 36 | 32K | - | - | Yes |
254
+
255
+ > **Note**:
256
+ > - `MRL Support` indicates whether the embedding model supports custom dimensions for the final embedding.
257
+ > - `Instruction Aware` notes whether the embedding or reranking model supports customizing the input instruction according to different tasks.
258
+ > - Our evaluation indicates that, for most downstream tasks, using instructions (instruct) typically yields an improvement of 1% to 5% compared to not using them. Therefore, we recommend that developers create tailored instructions specific to their tasks and scenarios. In multilingual contexts, we also advise users to write their instructions in English, as most instructions utilized during the model training process were originally written in English.
259
+
260
+
261
+ ## Usage
262
+
263
+ With Transformers versions earlier than 4.51.0, you may encounter the following error:
264
+ ```
265
+ KeyError: 'qwen3'
266
+ ```
267
+
268
+ ### Transformers Usage
269
+
270
+ ```python
271
+ # Requires transformers>=4.51.0
272
+ import torch
273
+ from transformers import AutoModel, AutoTokenizer, AutoModelForCausalLM
274
+
275
+ def format_instruction(instruction, query, doc):
276
+ if instruction is None:
277
+ instruction = 'Given a web search query, retrieve relevant passages that answer the query'
278
+ output = "<Instruct>: {instruction}\n<Query>: {query}\n<Document>: {doc}".format(instruction=instruction,query=query, doc=doc)
279
+ return output
280
+
281
+ def process_inputs(pairs):
282
+ inputs = tokenizer(
283
+ pairs, padding=False, truncation='longest_first',
284
+ return_attention_mask=False, max_length=max_length - len(prefix_tokens) - len(suffix_tokens)
285
+ )
286
+ for i, ele in enumerate(inputs['input_ids']):
287
+ inputs['input_ids'][i] = prefix_tokens + ele + suffix_tokens
288
+ inputs = tokenizer.pad(inputs, padding=True, return_tensors="pt", max_length=max_length)
289
+ for key in inputs:
290
+ inputs[key] = inputs[key].to(model.device)
291
+ return inputs
292
+
293
+ @torch.no_grad()
294
+ def compute_logits(inputs, **kwargs):
295
+ batch_scores = model(**inputs).logits[:, -1, :]
296
+ true_vector = batch_scores[:, token_true_id]
297
+ false_vector = batch_scores[:, token_false_id]
298
+ batch_scores = torch.stack([false_vector, true_vector], dim=1)
299
+ batch_scores = torch.nn.functional.log_softmax(batch_scores, dim=1)
300
+ scores = batch_scores[:, 1].exp().tolist()
301
+ return scores
302
+
303
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-Reranker-4B", padding_side='left')
304
+ model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-Reranker-4B").eval()
305
+
306
+ # We recommend enabling flash_attention_2 for better acceleration and memory saving.
307
+ # model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-Reranker-4B", torch_dtype=torch.float16, attn_implementation="flash_attention_2").cuda().eval()
308
+
309
+ token_false_id = tokenizer.convert_tokens_to_ids("no")
310
+ token_true_id = tokenizer.convert_tokens_to_ids("yes")
311
+ max_length = 8192
312
+
313
+ prefix = "<|im_start|>system\nJudge whether the Document meets the requirements based on the Query and the Instruct provided. Note that the answer can only be \"yes\" or \"no\".<|im_end|>\n<|im_start|>user\n"
314
+ suffix = "<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n"
315
+ prefix_tokens = tokenizer.encode(prefix, add_special_tokens=False)
316
+ suffix_tokens = tokenizer.encode(suffix, add_special_tokens=False)
317
+
318
+ task = 'Given a web search query, retrieve relevant passages that answer the query'
319
+
320
+ queries = ["What is the capital of China?",
321
+ "Explain gravity",
322
+ ]
323
+
324
+ documents = [
325
+ "The capital of China is Beijing.",
326
+ "Gravity is a force that attracts two bodies towards each other. It gives weight to physical objects and is responsible for the movement of planets around the sun.",
327
+ ]
328
+
329
+ pairs = [format_instruction(task, query, doc) for query, doc in zip(queries, documents)]
330
+
331
+ # Tokenize the input texts
332
+ inputs = process_inputs(pairs)
333
+ scores = compute_logits(inputs)
334
+
335
+ print("scores: ", scores)
336
+ ```
337
+
338
+ ### vLLM Usage
339
+
340
+ ```python
341
+ # Requires vllm>=0.8.5
342
+ import logging
343
+ from typing import Dict, Optional, List
344
+
345
+ import json
346
+ import logging
347
+
348
+ import torch
349
+
350
+ from transformers import AutoTokenizer, is_torch_npu_available
351
+ from vllm import LLM, SamplingParams
352
+ from vllm.distributed.parallel_state import destroy_model_parallel
353
+ import gc
354
+ import math
355
+ from vllm.inputs.data import TokensPrompt
356
+
357
+
358
+
359
+ def format_instruction(instruction, query, doc):
360
+ text = [
361
+ {"role": "system", "content": "Judge whether the Document meets the requirements based on the Query and the Instruct provided. Note that the answer can only be \"yes\" or \"no\"."},
362
+ {"role": "user", "content": f"<Instruct>: {instruction}\n\n<Query>: {query}\n\n<Document>: {doc}"}
363
+ ]
364
+ return text
365
+
366
+ def process_inputs(pairs, instruction, max_length, suffix_tokens):
367
+ messages = [format_instruction(instruction, query, doc) for query, doc in pairs]
368
+ messages = tokenizer.apply_chat_template(
369
+ messages, tokenize=True, add_generation_prompt=False, enable_thinking=False
370
+ )
371
+ messages = [ele[:max_length] + suffix_tokens for ele in messages]
372
+ messages = [TokensPrompt(prompt_token_ids=ele) for ele in messages]
373
+ return messages
374
+
375
+ def compute_logits(model, messages, sampling_params, true_token, false_token):
376
+ outputs = model.generate(messages, sampling_params, use_tqdm=False)
377
+ scores = []
378
+ for i in range(len(outputs)):
379
+ final_logits = outputs[i].outputs[0].logprobs[-1]
380
+ token_count = len(outputs[i].outputs[0].token_ids)
381
+ if true_token not in final_logits:
382
+ true_logit = -10
383
+ else:
384
+ true_logit = final_logits[true_token].logprob
385
+ if false_token not in final_logits:
386
+ false_logit = -10
387
+ else:
388
+ false_logit = final_logits[false_token].logprob
389
+ true_score = math.exp(true_logit)
390
+ false_score = math.exp(false_logit)
391
+ score = true_score / (true_score + false_score)
392
+ scores.append(score)
393
+ return scores
394
+
395
+ number_of_gpu = torch.cuda.device_count()
396
+ tokenizer = AutoTokenizer.from_pretrained('Qwen/Qwen3-Reranker-4B')
397
+ model = LLM(model='Qwen/Qwen3-Reranker-4B', tensor_parallel_size=number_of_gpu, max_model_len=10000, enable_prefix_caching=True, gpu_memory_utilization=0.8)
398
+ tokenizer.padding_side = "left"
399
+ tokenizer.pad_token = tokenizer.eos_token
400
+ suffix = "<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n"
401
+ max_length=8192
402
+ suffix_tokens = tokenizer.encode(suffix, add_special_tokens=False)
403
+ true_token = tokenizer("yes", add_special_tokens=False).input_ids[0]
404
+ false_token = tokenizer("no", add_special_tokens=False).input_ids[0]
405
+ sampling_params = SamplingParams(temperature=0,
406
+ max_tokens=1,
407
+ logprobs=20,
408
+ allowed_token_ids=[true_token, false_token],
409
+ )
410
+
411
+
412
+ task = 'Given a web search query, retrieve relevant passages that answer the query'
413
+ queries = ["What is the capital of China?",
414
+ "Explain gravity",
415
+ ]
416
+ documents = [
417
+ "The capital of China is Beijing.",
418
+ "Gravity is a force that attracts two bodies towards each other. It gives weight to physical objects and is responsible for the movement of planets around the sun.",
419
+ ]
420
+
421
+ pairs = list(zip(queries, documents))
422
+ inputs = process_inputs(pairs, task, max_length-len(suffix_tokens), suffix_tokens)
423
+ scores = compute_logits(model, inputs, sampling_params, true_token, false_token)
424
+ print('scores', scores)
425
+
426
+ destroy_model_parallel()
427
+ ```
428
+
429
+
430
+ 📌 **Tip**: We recommend that developers customize the `instruct` according to their specific scenarios, tasks, and languages. Our tests have shown that in most retrieval scenarios, not using an `instruct` on the query side can lead to a drop in retrieval performance by approximately 1% to 5%.
431
+
432
+ ## Evaluation
433
+
434
+ | Model | Param | MTEB-R | CMTEB-R | MMTEB-R | MLDR | MTEB-Code | FollowIR |
435
+ |------------------------------------|--------|---------|---------|---------|--------|-----------|----------|
436
+ | **Qwen3-Embedding-0.6B** | 0.6B | 61.82 | 71.02 | 64.64 | 50.26 | 75.41 | 5.09 |
437
+ | Jina-multilingual-reranker-v2-base | 0.3B | 58.22 | 63.37 | 63.73 | 39.66 | 58.98 | -0.68 |
438
+ | gte-multilingual-reranker-base | 0.3B | 59.51 | 74.08 | 59.44 | 66.33 | 54.18 | -1.64 |
439
+ | BGE-reranker-v2-m3 | 0.6B | 57.03 | 72.16 | 58.36 | 59.51 | 41.38 | -0.01 |
440
+ | **Qwen3-Reranker-0.6B** | 0.6B | 65.80 | 71.31 | 66.36 | 67.28 | 73.42 | 5.41 |
441
+ | **Qwen3-Reranker-4B** | 4B | **69.76** | 75.94 | 72.74 | 69.97 | 81.20 | **14.84** |
442
+ | **Qwen3-Reranker-8B** | 8B | 69.02 | **77.45** | **72.94** | **70.19** | **81.22** | 8.05 |
443
+
444
+ > **Note**:
445
+ > - Evaluation results for reranking models. We use the retrieval subsets of MTEB(eng, v2), MTEB(cmn, v1), MMTEB and MTEB (Code), which are MTEB-R, CMTEB-R, MMTEB-R and MTEB-Code.
446
+ > - All scores are our runs based on the top-100 candidates retrieved by dense embedding model [Qwen3-Embedding-0.6B](https://huggingface.co/Qwen/Qwen3-Embedding-0.6B).
447
+
448
+ ## Citation
449
+ If you find our work helpful, feel free to give us a cite.
450
+
451
+ ```
452
+ @misc{qwen3-embedding,
453
+ title = {Qwen3-Embedding},
454
+ url = {https://qwenlm.github.io/blog/qwen3/},
455
+ author = {Qwen Team},
456
+ month = {May},
457
+ year = {2025}
458
+ }
459
+ ```
configuration.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"task":"sentence-embedding"}
gitattributes ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz 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-4B-f16.gguf filter=lfs diff=lfs merge=lfs -text
37
+ Qwen3-Reranker-4B-f16_q8_0.gguf filter=lfs diff=lfs merge=lfs -text
38
+ Qwen3-Reranker-4B-bf16_q8_0.gguf filter=lfs diff=lfs merge=lfs -text
39
+ Qwen3-Reranker-4B-f16_q6_k.gguf filter=lfs diff=lfs merge=lfs -text
40
+ Qwen3-Reranker-4B-bf16_q6_k.gguf filter=lfs diff=lfs merge=lfs -text
41
+ Qwen3-Reranker-4B-f16_q4_k.gguf filter=lfs diff=lfs merge=lfs -text
42
+ Qwen3-Reranker-4B-bf16_q4_k.gguf filter=lfs diff=lfs merge=lfs -text
43
+ Qwen3-Reranker-4B-q2_k_l.gguf filter=lfs diff=lfs merge=lfs -text
44
+ Qwen3-Reranker-4B-q3_k_l.gguf filter=lfs diff=lfs merge=lfs -text
45
+ Qwen3-Reranker-4B-q4_k_l.gguf filter=lfs diff=lfs merge=lfs -text
46
+ Qwen3-Reranker-4B-q5_k_l.gguf filter=lfs diff=lfs merge=lfs -text
47
+ Qwen3-Reranker-4B-q6_k_l.gguf filter=lfs diff=lfs merge=lfs -text
48
+ Qwen3-Reranker-4B-q2_k_m.gguf filter=lfs diff=lfs merge=lfs -text
49
+ Qwen3-Reranker-4B-q2_k_s.gguf filter=lfs diff=lfs merge=lfs -text
50
+ Qwen3-Reranker-4B-q3_k_m.gguf filter=lfs diff=lfs merge=lfs -text
51
+ Qwen3-Reranker-4B-q3_k_s.gguf filter=lfs diff=lfs merge=lfs -text
52
+ Qwen3-Reranker-4B-q4_k_m.gguf filter=lfs diff=lfs merge=lfs -text
53
+ Qwen3-Reranker-4B-q4_k_s.gguf filter=lfs diff=lfs merge=lfs -text
54
+ Qwen3-Reranker-4B-q5_k_m.gguf filter=lfs diff=lfs merge=lfs -text
55
+ Qwen3-Reranker-4B-q5_k_s.gguf filter=lfs diff=lfs merge=lfs -text
56
+ Qwen3-Reranker-4B-q6_k_m.gguf filter=lfs diff=lfs merge=lfs -text
57
+ Qwen3-Reranker-4B-q8_0.gguf filter=lfs diff=lfs merge=lfs -text
58
+ Qwen3-Reranker-4B-q4_0.gguf filter=lfs diff=lfs merge=lfs -text
59
+ Qwen3-Reranker-4B-q4_1.gguf filter=lfs diff=lfs merge=lfs -text
60
+ Qwen3-Reranker-4B-q4_0_l.gguf filter=lfs diff=lfs merge=lfs -text
61
+ Qwen3-Reranker-4B-q4_1_l.gguf filter=lfs diff=lfs merge=lfs -text
62
+ Qwen3-Reranker-4B-q5_0.gguf filter=lfs diff=lfs merge=lfs -text
63
+ Qwen3-Reranker-4B-q5_1.gguf filter=lfs diff=lfs merge=lfs -text
64
+ Qwen3-Reranker-4B-q5_0_l.gguf filter=lfs diff=lfs merge=lfs -text
65
+ Qwen3-Reranker-4B-q5_1_l.gguf filter=lfs diff=lfs merge=lfs -text
66
+ Qwen3-Reranker-4B-iq2_xs.gguf filter=lfs diff=lfs merge=lfs -text
67
+ Qwen3-Reranker-4B-iq2_xxs.gguf filter=lfs diff=lfs merge=lfs -text
68
+ Qwen3-Reranker-4B-iq2_s.gguf filter=lfs diff=lfs merge=lfs -text
69
+ Qwen3-Reranker-4B-iq2_m.gguf filter=lfs diff=lfs merge=lfs -text
70
+ Qwen3-Reranker-4B-iq3_xs.gguf filter=lfs diff=lfs merge=lfs -text
71
+ Qwen3-Reranker-4B-iq3_xxs.gguf filter=lfs diff=lfs merge=lfs -text
72
+ Qwen3-Reranker-4B-iq3_s.gguf filter=lfs diff=lfs merge=lfs -text
73
+ Qwen3-Reranker-4B-iq3_m.gguf filter=lfs diff=lfs merge=lfs -text
74
+ Qwen3-Reranker-4B-iq4_xs.gguf filter=lfs diff=lfs merge=lfs -text
75
+ Qwen3-Reranker-4B-iq4_nl.gguf filter=lfs diff=lfs merge=lfs -text
76
+ Qwen3-Reranker-4B.imatrix filter=lfs diff=lfs merge=lfs -text
77
+ Qwen3-Reranker-4B-bf16.gguf filter=lfs diff=lfs merge=lfs -text