<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Halogen 0.16版更新 實測NPU vs GPU vs CPU 驅動Embedding與Reranker]]></title><description><![CDATA[<h1>Qwen3 RAG對決：NPU vs iGPU vs CPU（Strix Halo，同機實測）</h1>
<blockquote>
<p dir="auto">上次<a href="https://lcz.me/topic/1659/15">實測Halogen Flash Server跑Qwen 3.8 Flash Next</a>一陣子了，github不斷更新，這版v0.16比較有趣的是可以用NPU跑Embedding、Reranker、Dicider的小模型了。</p>
</blockquote>
<hr />
<p dir="auto">v0.16內建了Qwen的Embedding、Reranker、Decider，<br />
Decider是跟Jev對標的推論模型，我目前還沒想到實戰用途，<br />
而Embedding與Reranker實戰用途就很明確了，老早就廣泛被RAG或向量資料庫拿來做知識、文件管理，所以直接測這兩兄弟<br />
兩者通常在資訊檢索（如 RAG 搜尋系統）中搭配使用，分工如下：</p>
<ul>
<li>
<p dir="auto"><strong>Embedding（向量化 / 初篩）</strong><br />
<strong>作用</strong>：把文字轉換成包含語意特徵的「數字向量」。<br />
<strong>定位</strong>：負責<strong>大海撈針</strong>。透過計算向量間的距離（如餘弦相似度），以極快速度從數百萬筆資料中挑出初步相關的幾十到幾百筆結果（速度快、算力成本低，但語意理解深度有限）。</p>
</li>
<li>
<p dir="auto"><strong>Reranker（重排序 / 精算）</strong><br />
<strong>作用</strong>：將使用者的問題與初篩出來的每篇文章配對，放入模型（如 Cross-Encoder）深度交叉比對相關性並重新打分排序。<br />
<strong>定位</strong>：負責<strong>去蕪存菁</strong>。精準度極高，能挑出最核心的幾筆交給後續模型使用（理解深度高，但計算慢、成本高，無法直接對海量資料運算）。</p>
</li>
</ul>
<p dir="auto"><strong>總結</strong>：<strong>Embedding 負責「快選前 100 名」，Reranker 負責「從中精挑前 3 名」。</strong><br />
如果你的文件或知識量巨大，不可能全部塞KV Cache、成本太高，RAG的用意就是將向量庫落盤到SSD甚至HDD。<br />
過去能驅動這類模型的推論引擎主流就是llama.cpp與vllm，現在Halogen是頭一個做到能用NPU做向量處理的</p>
<p dir="auto">除了測速度、RAG很重要的是召回正確性，這次也出了題目一併測試。</p>
<hr />
<h2>1. 測試環境</h2>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>項目</th>
<th>內容</th>
</tr>
</thead>
<tbody>
<tr>
<td>APU</td>
<td>AMD Strix Halo <code>gfx1151</code>，128G 統一記憶體（OS 可見 124G）</td>
</tr>
<tr>
<td>OS</td>
<td>Nobara 44，kernel 7.1.4，ROCm 7.2.4</td>
</tr>
<tr>
<td>NPU 側</td>
<td>halogen-flash-server <strong>0.16.0</strong>，<code>HALOGEN_NPU_MODELS</code>，<code>/dev/accel/accel0</code>＋XRT 2.26.0（COPR），IOMMU on</td>
</tr>
<tr>
<td>iGPU 側</td>
<td>llama.cpp fork（ROCmFPX build），vulkan router <code>:8002</code>，<code>GGML_HIP_ENABLE_UNIFIED_MEMORY=1</code></td>
</tr>
<tr>
<td>CPU 側</td>
<td>同一 fork binary，<code>-ngl 0</code>，32 thread，臨時 <code>:8109</code>/<code>:8110</code>（embed 加 <code>-ub 2048</code>，見 §4），測完即下</td>
</tr>
<tr>
<td>Embedding 權重</td>
<td>NPU：peonist <code>qwen3-embedding-0.6b</code>（精度未公開，估 4–5bpw）；iGPU／CPU：<code>enacimie/Qwen3-Embedding-0.6B-Q4_K_M-GGUF</code>（Q4_K_M，396MB）</td>
</tr>
<tr>
<td>Reranker 權重</td>
<td>NPU：peonist <code>qwen3-reranker-0.6b</code>；iGPU／CPU：<code>dean2155/Qwen3-Reranker-0.6B-Q4_K_M</code>（<img src="https://lcz.me/assets/plugins/nodebb-plugin-emoji/emoji/android/26a0.png?v=fe25256ab4a" class="not-responsive emoji emoji-android emoji--warning" style="height:1.4em;width:auto;vertical-align:middle" title="⚠" alt="⚠" />️第三方量化，非官方）</td>
</tr>
<tr>
<td>輸出維度</td>
<td>三邊都是 1024</td>
</tr>
</tbody>
</table>
<hr />
<h2>2. halogen 版本追蹤（NPU 部分）</h2>
<ul>
<li>0.16.0 新增 NPU 小模型同端口（decider-0.8b／qwen3-embedding-0.6b／qwen3-reranker-0.6b）。</li>
<li>開通代價（<code>.55</code> 實錄）：grub 刪 <code>amd_iommu=off</code>（驅動拒綁，journal 明寫）→COPR 裝 XRT 2.26.0 三件→容器接 <code>/dev/accel/accel0</code>＋lib 三份雙掛（<code>lib/</code>＋<code>lib64/</code> 都要，少一邊拒啟）＋<code>/sys:/host/sys</code>＋<code>/models</code> 改 rw。</li>
</ul>
<hr />
<h2>3. embedding 跟 reranker 是做什麼的（RAG 兩件套）</h2>
<ul>
<li><strong>Embedding</strong>：把文字壓成 1024 維向量，語意相近＝夾角小（cosine 高）。RAG 第一步：query 和文件都轉向量，用 cosine 撈候選。本次驗法：同義句 vs 無關句，gap 越大越好。</li>
<li><strong>Reranker</strong>：把候選文件和 query 一對一精排（cross-encoder），輸出相關分數重排序。本次驗法：4 文件中狐狸那篇應該第一（query：fox by the river）。</li>
</ul>
<hr />
<h2>4.測試題目</h2>
<p dir="auto">RAG應用 速度不是唯一 故召回與排序的正確性是重點</p>
<h3>速度題</h3>
<ul>
<li>
<p dir="auto"><strong>短句</strong>（~10 tok）：<code>The quick brown fox jumps over the lazy dog.</code> → <code>/v1/embeddings</code>，計 wall 時間。先打一次 warmup 不計分，再量。</p>
</li>
<li>
<p dir="auto"><strong>長文</strong>（1401 tok）：<code>"Strix Halo unified memory architecture review" ×200</code>（空格連接）→ 同 endpoint。1401 是 server 回報的 actual prompt_tokens。</p>
</li>
<li>
<p dir="auto"><strong>Rerank</strong>：query＝<code>fox by the river</code>，4 文件：</p>
<ol>
<li><code>The fox jumped near the river bank at dawn.</code></li>
<li><code>LPDDR5X bandwidth reaches 256 gigabytes per second.</code></li>
<li><code>The bank approved the loan yesterday afternoon.</code></li>
<li><code>Canine sleep patterns vary by breed and age.</code></li>
</ol>
<p dir="auto">→ <code>/v1/rerank</code>（vulkan/CPU）或 <code>:8731/v1/rerank</code>（NPU），取 relevance_score 排序，計時＋記順序。</p>
</li>
</ul>
<h3>正確性題</h3>
<ul>
<li><strong>Embedding cosine</strong>：三句——原句（fox jumps...）、同義改寫（<code>A fast dark fox leaps above a sleepy canine.</code>）、無關句（<code>Quantum entanglement enables instant communication.</code>）。算 cos(原句,同義) vs cos(原句,無關)，gap 越大越好。dim 都是 1024。</li>
<li><strong>Rerank 排序</strong>：同上 4 文件，正解 index 0（狐狸篇）第一。LPDDR 篇（index 1）是干擾項（跟 query 零語意交集，純字面 bank 撞詞的是 index 2）。</li>
</ul>
<h3>控制條件</h3>
<ul>
<li>同文本跑三邊（NPU／iGPU／CPU），temperature 不影響 embedding（確定性），rerank 取預設參數</li>
<li>每項 2–3 次，報告取區間（NPU 長文 0.36/0.38/0.54 那次 variance 有標）</li>
</ul>
<h2>5. 速度比對（同文本，Q4 對 Q4）</h2>
<h3>Embedding</h3>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>輸入</th>
<th>NPU</th>
<th>iGPU（Q4_K_M）</th>
<th>CPU（Q4_K_M）</th>
</tr>
</thead>
<tbody>
<tr>
<td>短句（~10 tok）</td>
<td>0.104–0.119s</td>
<td><strong>0.039–0.044s</strong></td>
<td>0.050–0.052s</td>
</tr>
<tr>
<td>長文 1400 tok</td>
<td>0.361–0.544s</td>
<td><strong>0.218s</strong></td>
<td>0.483–0.693s</td>
</tr>
</tbody>
</table>
<h3>Rerank（4 文件，同 query）</h3>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th></th>
<th>NPU</th>
<th>iGPU（Q4_K_M）</th>
<th>CPU（Q4_K_M）</th>
</tr>
</thead>
<tbody>
<tr>
<td>耗時</td>
<td>0.504–1.057s</td>
<td><strong>0.067–0.298s</strong></td>
<td>0.229–0.253s</td>
</tr>
</tbody>
</table>
<p dir="auto">小結：<strong>短查詢 iGPU 最快（0.04s），長文也是 iGPU 最快（0.22s），NPU（0.36–0.54s）＋CPU（0.48–0.69s）居次</strong>。0.6B 這量級，iGPU 算力說了算；NPU 的價值在零 burden（不佔VRAM、不開整組 vulkan）＋長文開箱不炸。</p>
<hr />
<h2>6. 正確性比對（Q4 對 Q4）</h2>
<h3>Embedding cosine</h3>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th></th>
<th>同義</th>
<th>無關</th>
<th>gap</th>
</tr>
</thead>
<tbody>
<tr>
<td>NPU</td>
<td>0.7096</td>
<td>0.4202</td>
<td>0.2895 <img src="https://lcz.me/assets/plugins/nodebb-plugin-emoji/emoji/android/2705.png?v=fe25256ab4a" class="not-responsive emoji emoji-android emoji--white_check_mark" style="height:1.4em;width:auto;vertical-align:middle" title="✅" alt="✅" /></td>
</tr>
<tr>
<td>iGPU Q4_K_M</td>
<td>0.8131</td>
<td>0.4698</td>
<td>0.3433 <img src="https://lcz.me/assets/plugins/nodebb-plugin-emoji/emoji/android/2705.png?v=fe25256ab4a" class="not-responsive emoji emoji-android emoji--white_check_mark" style="height:1.4em;width:auto;vertical-align:middle" title="✅" alt="✅" /></td>
</tr>
<tr>
<td>CPU Q4_K_M</td>
<td>0.8113</td>
<td>0.4616</td>
<td>0.3497 <img src="https://lcz.me/assets/plugins/nodebb-plugin-emoji/emoji/android/2705.png?v=fe25256ab4a" class="not-responsive emoji emoji-android emoji--white_check_mark" style="height:1.4em;width:auto;vertical-align:middle" title="✅" alt="✅" /></td>
</tr>
</tbody>
</table>
<p dir="auto">三邊都正確分離。llama 系兩邊 gap 一致（0.34–0.35，同權重同精度）；NPU 窄一點（0.29，自家量化精度未知），但遠過門檻。</p>
<h3>Rerank 排序（query：fox by the river，正解狐狸篇 index 0）</h3>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th></th>
<th>排序</th>
<th>頂部</th>
</tr>
</thead>
<tbody>
<tr>
<td>NPU</td>
<td>[0, 3, 2, 1]（兩次一致）</td>
<td><img src="https://lcz.me/assets/plugins/nodebb-plugin-emoji/emoji/android/2705.png?v=fe25256ab4a" class="not-responsive emoji emoji-android emoji--white_check_mark" style="height:1.4em;width:auto;vertical-align:middle" title="✅" alt="✅" /> 語意對</td>
</tr>
<tr>
<td>iGPU Q4_K_M</td>
<td>[1, 2, 0, 3]（兩次一致）</td>
<td><img src="https://lcz.me/assets/plugins/nodebb-plugin-emoji/emoji/android/26a0.png?v=fe25256ab4a" class="not-responsive emoji emoji-android emoji--warning" style="height:1.4em;width:auto;vertical-align:middle" title="⚠" alt="⚠" />️ LPDDR 篇第一</td>
</tr>
<tr>
<td>CPU Q4_K_M</td>
<td>[0, 2, 3, 1]</td>
<td><img src="https://lcz.me/assets/plugins/nodebb-plugin-emoji/emoji/android/2705.png?v=fe25256ab4a" class="not-responsive emoji emoji-android emoji--white_check_mark" style="height:1.4em;width:auto;vertical-align:middle" title="✅" alt="✅" /> 狐狸篇第一</td>
</tr>
</tbody>
</table>
<p dir="auto">重點發現：<strong>同一個 Q4_K_M，CPU 排對、vulkan 排錯</strong>——server 端處理（模板／參數）會影響排序，權重相同≠結果相同。NPU 兩次都對可以說是正確又一致。iGPU 的錯排打了折扣看（第三方量化），但 CPU 同量化排對，說明問題在 vulkan 那側的處理，不在權重。</p>
<hr />
<h2>7. 結論</h2>
<ol>
<li><strong>三方重排</strong>：短文延遲 iGPU（0.04s）＞CPU（0.05s）＞NPU（0.11s）；長文 iGPU（0.22s）＞NPU（0.36–0.54s）＞CPU（0.48–0.69s）。0.6B 這量級 iGPU 通吃，NPU 贏在零 burden 不在速度。</li>
<li><strong>正確性</strong>：embedding 三邊全過；rerank NPU＝CPU＞vulkan（同權重不同 server 結果不同，server 也是變量）。</li>
<li><strong>成本</strong>：NPU 幾 GB 零 burden；CPU 零成本隨起隨下；GPU需vulkan 整組。</li>
<li><strong>實用建議</strong>：RAG 長文走 NPU；短 query 要極限延遲開 vulkan；iGPU 不在時 CPU 完全夠打。</li>
<li>AI Max+ 395的CPU是有AVX 512指令級的ZEN5新架構，對CPU推論的矩陣運算幫助很大，如果是不支援AVX512的CPU效果會大打折扣。</li>
<li>.利用NPU最大價值是可以把CPU與GPU的開銷節省下來做其他事。</li>
</ol>
]]></description><link>https://lcz.me/topic/2045</link><generator>RSS for Node</generator><lastBuildDate>Mon, 12 Oct 2026 13:28:43 GMT</lastBuildDate><atom:link href="https://lcz.me/topic/2045.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 02 Oct 2026 07:14:30 GMT</pubDate><ttl>60</ttl></channel></rss>