【評測】Qwen3-Embedding模型初體驗

回到目錄

【評測】Qwen3-Embedding模型初體驗

模型的介紹頁面
0.6B運行配置:筆記本i5-8265U,16G內存,無GPU核顯運行,win10操作系統
8B運行配置:AMD8700G,64G內存,4090D 24G顯存,ubuntu24.04操作系統

下面直接使用介紹頁面的sample代碼體驗一下模型的威力。

1. modelscope下載模型

$ modelscope download --model Qwen/Qwen3-Embedding-0.6B
$ modelscope download --model Qwen/Qwen3-Embedding-8B
0.6B模型 1.12GB 8B模型 14.1GB

2. 修改sample代碼從本地加載模型

默認代碼運行報錯:
OSError: We couldn’t connect to ‘https://huggingface.co’ to load the files, and couldn’t find them in the cached files.

# test_qwen3-embedding.py# Requires transformers>=4.51.0
# Requires sentence-transformers>=2.7.0from sentence_transformers import SentenceTransformer# Load the model
#model = SentenceTransformer("Qwen/Qwen3-Embedding-8B")  改為下面代碼本地加載模型
model = SentenceTransformer("C:\\Users\\Administrator\\.cache\\modelscope\\hub\models\\Qwen\\Qwen3-Embedding-8B")# We recommend enabling flash_attention_2 for better acceleration and memory saving,
# together with setting `padding_side` to "left":
# model = SentenceTransformer(
#     "Qwen/Qwen3-Embedding-8B",
#     model_kwargs={"attn_implementation": "flash_attention_2", "device_map": "auto"},
#     tokenizer_kwargs={"padding_side": "left"},
# )# The queries and documents to embed
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.",
]# Encode the queries and documents. Note that queries benefit from using a prompt
# Here we use the prompt called "query" stored under `model.prompts`, but you can
# also pass your own prompt via the `prompt` argument
query_embeddings = model.encode(queries, prompt_name="query")
document_embeddings = model.encode(documents)# Compute the (cosine) similarity between the query and document embeddings
similarity = model.similarity(query_embeddings, document_embeddings)
print(similarity)
# tensor([[0.7493, 0.0751],
#         [0.0880, 0.6318]])

可能是機器配置太低問題,無法正常執行出結果
D:\workspace\test_qwen3-embedding.py:8: SyntaxWarning: invalid escape sequence ‘\m’
model = SentenceTransformer(“C:\Users\Administrator\.cache\modelscope\hub\models\Qwen\Qwen3-Embedding-8B”)
Loading checkpoint shards: 25%|██████████████▎ | 1/4 [00:14<00:42, 14.24s/it]

3. 修改sample代碼為0.6B模型

# test_qwen3-embedding.py
。。。
# Load the model
#model = SentenceTransformer("Qwen/Qwen3-Embedding-8B")  改為下面代碼本地加載模型
model = SentenceTransformer("C:\\Users\\Administrator\\.cache\\modelscope\\hub\models\\Qwen\\Qwen3-Embedding-8B")
。。。

(workspace) PS D:\workspace> uv run .\test_qwen3-embedding.py
D:\workspace\test_qwen3-embedding.py:8: SyntaxWarning: invalid escape sequence ‘\m’
model = SentenceTransformer(“C:\Users\Administrator\.cache\modelscope\hub\models\Qwen\Qwen3-Embedding-0.6B”)
tensor([[0.7646, 0.1414],
[0.1355, 0.6000]])

運行成功,幾秒鐘出結果,CPU呼呼的轉

4. 4090D機器上運行8B模型

