Prhub

#36740 cookbook: add a Speculative card to the GLM-5.3-Flash playground

原始 PR 作者 zijiexia 合并时间 2026-08-28 07:04 文件变更 3 提交数 2 评论 1 代码增减 +103 / -2

执行摘要

GLM-5.3-Flash 文档新增投机解码卡片并修复 flag 残留

PR body 指出 GLM-5.3-Flash Deploy 面板只能通过 Strategy 维度触达投机解码(Low Latency 即 adaptive MTP 5/1/6,High Throughput 即关闭),读者想换算法或在 High Throughput 配置上叠加 MTP 只能手改命令。DFlash2 尤其不可达:它的 block-diffusion draft 是独立 checkpoint,没有任何 cell 引用。

值得精读的文档工程型 PR,尤其关注两点:一是 '_playground.jsx' 中 deriveFromBase 与 apply 的 strip/derive 联动设计,这是"配置派生一致性的维护范式";二是 note 字段作为"可选但需前置条件"的 UI 模式,对文档交互设计有参考价值。建议关注其关联的 follow-up(speculative flag 家族补全)与 #36507 合入后的 note 清理。

讨论亮点

review_comments 为 0,仅一条 mintlify bot 的 preview 部署评论;wisclmy0611 已 APPROVED。本 PR 的"讨论"主要集中在 PR body 自述的设计权衡中:

  • --speculative-adaptive 的归属:自适应草稿深度被视为 EAGLE 预设的一部分而非独立旋钮,因此 base cell 携带时必须一并剥离,否则服务端会告警(只有 EAGLE/EAGLE3 识别)。修复前 sweep 发现 12 处孤儿/重复,全部为该 flag。
  • note 字段的引入:renderChip 只给禁用 chip 显示 tooltip,而 DFlash2 是"可选但需要额外前置条件",条件无处安放,因此新增选项级 note,仅在该选项生效时渲染。
  • flag 家族完整性留白:PR 明确列出 speculative 家族仍缺 --speculative-draft-model-path 等 8 个 flag,影响 rednote/dots3-note.jsx 与 Qwen/qwen3.8-27b.jsx 等其他页面(draft 路径残留与重复 emit),但补全会改变约 8 个模型页面的默认 chip 选中态,故留作后续独立评审。

实现拆解

  1. 添加 speculative 轴配置(docs/src/snippets/configs/zai-org/glm-5.3-flash.jsx):在 playgroundFeatures 下新增 speculative 单选项卡片,含 4 个选项:Inherited from base、Off (greedy)、EAGLE / Adaptive MTP 5-1-6(与 Low Latency cell 的 flag 字节一致,保证 base 派生命中)、DFlash2(--speculative-algorithm DFLASH + draft 路径 incoai/GLM-5.3-Flash-DFlash2 + --speculative-draft-attention-backend fa4,不设 num-draft-tokens 由 draft checkpoint 推断块大小)。每个选项通过 disable 数组声明在 DP-Attention 开启或 AMD ROCm 硬件下的不可用原因。
  2. 扩展 Playground 引擎(docs/src/snippets/_playground.jsx):在 speculative 轴的 deriveFromBase 过滤器中加入 --speculative-adaptive,并在 apply 的 stripFlagsByFirstToken 列表中补入同类 flag,此前缺位导致 Off 选项残留孤立 --speculative-adaptive,或重新选取 EAGLE 时 flag 重复出现;新增可选 note 字段,渲染在当前生效选项下方(amber 样式),用于展示命令可运行的前置条件。
  3. 同步 cookbook 文档(docs/cookbook/autoregressive/GLM/GLM-5.3-Flash.mdx):在 §2 增加 "Change the speculative algorithm" 小节,解释三个算法 chip 的语义与限制,并在 Playground 简介中补充 speculative decoding 能力。
  4. 验证方式:运行 node docs/scripts/check_cookbook_configs.mjs;并用脚本模拟 overlayCompose -> deriveFromBase -> apply 全链路,覆盖 15 个 cell x 4 个 chip(9 种硬件 x 两种策略),确认任意组合都能产出合法命令,修复前同链路报 12 处孤儿/重复 flag 问题。
文件 模块 状态 重要度
docs/src/snippets/_playground.jsx 文档组件 modified 6.46
docs/src/snippets/configs/zai-org/glm-5.3-flash.jsx 模型配置 modified 6.37
docs/cookbook/autoregressive/GLM/GLM-5.3-Flash.mdx 文档正文 modified 3.05

关键符号

speculative.deriveFromBase speculative.apply Playground render(note 渲染)

关键源码片段

docs/src/snippets/_playground.jsx core-logic

Playground 引擎核心文件:新增 note 字段的解析 / 渲染,speculative 轴 deriveFromBase 过滤与 apply strip 列表补入 --speculative-adaptive,修复 Off 选项的孤儿 / 重复 flag,是本 PR 中唯一有通用引擎逻辑改动的文件。

