在 RTX 5060 Ti 16GB 上部署 Qwen3.6-35B-A3B(HauhauCS uncensored)的最佳实践
> **本文同步自 [GitHub Gist](https://gist.github.com/felix021/848b1122091620b8b332bea33c911504)**,后续如有更新只会在 Gist 上进行,本文不再同步。
> 单卡 16GB 跑满血 35B MoE 的实测部署方案。
> 硬件:RTX 5060 Ti 16GB(Blackwell, sm_120)+ Ryzen 5 9600X 6 核 + 32GB DDR5。
> 测试时间:2026-06,llama.cpp commit `3292da0`,CUDA 12.8 构建。
---
## 一、这套方案能达到什么效果
部署 **HauhauCS / Qwen3.6-35B-A3B-Uncensored-Aggressive**(IQ4_XS,17.4 GB,去审查版),200K 上下文 + 视觉,单卡 16GB:
| 指标 | 视觉配置(当前生产,moe=14+mmproj,prefill 优先) | 纯文本(moe=12,无 mmproj) |
|------|:----------------------------------:|:--------------------------:|
| **Decode** | ~61 tok/s | ~70 tok/s |
| **Prefill** | **~1960 tok/s** | ~1810 tok/s |
| **上下文** | 200K(每槽,parallel 1) | 200K |
| 显存占用 | 15.2 GB / 16 GB(余 0.68 GB) | 15.0 GB / 16 GB(余 0.8 GB) |
| 图片识别 | ✅ 普通图正常;超大图余量紧(要更稳用 moe=15,见 3.4) | ❌ |
| 模型质量 | AIME26 53.3 / MMLU-Pro 72.9 / C-Eval 70 / LiveCodeBench v6 40 | 同左 |
对比官方原版(AIME 92.7 / MMLU 85.2 / C-Eval 90 / LCB 80.4)有量化损失,但远超 2-bit(UD-IQ2_M:AIME 30 / LCB 13)。同模型在 2080Ti 11G 上 decode ~40 tok/s,本方案快约 75%。
**核心思路**:模型 17.4 GB 超过 16GB 显存,靠 llama.cpp 的 `--n-cpu-moe` 把一部分 MoE 专家层留 CPU、其余放 GPU,配合 4-bit KV cache 和 CUDA 后端,在单卡上跑满血 35B。**关键:用 thinking-off 模式调用**(见第四节)。
---
## 二、部署
### 2.1 下载模型
```bash
# HauhauCS uncensored IQ4_XS(HF-only;国内用 hf-mirror 镜像直连,~12MB/s)
aria2c -x16 -s16 "https://hf-mirror.com/HauhauCS/Qwen3.6-35B-A3B-Uncensored-HauhauCS-Aggressive/resolve/main/Qwen3.6-35B-A3B-Uncensored-HauhauCS-Aggressive-IQ4_XS.gguf"
# 视觉投影(可选,识图用;同仓库 mmproj-f16,~0.85GB)
aria2c -x16 -s16 "https://hf-mirror.com/HauhauCS/Qwen3.6-35B-A3B-Uncensored-HauhauCS-Aggressive/resolve/main/mmproj-Qwen3.6-35B-A3B-Uncensored-HauhauCS-Aggressive-f16.gguf"
```
> 不需要 uncensored 的话,base 版 `bartowski/Qwen3.6-35B-A3B-IQ4_XS` 可从 ModelScope 直连(19.7 GB,参数改 `--n-cpu-moe 14`)。
### 2.2 编译 llama.cpp(必须 CUDA,不要 Vulkan)
5060Ti 是 Blackwell(sm_120),需 CUDA 12.8+。
```bash
git clone https://github.com/ggml-org/llama.cpp && cd llama.cpp
cmake -B build-cuda128 -DGGML_CUDA=ON
cmake --build build-cuda128 --config Release -j
```
> ⚠️ 默认 `cmake -B build` 不开 `GGML_CUDA` 会落到 Vulkan,**decode 直接腰斩**(实测 Vulkan 比 CUDA 慢约一半)。这是最常踩的坑。
### 2.3 启动命令(200K,最优参数)
```bash
./build-cuda128/bin/llama-server \
-m ./models/Qwen3.6-35B-A3B-Uncensored-HauhauCS-Aggressive-IQ4_XS.gguf \
--mmproj ./models/mmproj-Qwen3.6-35B-A3B-Q6_K.gguf \
-ngl 41 --n-cpu-moe 14 \
-c 200000 -b 4096 -ub 1152 \
-t 6 -tb 6 -fa on --no-mmap --parallel 1 \
-ctk q4_0 -ctv q4_0 \
--chat-template-file ./templates/qwen3.6-35b-a3b-claude-compatible.jinja \
--reasoning off \
--jinja --metrics --host 0.0.0.0 --port 8080
```
> **视觉配置(当前生产,prefill 优先)**:`--n-cpu-moe 14` + `-b 4096 -ub 1152` + `--mmproj`,decode ~61、prefill **~1960**、200K、可识图、余 0.68 GB(文本场景稳;超大图要更稳可降到 `moe=15 -ub 1024`,prefill ~1760 但余 1.2 GB,见 3.4)。
> **纯文本极致速度**:去掉 `--mmproj`,`--n-cpu-moe` 改 `12`、`-ub 1536`,decode ~70、prefill ~1929。
> `--chat-template-file` + `--reasoning off` 是接 Claude Code / OpenAI 客户端**必需**的两项(见第五节)。
### 2.4 参数说明
| 参数 | 值 | 说明 |
|------|-----|------|
| `-ngl 41` | 全 40 层 dense/attention 上 GPU | 模型 40 层,41≥40 即全 offload |
| **`--n-cpu-moe 14`** | 前 14 层 MoE 专家留 CPU,后 26 层上 GPU | 视觉 prefill 优先值;要图更稳用 15,纯文本用 12(见第三节) |
| `--mmproj` | Q6_K (583 MB) | 视觉投影;**无 Q4 版**,Q6_K 是最小可用(见 3.4) |
| `-c 200000` | 200K 上下文 | KV q4+GQA 约 1.2 GB |
| **`-ub 1152`** | physical ubatch | prefill 随 ub 平滑上升(见 3.2);当前 `moe=14 -b 4096 -ub 1152`。**不得大于 `-b`** |
| `-t 6 -tb 6` | 线程数 = 物理核数 | 过调度反而变慢 |
| `-fa on` | Flash Attention | 必开 |
| **`--no-mmap`** | 禁用 mmap | 配合 `--n-cpu-moe` 必加,否则 CPU 专家懒加载拖慢 decode |
| `--parallel 1` | 单并发槽 | parallel 2 切槽不省显存、6 核机器实测总吞吐反降(见 3.4);本模式(parallel 1)多请求服务端排队、不拒绝 |
| `-ctk/-ctv q4_0` | KV cache 4-bit | 合法值 f32/f16/bf16/q8_0/q4_0/q4_1/iq4_nl/q5_0/q5_1(**无 `g4_0`**) |
| **`--chat-template-file`** | qwen3.6-35b-a3b-claude-compatible.jinja | 覆盖内置模板,**不强制 system 在首位 + 支持 tools + 还原多轮 thinking**,见第五节 |
| **`--reasoning off`** | 服务端强制关闭 thinking | abliterated 模型 thinking 已坏;客户端不传 `enable_thinking` 时必需 |
---
## 三、200K 下的参数寻优
### 3.1 `--n-cpu-moe`(decode 杠杆,纯文本)
decode 时 GPU 利用率仅 ~34%,瓶颈在 CPU 端专家计算——专家越少留 CPU 越快,但越占显存。200K(无 mmproj)下的扫描:
| `--n-cpu-moe` | 显存余量 | decode | prefill | 评价 |
|:-:|:-:|:-:|:-:|------|
| 14 | 2.1 GB | ~56 | 1123 | 最安全但慢 |
| **12** | **0.8–1.3 GB** | **67–70** | **1311** | ✅ **纯文本最优** |
| 11 | 0.9 GB | 69.7 | 1367 | decode 略快、余量略少 |
| 10 | 0.5 GB | 74.3 | 1422 | 太紧,OOM 风险 |
→ 纯文本用 **moe=12**。加 mmproj 后要降到 15(见 3.4)。
### 3.2 `-ub`(prefill 杠杆)
`-ub`(physical ubatch)越大,prefill 越快。细扫(moe=15+mmproj+200K,`-b 4096` 解除上限):
| -ub | prefill | decode | 显存余量 |
|-----|---------|--------|---------|
| 512 | 1158 | ~64 | 1.7 GB |
| 768 | 1382 | ~64 | 1.5 GB |
| 1024 | 1643 | ~64 | 1.2 GB |
| 1280 | 1737 | ~64 | 1.0 GB |
| 1536 | 1929 | ~64 | 0.7 GB |
| 2048 | 2144 | ⚠️ 4 | 0.2 GB(崩)|
prefill 随 ub **平滑上升**(每 +256 ub ≈ +124MB 显存,边际递减),**没有"断层"**。decode 与 ub 无关(恒 ~64),但 ub=2048 显存只剩 222MB,decode 崩到 4——不可用。
→ **按显存预算选值**:视觉配置(要留 4K 图 spike ~440MB 余量)用 **1024**(prefill 1643、余 1.2GB);纯文本显存宽裕可上 **1536**(~1929)。注意 `-ub` 不得大于 `-b`(要测 >1024 需把 `-b` 同步调大,否则被截断)。
### 3.3 显存账本(当前生产 moe=14,200K)
```
GPU ~15.2 GB:dense/attention 全 40 层 ~3.5G + 后 26 层 MoE 专家 ~9.5G + KV 200K(q4) ~1.2G + mmproj ~0.85G
CPU:前 14 层 MoE 专家(靠 --no-mmap 进 RAM)~4.6 GB
```
### 3.4 视觉(mmproj)的显存、安全余量与 prefill 取舍
**两个关键实测**:
1. 4K 大图处理时显存 spike 仅 **~440 MiB**(Qwen-VL 视觉 token 有上限,再大的图也封顶)。
2. **prefill 是 GPU-bound(利用率 100% 满载)**——所以 `-tb`/线程/numa/mlock 等 flag 全部无效(已验证,均在 ±2% 噪声)。能提速 prefill 的只有 **`-ub`(更大 GPU 批次)** 和 **更低的 `--n-cpu-moe`(更多专家留 GPU、少搬 RAM)**,两者都吃显存。
视觉配置(+mmproj+200K)的取舍:
| 配置 | idle 余量 | prefill | decode | 大图 | 适用 |
|------|:-:|:-:|:-:|:-:|------|
| moe=13 (+mmproj) | 0.4 GB | — | — | ❌ OOM | 视觉不可用 |
| **moe=14 + ub1152(当前生产)** | **0.68 GB** | **~1960** | ~61 | ⚠️ 普通图正常、超大图紧 | **prefill 优先**(Claude Code 文本为主) |
| moe=15 + ub1024 | 1.2 GB | ~1760 | ~62 | ✅ 安全(4K 峰值余 0.8GB) | 图安全优先 |
→ **prefill 优先选 moe=14+ub1152**(prefill ~1960,文本场景稳,偶发普通图也行,仅极端大图/多图有风险);**重度识图选 moe=15+ub1024**(prefill 低 ~10% 但大图稳)。moe=13 会 OOM,**14 是视觉下限**。
- **无 Q4 mmproj**:公开仓库只有 f16/Q6_K;`llama-quantize` 不支持 clip 架构,本地也做不出 Q4。最小是 **Q6_K (583 MB)**。
- **`--parallel 2` 不省显存、且实测更慢**:KV 按 `-c` 总量预分配,parallel 只切槽(每槽上下文 200K→100K),并发识图反而双倍 spike。**性能代价(2026-08 实测)**:6 核 CPU-MoE 是 decode 瓶颈,2 路并发每路掉到 ~22 tok/s(单发 ~60),总吞吐反降到 ~44 tok/s,互相挤兑。而 `parallel=1` 多请求在服务端 `defer` 排队(不拒绝),各自仍跑满 ~60 tok/s,只是后到的请求要等先到的跑完。**这台 6 核机器不建议开 parallel 2**,除非必须避免"短请求被长请求阻塞"(如翻译要即时响应、不能排在 agent 长生成后),才用 parallel 2 换即时响应。若必须并发又想给某槽更大上下文,`--kv-unified` 可让单槽上限从 `n_ctx/n_parallel` 升到完整 `n_ctx`(动态共享池,源码 `llama-context.cpp` 中 `n_ctx_seq = n_ctx`)。
---
## 四、模型选型与质量评测
### 4.1 质量分数(thinking-off)
| 指标 | HauhauCS IQ4_XS | 官方原版 | 之前 UD-IQ2_M |
|------|:-:|:-:|:-:|
| AIME26(30 题) | **53.3** | 92.7 | 30.0 |
| MMLU-Pro(70 采样) | 72.9 | 85.2 | 67.1 |
| C-Eval(20 采样) | 70.0 | 90.0 | 65.0 |
| LiveCodeBench v6(15 题) | **40.0** | 80.4 | 13.3 |
> 评测方法:AIME26 全 30 题 / MMLU-Pro 分层 70 采样 / C-Eval 10 学科×2 / LCB v6 slice 0:15,均 thinking-off。MMLU-Pro/C-Eval 为代表性采样,非全集。
### 4.2 为什么选 HauhauCS(而非 Opus 蒸馏 abliterated)
| 模型 | AIME | MMLU | C-Eval | LCB | decode | 体积 |
|------|:-:|:-:|:-:|:-:|:-:|:-:|
| **HauhauCS IQ4_XS** | **53.3** | 72.9 | **70** | **40** | **70 t/s** | 17.4G |
| shennguyen Opus4.7-abliterated Q4_K_M | 36.7 | 72.9 | 65 | 26.7 | 64 t/s | 19.7G |
HauhauCS 全面领先(AIME +16.6、LCB +13.3、还更快更小)。要 uncensored 选它。
### 4.3 ⚠️ 关键:abliterated 模型必须 thinking-off
实测 thinking-on(token 放宽到 16384,不计耗时):
| Benchmark | thinking-OFF | thinking-ON |
|-----------|:-:|:-:|
| AIME26 | **53.3%** | 16.7%(差 3.2×) |
| LiveCodeBench v6 | 40.0% | 40.0%(持平,但费 5× token) |
abliteration 破坏了 thinking 收敛能力——模型在 `` 里一路生成到 token 上限,给不出干净结论。**两个 abliterated 版本都这样**。所以务必 `enable_thinking=false`。
> 若一定要 thinking 模式做 agentic 编程 → 别用 abliterated,选 base `bartowski` IQ4_XS 或非 abliterated 的 `hesamation` Opus-4.6 蒸馏。
> 解析注意:llama.cpp 把 thinking 内容放 `message.reasoning_content`(非 `content`);thinking-off 时内容在 `content`,正常解析。
---
## 五、接入 Claude Code / OpenAI 客户端
把模型当 OpenAI 兼容 API 用(尤其 Claude Code 这类 agentic 客户端)会踩两个坑,必须加两个参数。
### 5.1 报错:`System message must be at the beginning`(400)
HauhauCS 内置 chat template 有强制检查:system 不在首位就 `raise_exception`。Claude Code / 很多客户端发的消息顺序会触发它(llama.cpp 生成 parser 时跑到该异常,返回 400)。
**修复**:用一份 claude-compatible 模板覆盖(不强制 system 在首位、支持 tools):
```bash
--chat-template-file ./templates/qwen3.6-35b-a3b-claude-compatible.jinja
```
### 5.2 模型偷偷 thinking(content 空、token 浪费)
abliterated 模型的 thinking 是坏的(见 4.3),但客户端(Claude Code)不会传 `enable_thinking`,仅靠模板默认压不住——模型会自己重开 `` 思考,答案进 `reasoning_content`、`content` 为空,agent 拿不到回复。
**修复**:服务端强制关闭 thinking:
```bash
--reasoning off
```
`--reasoning off` 对所有请求生效(无论客户端是否传 `enable_thinking`),模型直接在 `content` 回答或调用 tool。
### 5.3 验证(修复后)
| 测试 | 结果 |
|------|------|
| system 不在首位 + 无 `enable_thinking` | `content="4"`、无 thinking、无报错 ✅ |
| tools 请求 | 正确 `tool_calls`(如 `get_weather(Beijing)`)、无 thinking ✅ |
### 5.4 模板文件 `qwen3.6-35b-a3b-claude-compatible.jinja`
基于标准 Qwen3-VL chat template,改动:①去掉 system 位序强制;②支持 tools/tool_calls(带 `` 格式提醒,提升 Claude Code 工具调用稳定性);③默认 thinking-off(配合 `--reasoning off` 双保险);④**还原多轮 `reasoning_content`**——把历史 assistant 的 `... ` 正确拆回 thinking(否则 Claude Code 多轮对话会把上一轮 thinking 当正文喂回去,污染上下文)。完整内容(与仓库 `templates/qwen3.6-35b-a3b-claude-compatible.jinja` 同步):
```jinja
{%- set image_count = namespace(value=0) %}
{%- set video_count = namespace(value=0) %}
{%- macro render_content(content, do_vision_count, is_system_content=false) %}
{%- if content is string %}
{{- content }}
{%- elif content is iterable and content is not mapping %}
{%- for item in content %}
{%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
{%- if is_system_content %}
{{- raise_exception('System message cannot contain images.') }}
{%- endif %}
{%- if do_vision_count %}
{%- set image_count.value = image_count.value + 1 %}
{%- endif %}
{%- if add_vision_id %}
{{- 'Picture ' ~ image_count.value ~ ': ' }}
{%- endif %}
{{- '<|vision_start|><|image_pad|><|vision_end|>' }}
{%- elif 'video' in item or item.type == 'video' %}
{%- if is_system_content %}
{{- raise_exception('System message cannot contain videos.') }}
{%- endif %}
{%- if do_vision_count %}
{%- set video_count.value = video_count.value + 1 %}
{%- endif %}
{%- if add_vision_id %}
{{- 'Video ' ~ video_count.value ~ ': ' }}
{%- endif %}
{{- '<|vision_start|><|video_pad|><|vision_end|>' }}
{%- elif 'text' in item %}
{{- item.text }}
{%- else %}
{{- raise_exception('Unexpected item type in content.') }}
{%- endif %}
{%- endfor %}
{%- elif content is none or content is undefined %}
{{- '' }}
{%- else %}
{{- raise_exception('Unexpected content type.') }}
{%- endif %}
{%- endmacro %}
{%- if not messages %}
{{- raise_exception('No messages provided.') }}
{%- endif %}
{%- if tools and tools is iterable and tools is not mapping %}
{{- '<|im_start|>system\n' }}
{{- "# Tools\n\nYou have access to the following functions:\n\n" }}
{%- for tool in tools %}
{{- "\n" }}
{{- tool | tojson }}
{%- endfor %}
{{- "\n " }}
{{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n\n\n\nvalue_1\n \n\nThis is the value for the second parameter\nthat can span\nmultiple lines\n \n \n \n\n\nReminder:\n- Function calls MUST follow the specified format: an inner block must be nested within XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n ' }}
{%- if messages[0].role == 'system' %}
{%- set content = render_content(messages[0].content, false, true)|trim %}
{%- if content %}
{{- '\n\n' + content }}
{%- endif %}
{%- endif %}
{{- '<|im_end|>\n' }}
{%- else %}
{%- if messages[0].role == 'system' %}
{%- set content = render_content(messages[0].content, false, true)|trim %}
{{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
{%- endif %}
{%- endif %}
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
{%- for message in messages[::-1] %}
{%- set index = (messages|length - 1) - loop.index0 %}
{%- if ns.multi_step_tool and message.role == "user" %}
{%- set content = render_content(message.content, false)|trim %}
{%- if not(content.startswith('') and content.endswith(' ')) %}
{%- set ns.multi_step_tool = false %}
{%- set ns.last_query_index = index %}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- if ns.multi_step_tool %}
{{- raise_exception('No user query found in messages.') }}
{%- endif %}
{%- for message in messages %}
{%- set content = render_content(message.content, true, message.role == "system")|trim %}
{%- if message.role == "system" %}
{%- if not loop.first %}
{{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
{%- endif %}
{%- elif message.role == "user" %}
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
{%- elif message.role == "assistant" %}
{%- set reasoning_content = '' %}
{%- if message.reasoning_content is string %}
{%- set reasoning_content = message.reasoning_content %}
{%- else %}
{%- if ' ' in content %}
{%- set reasoning_content = content.split(' ')[0].rstrip('\n').split('')[-1].lstrip('\n') %}
{%- set content = content.split(' ')[-1].lstrip('\n') %}
{%- endif %}
{%- endif %}
{%- set reasoning_content = reasoning_content|trim %}
{%- if loop.index0 > ns.last_query_index %}
{{- '<|im_start|>' + message.role + '\n\n' + reasoning_content + '\n \n\n' + content }}
{%- else %}
{{- '<|im_start|>' + message.role + '\n' + content }}
{%- endif %}
{%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
{%- for tool_call in message.tool_calls %}
{%- if tool_call.function is defined %}
{%- set tool_call = tool_call.function %}
{%- endif %}
{%- if loop.first %}
{%- if content|trim %}
{{- '\n\n\n\n' }}
{%- else %}
{{- '\n\n' }}
{%- endif %}
{%- else %}
{{- '\n\n\n' }}
{%- endif %}
{%- if tool_call.arguments is defined %}
{%- for args_name, args_value in tool_call.arguments|items %}
{{- '\n' }}
{%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
{{- args_value }}
{{- '\n \n' }}
{%- endfor %}
{%- endif %}
{{- ' \n ' }}
{%- endfor %}
{%- endif %}
{{- '<|im_end|>\n' }}
{%- elif message.role == "tool" %}
{%- if loop.previtem and loop.previtem.role != "tool" %}
{{- '<|im_start|>user' }}
{%- endif %}
{{- '\n\n' }}
{{- content }}
{{- '\n ' }}
{%- if not loop.last and loop.nextitem.role != "tool" %}
{{- '<|im_end|>\n' }}
{%- elif loop.last %}
{{- '<|im_end|>\n' }}
{%- endif %}
{%- else %}
{{- raise_exception('Unexpected message role.') }}
{%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
{{- '<|im_start|>assistant\n' }}
{%- if enable_thinking is defined and enable_thinking is true %}
{{- '\n' }}
{%- else %}
{{- '\n\n \n\n' }}
{%- endif %}
{%- endif %}
```
> 客户端侧:Claude Code 用 `ANTHROPIC_BASE_URL`/OpenAI 兼容 endpoint 指向 `http://:8080/v1` 即可。llama.cpp 把 thinking 放 `message.reasoning_content`(非 `content`);`--reasoning off` 后 content 直接是答案。
---
## 六、踩过的坑(无效 / 不建议)
- **投机解码(MTP / ngram)**:对真实生成无提速。`draft-mtp` 净提速 0(开销抵消收益);`ngram-mod` 仅近乎逐字重复时快 3.5×。decode 是 CPU-MoE 瓶颈,投机解码解决不了。
- **KV cache 放内存(`--no-kv-offload`)**:能把 active KV 移到 RAM 省 ~1.2 GB,但 **decode 暴跌 74→25 t/s**(attention 每 token 跨 PCIe 读 KV,变 PCIe 瓶颈)。完全不值得,KV 必须留 VRAM;要省只有靠 q4 量化(200K 仅 ~1.2 GB,已最小)。
- **thinking 模式**:见 4.3,abliterated 版必坏。
- **线程过调度**:6 核机器 `-t 8 -tb 16` 反而比 `-t 6 -tb 6` 慢。
- **其他 CPU 侧 flag 实测无效**:`--mlock` / `--numa isolate` / `--cpu-strict 1` / `--poll 100` 对 prefill/decode 都在 ±2% 噪声内(社区那些 tip 多针对 Apple Silicon 统一内存或多路服务器,本机 6 核单 socket 不适用)。decode 卡在 RAM 带宽(搬运 CPU 专家权重),调度类 flag 改变不了。
- **AVX-512 仅值 ~5% decode、0% prefill**:A/B 实测(同配置,仅开关 AVX512)——decode 66→63 t/s(−5%),prefill 不变(~1948,GPU-bound)。AVX-512 的 512-bit 向量提速的是 CPU 矩阵"算",但 decode 瓶颈是 RAM 带宽"搬",算得再快也得等内存喂,所以收益小。prefill 完全在 GPU 上,AVX-512 无关。**结论:保持 `GGML_NATIVE=ON`(自动开 AVX512)即可,白送的 5% decode 别丢;不值得为它单独折腾,也不值得关。**
- **唯一有用的"其他"优化 = prompt cache**(`--cache-ram`,默认 8GB **已开**):重复 prompt 实测 **8.6× 加速**(Claude Code 同一 system prompt:1.54s→0.18s,2831 token 命中 2816)。保持默认开启即可。
- **`--n-cpu-moe 0`(全上 GPU)**:模型塞不进 16GB,必 OOM。
- **Cache 有效期**:active KV 随 slot 存在到重置/重启;`--cache-ram`(默认 8GB)的 prompt cache 在内存、重启丢失;`--session FILE` 可持久化 KV 到磁盘跨重启。
---
## 七、小结
- **单卡 16GB 跑满血 35B MoE + 视觉完全可行**:当前生产 HauhauCS IQ4_XS,`moe=14 -ub 1152`+mmproj,decode ~61、**prefill ~1960**、200K 上下文、可识图(余 0.68 GB,文本场景稳)。要图更稳切 `moe=15 -ub 1024`(prefill ~1760、余 1.2 GB);纯文本去 mmproj 上 `moe=12 -ub 1536`(decode ~70、prefill ~1929)。
- 速度三要素(按重要性):**①CUDA 后端 ②`--n-cpu-moe` 调到 VRAM 上限 ③`--no-mmap`**;prefill 是 GPU-bound,再加 **`-ub`**(视觉 1152 / 文本 1536),`-tb`/numa/mlock 等 flag 实测无效(见 3.4)。
- 要 uncensored 选 HauhauCS(强于 Opus-abliterated),但**务必 thinking-off**。
- **接 Claude Code / OpenAI 客户端必加** `--chat-template-file`(claude-compatible,否则 system 位序报 400)+ `--reasoning off`(否则偷偷 thinking、content 空)。
- 视觉下限:**moe≥14**(13 会 OOM);无 Q4 mmproj;`--parallel 2` 切槽不省显存、6 核机器实测总吞吐反降(每路 22 vs 60 tok/s),不建议。
- 投机解码、KV 放内存、thinking 模式——都是本场景的伪优化或坑。
---
## 八、版本与上游(2026-07 复测)
**问题**:主线又跑了两个月,要不要升级?结论:**为速度不必升,为稳定性/视觉可升。**
- 当前 pin 在 commit `3292da0`(tag `b9441`,2026-05-31);复测时主线最新 `b10189`(2026-07-30),落后约 750 个 build。
- **同配置 A/B**(`llama-bench -mmp 0`,moe=14 / ub=1152 / q4_0 KV / fa / 6 线程,8 次重复交错):
| 测试 | b9441 | b10189 | 差异 |
|------|:-:|:-:|:-:|
| pp512 | ~1020 | ~1024 | +0.4% |
| pp4096 | ~1518 | ~1525 | +0.5% |
| tg128 | ~69.6 | ~67.9 | −2.4% |
全部落在 ±1% 噪声内 → **升级对 prefill/decode 没有提速**。
- **为什么提不动**:那些诱人的 MoE 性能 PR **都没合并**——自适应专家 VRAM 缓存([#24524](https://github.com/ggml-org/llama.cpp/pull/24524),closed 未合并)、CUDA MoE expert fusion([#26160](https://github.com/ggml-org/llama.cpp/pull/26160) closed / [#25952](https://github.com/ggml-org/llama.cpp/pull/25952) open)、`--n-cpu-moe` decode 提速([#20596](https://github.com/ggml-org/llama.cpp/pull/20596) open)。decode 瓶颈仍是 CPU 侧专家权重的内存带宽(GPU 利用率仅 ~34%),主线没动这个。
- **EAGLE3 投机解码实测(净负)**:用 [EntityDeletr 的 Q5_K_M draft](https://huggingface.co/EntityDeletr/Qwen3.6-35B-A3B-Caption-Eagle3DraftModel-GGUF),`--spec-type draft-eagle3`:**接受率只有 4.3%**(标称 83%——draft 训于 base+coco,与 HauhauCS uncensored 目标分布失配),decode **67→22 tok/s(约 3× 变慢)**,`--spec-draft-n-max 16` 直接 OOM 崩溃。→ 本场景投机解码仍是坑(印证第六节)。
- **升级的真正理由(非速度)**:`b9441` 之后合并了一批稳定性/视觉/jinja 修复,值得择机跟进——`-ncmoe` MoE 崩溃([#25028](https://github.com/ggml-org/llama.cpp/pull/25028))、长上下文 FA 的 KQ-mask 整数溢出([#24945](https://github.com/ggml-org/llama.cpp/pull/24945))、qwen3vl 视觉位置编码插值修正([#25781](https://github.com/ggml-org/llama.cpp/pull/25781))、qwen-vl frame merge([#21858](https://github.com/ggml-org/llama.cpp/pull/21858))、jinja `call` 语句支持([#24847](https://github.com/ggml-org/llama.cpp/pull/24847))、CUDA MoE/FA 编入 PDL([#24087](https://github.com/ggml-org/llama.cpp/pull/24087)/[#25185](https://github.com/ggml-org/llama.cpp/pull/25185),Blackwell 受益但本配置实测在噪声内)。
> ⚠️ **测量坑**:`llama-bench` 的 prompt 是全词表**均匀随机 token**(`std::rand()%n_vocab`),对 ncmoe MoE 会触发最坏 expert fan-out、最大化 CPU 专家内存带宽 → **系统性低估 prefill**。上表 pp ~1520 是这个最坏值;**产线 server 真实 prefill ≈ 2100 tok/s**(实测:6401 token / 3037 ms,moe=14+ub1152+mmproj),与本节上方 ~1960 一致、甚至更高。所以别拿 `llama-bench` 的 pp 绝对值对比产线;**版本间相对对比仍有效**(同方法测两边)。decode(tg)不受影响——生成 token 是模型真实分布。
---
*所有数据为本机实测(2026-06;第八节为 2026-07 复测),硬件/驱动不同会有差异。模型来自社区(HauhauCS / bartowski / shennguyen 等),部署基于 llama.cpp。MMLU-Pro/C-Eval 为代表性采样。*
同分类推荐文章
- 科技爱好者周刊(第 416 期):编程已经面目全非 (2026-11-14 04:10:02)
- AI Native 实践续篇:迈向 Stage 8 (2026-11-14 02:40:02)
- Is Your Organization Messing Up AI Adoption? (2026-11-14 00:40:02)
建议继续学习
- 正式开源!美团 LongCat-2.0 同步开放国产卡推理代码 (累计阅读 679)
- 美团 LongCat-2.0 正式发布:在国产算力集群上完成全流程训练与推理的万亿参数模型 (累计阅读 463)
- 在 RTX 5060 Ti 16GB 上部署 Qwen3.8-27B(UD-Q3_K_XL)的实测方案 (累计阅读 463)
- OpenAI gpt-oss-120b & gpt-oss-20b 模型技术报告英中对照版 (累计阅读 406)
- LongCat-Flash:美团发布的高效MoE大模型,支持智能体任务,推理速度达100 token/秒 (累计阅读 386)
- 深度解析Kimi K2:当 1T 参数不再只是“大”,而是“能动手”的开放智能体 (累计阅读 355)
- Qwen3.6-35B-A3B 混合架构闲聊: MoE、prefill/decode、SSM 与缓存 (累计阅读 347)
- 编译llama.cpp (累计阅读 120)