報錯:torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 192.00 MiB. GPU 0 has a total capacity of 23.64 GiB of which 72.94 MiB is free. Process 3052744 has 434.64 MiB memory in use. Including non-PyTorch memory, this process has 23.12 GiB memory in use. Of the allocated memory 22.78 GiB is allocated by PyTorch, and 1.10 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)
(

# test_qwen3-embedding.py
。。。
# Load the model
model = SentenceTransformer("/mnt/wd4t/models/modlescope/Qwen3-Embedding-8B", device="cuda", model_kwargs={"torch_dtype": "auto"})   <-- 修改加載模型代碼
$ uv run test_qwen3_embedding.py
Loading checkpoint shards: 100%|██████████████████████████████████████████████████████████| 4/4 [00:01<00:00,  2.48it/s]tensor([[0.7471, 0.0770],[0.0894, 0.6321]])

運行出來的結果與sample源代碼的結果基本一致。

回到目錄

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

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

相關文章

MPLAB X IDE ?軟件安裝與卸載

1、下載MPLAB X IDE V6.25 MPLAB X IDE | Microchip Technology 正常選Windows&#xff0c;點擊Download&#xff0c;等待自動下載完成&#xff1b; MPLAB X IDE 一臺電腦上可以安裝多個版本&#xff1b; 2、安裝MPLAB X IDE V6.25 右鍵以管理員運行&#xff1b;next; 勾選 I a…

PLC入門【2】PLC的接線

02 PLC的接線 PLC 的品牌介紹&#xff0c;PLC的接線 1、PLC 大體分為歐式和日式 2、只要學會三菱的&#xff0c;整個日式的也差不多會了。 3、PLC 分為晶體管輸出和繼電器輸出。 4、PLC 接線都差不多的 我們主要是講這個三菱的 PLC&#xff0c; 三菱和臺達的 PLC&#xff0c;…

Hibernate Validator 數據驗證

Hibernate Validator不僅可以用于Controller層的參數驗證&#xff0c;還可以在Service層、Repository層或任何其他層中使用。 手動驗證 在任何地方都可以通過Validator接口手動觸發驗證&#xff1a; public class ManualValidationExample {public void validateObject(Obje…

【深度學習】表示學習:深度學習的數據解構與重構藝術

作者選擇了由 Ian Goodfellow、Yoshua Bengio 和 Aaron Courville 三位大佬撰寫的《Deep Learning》(人工智能領域的經典教程&#xff0c;深度學習領域研究生必讀教材),開始深度學習領域學習&#xff0c;深入全面的理解深度學習的理論知識。 之前的文章參考下面的鏈接&#xf…

如何在PowerBI中使用Analyze in Excel

如何在PowerBI中使用Analyze in Excel 之前分享過如何使用DAXStudio將PowerBI與Excel連接 &#xff0c;今天介紹另外一個工具&#xff0c;也可以實現同樣的功能&#xff0c;Analyze in Excel。 使用Analyze in Excel 第一步&#xff1a; 首先準備好一個PBIX文件&#xff0c…

AI應用工程師面試

技術基礎 簡述人工智能、機器學習和深度學習之間的關系。 人工智能是一個廣泛的概念,旨在讓機器能夠模擬人類的智能行為。機器學習是人工智能的一個子集,它專注于開發算法和模型,讓計算機能夠從數據中學習規律并進行預測。深度學習則是機器學習的一個分支,它利用深度神經網…

基于定制開發開源AI智能名片S2B2C商城小程序的首屏組件優化策略研究

摘要&#xff1a;在數字化轉型背景下&#xff0c;用戶對首屏交互效率的訴求日益提升。本文以"定制開發開源AI智能名片S2B2C商城小程序"為技術載體&#xff0c;結合用戶行為數據與認知心理學原理&#xff0c;提出首屏組件動態布局模型。通過分析搜索欄、掃碼入口、個人…

day50 隨機函數與廣播機制

目錄 一、隨機張量的生成 1.1 torch.randn() 函數 1.2 其他隨機函數 1.3 輸出維度測試 二、廣播機制 2.1 廣播機制的規則 2.2 加法的廣播機制 二維張量與一維向量相加 三維張量與二維張量相加 二維張量與標量相加 高維張量與低維張量相加 2.3 乘法的廣播機制 批量…

Java持久層技術對比:Hibernate、MyBatis與JPA的選擇與應用

目錄 簡介持久層技術概述Hibernate詳解MyBatis詳解JPA詳解技術選型對比最佳實踐與應用場景性能優化策略未來發展趨勢總結與建議 簡介 在Java企業級應用開發中&#xff0c;持久層&#xff08;Persistence Layer&#xff09;作為連接業務邏輯與數據存儲的橋梁&#xff0c;其技…

【2025CVPR】模型融合新范式:PLeaS算法詳解(基于排列與最小二乘的模型合并技術)

本文深入解析ICLR 2025頂會論文《PLeaS: Merging Models with Permutations and Least Squares》,揭示模型融合領域突破性進展. 一、問題背景:模型合并的核心挑戰 隨著開源模型的爆發式增長,如何高效合并多個專用模型成為關鍵挑戰。傳統方法存在三大痛點: ?初始化依賴?…

磁盤空間清道夫FolderSize 系列:可視化分析 + 重復文件識別,

各位電腦小能手們&#xff0c;今天來給大家嘮嘮Folder類軟件&#xff01;這玩意兒主要是為了文件夾管理、監控、安全還有優化這些需求設計的&#xff0c;不同工具的功能各有側重。下面我就結合多個搜索結果&#xff0c;給大家分類介紹一下。 軟件下載地址安裝包 首先是文件夾空…

嵌入式全棧面試指南:TCP/IP、C 語言基礎、STM32 外設與 RT?Thread

作為嵌入式工程師&#xff0c;面試時往往不僅要展示基礎編程能力&#xff0c;還要兼具網絡協議、硬件驅動、實時操作系統&#xff08;RTOS&#xff09;等方面的知識深度。本文將從TCP/IP 協議、C 語言核心基礎、STM32 IO 與外設驅動、RT?Thread 及其多任務/IPC四大模塊進行全面…

Git 命令全流程總結

以下是從初始化到版本控制、查看記錄、撤回操作的 Git 命令全流程總結&#xff0c;按操作場景分類整理&#xff1a; 一、初始化與基礎操作 操作命令初始化倉庫git init添加所有文件到暫存區git add .提交到本地倉庫git commit -m "提交描述"首次提交需配置身份git c…

軟件功能測試報告都包含哪些內容?

軟件功能測試報告是軟件開發生命周期中的重要文檔&#xff0c;主要涵蓋以下關鍵內容&#xff1a;    1.測試概況&#xff1a;概述測試目標、范圍和方法&#xff0c;確保讀者對測試背景有清晰了解。 2.測試環境&#xff1a;詳細描述測試所用的硬件、軟件環境&#xff0c;確保…

OpenCV CUDA模塊圖像處理------雙邊濾波的GPU版本函數bilateralFilter()

操作系統&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 編程語言&#xff1a;C11 算法描述 該函數在 GPU 上執行雙邊濾波操作&#xff0c;是一種非線性平滑濾波器&#xff0c;能夠在 保留邊緣的同時去除噪聲。 函數原型 void cv::cuda:…

Perplexity AI:重塑你的信息探索之旅

在信息爆炸的時代&#xff0c;如何快速、精準地獲取所需知識&#xff0c;并將其轉化為行動力&#xff1f;答案或許就藏在 Perplexity AI 這款強大的智能工具中。它不僅僅是一個搜索引擎&#xff0c;更是一個能理解你、與你對話、為你深度解析信息的智能伙伴。告別繁瑣的信息篩選…

Java高級反射實戰:15個場景化編程技巧與底層原理解析

引用 在Java的世界里&#xff0c;反射機制如同賦予開發者一把“萬能鑰匙”&#xff0c;它打破了靜態編程的邊界&#xff0c;讓代碼在運行時擁有動態獲取類信息、操作對象屬性和方法的能力。從Spring框架的依賴注入&#xff0c;到MyBatis的SQL映射生成&#xff1b;從JSON序列化…

構建 MCP 服務器:第 3 部分 — 添加提示

這是我們構建 MCP 服務器的四部分教程的第三部分。在第一部分中&#xff0c;我們使用基本資源創建了第一個MCP 服務器&#xff1b;在第二部分中&#xff0c;我們添加了資源模板并改進了代碼組織。現在&#xff0c;我們將進一步重構代碼并添加提示功能。 什么是 MCP 提示&#…

MySQL 索引優化(Explain執行計劃) 詳細講解

&#x1f91f;致敬讀者 &#x1f7e9;感謝閱讀&#x1f7e6;笑口常開&#x1f7ea;生日快樂?早點睡覺 &#x1f4d8;博主相關 &#x1f7e7;博主信息&#x1f7e8;博客首頁&#x1f7eb;專欄推薦&#x1f7e5;活動信息 文章目錄 MySQL 索引優化&#xff08;Explain執行計劃…

使用 IntelliJ IDEA 安裝通義靈碼(TONGYI Lingma)插件,進行后端 Java Spring Boot 項目的用戶用例生成及常見問題處理

一、什么是通義靈碼&#xff08;TONGYI Lingma&#xff09;&#xff1f; 通義靈碼是阿里巴巴推出的智能代碼輔助工具&#xff0c;結合大模型技術&#xff0c;支持代碼生成、用例生成、代碼補全等功能&#xff0c;能極大提升開發效率。 二、在 IDEA 中安裝通義靈碼插件 打開 In…