Qwen3-Reranker-0.6B 模型結構

模型加載

import torch
from modelscope import AutoModel, AutoTokenizer, AutoModelForCausalLMtokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-Reranker-0.6B", padding_side='left')
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-Reranker-0.6B").eval()

模型結構與配置

model
Qwen3ForCausalLM((model): Qwen3Model((embed_tokens): Embedding(151669, 1024)(layers): ModuleList((0-27): 28 x Qwen3DecoderLayer((self_attn): Qwen3Attention((q_proj): Linear(in_features=1024, out_features=2048, bias=False)(k_proj): Linear(in_features=1024, out_features=1024, bias=False)(v_proj): Linear(in_features=1024, out_features=1024, bias=False)(o_proj): Linear(in_features=2048, out_features=1024, bias=False)(q_norm): Qwen3RMSNorm((128,), eps=1e-06)(k_norm): Qwen3RMSNorm((128,), eps=1e-06))(mlp): Qwen3MLP((gate_proj): Linear(in_features=1024, out_features=3072, bias=False)(up_proj): Linear(in_features=1024, out_features=3072, bias=False)(down_proj): Linear(in_features=3072, out_features=1024, bias=False)(act_fn): SiLU())(input_layernorm): Qwen3RMSNorm((1024,), eps=1e-06)(post_attention_layernorm): Qwen3RMSNorm((1024,), eps=1e-06)))(norm): Qwen3RMSNorm((1024,), eps=1e-06)(rotary_emb): Qwen3RotaryEmbedding())(lm_head): Linear(in_features=1024, out_features=151669, bias=False)
)
model.config
Qwen3Config {"architectures": ["Qwen3ForCausalLM"],"attention_bias": false,"attention_dropout": 0.0,"bos_token_id": 151643,"eos_token_id": 151645,"head_dim": 128,"hidden_act": "silu","hidden_size": 1024,"initializer_range": 0.02,"intermediate_size": 3072,"layer_types": ["full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention","full_attention"],"max_position_embeddings": 40960,"max_window_layers": 28,"model_type": "qwen3","num_attention_heads": 16,"num_hidden_layers": 28,"num_key_value_heads": 8,"rms_norm_eps": 1e-06,"rope_scaling": null,"rope_theta": 1000000,"sliding_window": null,"tie_word_embeddings": true,"torch_dtype": "float32","transformers_version": "4.55.2","use_cache": true,"use_sliding_window": false,"vocab_size": 151669
}

模型使用

def format_instruction(instruction, query, doc):if instruction is None:instruction = 'Given a web search query, retrieve relevant passages that answer the query'output = "<Instruct>: {instruction}\n<Query>: {query}\n<Document>: {doc}".format(instruction=instruction,query=query, doc=doc)return outputdef process_inputs(pairs):inputs = tokenizer(pairs, padding=False, truncation='longest_first',return_attention_mask=False, max_length=max_length - len(prefix_tokens) - len(suffix_tokens))for i, ele in enumerate(inputs['input_ids']):inputs['input_ids'][i] = prefix_tokens + ele + suffix_tokensinputs = tokenizer.pad(inputs, padding=True, return_tensors="pt", max_length=max_length)for key in inputs:inputs[key] = inputs[key].to(model.device)return inputs@torch.no_grad()
def compute_logits(inputs, **kwargs):batch_scores = model(**inputs).logits[:, -1, :]true_vector = batch_scores[:, token_true_id]false_vector = batch_scores[:, token_false_id]batch_scores = torch.stack([false_vector, true_vector], dim=1)batch_scores = torch.nn.functional.log_softmax(batch_scores, dim=1)scores = batch_scores[:, 1].exp().tolist()return scores# We recommend enabling flash_attention_2 for better acceleration and memory saving.
# model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-Reranker-0.6B", torch_dtype=torch.float16, attn_implementation="flash_attention_2").cuda().eval()
token_false_id = tokenizer.convert_tokens_to_ids("no")
token_true_id = tokenizer.convert_tokens_to_ids("yes")
max_length = 8192prefix = "<|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"
suffix = "<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n"
prefix_tokens = tokenizer.encode(prefix, add_special_tokens=False)
suffix_tokens = tokenizer.encode(suffix, add_special_tokens=False)task = 'Given a web search query, retrieve relevant passages that answer the query'queries = ["What is the capital of China?","Explain gravity",
]documents = ["The capital of China is Beijing.","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.",
]pairs = [format_instruction(task, query, doc) for query, doc in zip(queries, documents)]# Tokenize the input texts
inputs = process_inputs(pairs)
scores = compute_logits(inputs)print("scores: ", scores)
scores:  [0.9994982481002808, 0.9993619322776794]

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/920971.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/920971.shtml
英文地址,請注明出處:http://en.pswp.cn/news/920971.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

