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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈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. 对于局部定义的对象&#…