<?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[踩坑分享:SGLang,attention backend 请用 flashinfer,别用 triton —— 适用于消费级 Blackwell]]></title><description><![CDATA[<p dir="auto">我的AI主机是 RTX PRO 5000 48G, 之前一直用的是 vLLM + Qwen3.8 27B NVFP4. 后来在 <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry" aria-label="Profile: terry">@<bdi>terry</bdi></a> 以及 Hermes 的帮助下, 部署了 SGLang + Qwen3.8 27B NVFP4. 不过部署好之后, 总感觉长上下文时候变慢, 所以又切换回了 vLLM.</p>
<p dir="auto">这个10.1假期, 让Agent彻底搞了一遍, 把 attention backend 从 triton 改成了 flashinfer, 结果大有改观: 长上下文从 10+ token/s 提升到了 100+ token/s.</p>
<p dir="auto">我的AI主机配置:</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>项</th>
<th>值</th>
</tr>
</thead>
<tbody>
<tr>
<td>GPU</td>
<td>NVIDIA RTX PRO 5000 Blackwell, 48G (SM120), 驱动 595.91.07, CUDA 13.2</td>
</tr>
<tr>
<td>CPU</td>
<td>AMD Ryzen 7 9700X (8C/16T)</td>
</tr>
<tr>
<td>内存</td>
<td>128 GB</td>
</tr>
<tr>
<td>SSD</td>
<td>WD_BLACK SN850X 4TB</td>
</tr>
<tr>
<td>系统</td>
<td>Ubuntu 26.04 LTS + Docker</td>
</tr>
</tbody>
</table>
<p dir="auto">引擎: SGLang v0.5.21(官方镜像), Qwen3.8 27B NVFP4 (RadixArk) + DFlash2 投机解码, 256K 上下文; vLLM (MTP x2) 作备用一键回退.</p>
<p dir="auto">以下为AI生成的详细总结, 注意不同轮次的数据有差异, 是因为脚本和数据的差异, 不能相互比较. 同一轮次的A/B测试有比较意义.<br />
总体上来说, 短coding轻松上200; 长coding 160多; 散文则只能跑到 60多到80多.</p>
<hr />
<h2>背景</h2>
<p dir="auto">之前做了一轮同口径 A/B 测试:SGLang vs vLLM(MTP x2),结果长上下文下 SGLang 惨败:</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>上下文长度</th>
<th style="text-align:right">SGLang(旧档)</th>
<th style="text-align:right">vLLM MTP x2</th>
</tr>
</thead>
<tbody>
<tr>
<td>8K</td>
<td style="text-align:right">73.6 tok/s</td>
<td style="text-align:right">77.6</td>
</tr>
<tr>
<td>32K</td>
<td style="text-align:right">38.7</td>
<td style="text-align:right">78.5</td>
</tr>
<tr>
<td><strong>120K</strong></td>
<td style="text-align:right"><strong>12.9</strong></td>
<td style="text-align:right"><strong>70.3</strong></td>
</tr>
</tbody>
</table>
<p dir="auto">当时我下的结论是:<strong>长上下文下投机解码是净亏的</strong>,交叉点大概在 20–25K,归因给了"算法性质"。生产环境不得以切回 vLLM,SGLang 搁置。</p>
<h2>这次彻底排查发现:结论是错的,根因是一行配置</h2>
<p dir="auto">前两天找时间把 SGLang 从头查了一遍。先用隔离变量法(同镜像、同模型、同 bench,只改一个参数)逐窗口测下来,发现:</p>
<p dir="auto"><strong>同样的镜像、同样的模型,只把 <code>--attention-backend</code> 从 <code>triton</code> 改成 <code>flashinfer</code>,120K 场景每步成本从 193ms 降到 28ms(便宜 6.8×),接受长度几乎不变。</strong></p>
<p dir="auto">机制上:DFlash2 的验证阶段是"多个草稿 token 共享一次 KV 读"的路径,这条路径 <strong>flashinfer 在长上下文下做对了,triton 的后端实现在长上下文下退化</strong>。所以慢的不是"投机猜得准不准"(accept length 两臂几乎一样),而是每步的验证成本。</p>
<p dir="auto">改完之后的成绩:</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>上下文</th>
<th style="text-align:right">改前(triton+DFlash2)</th>
<th style="text-align:right">改后(flashinfer+DFlash2)</th>
</tr>
</thead>
<tbody>
<tr>
<td>8K</td>
<td style="text-align:right">73.6</td>
<td style="text-align:right">119.4</td>
</tr>
<tr>
<td>32K</td>
<td style="text-align:right">38.7</td>
<td style="text-align:right">111.5</td>
</tr>
<tr>
<td><strong>120K</strong></td>
<td style="text-align:right"><strong>12.9</strong></td>
<td style="text-align:right"><strong>116.7</strong></td>
</tr>
</tbody>
</table>
<p dir="auto">120K 直接 <strong>9 倍</strong>,而且反超 vLLM 66%。</p>
<h2>顺带做了一轮 vLLM vs SGLang 同输入回放</h2>
<p dir="auto">既然 SGLang 修好了,切不切回去需要证据。对两个引擎发逐字节相同的请求(thinking off、temp 0),每场景重复 3 次取中位:</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>场景</th>
<th style="text-align:right">vLLM</th>
<th style="text-align:right">SGLang</th>
</tr>
</thead>
<tbody>
<tr>
<td>冷 prefill @129K</td>
<td style="text-align:right">3,322 tok/s</td>
<td style="text-align:right"><strong>4,169</strong> (+26%)</td>
</tr>
<tr>
<td>decode @54.5K</td>
<td style="text-align:right">67.4</td>
<td style="text-align:right"><strong>93.0</strong> (+38%)</td>
</tr>
<tr>
<td>decode @129K</td>
<td style="text-align:right">63.4</td>
<td style="text-align:right"><strong>80.3</strong> (+27%)</td>
</tr>
<tr>
<td>短上下文 decode</td>
<td style="text-align:right"><strong>80.8</strong></td>
<td style="text-align:right">79.4(打平)</td>
</tr>
<tr>
<td>并发 4 聚合</td>
<td style="text-align:right">210–229</td>
<td style="text-align:right"><strong>380–401</strong> (~1.7×)</td>
</tr>
<tr>
<td>能耗 / 1K 输出 token</td>
<td style="text-align:right">5,519 J</td>
<td style="text-align:right"><strong>3,386 J</strong>(−39%)</td>
</tr>
<tr>
<td>原尺寸扫描图(1275×1650)</td>
<td style="text-align:right"><strong>HTTP 400</strong></td>
<td style="text-align:right">OK</td>
</tr>
</tbody>
</table>
<p dir="auto">结论:SGLang 在 prefill、长上下文解码、并发、vision 上全面领先(短上下文解码打平),能耗低 39%,而且只有它吃得了原尺寸扫描图(vLLM 直接 400 拒绝)。<strong>主力切回 SGLang</strong>,vLLM 留作一键回退。</p>
<h2>上网查了一圈:不是孤例</h2>
<p dir="auto">写这篇之前我上网搜了下,发现这个坑社区早有反应:</p>
<ol>
<li>
<p dir="auto"><strong>SGLang 官方 issue <a href="https://github.com/sgl-project/sglang/issues/2271" rel="nofollow ugc">#2271</a></strong>《Optimize triton decoding kernels for long context》直接点题:官方自己测出 triton decode kernel 在长上下文掉速严重,而 flashinfer 几乎不掉。原帖数据(同模型同机):</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>后端</th>
<th style="text-align:right">上下文 200</th>
<th style="text-align:right">上下文 2000</th>
</tr>
</thead>
<tbody>
<tr>
<td>triton</td>
<td style="text-align:right">147.64 tok/s</td>
<td style="text-align:right">126.41(↓14%)</td>
</tr>
<tr>
<td>flashinfer</td>
<td style="text-align:right">144.17</td>
<td style="text-align:right">143.35(基本不掉)</td>
</tr>
</tbody>
</table>
<p dir="auto">那个时代的差距还不算夸张,但方向一致——triton 的 decode 路径对上下文长度敏感,flashinfer 不敏感。到我这张卡(消费级 Blackwell)+ DFlash2 上,这个退化被放大成了 6.8 倍。</p>
</li>
<li>
<p dir="auto"><strong>官方文档的 <a href="https://docs.sglang.io/docs/advanced_features/attention_backend" rel="nofollow ugc">attention backend 选型指南</a></strong> 里,Blackwell 的默认/推荐就是 <code>flashinfer</code>;消费级 Blackwell(RTX PRO 5000/6000、RTX 50 系列这一档,内部代号 SM120)的 full attention 官方支持 <code>triton</code> 或 <code>flashinfer</code> 二选一——也就是说我旧档挂 <code>triton</code> 不算违规,但官方推荐的那条路一直摆在旁边,我没走。</p>
</li>
<li>
<p dir="auto"><strong>SGLang 还有一个 <a href="https://github.com/sgl-project/sglang/issues/19637" rel="nofollow ugc">SM120 性能优化专项 thread(#19637)</a></strong>,社区一直在给这批新卡抠 attention backend 的选择——能看出消费级 Blackwell 是新架构、坑比较多,不只是我一个人踩。</p>
</li>
</ol>
<h2>给大家的几点教训</h2>
<ol>
<li><strong>"投机解码在长上下文赚不赚"这类结论,必须带上当时的 attention backend。</strong> 我的"净亏"结论只在 triton 下成立,后端一换就反转。先定后端,再谈投机,顺序反了会得出可移植性为零的结论。</li>
<li><strong>判断投机赚不赚的通式是 <code>accept length ÷ 每步成本相对倍数 &gt; 1</code></strong>,accept 长度本身不是判据——两臂 accept 几乎一样,结论却可以相反。</li>
<li>官方 cookbook 对 Blackwell 消费卡就是建议用 <code>flashinfer</code>,我旧档一直挂着 <code>triton</code>,血泪教训。</li>
<li>诚实说一个局限:我这轮 A/B 里两边跑的是<strong>不同的 NVFP4 检查点</strong>(vLLM 侧是 orcarouter 版,SGLang 侧是 RadixArk 版),"SGLang 更快"里混着模型因素,想彻底拆干净需要同一检查点双引擎各服务一次。</li>
</ol>
<h2>最终生产配置(供参考)</h2>
<p dir="auto">Docker 运行 SGLang(官方镜像,v0.5.21 系列),启动参数:</p>
<pre><code class="language-bash">sglang serve \
  --model-path /models-ai/Qwen3.8-27B-NVFP4-RadixArk \
  --context-length 262144 \
  --max-total-tokens 262144 \
  --kv-cache-dtype fp8_e4m3 \
  --mem-fraction-static 0.90 \
  --max-running-requests 4 \
  --max-mamba-cache-size 20 \
  --mamba-ssm-dtype bfloat16 \
  --mamba-radix-cache-strategy extra_buffer \
  --speculative-algorithm DFLASH \
  --speculative-draft-model-path /models-ai/Qwen3.8-27B-DFlash2 \
  --speculative-num-draft-tokens 8 \
  --attention-backend flashinfer \
  --linear-attn-backend triton \
  --chunked-prefill-size 2048 \
  --max-prefill-tokens 8192 \
  --cuda-graph-max-bs-decode 8 \
  --cuda-graph-max-bs-prefill 1024 \
  --cuda-graph-backend-prefill disabled \
  --tool-call-parser qwen3_coder \
  --reasoning-parser qwen3
</code></pre>
<p dir="auto">关键改动就是其中一行:<code>--attention-backend triton → flashinfer</code>(唯一影响大的改动)。<br />
注意 <code>--linear-attn-backend</code> 保持 <code>triton</code>——消费级 Blackwell 上 linear attention 没有 flashinfer 可选,已实测否证。</p>
<p dir="auto">改一行配置,120K 解码从 12.9 到 116.7 tok/s。希望有人从中少走弯路。</p>
]]></description><link>https://lcz.me/topic/2129</link><generator>RSS for Node</generator><lastBuildDate>Mon, 12 Oct 2026 14:26:52 GMT</lastBuildDate><atom:link href="https://lcz.me/topic/2129.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 06 Oct 2026 03:39:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to 踩坑分享:SGLang,attention backend 请用 flashinfer,别用 triton —— 适用于消费级 Blackwell on Tue, 06 Oct 2026 03:49:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tony-wang" aria-label="Profile: Tony-Wang">@<bdi>Tony-Wang</bdi></a> 卖豆浆的看到开奔驰的，也要涨点价格，<img src="https://lcz.me/assets/plugins/nodebb-plugin-emoji/emoji/android/1f602.png?v=fe25256ab4a" class="not-responsive emoji emoji-android emoji--joy" style="height:1.4em;width:auto;vertical-align:middle" title="😂" alt="😂" /></p>
]]></description><link>https://lcz.me/post/22744</link><guid isPermaLink="true">https://lcz.me/post/22744</guid><dc:creator><![CDATA[terry]]></dc:creator><pubDate>Tue, 06 Oct 2026 03:49:15 GMT</pubDate></item><item><title><![CDATA[Reply to 踩坑分享:SGLang,attention backend 请用 flashinfer,别用 triton —— 适用于消费级 Blackwell on Tue, 06 Oct 2026 03:45:44 GMT]]></title><description><![CDATA[<p dir="auto">它就是给我抄了个12.9 <img src="https://lcz.me/assets/plugins/nodebb-plugin-emoji/emoji/android/1f622.png?v=fe25256ab4a" class="not-responsive emoji emoji-android emoji--cry" style="height:1.4em;width:auto;vertical-align:middle" title=":cry:" alt="😢" /></p>
<p dir="auto">难道它见人下菜碟? 我对AI从来都是客客气气的 <img src="https://lcz.me/assets/plugins/nodebb-plugin-emoji/emoji/android/1f576.png?v=fe25256ab4a" class="not-responsive emoji emoji-android emoji--dark_sunglasses" style="height:1.4em;width:auto;vertical-align:middle" title=":dark_sunglasses:" alt="🕶" /></p>
]]></description><link>https://lcz.me/post/22741</link><guid isPermaLink="true">https://lcz.me/post/22741</guid><dc:creator><![CDATA[Tony Wang]]></dc:creator><pubDate>Tue, 06 Oct 2026 03:45:44 GMT</pubDate></item><item><title><![CDATA[Reply to 踩坑分享:SGLang,attention backend 请用 flashinfer,别用 triton —— 适用于消费级 Blackwell on Tue, 06 Oct 2026 03:43:08 GMT]]></title><description><![CDATA[<p dir="auto">我哥一定是大别野在村里，刚通网，一般让AI抄作业，再怎么都不会抄到12.9的。别提我，我就是什么参数都不加，纯手工配置，4090也是40t/s。</p>
]]></description><link>https://lcz.me/post/22738</link><guid isPermaLink="true">https://lcz.me/post/22738</guid><dc:creator><![CDATA[terry]]></dc:creator><pubDate>Tue, 06 Oct 2026 03:43:08 GMT</pubDate></item></channel></rss>