// speculative 轴:单选。current = 保持 base 不动,off = 剥离(greedy),
// 其他选项 = 剥离 base 的 --speculative-* 后拼接 option.flags。
// 该轴还会渲染选项自带的可选 `note`(前置条件提示),见下方 render 部分。
speculative: {
  initState: () => "current",  // 把 base 单元格里出现的 --speculative-* flag 集合与每个选项预设比对:
  // 完全没有 → "off";有一些但无预设匹配 → "current"。
  deriveFromBase: (cell, fc) => {
    const flags = (cell && cell.flags) || [];
    const baseSpec = flags.filter((f) => {
      const head = f.split(/[\s=]/)[0];
      return head === "--speculative-algorithm"
          || head === "--speculative-num-steps"
          || head === "--speculative-eagle-topk"
          || head === "--speculative-num-draft-tokens"
          // 自适应草稿深度是 EAGLE 预设的一部分,不是独立旋钮:
          // base 携带它时,切换算法必须一起剥离,否则 flag 残留且
          // 只有 EAGLE/EAGLE3 会识别它,服务端会告警。
          || head === "--speculative-adaptive"
          || head === "--speculative-dspark-block-size"
          || head === "--enable-linear-replayssm-spec"
          || head === "--linear-replayssm-cache-len"
          || head === "--speculative-ngram-max-bfs-breadth";
    });
    if (baseSpec.length === 0) return "off";
    for (const opt of (fc.options || [])) {
      if (!opt.flags || opt.flags.length !== baseSpec.length) continue;
      const ok = opt.flags.every((pf) => baseSpec.includes(pf));
      if (ok) return opt.id;
    }
    return "current";
  },  apply: ({ flags, value, fc, sel, h, derived }) => {
    if (value === "current") return { flags };
    // 与 base 已一致时保持原位,避免 flag 顺序抖动产生假 diff。
    if (derived && value === derived) return { flags };
    const picked = (fc.options || []).find((p) => p.id === value);
    if (picked && h.evaluateChip(picked, {
      ...sel,
      dpAttnOn: h.hasFlag(flags, "--enable-dp-attention"),
    }).disabled) {
      // 被禁用的 chip 不允许泄漏进命令,直接保持 base 不动。
      return { flags };
    }
    // 剥离全部旧 speculative flag,再拼接所选预设,避免孤儿 /
    // 重复 flag(修复前 --speculative-adaptive 会残留或重复 emit)。
    flags = h.stripFlagsByFirstToken(flags, [
      "--speculative-algorithm", "--speculative-num-steps",
      "--speculative-eagle-topk", "--speculative-num-draft-tokens",
      "--speculative-adaptive",
      "--speculative-dspark-block-size",
      "--enable-linear-replayssm-spec",
      "--linear-replayssm-cache-len",
      "--speculative-ngram-max-bfs-breadth",
    ]);
    // ... 随后把 picked.flags 拼入并返回
  },
}
// 选项上可带可选 note:命令能组合出来、但运行前读者还需满足的前置条件
//(例如依赖尚未合入 pin 定镜像的代码)。只在该选项为当前生效选项时渲染,
// 卡片保持 chip 行形态,直到这个选择真正需要读者行动。
const note = (visible.find((c) => c.value === display) || {}).note;
return (
  <div key={axisId} style={s.card}>
    <div style={s.compactRow}>title + chips</div>
    {note && <div style={s.axisNote}>{note}</div>}
  </div>
);
docs/src/snippets/configs/zai-org/glm-5.3-flash.jsx core-logic

GLM-5.3-Flash 专属配置:新增 speculative 轴 4 个选项,声明 EAGLE 与 DFlash2 的 flags、禁用条件(DP-Attention / AMD ROCm)及 DFlash2 的 note 前置条件说明,是本 PR 的功能落地文件。