無參 MOS 算法的評估方式

一、無參 MOS 算法 在音頻處理和質量評估領域&#xff0c;MOS&#xff08;Mean Opinion Score&#xff09;是一種常用的主觀評價指標&#xff0c;用于衡量音頻質量。然而&#xff0c;獲取主觀 MOS 評分通常需要大量的人力和時間。因此&#xff0c;無參 MOS 算法應運而生&#…

Flowable——配置使用Flowable-UI

文章目錄 前言 框架選型與版本 flowable-ui 搭建 依賴引入 springboot 主要版本 flowable 相關 log4j 日志配置項 配置文件 log4j配置文件 application.yml 增加啟動類并啟動程序 項目整體結構 前言 最近對工作流的flowable比較感興趣,匯總記錄一下相關的研究學習知識點。 框…

2025大學生必考互聯網行業證書排名?

在互聯網行業蓬勃發展的當下&#xff0c;大學生若想畢業后順利投身其中&#xff0c;提前考取相關高含金量證書不失為明智之舉。這些證書不僅能證明專業能力&#xff0c;還能在求職時為你增添競爭優勢。接下來&#xff0c;為大家詳細介紹 2025 年大學生必考的互聯網行業證書排名…

【并發系列-01】高并發系統架構設計原理

【并發系列-01】高并發系統架構設計原理 1. 業務場景&#xff1a;當雙11遇上技術挑戰 1.1 問題場景描述 想象一下這樣的場景&#xff1a;某電商平臺在雙11期間&#xff0c;短短30分鐘內涌入了500萬用戶&#xff0c;同時發起了超過2000萬次商品查詢請求和100萬次下單操作。而平時…

【Vue2 ?】Vue2 入門之旅(八):過渡與動畫

前幾篇我們學習了事件處理。本篇將介紹 過渡與動畫&#xff0c;讓 Vue 頁面更加生動。 目錄 transition 組件進入與離開過渡過渡類名結合 CSS 動畫JavaScript 鉤子小結 transition 組件 Vue 提供了內置組件 <transition>&#xff0c;可以為元素或組件的進入和離開添加動…

【LeetCode】力扣刷題攻略路線推薦!適合新手小白入門~(含各類題目序號)

力扣上有許多數據結構及算法的練習&#xff0c;但是如果由第一題【兩數之和】開始刷&#xff0c;會讓50%的人倒在起點。所以我們刷題要講究路線攻略以及技巧~大體路線方向由簡入難數學數組鏈表字符串哈希表雙指針遞歸棧隊列樹圖與回溯算法貪心動態規劃刷題技巧 建議刷題的時候分…

Windows 電腦發現老是自動訪問外網的域名排障步驟

Windows 電腦發現老是自動訪問外網的域名,如何排障 一、基礎信息獲取與進程定位 1.1、確認進程關鍵信息 1.2、進程合法性初步驗證 二、網絡連接深度分析 2.1、目的IP/域名溯源 2.2、端口與協議檢查 三、進程行為與系統異常排查 3.1、進程啟動與依賴分析 3.2、系統異常行為掃描…

curl、python-requests、postman和jmeter的對應關系

一、初識curlcurl 是一個功能強大的命令行工具&#xff0c;用于傳輸數據&#xff0c;支持多種協議&#xff08;如 HTTP、HTTPS、FTP 等&#xff09;。分析以下curl&#xff1a;curl "https://$HOST/mon/adm/au/opera" --header "Authorization: $AUTH" -X …

【MySQL】初識數據庫基礎

【MySQL】初識數據庫基礎 &#x1f525;個人主頁&#xff1a;大白的編程日記 &#x1f525;專欄&#xff1a;MySQL筆記 文章目錄【MySQL】初識數據庫基礎前言一. 數據庫基礎&#xff08;重點&#xff09;1.1 什么是數據庫1.2 主流數據庫1.3 基本使用1.3.1 MySQL安裝1.3.2 連接…

微服務Docker-compose之若依部署

目錄 1.創建一個文件夾 2.上傳壓縮包 3.解壓 4.執行ry1文件 5.執行ry2文件 6.進入nginx的html目錄解壓dist文件 7.執行ry3文件 8.訪問nacos 9.訪問若依 1.創建一個文件夾 2.上傳壓縮包 3.解壓 4.執行ry1文件 5.執行ry2文件 6.進入nginx的html目錄解壓dist文件 7.執行ry…

