<?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[(學術) ninfer 可支援的 去審查Qwen3.8-27B nvfp4：製作方法]]></title><description><![CDATA[<p dir="auto">"This repository/article is for academic and AI safety research purposes only. It demonstrates how model weights react to specific transformations. No model weights are hosted or redistributed here. Users are responsible for ensuring compliance with the original model's license when applying these techniques locally."</p>
<p dir="auto">ninfer目前認可模型並不是uncensored<br />
所以有很多不雅的事不能試（例如請模型創作正妹..................................................................................挖鼻孔照片....）</p>
<p dir="auto">我想應該很多大神早就做出來了，只是忘了分享，因此拋磚引玉一下<br />
以下純學術討論（不提供模型下載）!!!!!!!!!!!! 但你可以用自己顯卡去實現自己的uncensored模型</p>
<blockquote>
<p dir="auto"><strong>適用</strong>：手上有一份同架構（Qwen3.8-27B / 64 層 / vocab 248320）的去審查（abliterated / uncensored）權重，想在 NInfer 引擎上跑，且<strong>不想改引擎、不想換 binary、不想重學啟動參數</strong>。<br />
<strong>本文只講四件事</strong>：製作方法、執行步驟、資料來源、為什麼「原本那套 NInfer 可以無痛接入」。<br />
<strong>不講</strong>：效能數字、量化路徑對比、TP2 雙卡細則、其它引擎。<br />
本流程 = 2026-09-22 實測跑通的可重現 SOP（uncensored 重轉 nvfp4 後與標準 artifact <strong>同 runtime identity</strong>）。</p>
</blockquote>
<h2>1. 為什麼無痛接入（先講結論）</h2>
<p dir="auto">「uncensored」不是新模型——它是<strong>同一個 base 的權重「值」改動</strong>（abliteration 只動 <code>attn.o_proj</code> / <code>mlp.down_proj</code> 的 residual stream），<strong>不動 shape / vocab / tokenizer / layer 排程</strong>。</p>
<p dir="auto">因為 NInfer 的 <code>convert.py</code> / <code>convert_nvfp4.py</code> 對權重是「餵進去的值重新量化」，uncensored 的 bf16 / nvfp4 權重<strong>直接餵</strong>就能產出一個 <code>.ninfer</code> artifact。產出後：</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>項目</th>
<th>標準模型</th>
<th>uncensored 模型</th>
</tr>
</thead>
<tbody>
<tr>
<td>NInfer binary</td>
<td><code>ninfer-serve</code></td>
<td><strong>同一支</strong></td>
</tr>
<tr>
<td>啟動參數</td>
<td><code>--spec dflash2 --draft-tokens 8 ...</code></td>
<td><strong>完全相同</strong></td>
</tr>
<tr>
<td>runtime identity</td>
<td><code>qwen3.8-27b/nvfp4</code></td>
<td><strong><code>qwen3.8-27b/nvfp4</code>（v2 重轉後相同）</strong></td>
</tr>
<tr>
<td>唯一差別</td>
<td>artifact 檔</td>
<td><strong>只換 artifact 檔 + model-id</strong></td>
</tr>
</tbody>
</table>
<p dir="auto">換句話說：<strong>原本跑標準模型的那套 NInfer 環境、那支 binary、那套啟動參數，把 artifact 路徑指到 uncensored、model-id 改一下，就能直接跑。</strong> 不用重裝、不用改引擎、不用重學參數。</p>
<h2>2. 製作方法（產出 <code>.ninfer</code> artifact）</h2>
<h3>2.1 準備三份料</h3>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>料</th>
<th>用途</th>
<th>格式要求</th>
</tr>
</thead>
<tbody>
<tr>
<td>uncensored base 權重</td>
<td>模型主體</td>
<td><strong>safetensors</strong>（bf16 可直餵 groupwise-int 路）</td>
</tr>
<tr>
<td>DFlash2 配重</td>
<td>投機解碼 draft head</td>
<td><strong>safetensors</strong>（<code>model.safetensors</code> 單檔 + 含 <code>dflash_config</code> 的 <code>config.json</code>；<strong>GGUF 不行</strong>）</td>
</tr>
<tr>
<td>官方 frontend 6 檔</td>
<td>tokenizer / chat template 等</td>
<td>用<strong>官方</strong>的，不是 uncensored repo 的（見 §2.3）</td>
</tr>
</tbody>
</table>
<h3>2.2 下載 uncensored 權重（用 <code>snapshot_download</code>，別用 <code>hf download</code>）</h3>
<pre><code class="language-bash">python3 -c "
import os; os.environ['HF_XET_HIGH_PERFORMANCE']='1'
from huggingface_hub import snapshot_download
snapshot_download(
  'JonathanColetti/Qwen3.8-27B-Uncensored',
  allow_patterns=['model-[0-9]*.safetensors','model-mtp.safetensors',
                  'model.safetensors.index.json','config.json'],
  local_dir='$HOME/.llama/&lt;EXP&gt;/uncensored', max_workers=16)"
</code></pre>
<blockquote>
<p dir="auto"><img src="https://lcz.me/assets/plugins/nodebb-plugin-emoji/emoji/android/26a0.png?v=ecb7c61779a" class="not-responsive emoji emoji-android emoji--warning" style="height:23px;width:auto;vertical-align:middle" title="⚠" alt="⚠" />️ <strong>坑</strong>：<code>hf download</code> CLI 會把多個 <code>--include</code> 誤解成正位元字面檔名，12 個大 shard 一個都不下、只抓小檔。一律改用 <code>snapshot_download(allow_patterns=)</code>。</p>
</blockquote>
<h3>2.3 用「官方」frontend 6 檔，不用 uncensored repo 的</h3>
<p dir="auto">uncensored repo 是 transformers re-save，<code>tokenizer.json</code> 的 byte-ordering 跟官方不同 → 直接餵會被 converter 的 SHA256 gate 擋。vocab 已驗證與官方相同，所以<strong>語意零損失，直接用官方檔</strong>：</p>
<pre><code class="language-bash"># 官方 6 檔 @ base revision 1d4bf0f2ff6012fd82039f2fa52739d0dd7c60c0
BASE="https://huggingface.co/Qwen/Qwen3.8-27B/resolve/1d4bf0f2ff6012fd82039f2fa52739d0dd7c60c0"
for f in tokenizer.json tokenizer_config.json chat_template.jinja \
         generation_config.json preprocessor_config.json video_preprocessor_config.json; do
  curl -sL "$BASE/$f" -o &lt;UNC_DIR&gt;/$f
done
# 驗證：sha256sum 六檔應全等於 convert.py 的 OFFICIAL_RESOURCE_SHA256
</code></pre>
<h3>2.4 轉換（模組模式，別直接跑 script）</h3>
<pre><code class="language-bash">cd &lt;NINFER_SRC_ROOT&gt;
export PYTHONPATH=&lt;NINFER_SRC_ROOT&gt;
export CUDA_VISIBLE_DEVICES=&lt;idle GPU&gt;
python3 -m tools.convert.qwen3_8_27b.convert \
  --model &lt;UNC_DIR&gt; \
  --dflash2-model &lt;DF2_DIR&gt; \
  --out &lt;OUT&gt;.ninfer \
  --device cuda
</code></pre>
<blockquote>
<p dir="auto"><img src="https://lcz.me/assets/plugins/nodebb-plugin-emoji/emoji/android/26a0.png?v=ecb7c61779a" class="not-responsive emoji emoji-android emoji--warning" style="height:23px;width:auto;vertical-align:middle" title="⚠" alt="⚠" />️ <strong>坑</strong>：不能用 <code>python3 tools/.../convert.py</code> 直接跑——會 <code>ImportError: attempted relative import with no known parent package</code>（converter 內部用 <code>from . import dflash2_recipe</code>）。<strong>必須 <code>python3 -m</code> 模組模式</strong>、從 source root 執行。</p>
</blockquote>
<blockquote>
<p dir="auto"><strong>兩條量化路（擇一）</strong>：</p>
<ul>
<li><code>convert.py</code>（groupwise-int 路）：直接餵 bf16，記憶體內重新量化。簡單快速。</li>
<li><code>convert_nvfp4.py</code>（nvfp4 路）：吃一個<strong>預先量化好的 vLLM compressed-tensors NVFP4 checkpoint</strong>（<code>--quantized-model</code>），<strong>不</strong>在記憶體重量化。→ 要讓 uncensored 與標準 artifact <strong>同 runtime identity（nvfp4）</strong>、真正「無痛同速」，走這條。</li>
</ul>
</blockquote>
<h2>3. 執行步驟（上線，無痛接入）</h2>
<pre><code class="language-ini"># ~/.config/systemd/user/ninfer-dryrun.service  [Service]
Environment=CUDA_VISIBLE_DEVICES=&lt;idle GPU&gt;
ExecStart=&lt;NINFER_BINARY&gt; &lt;UNCERTAINSED_ARTIFACT&gt; \
  --host 127.0.0.1 --port &lt;獨立port&gt; --device 0 \
  --max-context 262144 --kv-dtype nvfp4 --kv-capacity 334000 --max-concurrency 3 \
  --prefill-chunk 1024 --pending-timeout-ms 600000 \
  --spec dflash2 --draft-tokens 8 --lm-head-draft \
  --model-id qwen38-uncensored \
  --vision --media-cache-mib 256 --media-live-mib 512 --host-state-slots 8 --host-kv-mib 8192
</code></pre>
<pre><code class="language-bash">systemctl --user daemon-reload &amp;&amp; systemctl --user start ninfer-dryrun
# ~8s 後
curl -s http://127.0.0.1:&lt;port&gt;/health    # 應 {"status":"ok"}
# 測試完：systemctl --user stop ninfer-dryrun &amp;&amp; rm unit &amp;&amp; daemon-reload
</code></pre>
<h3>3.1 dry-run 驗證項（三項全過才算數）</h3>
<ul>
<li><code>engine ready</code>（runtime identity 應為 <code>qwen3.8-27b/nvfp4</code>）+ <code>CUDA graphs ready</code></li>
<li>發一個正常 prompt，確認輸出正確</li>
<li><strong>去審查行為驗證</strong>：拿「base 會拒、uncensored 不該拒的有害請求」餵<strong>兩端</strong>（base 主腦 + uncensored），比對<strong>拒率 delta</strong>——base 高拒 + uncensored 低拒 + delta 大 → 去審查真生效。（不是找「只有 uncensored 能答的題」，那是能力差異不是去審查。）</li>
</ul>
<h3>3.2 上線</h3>
<h2>4. 資料來源</h2>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>來源</th>
<th>說明</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://huggingface.co/JonathanColetti/Qwen3.8-27B-Uncensored" rel="nofollow ugc">JonathanColetti/Qwen3.8-27B-Uncensored</a></td>
<td>uncensored base 權重（bf16，12 shard）</td>
</tr>
<tr>
<td><a href="https://huggingface.co/z-lab/Qwen3.8-27B-DFlash2" rel="nofollow ugc">z-lab/Qwen3.8-27B-DFlash2</a></td>
<td>DFlash2 投機解碼配重（safetensors + config）</td>
</tr>
<tr>
<td><a href="https://huggingface.co/Qwen/Qwen3.8-27B" rel="nofollow ugc">Qwen/Qwen3.8-27B</a> @ <code>1d4bf0f2ff6012fd82039f2fa52739d0dd7c60c0</code></td>
<td>官方 frontend 6 檔（tokenizer / chat_template 等，SHA256 gate 基準）</td>
</tr>
<tr>
<td>NInfer <code>tools/convert/qwen3_8_27b/convert.py</code></td>
<td>groupwise-int 轉換路（<code>OFFICIAL_RESOURCE_SHA256</code>、<code>check_members</code>、<code>validate_base_compatibility</code>）</td>
</tr>
<tr>
<td>NInfer <code>tools/convert/qwen3_8_27b/convert_nvfp4.py</code></td>
<td>nvfp4 轉換路（吃 vLLM compressed-tensors NVFP4 checkpoint；<code>recipe_nvfp4.py</code> 格式合約）</td>
</tr>
<tr>
<td>本地 SOP</td>
<td><code>ninfer-uncensored-qwen38-convert-20260921.md</code>（完整實測 + 踩坑）、<code>ninfer-uncensored-vs-standard-perf-20260921.md</code> §5.5（TP2 狀態）</td>
</tr>
</tbody>
</table>
<hr />
<p dir="auto"><em>本檔為 LCZ 貼文規格（2~3 欄 pipe table、阿拉伯數字章節、code fence 標語言、資料來源連結）。貼上 lcz 前寬表已控制在 3 欄內。</em></p>
]]></description><link>https://lcz.me/topic/1880</link><generator>RSS for Node</generator><lastBuildDate>Fri, 25 Sep 2026 21:27:23 GMT</lastBuildDate><atom:link href="https://lcz.me/topic/1880.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 22 Sep 2026 03:38:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to (學術) ninfer 可支援的 去審查Qwen3.8-27B nvfp4：製作方法 on Wed, 23 Sep 2026 19:02:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/terry" aria-label="Profile: terry">@<bdi>terry</bdi></a> 破解的AI模型配合破解的影片生成模型....相得益彰啊......</p>
]]></description><link>https://lcz.me/post/20352</link><guid isPermaLink="true">https://lcz.me/post/20352</guid><dc:creator><![CDATA[David Chen]]></dc:creator><pubDate>Wed, 23 Sep 2026 19:02:37 GMT</pubDate></item><item><title><![CDATA[Reply to (學術) ninfer 可支援的 去審查Qwen3.8-27B nvfp4：製作方法 on Tue, 22 Sep 2026 13:19:25 GMT]]></title><description><![CDATA[<p dir="auto">坛友们玩的这么深？都开始定制模型了？完全看不懂。</p>
]]></description><link>https://lcz.me/post/20081</link><guid isPermaLink="true">https://lcz.me/post/20081</guid><dc:creator><![CDATA[terry]]></dc:creator><pubDate>Tue, 22 Sep 2026 13:19:25 GMT</pubDate></item></channel></rss>