// ----- Card: "Speculative" -----
// Deploy 面板只能通过 Strategy 维度选择投机解码(Low Latency = adaptive MTP,
// High Throughput = off),本卡片提供更细粒度控制,并补上没有任何 cell 携带的
// DFlash2(其 draft 是独立 checkpoint)。
// EAGLE 预设与 Low Latency cells 字节一致,故 Low Latency base 会派生到该 chip
// (而非显示 Inherited from base),重复点选为无操作,不产生假 diff。
speculative: {
  options: [
    { id: "current", label: "Inherited from base" },
    { id: "off", label: "Off (greedy)" },
    {
      id: "eagle",
      label: "EAGLE / Adaptive MTP 5-1-6",
      flags: [
        "--speculative-algorithm EAGLE",
        "--speculative-num-steps 5",
        "--speculative-eagle-topk 1",
        "--speculative-num-draft-tokens 6",
        "--speculative-adaptive",
      ],
      disable: [
        {
          when: { dpAttnOn: [true] },
          reason: "Adaptive MTP does not support DP-Attention — the server falls back to a static draft depth and warns. Turn DP-Attention off in the Attention card above.",
        },
        {
          when: { hw: ["mi300x", "mi325x", "mi355x"] },
          reason: "MTP speculative decoding has not been validated for GLM-5.3-Flash on AMD ROCm; the Strategy row disables Low Latency there for the same reason.",
        },
      ],
    },
    {
      id: "dflash",
      label: "DFlash2",
      // Block-wise draft:块大小从 draft checkpoint 推断,所以不设
      // --speculative-num-draft-tokens。draft 是稠密模型,不能跑在
      // 目标模型的 DSA 后端上,因此必须显式指定 draft attention backend。
      flags: [
        "--speculative-algorithm DFLASH",
        "--speculative-draft-model-path incoai/GLM-5.3-Flash-DFlash2",
        "--speculative-draft-attention-backend fa4",
      ],
      // DFLASH 需要该模型的 hidden-state capture(#36708),目前合入的是
      // #36507 的 xinyuan/glm-5.3-flash-support 分支而非 main,所以 Install
      // 手风琴 pin 定的镜像不含该能力。待 #36507 合入并发布新镜像后删除本条。
      note: "⚠️ Needs the GLM-5.3-Flash hidden-state capture from PR #36708. It is merged into the PR #36507 support branch (xinyuan/glm-5.3-flash-support), not into main, so pull that branch at its current head — or add #36708's commit on top of an older checkout — before serving. The lmsysorg/sglang:glm-5.3-flash image alone is not enough.",
      disable: [
        {
          when: { dpAttnOn: [true] },
          reason: "DFLASH speculative decoding does not support DP-Attention — the server rejects the combination at startup. Turn DP-Attention off in the Attention card above.",
        },
        {
          when: { hw: ["mi300x", "mi325x", "mi355x"] },
          reason: "DFLASH speculative decoding only supports CUDA and NPU devices; the server rejects it on ROCm at startup.",
        },
      ],
    },
  ],
},

评论区精华

--speculative-adaptive 未纳入 strip 列表导致孤儿 / 重复 flag 正确性

PR body 自述:speculative 轴的 flag 家族之前未包含 --speculative-adaptive,选择 Off (greedy) 后该 flag 会作为孤儿残留(无算法头),选择 EAGLE 预设时又会重复 emit。修复前对 15 cell x 4 chip 的 sweep 发现 12 处孤儿 / 重复问题,全部指向该 flag。

结论:在 deriveFromBase 过滤器和 apply 的 stripFlagsByFirstToken 列表中同时补入 --speculative-adaptive,并解释其属于 EAGLE 预设的一部分。 · 已解决

note 字段:可选选项的前置条件如何展示 设计

DFlash2 可被选择,但依赖 #36708 的 hidden-state capture(合入 #36507 支持分支而非 main),pin 定镜像不包含。renderChip 只在 chip 禁用时显示 tooltip,无法承载 " 当前选项需要前置条件 " 的提示,故新增选项级 note 字段。

结论:speculative 选项可携带可选 note,仅在选项生效时以 amber 样式渲染于 chip 行下方;当前无其他配置使用该字段,不影响其他页面。 · 已解决

speculative flag 家族完成度(follow-up) 设计

PR body 列出引擎 speculative 家族仍缺 --speculative-draft-model-path(76 处使用)、--speculative-use-rejection-sampling 等 8 个 flag,导致其他页面如 rednote/dots3-note.jsx 选择 Off 时残留 draft 路径、Qwen/qwen3.8-27b.jsx 重复 emit draft model path。但补全会改变约 8 个模型页面的默认 chip 选中态,需要独立评审。

结论:本 PR 明确不处理,留作 follow-up;当前仅修复 GLM-5.3-Flash 配置实际使用的 --speculative-adaptive。 · 未解决(后续工作)

风险与影响

  1. DFlash2 选项依赖 #36708 的 hidden-state capture,该改动合入 #36507 支持分支 xinyuan/glm-5.3-flash-support 而未合入 main,官方镜像不包含;若读者按网页提示直接使用镜像,命令无法启动。note 已就地说明,但这是临时方案,合入 main 后如不及时移除过期说明可能误导。
  2. 引擎改动虽经验证(15 cell x 4 chip 全组合),但 speculative 轴在其他模型页面(如 rednote/dots3-note.jsx 使用 --speculative-draft-model-path 的页面)仍存在 flag 家族未补全的残留问题,本 PR 未解决,属已知遗留。
  3. DFlash2 方案在 cookbook 硬件上未做基准测量,文档中组合的启动参数与新模型行为(如 block 大小推断)缺少实测背书。

影响范围集中在 SGLang 文档站 cookbook 页面:GLM-5.3-Flash Playground 交互面板新增投机解码控制,读者无需手改命令即可切换 EAGLE / DFlash2。引擎层面 _playground.jsx 的 note 机制是可复用的新能力,后续其他模型页也可声明 note;--speculative-adaptive 修复消除了 Off 选项下 flag 残留的潜在错误命令。对运行时无代码路径影响,团队侧需要跟进在 #36507 合入后更新 note 文案。

依赖未合入 main 的代码能力 speculative flag 家族未补全 无自动化测试覆盖 DFlash2 组合未实测

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论