《中國棒球》健將級運動員什么水平·棒球1號位

棒球國家健將級の神級科普&#xff5c;國內TOP1%??國際能打嗎&#xff1f;1. 什么是"國家健將級"&#xff1f;&#xff5c;What is "Master Sportsman"&#xff1f;中國運動員等級天花板&#xff1a;僅次"國際健將"的最高國家級榮譽&#xff0…

NAT與內網穿透

目錄 一、為什么需要NAT&#xff1f; 二、NAT的核心&#xff1a;從“一對一”到“多對一” &#xff08;1&#xff09;靜態NAT &#xff08;2&#xff09;動態NAT &#xff08;3&#xff09;NAPT 三、NAPT的雙刃劍&#xff1a;安全與局 四、內網穿透 &#xff08;1&…

力扣222 代碼隨想錄Day15 第四題

完全二叉樹結點的數量class Solution { public:int countNodes(TreeNode* root) {if(rootNULL) return 0;TreeNode* leroot->left;TreeNode* riroot->right;int ld0;int rd0;while(le){lele->left;ld;}while(ri){riri->right;rd;}if(ldrd) return(2<<ld)-1;i…

Node.js異步編程:Callback/Promise/Async

Node.js異步編程&#xff1a;Callback/Promise/Async引言Node.js以其非阻塞I/O和事件驅動架構而聞名&#xff0c;這使得異步編程成為Node.js開發中的核心概念。在Node.js中&#xff0c;處理異步操作經歷了從Callback到Promise再到Async/Await的演進過程。本文將探討這三種異步編…

野火STM32Modbus主機讀取寄存器/線圈失敗(一)-解決接收中斷不觸發的問題

接收中斷不觸發 前情提要 在自己的開發板上移植了野火的modbus主機程序。 野火主機程序移植 野火主機代碼理解與使用 問題背景 我使用STM32顯示板作為Modbus主機連接電腦&#xff0c;并在電腦上運行Modbus Slave軟件。測試中發現&#xff0c;讀取保持寄存器和輸入寄存器均失…

5種常見的網絡安全漏洞及防護建議

五種常見的網絡安全漏洞及防護建議在數字化時代&#xff0c;網絡安全已成為個人和企業面臨的重要挑戰。網絡攻擊手段不斷升級&#xff0c;黑客利用各種漏洞入侵系統、竊取數據或破壞服務。了解常見的網絡安全漏洞并采取相應的防護措施&#xff0c;是保障信息安全的關鍵。本文將…

mysql5.6+分頁時使用 limit+order by 會出現數據重復問題

mysql5.6分頁時使用 limitorder by 會出現數據重復問題 問題描述 在MySQL中我們通常會采用limit來進行翻頁查詢&#xff0c;比如limit(0,10)表示列出第一頁的10條數據&#xff0c;limit(10,10)表示列出第二頁。但是&#xff0c;當limit遇到order by的時候&#xff0c;可能會出現…

【XR技術概念科普】VST(視頻透視)vs OST(光學透視):解碼MR頭顯的兩種核心技術路徑

混合現實(MR)頭顯作為連接虛擬與現實世界的橋梁&#xff0c;其核心技術路徑主要分為視頻透視(VST)和光學透視(OST)兩種。本文將深入探討這兩種技術的原理、優缺點、代表性產品、應用場景及未來發展趨勢&#xff0c;為讀者全面解析MR頭顯的技術選擇。一、VST技術詳解1.1 VST技術…

VR智慧樓宇技術:打造智能辦公空間的卓越方案?

在華銳視點打造的極具創新性的VR智慧樓宇的智能辦公空間里&#xff0c;員工的工作模式迎來了前所未有的、徹頭徹尾的顛覆性變革。憑借華銳視點自主研發的先進VR設備&#xff0c;哪怕員工遠在千里之外的不同城市&#xff0c;甚至身處不同國家&#xff0c;也能如同真切地置身于同…

C++ 面試考點 類成員函數的調用時機

構造函數和析構函數的調用時機 1. 對于全局定義的對象&#xff0c;每當程序開始運行&#xff0c;在主函數 main 接受程序控制權之前&#xff0c;就調 用構造函數創建全局對象&#xff0c;整個程序結束時&#xff0c;自動調用全局對象的析構函數。 2. 對于局部定義的對象&#…