> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sglang.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Kimi-K3

> Deploy Moonshot AI's Kimi-K3 with SGLang — a 2.8T-parameter hybrid Mixture-of-Experts vision-language model (Kimi Delta Attention + MLA, 16/896 active experts) with NVIDIA and AMD recipes.

export const Playground = ({config}) => {
  if (!config) {
    return <div style={{
      padding: 12,
      color: "#b91c1c"
    }}>Playground: missing <code>config</code> prop</div>;
  }
  const DIMENSIONS = ["hw", ...(config.matchDims || [{
    id: "variant"
  }, {
    id: "quant"
  }, {
    id: "strategy"
  }, {
    id: "nodes"
  }]).map(d => d.id)];
  const optionVisible = (opt, sel) => typeof opt.showWhen !== "function" || opt.showWhen(sel);
  const optionDisabled = (opt, sel) => typeof opt.disabled === "function" ? opt.disabled(sel) : !!opt.disabled;
  const visibleOptions = (spec, sel) => (spec.options || []).filter(o => optionVisible(o, sel));
  const rowVisible = (spec, sel) => (typeof spec.showWhen !== "function" || spec.showWhen(sel)) && visibleOptions(spec, sel).length > 0;
  const overlayPick = sel => {
    const picked = [];
    for (const spec of config.overlayDims || []) {
      if (!rowVisible(spec, sel)) continue;
      const opt = (spec.options || []).find(o => o.id === sel[spec.id]);
      if (opt && !optionDisabled(opt, sel)) picked.push(opt);
    }
    return picked;
  };
  const overlayPart = (sel, key) => {
    const out = [];
    for (const opt of overlayPick(sel)) {
      const add = typeof opt[key] === "function" ? opt[key](sel) : opt[key];
      if (add) out.push(...add);
    }
    return out;
  };
  const overlayCompose = (cellFlags, sel) => {
    const strip = overlayPart(sel, "stripPrefixes");
    const add = overlayPart(sel, "flags");
    if (!strip.length) return [...cellFlags || [], ...add];
    const used = new Set();
    const replacementsFor = tok => {
      const out = [];
      add.forEach((f, i) => {
        if (used.has(i) || f.split(/[\s=]/)[0] !== tok) return;
        used.add(i);
        out.push(f);
      });
      return out;
    };
    const out = [];
    for (const f of cellFlags || []) {
      const tok = f.split(/[\s=]/)[0];
      if (!strip.includes(tok)) out.push(f); else out.push(...replacementsFor(tok));
    }
    add.forEach((f, i) => {
      if (!used.has(i)) out.push(f);
    });
    return out;
  };
  const withOverlay = (cell, sel) => cell && ({
    ...cell,
    flags: overlayCompose(cell.flags, sel),
    env: [...cell.env || [], ...overlayPart(sel, "env")]
  }) || cell;
  const STORAGE_KEY = "sglang-deploy-env";
  const DEPLOYMENT_COMPONENT_ID = "deployment-configurator";
  const pgFeatures = config.playgroundFeatures || ({});
  const PD_PORTS = {
    prefill: {
      serve: 30000,
      dist: 30335
    },
    decode: {
      serve: 30100,
      dist: 30435
    }
  };
  const findCell = (cells, sel) => cells.find(c => DIMENSIONS.every(d => c.match[d] === sel[d]));
  const findMatchingCell = (cells, sel, pgEnv, pgFlags) => {
    const fixedDims = DIMENSIONS.filter(d => d !== "strategy");
    const flagsEq = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]);
    const envEq = (a, b) => {
      if (a.length !== b.length) return false;
      const set = new Set(a);
      for (const x of b) if (!set.has(x)) return false;
      return true;
    };
    for (const c of cells) {
      if (fixedDims.some(d => c.match[d] !== sel[d])) continue;
      if (flagsEq(c.flags || [], pgFlags || []) && envEq(c.env || [], pgEnv || [])) {
        return c;
      }
    }
    return null;
  };
  const resolveModelName = sel => {
    const keys = [`${sel.hw}|${sel.variant}|${sel.quant}`, `${sel.variant}|${sel.quant}`, `${sel.hw}|${sel.quant}`, sel.quant];
    for (const k of keys) {
      const hit = config.modelNames[k];
      if (hit) return hit;
    }
    return "";
  };
  const interpolate = (text, env, modelName) => text.replace(/{{(\w+)}}/g, (_, key) => key === "MODEL_NAME" ? modelName : env[key] ?? `{{${key}}}`);
  const parseNnodes = id => {
    if (id === "single") return 1;
    const m = (/^multi-(\d+)$/).exec(id);
    return m ? parseInt(m[1], 10) : 1;
  };
  const placeholderDefaults = schema => {
    const out = {};
    for (const [k, v] of Object.entries(schema || ({}))) out[k] = v.default ?? "";
    return out;
  };
  const matchConstraint = (base, constraint) => {
    if (!constraint || typeof constraint !== "object") return false;
    const entries = Object.entries(constraint);
    if (entries.length === 0) return false;
    return entries.every(([k, vs]) => Array.isArray(vs) && vs.includes(base[k]));
  };
  const evaluateChip = (entry, base) => {
    if (entry === null || typeof entry !== "object") {
      return {
        value: entry,
        label: undefined,
        hidden: false,
        disabled: false,
        disableReason: ""
      };
    }
    const hidden = entry.hide ? matchConstraint(base, entry.hide) : false;
    let disabled = entry.disabled === true || entry.disable === true;
    let disableReason = entry.disableReason || "";
    if (!disabled && entry.disable && typeof entry.disable === "object") {
      if (Array.isArray(entry.disable)) {
        for (const item of entry.disable) {
          const cond = item && item.when || item;
          if (matchConstraint(base, cond)) {
            disabled = true;
            if (item && item.reason) disableReason = item.reason;
            break;
          }
        }
      } else {
        disabled = matchConstraint(base, entry.disable);
      }
    }
    return {
      ...entry,
      value: entry.id !== undefined ? entry.id : entry.value,
      label: entry.label,
      hidden,
      disabled,
      disableReason
    };
  };
  const findEntry = (entries, picked) => {
    for (const e of entries || []) {
      const v = e === null || typeof e !== "object" ? e : e.id !== undefined ? e.id : e.value;
      if (v === picked) return e;
    }
    return null;
  };
  const isHidden = (entries, picked, base) => {
    const e = findEntry(entries, picked);
    if (e === null || e === undefined) return false;
    return evaluateChip(e, base).hidden;
  };
  const stripFlagsByFirstToken = (flags, prefixes) => {
    const set = new Set(prefixes);
    return flags.filter(f => !set.has(f.split(/[\s=]/)[0]));
  };
  const stripEnvByPrefix = (envList, prefixes) => {
    if (!prefixes || !prefixes.length) return envList;
    const set = new Set(prefixes);
    return envList.filter(e => !set.has(e.split("=")[0]));
  };
  const insertBeforeTail = (flags, additions) => {
    const idx = flags.findIndex(f => f.startsWith("--host"));
    const at = idx === -1 ? flags.length : idx;
    const out = flags.slice();
    out.splice(at, 0, ...additions);
    return out;
  };
  const insertAfter = (flags, afterAnyOf, additions) => {
    let idx = -1;
    for (const anchor of afterAnyOf) {
      idx = flags.findIndex(f => f.split(/[\s=]/)[0] === anchor);
      if (idx !== -1) break;
    }
    if (idx === -1) idx = flags.findIndex(f => f.startsWith("--model-path"));
    const out = flags.slice();
    out.splice(idx + 1, 0, ...additions);
    return out;
  };
  const parseIntFlag = (flags, prefix) => {
    for (const f of flags || []) {
      if (f.split(/[\s=]/)[0] !== prefix) continue;
      const rest = f.slice(prefix.length).replace(/^[\s=]+/, "");
      const n = parseInt(rest, 10);
      if (!isNaN(n)) return n;
    }
    return null;
  };
  const hasFlag = (flags, name) => (flags || []).some(f => f.split(/[\s=]/)[0] === name);
  const findFlagArg = (flags, prefix) => {
    for (const f of flags || []) {
      if (f.split(/[\s=]/)[0] !== prefix) continue;
      const rest = f.slice(prefix.length).replace(/^[\s=]+/, "");
      return rest.length ? rest : null;
    }
    return null;
  };
  const TP_HEADS = ["--tp-size", "--tp", "--tensor-parallel-size"];
  const EP_HEADS = ["--ep-size", "--ep", "--expert-parallel-size"];
  const parseIntFlagAny = (flags, heads) => {
    for (const head of heads) {
      const n = parseIntFlag(flags, head);
      if (n !== null) return n;
    }
    return null;
  };
  const flagSpelling = (flags, heads, fallback) => heads.find(head => (flags || []).some(f => f.split(/[\s=]/)[0] === head)) || fallback;
  const ANCHOR_NEAR_MODEL_PATH = ["--model-path"];
  const ANCHOR_NEAR_TP = ["--tp-size", "--tp", "--model-path"];
  const ANCHOR_NEAR_DP = ["--dp", "--tp-size", "--tp", "--model-path"];
  const ANCHOR_NEAR_DPATTN = ["--enable-dp-attention", "--dp", "--tp-size", "--tp", "--model-path"];
  const ANCHOR_NEAR_MOE = ["--moe-a2a-backend", "--moe-runner-backend", "--enable-dp-attention", "--dp", "--tp-size", "--tp", "--model-path"];
  const helpers = {
    matchConstraint,
    evaluateChip,
    findEntry,
    isHidden,
    stripFlagsByFirstToken,
    stripEnvByPrefix,
    insertBeforeTail,
    insertAfter,
    parseIntFlag,
    hasFlag,
    findFlagArg,
    TP_HEADS,
    EP_HEADS,
    parseIntFlagAny,
    flagSpelling,
    ANCHOR_NEAR_MODEL_PATH,
    ANCHOR_NEAR_TP,
    ANCHOR_NEAR_DP,
    ANCHOR_NEAR_DPATTN,
    ANCHOR_NEAR_MOE
  };
  const CP_ENABLE_HEADS = ["--enable-prefill-cp", "--enable-nsa-prefill-context-parallel", "--enable-dsa-prefill-context-parallel", "--enable-prefill-context-parallel"];
  const CP_MODE_HEADS = ["--nsa-prefill-cp-mode", "--dsa-prefill-cp-mode", "--prefill-cp-mode"];
  const CP_OWNED_HEADS = [...CP_ENABLE_HEADS, ...CP_MODE_HEADS, "--cp-strategy", "--attn-cp-size"];
  const CP_MODE_TO_STRATEGY = {
    "in-seq-split": "zigzag",
    "round-robin-split": "interleave"
  };
  const cpEnabledIn = flags => CP_ENABLE_HEADS.some(head => hasFlag(flags, head));
  const bakedCpStrategy = flags => findFlagArg(flags, "--cp-strategy") || CP_MODE_TO_STRATEGY[findFlagArg(flags, "--nsa-prefill-cp-mode")] || CP_MODE_TO_STRATEGY[findFlagArg(flags, "--dsa-prefill-cp-mode")] || CP_MODE_TO_STRATEGY[findFlagArg(flags, "--prefill-cp-mode")] || null;
  const AXIS_HANDLERS = {
    attention: {
      initState: () => ({
        tp: null,
        cp: null,
        cpStrategy: null,
        dpAttn: null
      }),
      deriveFromBase: (cell, fc, h) => {
        const flags = cell && cell.flags || [];
        const dpVal = h.parseIntFlag(flags, "--dp");
        const hasDpAttn = h.hasFlag(flags, "--enable-dp-attention");
        let dpAttn;
        if (dpVal !== null) dpAttn = dpVal; else if (hasDpAttn) dpAttn = 1; else dpAttn = false;
        const cpSize = h.parseIntFlag(flags, "--attn-cp-size");
        return {
          tp: h.parseIntFlagAny(flags, h.TP_HEADS),
          cp: cpEnabledIn(flags) ? cpSize !== null ? cpSize : 2 : null,
          cpStrategy: bakedCpStrategy(flags),
          dpAttn
        };
      },
      apply: ({flags, env, value, fc, sel, h}) => {
        const knobEntry = id => (fc.knobs || []).find(k => k.id === id) || ({});
        const factsNow = () => ({
          ...sel || ({}),
          dpAttnOn: h.hasFlag(flags, "--enable-dp-attention"),
          cpOn: cpEnabledIn(flags),
          cpStrategy: bakedCpStrategy(flags) || "interleave",
          effTp: h.parseIntFlagAny(flags, h.TP_HEADS)
        });
        const cpSizeTargetNow = () => {
          if (knobEntry("cp").freeSize) return null;
          const dpIntent = value.dpAttn !== null && value.dpAttn !== undefined ? value.dpAttn : h.hasFlag(flags, "--enable-dp-attention") ? h.parseIntFlag(flags, "--dp") ?? 1 : false;
          if (typeof dpIntent === "number" && dpIntent > 1) return null;
          return h.parseIntFlagAny(flags, h.TP_HEADS);
        };
        const blocked = (id, v) => {
          const facts = factsNow();
          const kc = h.evaluateChip(knobEntry(id), facts);
          if (kc.hidden || kc.disabled) return true;
          if (id === "cp" && typeof v === "number" && v > 1) {
            const target = cpSizeTargetNow();
            if (target !== null && v !== target) return true;
          }
          const e = h.findEntry(knobEntry(id).values || [], v);
          return !!(e !== null && e !== undefined && h.evaluateChip(e, facts).disabled);
        };
        if (value.tp !== null && !blocked("tp", value.tp)) {
          const tpHead = h.flagSpelling(flags, h.TP_HEADS, "--tp");
          flags = h.stripFlagsByFirstToken(flags, h.TP_HEADS);
          flags = h.insertAfter(flags, h.ANCHOR_NEAR_MODEL_PATH, [`${tpHead} ${value.tp}`]);
        }
        const cpStrategyOverride = value.cpStrategy && !blocked("cpStrategy", value.cpStrategy) ? value.cpStrategy : null;
        const cpPick = value.cp !== null ? value.cp : cpStrategyOverride && cpEnabledIn(flags) ? h.parseIntFlag(flags, "--attn-cp-size") ?? 2 : null;
        const cpStrategyPick = cpStrategyOverride || bakedCpStrategy(flags) || "interleave";
        if (cpPick !== null && !blocked("cp", cpPick)) {
          flags = h.stripFlagsByFirstToken(flags, CP_OWNED_HEADS);
          if (cpPick > 1) {
            flags = h.insertAfter(flags, h.ANCHOR_NEAR_DPATTN, [`--attn-cp-size ${cpPick}`, "--enable-prefill-cp", `--cp-strategy ${cpStrategyPick}`]);
          }
        }
        if (value.dpAttn !== null && value.dpAttn !== undefined && !blocked("dpAttn", value.dpAttn)) {
          flags = h.stripFlagsByFirstToken(flags, ["--dp", "--enable-dp-attention"]);
          if (typeof value.dpAttn === "number" && value.dpAttn > 0) {
            flags = h.insertAfter(flags, h.ANCHOR_NEAR_TP, [`--dp ${value.dpAttn}`, "--enable-dp-attention"]);
          }
        }
        return {
          flags,
          env
        };
      },
      render: ({axisId, value, setValue, fc, base, s, h, renderSelect, derived}) => {
        const knobs = fc.knobs || [];
        if (!knobs.length) return null;
        const setKnob = (k, v) => setValue({
          ...value,
          [k]: v
        });
        const labelFor = knob => c => {
          if (c.label !== undefined) return c.label;
          if (knob.id === "dpAttn") {
            const labelMap = knob.labels || ({
              "auto": "Auto",
              "false": "Off"
            });
            const k = c.value === null ? "auto" : String(c.value);
            return labelMap[k] || k;
          }
          return c.value === null ? "Auto" : String(c.value);
        };
        const knobDisplay = knob => {
          const v = value[knob.id];
          if (v !== null && v !== undefined) return v;
          if (derived && derived[knob.id] !== undefined) return derived[knob.id];
          return null;
        };
        const hideNullFor = knob => {
          const d = derived ? derived[knob.id] : null;
          return d !== null && d !== undefined ? [null] : [];
        };
        const entriesFor = knob => {
          const vals = knob.values || [null];
          if (knob.id !== "cp" || knob.freeSize) return vals;
          const target = base.cpSizeTarget;
          if (target === null || target === undefined) return vals;
          return vals.map(entry => {
            const v = entry === null || typeof entry !== "object" ? entry : entry.id !== undefined ? entry.id : entry.value;
            if (typeof v !== "number" || v <= 1 || v === target) return entry;
            const wrapped = entry === null || typeof entry !== "object" ? {
              value: entry
            } : {
              ...entry
            };
            return {
              ...wrapped,
              disabled: true,
              disableReason: `SGLang derives the prefill-CP size as attn_cp_size = TP / DP-Attention (= ${target} here), so only that size can be enabled.`
            };
          });
        };
        return <div key={axisId} style={s.card}>
            <div style={s.compactRow}>
              <span style={s.axisTitle}>Attention</span>
              {knobs.map(knob => {
          const kc = h.evaluateChip(knob, base);
          if (kc.hidden) return null;
          return <span key={knob.id} style={s.field}>
                    <span style={s.fieldLabel}>{knob.label || knob.id.toUpperCase()}</span>
                    {renderSelect(knobDisplay(knob), entriesFor(knob), nv => setKnob(knob.id, nv), base, labelFor(knob), {
            hideValues: hideNullFor(knob),
            disabled: kc.disabled,
            disabledReason: kc.disableReason
          })}
                  </span>;
        })}
            </div>
          </div>;
      }
    },
    moe: {
      initState: () => ({
        backend: null,
        ep: null,
        mmQuant: null
      }),
      deriveFromBase: (cell, fc, h) => {
        const flags = cell && cell.flags || [];
        const baseEnv = cell && cell.env || [];
        const a2a = h.findFlagArg(flags, "--moe-a2a-backend");
        const runner = h.findFlagArg(flags, "--moe-runner-backend");
        const fp4Acts = baseEnv.some(e => e.startsWith("SGLANG_OPT_DEEPGEMM_MEGA_MOE_USE_FP4_ACTS"));
        return {
          backend: a2a || runner || null,
          ep: h.parseIntFlagAny(flags, h.EP_HEADS),
          mmQuant: fp4Acts ? "w4a4" : "w4a8"
        };
      },
      apply: ({flags, env, value, fc, h, derived}) => {
        if (value.backend !== null) {
          flags = h.stripFlagsByFirstToken(flags, ["--moe-a2a-backend", "--moe-runner-backend"]);
          const backendEnvKeys = [];
          for (const o of fc.backend?.options || []) {
            for (const e of o.env || []) backendEnvKeys.push(e.split("=")[0]);
          }
          if (backendEnvKeys.length) env = h.stripEnvByPrefix(env, backendEnvKeys);
          const opt = (fc.backend?.options || []).find(o => o.id === value.backend);
          if (opt?.flags?.length) {
            flags = h.insertAfter(flags, h.ANCHOR_NEAR_DPATTN, opt.flags);
          }
          if (opt?.env?.length) env = [...env, ...opt.env];
        }
        const mq = fc.megamoeQuant;
        if (mq) {
          const quantKeys = [];
          for (const o of mq.options || []) {
            for (const e of o.env || []) quantKeys.push(e.split("=")[0]);
          }
          const effBackend = value.backend !== null ? value.backend : derived && derived.backend;
          if (effBackend === "megamoe") {
            env = h.stripEnvByPrefix(env, [...mq.stripEnv || [], ...quantKeys]);
            const quant = value.mmQuant != null ? value.mmQuant : derived && derived.mmQuant || "w4a8";
            const opt = (mq.options || []).find(o => o.id === quant);
            if (opt?.env?.length) env = [...env, ...opt.env];
          } else if (value.backend !== null) {
            env = h.stripEnvByPrefix(env, quantKeys);
          }
        }
        if (value.ep !== null) {
          const epHead = h.flagSpelling(flags, h.EP_HEADS, "--ep");
          flags = h.stripFlagsByFirstToken(flags, h.EP_HEADS);
          if (value.ep > 1) {
            flags = h.insertAfter(flags, h.ANCHOR_NEAR_MOE, [`${epHead} ${value.ep}`]);
          }
        }
        return {
          flags,
          env
        };
      },
      render: ({axisId, value, setValue, fc, base, s, renderSelect, derived}) => {
        if (!fc.backend && !fc.ep) return null;
        const setSlot = (k, v) => setValue({
          ...value,
          [k]: v
        });
        const slotDisplay = k => {
          const v = value[k];
          if (v !== null && v !== undefined) return v;
          if (derived && derived[k] !== undefined) return derived[k];
          return null;
        };
        const hideNull = k => {
          const d = derived ? derived[k] : null;
          return d !== null && d !== undefined ? [null] : [];
        };
        const mmOpt = (fc.backend?.options || []).find(o => o.id === "megamoe");
        const mmAvail = !!mmOpt && (!mmOpt.requiresHw || mmOpt.requiresHw.includes(base.hw)) && (!mmOpt.excludesStrategy || !mmOpt.excludesStrategy.includes(base.strategy));
        const backendIsMega = slotDisplay("backend") === "megamoe";
        return <div key={axisId} style={s.card}>
            <div style={s.compactRow}>
              <span style={s.axisTitle}>MoE</span>
              {fc.backend && <span style={s.field}>
                  <span style={s.fieldLabel}>Backend</span>
                  {renderSelect(slotDisplay("backend"), fc.backend.options || [], v => setSlot("backend", v), base, undefined, {
          hideValues: [...hideNull("backend"), ...mmAvail ? [] : ["megamoe"]]
        })}
                </span>}
              {fc.megamoeQuant && backendIsMega && <span style={s.field}>
                  <span style={s.fieldLabel}>Quantization</span>
                  {renderSelect(value.mmQuant != null ? value.mmQuant : derived && derived.mmQuant || "w4a8", fc.megamoeQuant.options || [], v => setSlot("mmQuant", v), base)}
                </span>}
              {fc.ep && <span style={s.field}>
                  <span style={s.fieldLabel}>{fc.ep.label || "EP"}</span>
                  {renderSelect(slotDisplay("ep"), fc.ep.values || [null], v => setSlot("ep", v), base, undefined, {
          hideValues: hideNull("ep")
        })}
                </span>}
            </div>
          </div>;
      }
    },
    parsers: {
      initState: fc => {
        const out = {};
        for (const item of fc.items || []) out[item.id] = null;
        return out;
      },
      deriveFromBase: (cell, fc, h) => {
        const flags = cell && cell.flags || [];
        const out = {};
        for (const item of fc.items || []) {
          const prefix = item.flag.split(/[\s=]/)[0];
          out[item.id] = h.hasFlag(flags, prefix);
        }
        return out;
      },
      apply: ({flags, env, value, fc, h, derived}) => {
        const items = fc.items || [];
        const eff = {};
        const baseOf = {};
        for (const item of items) {
          baseOf[item.id] = derived ? !!derived[item.id] : false;
          const v = value[item.id];
          eff[item.id] = v === null || v === undefined ? baseOf[item.id] : v;
        }
        const anyOverride = items.some(it => eff[it.id] !== baseOf[it.id]);
        if (!anyOverride) return {
          flags,
          env
        };
        flags = h.stripFlagsByFirstToken(flags, ["--reasoning-parser", "--tool-call-parser"]);
        const adds = [];
        for (const item of items) {
          if (eff[item.id]) adds.push(item.flag);
        }
        if (adds.length) flags = h.insertBeforeTail(flags, adds);
        return {
          flags,
          env
        };
      },
      render: ({axisId, value, setValue, fc, base, s, h, renderChip, derived}) => {
        const visible = (fc.items || []).map(item => ({
          item,
          c: h.evaluateChip(item, base)
        })).filter(({c}) => !c.hidden);
        if (visible.length === 0) return null;
        const effOn = id => {
          const v = value[id];
          if (v !== null && v !== undefined) return v;
          if (derived && derived[id] !== undefined) return derived[id];
          return false;
        };
        return <div key={axisId} style={s.card}>
            <div style={s.compactRow}>
              <span style={s.axisTitle}>Parsers</span>
              {visible.map(({item, c}) => <span key={item.id} style={s.field}>
                  {renderChip(item.label, effOn(item.id), true, () => setValue({
          ...value,
          [item.id]: !effOn(item.id)
        }), {
          disabled: c.disabled,
          disabledReason: c.disableReason
        })}
                </span>)}
            </div>
          </div>;
      }
    },
    speculative: {
      initState: () => "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" || head === "--speculative-dspark-block-size" || 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, env, value, fc, sel, h, derived}) => {
        if (value === "current") return {
          flags,
          env
        };
        if (derived && value === derived) return {
          flags,
          env
        };
        const picked = (fc.options || []).find(p => p.id === value);
        if (picked && h.evaluateChip(picked, {
          ...sel,
          dpAttnOn: h.hasFlag(flags, "--enable-dp-attention")
        }).disabled) {
          return {
            flags,
            env
          };
        }
        flags = h.stripFlagsByFirstToken(flags, ["--speculative-algorithm", "--speculative-num-steps", "--speculative-eagle-topk", "--speculative-num-draft-tokens", "--speculative-dspark-block-size", "--speculative-ngram-max-bfs-breadth"]);
        const preset = (fc.options || []).find(p => p.id === value);
        if (preset?.flags?.length) flags = h.insertBeforeTail(flags, preset.flags);
        return {
          flags,
          env
        };
      },
      render: ({axisId, value, setValue, fc, base, s, h, renderChip, derived}) => {
        const opts = fc.options || [];
        if (!opts.length) return null;
        const display = value !== "current" ? value : derived ? derived : "current";
        const hideCurrent = !!(derived && derived !== "current");
        const visible = opts.map(opt => h.evaluateChip(opt, base)).filter(c => !c.hidden && !(hideCurrent && c.value === "current"));
        if (visible.length === 0) return null;
        return <div key={axisId} style={s.card}>
            <div style={s.compactRow}>
              <span style={s.axisTitle}>Speculative</span>
              {visible.map(c => <span key={c.value} style={s.field}>
                  {renderChip(c.label, display, c.value, () => setValue(c.value), {
          disabled: c.disabled,
          disabledReason: c.disableReason
        })}
                </span>)}
            </div>
          </div>;
      }
    },
    pdDisagg: {
      initState: fc => ({
        mode: "off",
        transferBackend: (fc && (fc.transferBackends || [])[0] || ({})).id || "mooncake",
        ibDevice: "auto"
      }),
      apply: ({flags, env, value, sel, fc, h}) => {
        const bootstrapPort = h.findFlagArg(flags, "--disaggregation-bootstrap-port");
        flags = h.stripFlagsByFirstToken(flags, ["--disaggregation-mode", "--disaggregation-transfer-backend", "--disaggregation-ib-device", "--disaggregation-bootstrap-port"]);
        const backends = fc.transferBackends || [];
        const mode = (fc.modes || []).length ? value.mode : sel && sel.pdMode || "off";
        if (mode === "prefill" || mode === "decode") {
          const specAlgorithm = (h.findFlagArg(flags, "--speculative-algorithm") || "").toUpperCase();
          if ((fc.incompatibleSpeculativeAlgorithms || []).includes(specAlgorithm)) {
            flags = flags.filter(flag => !flag.split(/[\s=]/)[0].startsWith("--speculative-"));
          }
          const backend = value.transferBackend || (backends[0] || ({})).id || "mooncake";
          const adds = [`--disaggregation-mode ${mode}`, `--disaggregation-transfer-backend ${backend}`];
          if (bootstrapPort) {
            adds.push(`--disaggregation-bootstrap-port ${bootstrapPort}`);
          }
          if (value.ibDevice && value.ibDevice !== "auto") {
            adds.push(`--disaggregation-ib-device ${value.ibDevice}`);
          }
          const modeMeta = (fc.modes || []).find(m => m.id === mode);
          if (modeMeta && modeMeta.flags && modeMeta.flags.length) {
            flags = h.stripFlagsByFirstToken(flags, modeMeta.flags.map(f => f.split(/[\s=]/)[0]));
            adds.push(...modeMeta.flags);
          }
          flags = h.insertBeforeTail(flags, adds);
          const servePort = PD_PORTS[mode].serve;
          flags = flags.map(f => f.split(/[\s=]/)[0] === "--port" ? `--port ${servePort}` : f);
          const meta = backends.find(b => b.id === backend);
          if (meta && meta.env && meta.env.length) {
            const gate = meta.envWhen;
            const ok = !gate || Object.keys(gate).every(k => (gate[k] || []).includes(sel[k]));
            if (ok) env = [...env, ...meta.env.filter(e => !env.includes(e))];
          }
          if (modeMeta && modeMeta.env && modeMeta.env.length) {
            env = [...env, ...modeMeta.env.filter(e => !env.includes(e))];
          }
        }
        return {
          flags,
          env
        };
      },
      getRenderHints: (value, fc, context) => {
        const specAlgorithm = (context.h.findFlagArg(context.flags, "--speculative-algorithm") || "").toUpperCase();
        if ((fc.incompatibleSpeculativeAlgorithms || []).includes(specAlgorithm)) {
          return null;
        }
        if (value.mode === "prefill" || value.mode === "decode") {
          return {
            pdMode: value.mode
          };
        }
        return null;
      },
      render: ({axisId, value, setValue, fc, base, s, renderSelect}) => {
        const setSlot = (k, v) => setValue({
          ...value,
          [k]: v
        });
        const showModes = (fc.modes || []).length > 0;
        const showBackends = (fc.transferBackends || []).length > 0;
        const showIb = (fc.ibDevices || []).length > 0;
        if (!showModes && !showBackends && !showIb) return null;
        return <div key={axisId} style={s.card}>
            <div style={s.compactRow}>
              <span style={s.axisTitle}>PD Disagg</span>
              {showModes && <span style={s.field}>
                  <span style={s.fieldLabel}>Mode</span>
                  {renderSelect(value.mode, fc.modes, v => setSlot("mode", v), base)}
                </span>}
              {showBackends && <span style={s.field}>
                  <span style={s.fieldLabel}>Transfer Backend</span>
                  {renderSelect(value.transferBackend, fc.transferBackends, v => setSlot("transferBackend", v), base)}
                </span>}
              {showIb && <span style={s.field}>
                  <span style={s.fieldLabel}>IB Device</span>
                  {renderSelect(value.ibDevice, fc.ibDevices, v => setSlot("ibDevice", v), base)}
                </span>}
            </div>
          </div>;
      }
    },
    hisparse: {
      initState: fc => ({
        enable: false,
        hostRatio: fc && fc.defaultHostRatio || null
      }),
      apply: ({flags, env, value, fc, h}) => {
        const ownedHeads = ["--enable-hisparse", "--hisparse-config", ...(fc.requiredFlags || []).map(f => f.split(/\s/)[0])];
        flags = h.stripFlagsByFirstToken(flags, ownedHeads);
        const isDecode = flags.includes("--disaggregation-mode decode");
        if (value.enable && isDecode) {
          const ratio = value.hostRatio !== null && value.hostRatio !== undefined ? value.hostRatio : fc.defaultHostRatio || 10;
          const cfg = {
            ...fc.config || ({}),
            host_to_device_ratio: ratio
          };
          const adds = [...fc.requiredFlags || [], "--enable-hisparse", `--hisparse-config '${JSON.stringify(cfg)}'`];
          flags = h.insertBeforeTail(flags, adds);
        }
        return {
          flags,
          env
        };
      },
      render: ({axisId, value, setValue, fc, base, s, renderChip, renderSelect}) => {
        if (base.pdMode !== "decode") return null;
        const setSlot = (k, v) => setValue({
          ...value,
          [k]: v
        });
        const hasRatios = (fc.hostRatios || []).length > 0;
        return <div key={axisId} style={s.card}>
            <div style={s.compactRow}>
              <span style={s.axisTitle}>HiSparse</span>
              {typeof fc.showWhen !== "function" && <span style={s.field}>
                  {renderChip("Enable", value.enable, true, () => setSlot("enable", !value.enable))}
                </span>}
              {hasRatios && <span style={s.field}>
                  <span style={s.fieldLabel}>Host ratio</span>
                  {renderSelect(value.hostRatio, fc.hostRatios, v => setSlot("hostRatio", v), base)}
                </span>}
            </div>
          </div>;
      }
    },
    hicache: {
      initState: () => ({
        enable: null,
        backend: null,
        writePolicy: "auto"
      }),
      deriveFromBase: (cell, fc, h) => {
        const flags = cell && cell.flags || [];
        return {
          enable: h.hasFlag(flags, "--enable-hierarchical-cache"),
          backend: h.findFlagArg(flags, "--hicache-storage-backend"),
          writePolicy: h.findFlagArg(flags, "--hicache-write-policy") || "auto"
        };
      },
      apply: ({flags, env, value, fc, sel, h, derived}) => {
        if (fc.excludesHw && sel && fc.excludesHw.includes(sel.hw)) return {
          flags,
          env
        };
        if (typeof fc.showWhen === "function") {
          const set = (name, val) => {
            flags = h.stripFlagsByFirstToken(flags, [name]);
            if (val) flags = h.insertBeforeTail(flags, [`${name} ${val}`]);
          };
          if (value.backend) set("--hicache-storage-backend", value.backend);
          if (value.writePolicy && value.writePolicy !== "auto") {
            set("--hicache-write-policy", value.writePolicy);
          }
          return {
            flags,
            env
          };
        }
        const hasOverride = value.enable !== null || value.backend !== null || value.writePolicy && value.writePolicy !== "auto";
        if (!hasOverride) return {
          flags,
          env
        };
        const backendOptions = fc.backends || [];
        const ownedHeads = ["--enable-hierarchical-cache", "--hicache-ratio", "--hicache-size", "--hicache-write-policy", "--hicache-mem-layout", "--hicache-io-backend", "--hicache-storage-backend", "--hicache-storage-prefetch-policy", "--hicache-storage-backend-extra-config", ...(fc.requiredFlags || []).map(f => f.split(/\s/)[0]), ...backendOptions.flatMap(o => (o.flags || []).map(f => f.split(/\s/)[0]))];
        const ownedEnvKeys = [...fc.requiredEnv || [], ...backendOptions.flatMap(o => o.env || [])].map(e => e.split("=")[0]);
        flags = h.stripFlagsByFirstToken(flags, ownedHeads);
        if (ownedEnvKeys.length) env = h.stripEnvByPrefix(env, ownedEnvKeys);
        const enabled = value.enable !== null ? value.enable : !!(derived && derived.enable);
        const backend = value.backend !== null ? value.backend : derived && derived.backend || fc.defaultBackend || null;
        if (enabled) {
          const isAmd = sel && (/^mi\d/).test(sel.hw);
          const pdMode = h.findFlagArg(flags, "--disaggregation-mode") || "off";
          const pdBackend = h.findFlagArg(flags, "--disaggregation-transfer-backend");
          const roleOverride = (fc.roleOverrides || []).find(item => {
            if (!item || item.mode !== pdMode) return false;
            if (item.transferBackend && item.transferBackend !== pdBackend) return false;
            return !item.when || h.matchConstraint(sel, item.when);
          });
          const amdIo = roleOverride || isAmd && fc.amdIo;
          const ratio = amdIo && amdIo.ratio || 2;
          const useAmdIo = isAmd && amdIo;
          const adds = ["--enable-hierarchical-cache", `--hicache-ratio ${ratio}`];
          if (!useAmdIo) {
            adds.push("--hicache-size 0");
          }
          if (useAmdIo) {
            adds.push(`--hicache-mem-layout ${amdIo.memLayout}`, `--hicache-io-backend ${amdIo.ioBackend}`);
          } else if (backend) {
            adds.push("--hicache-mem-layout page_first_direct", "--hicache-io-backend direct");
          }
          const writePolicy = value.writePolicy && value.writePolicy !== "auto" ? value.writePolicy : amdIo && amdIo.writePolicy || "write_through";
          adds.push(`--hicache-write-policy ${writePolicy}`);
          if (isAmd && fc.amdStorageFileOnly ? backend === "file" : !!backend) {
            adds.push(`--hicache-storage-backend ${backend}`, `--hicache-storage-prefetch-policy ${amdIo && amdIo.prefetchPolicy || "wait_complete"}`);
          } else if (amdIo && amdIo.prefetchPolicy) {
            adds.push(`--hicache-storage-prefetch-policy ${amdIo.prefetchPolicy}`);
          }
          const backendOption = backendOptions.find(o => o.id === backend);
          adds.push(...backendOption?.flags || [], ...fc.requiredFlags || []);
          flags = h.insertBeforeTail(flags, adds);
          env = [...env, ...backendOption?.env || [], ...fc.requiredEnv || []];
        }
        return {
          flags,
          env
        };
      },
      render: ({axisId, value, setValue, fc, base, s, renderChip, renderSelect, derived}) => {
        if (fc.excludesHw && fc.excludesHw.includes(base.hw)) return null;
        const setSlot = (k, v) => setValue({
          ...value,
          [k]: v
        });
        const hasBackends = (fc.backends || []).length > 0;
        const hasPolicies = (fc.writePolicies || []).length > 0;
        const enabled = value.enable !== null ? value.enable : !!(derived && derived.enable);
        const hasAutoBackend = (fc.backends || []).some(o => o.id === null);
        const backend = value.backend !== null ? value.backend : hasAutoBackend ? null : derived && derived.backend || fc.defaultBackend || null;
        const writePolicy = value.writePolicy !== "auto" ? value.writePolicy : derived && derived.writePolicy || "auto";
        return <div key={axisId} style={s.card}>
            <div style={s.compactRow}>
              <span style={s.axisTitle}>HiCache</span>
              {typeof fc.showWhen !== "function" && <span style={s.field}>
                  {renderChip("Enable", enabled, true, () => setSlot("enable", !enabled))}
                </span>}
              {hasBackends && <span style={s.field}>
                  <span style={s.fieldLabel}>Storage</span>
                  {renderSelect(backend, fc.backends, v => setSlot("backend", v), base)}
                </span>}
              {hasPolicies && <span style={s.field}>
                  <span style={s.fieldLabel}>Write</span>
                  {renderSelect(writePolicy, fc.writePolicies, v => setSlot("writePolicy", v), base)}
                </span>}
            </div>
          </div>;
      }
    },
    flagSelects: {
      initState: (fc, base) => {
        const out = {};
        for (const spec of fc || []) {
          const d = typeof spec.default === "function" ? spec.default(base) : spec.default;
          out[spec.id] = d ?? null;
        }
        return out;
      },
      deriveFromBase: (cell, fc) => {
        const flags = cell && cell.flags || [];
        const out = {};
        for (const spec of fc || []) {
          const prefixes = spec.stripPrefixes || [];
          const fam = flags.filter(f => prefixes.includes(f.split(/[\s=]/)[0]));
          let hit = null;
          for (const opt of spec.options || []) {
            if (typeof opt.flags === "function") continue;
            const of = opt.flags || [];
            if (of.length === fam.length && of.every(x => fam.includes(x))) {
              hit = opt.id;
              break;
            }
          }
          out[spec.id] = hit;
        }
        return out;
      },
      apply: ({flags, env, value, fc, sel, h, derived}) => {
        const evalBase = {
          ...sel || ({}),
          dpAttnOn: h.hasFlag(flags, "--enable-dp-attention"),
          pdMode: h.findFlagArg(flags, "--disaggregation-mode") || "off"
        };
        for (const spec of fc || []) {
          if (typeof spec.showWhen === "function" && !spec.showWhen(sel, value, derived)) continue;
          const v = value ? value[spec.id] : null;
          if (v === null || v === undefined) continue;
          const d = derived ? derived[spec.id] : null;
          if (v === d) continue;
          const opt = (spec.options || []).find(o => o.id === v);
          if (!opt) continue;
          if (h.evaluateChip(opt, evalBase).disabled) continue;
          const optFlags = typeof opt.flags === "function" ? opt.flags(value, evalBase) : opt.flags || [];
          if (optFlags === null) continue;
          const strip = new Set(spec.stripPrefixes || []);
          const byTok = new Map();
          for (const f of optFlags) {
            const t = f.split(/[\s=]/)[0];
            if (!byTok.has(t)) byTok.set(t, []);
            byTok.get(t).push(f);
          }
          const consumed = new Set();
          const next = [];
          for (const f of flags) {
            const t = f.split(/[\s=]/)[0];
            if (byTok.has(t)) {
              if (!consumed.has(t)) {
                next.push(...byTok.get(t));
                consumed.add(t);
              }
            } else if (!strip.has(t)) {
              next.push(f);
            }
          }
          const fresh = [];
          for (const [t, fs] of byTok) {
            if (!consumed.has(t)) fresh.push(...fs);
          }
          flags = fresh.length ? h.insertBeforeTail(next, fresh) : next;
          const envKeys = [...spec.stripEnv || []];
          for (const o of spec.options || []) {
            for (const e of o.env || []) envKeys.push(e.split("=")[0]);
          }
          if (envKeys.length) env = h.stripEnvByPrefix(env, envKeys);
          if (opt.env && opt.env.length) env = [...env, ...opt.env];
        }
        return {
          flags,
          env
        };
      },
      render: ({axisId, value, setValue, fc, base, s, h, renderChip, derived}) => {
        const cards = [];
        for (const spec of fc || []) {
          if (typeof spec.showWhen === "function" && !spec.showWhen(base, value, derived)) continue;
          const opts = (spec.options || []).map(o => h.evaluateChip(o, base)).filter(c => !c.hidden);
          if (!opts.length) continue;
          const explicit = value ? value[spec.id] : null;
          const display = explicit !== null && explicit !== undefined ? explicit : derived ? derived[spec.id] : null;
          if (spec.control === "slider") {
            const idx = Math.max(0, opts.findIndex(c => c.value === display));
            const cur = opts[idx];
            cards.push(<div key={`${axisId}-${spec.id}`} style={s.card}>
                <div style={s.compactRow}>
                  <span style={s.axisTitle}>{spec.title}</span>
                  <input type="range" min={0} max={opts.length - 1} step={1} value={idx} onChange={e => setValue({
              ...value,
              [spec.id]: opts[Number(e.target.value)].value
            })} style={{
              flex: 1,
              minWidth: "120px",
              accentColor: "#D45D44"
            }} />
                  <span style={{
              ...s.axisTitle,
              minWidth: "24px",
              textAlign: "right"
            }}>
                    {cur ? cur.label : "-"}
                  </span>
                </div>
              </div>);
            continue;
          }
          cards.push(<div key={`${axisId}-${spec.id}`} style={s.card}>
              <div style={s.compactRow}>
                <span style={s.axisTitle}>{spec.title}</span>
                {opts.map(c => <span key={c.value} style={s.field}>
                    {renderChip(c.label, display, c.value, () => setValue({
            ...value,
            [spec.id]: c.value
          }), {
            disabled: c.disabled,
            disabledReason: c.disableReason
          })}
                  </span>)}
              </div>
            </div>);
        }
        return cards.length ? cards : null;
      }
    }
  };
  const applyAllDeltas = (baseFlags, baseEnv, allDeltas, sel, derivedMap) => {
    let flags = [...baseFlags];
    let env = [...baseEnv || []];
    let pdMode = null;
    for (const [axisId, handler] of Object.entries(AXIS_HANDLERS)) {
      const fc = pgFeatures[axisId];
      if (!fc) continue;
      const value = allDeltas[axisId];
      if (value === undefined) continue;
      const derived = derivedMap ? derivedMap[axisId] : null;
      const specAlgorithm = (findFlagArg(flags, "--speculative-algorithm") || "").toUpperCase() || null;
      const liveSel = {
        ...sel,
        specAlgorithm
      };
      const out = handler.apply({
        flags,
        env,
        value,
        fc,
        sel: liveSel,
        h: helpers,
        derived
      });
      flags = out.flags;
      env = out.env;
      if (handler.getRenderHints) {
        const hints = handler.getRenderHints(value, fc, {
          flags,
          env,
          sel: liveSel,
          h: helpers
        }) || ({});
        if (hints.pdMode) pdMode = hints.pdMode;
      }
    }
    return {
      flags,
      env,
      pdMode
    };
  };
  const renderCommandLines = (cell, flags, cellEnv, sel, envValues, pdMode = null, mode = "python") => {
    const modelName = resolveModelName(sel);
    let f = [...flags];
    const nnodesFlag = f.find(x => x.split(/[\s=]/)[0] === "--nnodes");
    const nnodesMatch = nnodesFlag && (/^--nnodes(?:\s+|=)(\d+)$/).exec(nnodesFlag.trim());
    const baseNnodes = sel.nodes !== undefined ? parseNnodes(sel.nodes) : cell && cell.nnodes || 1;
    const nnodes = nnodesMatch ? parseInt(nnodesMatch[1], 10) : baseNnodes;
    const multinode = nnodes > 1;
    if (multinode && !f.some(x => x.startsWith("--nnodes"))) {
      const PARALLELISM_ANCHORS = ["--enable-dp-attention", "--dp", "--tp-size", "--tp"];
      let at = -1;
      for (const anchor of PARALLELISM_ANCHORS) {
        at = f.findIndex(x => x.split(/[\s=]/)[0] === anchor);
        if (at !== -1) break;
      }
      if (at === -1) at = f.findIndex(x => x.startsWith("--model-path"));
      const distPort = pdMode && PD_PORTS[pdMode] ? PD_PORTS[pdMode].dist : 20000;
      f.splice(at + 1, 0, `--nnodes ${nnodes}`, `--node-rank {{NODE_RANK}}`, `--dist-init-addr {{NODE0_IP}}:${distPort}`);
    }
    let cmd;
    if (mode === "docker") {
      const di = config.dockerImages || ({});
      const image = di[`${sel.hw}|${sel.quant}|${sel.strategy}`] || di[`${sel.hw}|${sel.quant}`] || di[sel.hw] || "lmsysorg/sglang:dev";
      const dockerRunCommand = typeof config.dockerRunCommand === "function" ? config.dockerRunCommand(sel) : config.dockerRunCommand || "sglang serve";
      const portFlag = f.find(x => x.split(/[\s=]/)[0] === "--port");
      const servePort = portFlag ? portFlag.slice(("--port").length).trim() : "{{PORT}}";
      const hostNetwork = multinode || pdMode || typeof config.dockerHostNetworkWhen === "function" && config.dockerHostNetworkWhen(sel, {
        flags: f,
        env: cellEnv
      });
      const HW_MULTINODE_DOCKER_FLAGS = {
        "dgx-spark": ["--ulimit memlock=-1:-1", "--cap-add IPC_LOCK", "--device /dev/infiniband"]
      };
      const fabricFlags = HW_MULTINODE_DOCKER_FLAGS[sel.hw] || [];
      const dockerLines = ["docker run --gpus all", "  --shm-size 32g", hostNetwork ? "  --network host" : `  -p ${servePort}:${servePort}`, ...multinode ? fabricFlags.map(x => "  " + x) : [], "  -v ~/.cache/huggingface:/root/.cache/huggingface", ...(config.dockerMounts || []).map(mount => `  -v ${mount}`), `  --env "HF_TOKEN={{HF_TOKEN}}"`, ...cellEnv.map(e => `  --env ${e}`), "  --ipc=host", `  ${image}`, `  ${dockerRunCommand}`, ...f.map(x => "    " + x)];
      cmd = dockerLines.join(" \\\n");
    } else {
      const flagBlock = f.map(x => "  " + x).join(" \\\n");
      const envBlock = cellEnv.length ? cellEnv.join(" \\\n") + " \\\n" : "";
      cmd = `${envBlock}sglang serve \\\n${flagBlock}`;
    }
    if (multinode && config.multiNodeHints && config.multiNodeHints[sel.hw]) {
      const hint = config.multiNodeHints[sel.hw].map(line => line.length ? "# " + line : "#").join("\n");
      cmd = `${hint}\n${cmd}`;
    }
    cmd = interpolate(cmd, envValues, modelName);
    if (multinode) {
      const header = `# Multi-node (${nnodes} nodes). Run the same command on every node with:\n` + `#   <node-rank> = 0 on the head node, 1..${nnodes - 1} on the others\n` + `#   <node0-ip>  = IP of the head node (reachable from all others)`;
      cmd = `${header}\n${cmd}`;
    }
    if (pdMode === "prefill" || pdMode === "decode") {
      const sibling = pdMode === "prefill" ? "decode" : "prefill";
      const routerCfg = config.playgroundFeatures && config.playgroundFeatures.pdDisagg && config.playgroundFeatures.pdDisagg.router;
      const routerPort = routerCfg && routerCfg.port || 8000;
      const routerLine = routerCfg ? `# then front BOTH with the Router shown below.\n` + `# Client traffic (cURL) targets the router (:${routerPort}), not this role server.` : `# then front BOTH with a router; client traffic targets the router, not this role server.`;
      const hicacheCfg = config.playgroundFeatures && config.playgroundFeatures.hicache;
      const pdBackend = findFlagArg(f, "--disaggregation-transfer-backend");
      const hicacheEnabled = f.some(x => x === "--enable-hierarchical-cache");
      const hicacheNotice = hicacheEnabled && hicacheCfg ? (hicacheCfg.notices || []).find(item => {
        if (!item || item.mode !== pdMode) return false;
        if (item.transferBackend && item.transferBackend !== pdBackend) return false;
        return !item.when || matchConstraint(sel, item.when);
      }) : null;
      const noticeLine = hicacheNotice && hicacheNotice.text ? `# Note: ${hicacheNotice.text}\n` : "";
      const banner = `# === PD Disaggregation: ${pdMode.toUpperCase()} role ===\n` + noticeLine + `# Runs the ${pdMode} server. Also run the ${sibling} role on its peer host,\n` + routerLine;
      cmd = `${banner}\n${cmd}`;
    }
    return cmd;
  };
  const computeDiff = (baseStr, pgStr) => {
    const a = baseStr.split("\n");
    const b = pgStr.split("\n");
    const m = a.length, n = b.length;
    const dp = Array(m + 1).fill(null).map(() => new Array(n + 1).fill(0));
    for (let i = 1; i <= m; i++) {
      for (let j = 1; j <= n; j++) {
        if (a[i - 1] === b[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1; else dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
      }
    }
    const out = [];
    let i = m, j = n;
    while (i > 0 || j > 0) {
      if (i > 0 && j > 0 && a[i - 1] === b[j - 1]) {
        out.unshift({
          line: a[i - 1],
          kind: "unchanged"
        });
        i--;
        j--;
      } else if (j > 0 && (i === 0 || dp[i][j - 1] >= dp[i - 1][j])) {
        out.unshift({
          line: b[j - 1],
          kind: "added"
        });
        j--;
      } else {
        out.unshift({
          line: a[i - 1],
          kind: "removed"
        });
        i--;
      }
    }
    return out;
  };
  const serializeCell = (sel, env, flags) => {
    const matchEntries = [`hw: ${JSON.stringify(sel.hw)}`, `variant: ${JSON.stringify(sel.variant)}`, `quant: ${JSON.stringify(sel.quant)}`, `strategy: ${JSON.stringify(sel.strategy)}`, `nodes: ${JSON.stringify(sel.nodes)}`].join(", ");
    const fmtList = items => {
      if (!items || items.length === 0) return "[]";
      const lines = items.map(s => `        ${JSON.stringify(s)},`).join("\n");
      return `[\n${lines}\n      ]`;
    };
    return ["    {", `      match: { ${matchEntries} },`, "      verified: true,", `      env: ${fmtList(env)},`, `      flags: ${fmtList(flags)},`, "    },"].join("\n");
  };
  const buildSubmitUrl = (sel, fields) => {
    const gh = config.github || ({});
    const owner = gh.owner || "sgl-project";
    const repo = gh.repo || "sglang";
    const tmpl = gh.issueTemplate || "3-playground-verified-cell.yml";
    const cookbookModel = gh.cookbookModel || "deepseek-ai/deepseek-v4";
    const combo = `${sel.hw} / ${sel.variant} / ${sel.quant} / ${sel.strategy} / ${sel.nodes}`;
    const params = new URLSearchParams({
      template: tmpl,
      title: `[Playground] Verified cell: ${combo}`,
      model: cookbookModel,
      combination: combo,
      "cell-snippet": fields.cellSnippet || "",
      "existing-cell": fields.existingCell || "",
      "sglang-version": fields.sglangVersion || "",
      "bench-result": fields.benchResult || "",
      notes: fields.notes || ""
    });
    return `https://github.com/${owner}/${repo}/issues/new?${params.toString()}`;
  };
  const makeStyles = isDark => ({
    container: {
      maxWidth: "900px",
      margin: "0 auto",
      display: "flex",
      flexDirection: "column",
      gap: "6px"
    },
    card: {
      padding: "6px 10px",
      border: `1px solid ${isDark ? "#374151" : "#e5e7eb"}`,
      borderLeft: `3px solid ${isDark ? "#FDBA74" : "#FB923C"}`,
      borderRadius: "4px",
      background: isDark ? "#1f2937" : "#fff"
    },
    cardStack: {
      display: "flex",
      flexDirection: "column",
      gap: "6px"
    },
    baseStrip: {
      padding: "8px 12px",
      borderRadius: "4px",
      background: isDark ? "#064e3b" : "#d1fae5",
      color: isDark ? "#a7f3d0" : "#065f46",
      fontSize: "12px",
      display: "flex",
      alignItems: "center",
      gap: "10px"
    },
    title: {
      fontSize: "13px",
      fontWeight: "600",
      color: isDark ? "#e5e7eb" : "inherit",
      marginBottom: "8px"
    },
    compactRow: {
      display: "flex",
      flexWrap: "wrap",
      alignItems: "center",
      gap: "10px",
      rowGap: "4px"
    },
    axisTitle: {
      fontSize: "12px",
      fontWeight: 700,
      color: isDark ? "#FDBA74" : "#C2410C",
      letterSpacing: "0.02em",
      minWidth: "100px",
      flexShrink: 0
    },
    field: {
      display: "inline-flex",
      alignItems: "center",
      gap: "4px"
    },
    fieldLabel: {
      fontSize: "11px",
      fontWeight: 500,
      color: isDark ? "#9ca3af" : "#6b7280"
    },
    select: {
      padding: "2px 6px",
      border: `1px solid ${isDark ? "#4b5563" : "#d1d5db"}`,
      borderRadius: "3px",
      fontSize: "12px",
      background: isDark ? "#111827" : "#fff",
      color: isDark ? "#e5e7eb" : "#111827",
      cursor: "pointer",
      lineHeight: "1.4"
    },
    rowFlex: {
      display: "flex",
      flexWrap: "wrap",
      gap: "6px",
      alignItems: "center",
      flex: 1
    },
    subRow: {
      display: "flex",
      alignItems: "center",
      gap: "10px"
    },
    subLabel: {
      fontSize: "11px",
      fontWeight: 600,
      color: isDark ? "#9ca3af" : "#6b7280",
      minWidth: "96px",
      flexShrink: 0,
      letterSpacing: "0.02em"
    },
    chipRow: {
      display: "flex",
      flexWrap: "wrap",
      gap: "6px",
      flex: 1
    },
    chip: {
      padding: "3px 9px",
      border: `1px solid ${isDark ? "#9ca3af" : "#d1d5db"}`,
      borderRadius: "3px",
      cursor: "pointer",
      fontSize: "12px",
      userSelect: "none",
      background: isDark ? "#374151" : "#fff",
      color: isDark ? "#e5e7eb" : "inherit",
      textAlign: "center"
    },
    chipChecked: {
      background: "#D45D44",
      color: "white",
      borderColor: "#D45D44"
    },
    chipDisabled: {
      cursor: "not-allowed",
      opacity: 0.4
    },
    commandWrap: {
      position: "relative",
      background: isDark ? "#111827" : "#f5f5f5",
      borderRadius: "6px",
      border: `1px solid ${isDark ? "#374151" : "#e5e7eb"}`,
      overflow: "hidden"
    },
    commandHeader: {
      display: "flex",
      flexWrap: "wrap",
      justifyContent: "space-between",
      alignItems: "center",
      gap: "6px 10px",
      padding: "6px 10px",
      borderBottom: `1px solid ${isDark ? "#374151" : "#e5e7eb"}`,
      background: isDark ? "#1f2937" : "#fafafa"
    },
    commandPre: {
      padding: "12px 16px",
      fontFamily: "'Menlo', 'Monaco', 'Courier New', monospace",
      fontSize: "12px",
      lineHeight: "1.5",
      color: isDark ? "#e5e7eb" : "#374151",
      whiteSpace: "pre-wrap",
      overflowX: "auto",
      margin: 0
    },
    mtpWarn: {
      margin: "8px 0 0",
      padding: "8px 12px",
      borderRadius: "8px",
      fontSize: "12px",
      lineHeight: "1.45",
      background: isDark ? "#78350f" : "#fef3c7",
      color: isDark ? "#fde68a" : "#92400e",
      border: `1px solid ${isDark ? "#92400e" : "#fcd34d"}`
    },
    diffLineUnchanged: {
      display: "block"
    },
    diffLineAdded: {
      display: "block",
      background: isDark ? "rgba(16,185,129,0.15)" : "rgba(16,185,129,0.18)",
      color: isDark ? "#a7f3d0" : "#065f46",
      borderLeft: `3px solid #10b981`,
      paddingLeft: "8px",
      marginLeft: "-8px"
    },
    diffLineRemoved: {
      display: "block",
      background: isDark ? "rgba(239,68,68,0.10)" : "rgba(239,68,68,0.10)",
      color: isDark ? "#fca5a5" : "#991b1b",
      textDecoration: "line-through",
      opacity: 0.7,
      borderLeft: `3px solid #ef4444`,
      paddingLeft: "8px",
      marginLeft: "-8px"
    },
    badge: verified => ({
      display: "inline-flex",
      alignItems: "center",
      gap: "6px",
      padding: "2px 8px",
      borderRadius: "10px",
      background: verified ? isDark ? "#064e3b" : "#d1fae5" : isDark ? "#78350f" : "#fef3c7",
      color: verified ? isDark ? "#a7f3d0" : "#065f46" : isDark ? "#fde68a" : "#92400e",
      fontSize: "11px",
      fontWeight: 600
    }),
    badgeDot: verified => ({
      width: "8px",
      height: "8px",
      borderRadius: "50%",
      background: verified ? "#10b981" : "#f59e0b"
    }),
    iconButton: {
      padding: "4px 10px",
      border: `1px solid ${isDark ? "#4b5563" : "#d1d5db"}`,
      borderRadius: "4px",
      background: isDark ? "#1f2937" : "#fff",
      color: isDark ? "#e5e7eb" : "#374151",
      fontSize: "11px",
      fontWeight: 500,
      cursor: "pointer",
      display: "inline-flex",
      alignItems: "center",
      gap: "4px"
    },
    iconRow: {
      display: "inline-flex",
      flexWrap: "wrap",
      gap: "6px"
    },
    runModeWrap: {
      display: "inline-flex",
      border: `1px solid ${isDark ? "#4b5563" : "#d1d5db"}`,
      borderRadius: "10px",
      overflow: "hidden",
      fontSize: "11px",
      fontWeight: 600,
      userSelect: "none"
    },
    runModeChip: active => ({
      padding: "2px 10px",
      cursor: "pointer",
      background: active ? isDark ? "#1f2937" : "#fff" : "transparent",
      color: active ? isDark ? "#e5e7eb" : "#111827" : isDark ? "#9ca3af" : "#6b7280",
      borderRight: `1px solid ${isDark ? "#4b5563" : "#d1d5db"}`
    }),
    runModeChipLast: active => ({
      padding: "2px 10px",
      cursor: "pointer",
      background: active ? isDark ? "#1f2937" : "#fff" : "transparent",
      color: active ? isDark ? "#e5e7eb" : "#111827" : isDark ? "#9ca3af" : "#6b7280"
    }),
    headerLeft: {
      display: "inline-flex",
      flexWrap: "wrap",
      alignItems: "center",
      gap: "8px"
    },
    dialog: {
      background: isDark ? "#1f2937" : "#fff",
      color: isDark ? "#e5e7eb" : "#111827",
      borderRadius: "8px",
      padding: "20px",
      maxWidth: "720px",
      width: "92%",
      maxHeight: "calc(100vh - 80px)",
      overflowY: "auto",
      border: `1px solid ${isDark ? "#374151" : "#e5e7eb"}`,
      boxShadow: "0 10px 25px rgba(0,0,0,0.25)",
      margin: "auto"
    },
    modalHeader: {
      display: "flex",
      justifyContent: "space-between",
      alignItems: "center",
      marginBottom: "12px"
    },
    modalTitle: {
      fontSize: "15px",
      fontWeight: 600
    },
    modalCloseBtn: {
      background: "transparent",
      border: "none",
      color: "inherit",
      fontSize: "20px",
      cursor: "pointer",
      padding: "0 6px",
      lineHeight: 1
    },
    formField: {
      display: "flex",
      flexDirection: "column",
      gap: "4px",
      marginBottom: "10px"
    },
    formLabel: {
      fontSize: "12px",
      fontWeight: 500,
      color: isDark ? "#9ca3af" : "#4b5563"
    },
    formInput: {
      padding: "6px 10px",
      fontSize: "13px",
      border: `1px solid ${isDark ? "#4b5563" : "#d1d5db"}`,
      borderRadius: "4px",
      background: isDark ? "#111827" : "#fff",
      color: isDark ? "#e5e7eb" : "#111827",
      fontFamily: "'Menlo', 'Monaco', 'Courier New', monospace"
    },
    sectionHeading: {
      fontSize: "12px",
      fontWeight: 600,
      textTransform: "uppercase",
      letterSpacing: "0.04em",
      color: isDark ? "#9ca3af" : "#6b7280",
      margin: "12px 0 6px 0"
    },
    primaryBtn: {
      padding: "6px 14px",
      background: isDark ? "#FDBA74" : "#FB923C",
      color: isDark ? "#7C2D12" : "white",
      border: "none",
      borderRadius: "4px",
      cursor: "pointer",
      fontSize: "13px",
      fontWeight: 500
    },
    resetBtn: {
      marginLeft: "auto",
      padding: "2px 8px",
      fontSize: "11px",
      border: `1px solid ${isDark ? "#4b5563" : "#d1d5db"}`,
      borderRadius: "3px",
      background: "transparent",
      color: isDark ? "#9ca3af" : "#6b7280",
      cursor: "pointer"
    },
    switchBaseBtn: {
      padding: "2px 8px",
      fontSize: "11px",
      fontWeight: 600,
      border: `1px solid ${isDark ? "#FDBA74" : "#FB923C"}`,
      borderRadius: "3px",
      background: "transparent",
      color: isDark ? "#FDBA74" : "#C2410C",
      cursor: "pointer"
    },
    matchedHint: {
      fontSize: "11px",
      color: isDark ? "#9ca3af" : "#6b7280",
      marginLeft: "8px",
      display: "inline-flex",
      alignItems: "center",
      gap: "4px"
    },
    matchedSwitchBtn: {
      marginLeft: "4px",
      background: "transparent",
      border: "none",
      padding: 0,
      color: isDark ? "#FDBA74" : "#C2410C",
      cursor: "pointer",
      fontSize: "11px",
      fontWeight: 600,
      textDecoration: "underline",
      textUnderlineOffset: "2px"
    }
  });
  const [isDark, setIsDark] = useState(false);
  useEffect(() => {
    const check = () => {
      const html = document.documentElement;
      setIsDark(html.classList.contains("dark") || html.getAttribute("data-theme") === "dark" || html.style.colorScheme === "dark");
    };
    check();
    const observer = new MutationObserver(check);
    observer.observe(document.documentElement, {
      attributes: true,
      attributeFilter: ["class", "data-theme", "style"]
    });
    return () => observer.disconnect();
  }, []);
  const [env, setEnv] = useState(() => placeholderDefaults(config.placeholders));
  useEffect(() => {
    try {
      const raw = window.localStorage.getItem(STORAGE_KEY);
      if (raw) {
        const parsed = JSON.parse(raw);
        setEnv({
          ...placeholderDefaults(config.placeholders),
          ...parsed
        });
      }
    } catch {}
  }, []);
  const saveEnv = next => {
    setEnv(next);
    try {
      window.localStorage.setItem(STORAGE_KEY, JSON.stringify(next));
    } catch {}
  };
  const overlayDefaults = () => {
    const out = {};
    for (const d of config.overlayDims || []) {
      const opts = d.options || [];
      out[d.id] = d.default !== undefined ? d.default : opts[0] && opts[0].id || "";
    }
    return out;
  };
  const baseFallback = () => ({
    ...config.cells[0].match,
    ...overlayDefaults()
  });
  const initialBaseFromHash = () => {
    const fallback = baseFallback();
    if (typeof window === "undefined") return {
      ...fallback
    };
    const raw = window.location.hash.replace(/^#/, "");
    if (!raw) return {
      ...fallback
    };
    const params = new URLSearchParams(raw);
    const out = {
      ...fallback
    };
    params.forEach((value, key) => {
      if ((key in out)) out[key] = value;
    });
    return out;
  };
  const [base, setBase] = useState(() => initialBaseFromHash());
  useEffect(() => {
    const onHash = () => setBase(initialBaseFromHash());
    const onSelEvent = e => {
      const fallback = baseFallback();
      const incoming = e && e.detail || ({});
      const next = {
        ...fallback
      };
      for (const k of Object.keys(next)) {
        if (incoming[k] !== undefined) next[k] = incoming[k];
      }
      setBase(next);
    };
    window.addEventListener("hashchange", onHash);
    window.addEventListener("sglang-deploy-sel", onSelEvent);
    return () => {
      window.removeEventListener("hashchange", onHash);
      window.removeEventListener("sglang-deploy-sel", onSelEvent);
    };
  }, []);
  const [pgRatios, setPgRatios] = useState({
    eff: null,
    base: null
  });
  useEffect(() => {
    const onRatio = e => setPgRatios({
      eff: e.detail && e.detail.ratio || null,
      base: e.detail && (e.detail.baseRatio || e.detail.ratio) || null
    });
    window.addEventListener("sglang-k3-mamba-ratio", onRatio);
    return () => window.removeEventListener("sglang-k3-mamba-ratio", onRatio);
  }, []);
  const initialDeltas = () => {
    const out = {};
    for (const [axisId, handler] of Object.entries(AXIS_HANDLERS)) {
      const fc = pgFeatures[axisId];
      if (fc) out[axisId] = handler.initState(fc, base);
    }
    return out;
  };
  const [deltas, setDeltas] = useState(initialDeltas);
  useEffect(() => {
    setDeltas(initialDeltas());
  }, [Object.keys(base).sort().map(k => `${k}=${base[k]}`).join("&")]);
  const [modal, setModal] = useState(null);
  const openDialog = el => {
    if (el && !el.open) {
      try {
        el.showModal();
      } catch {}
    }
  };
  const onDialogClick = e => {
    if (e.target !== e.currentTarget) return;
    const r = e.currentTarget.getBoundingClientRect();
    const {clientX: x, clientY: y} = e;
    if (x < r.left || x > r.right || y < r.top || y > r.bottom) setModal(null);
  };
  useEffect(() => {
    const ID = "__playground_dialog_backdrop";
    if (document.getElementById(ID)) return undefined;
    const style = document.createElement("style");
    style.id = ID;
    style.textContent = `dialog::backdrop { background: rgba(0, 0, 0, 0.5); }`;
    document.head.appendChild(style);
    return () => {
      const el = document.getElementById(ID);
      if (el) el.remove();
    };
  }, []);
  const [copied, setCopied] = useState(false);
  const [curlCopied, setCurlCopied] = useState(false);
  const [routerCopied, setRouterCopied] = useState(false);
  const [envDraft, setEnvDraft] = useState(env);
  useEffect(() => {
    if (modal === "env") setEnvDraft(env);
  }, [modal, env]);
  const [runMode, setRunMode] = useState("python");
  const [submitDraft, setSubmitDraft] = useState({
    sglangVersion: "",
    benchResult: "",
    notes: ""
  });
  const [submitAttest, setSubmitAttest] = useState({
    ranCommand: false,
    reachedReady: false,
    outputCorrect: false
  });
  useEffect(() => {
    if (modal === "submit") {
      setSubmitDraft({
        sglangVersion: "",
        benchResult: "",
        notes: ""
      });
      setSubmitAttest({
        ranCommand: false,
        reachedReady: false,
        outputCorrect: false
      });
    }
  }, [modal]);
  const s = makeStyles(isDark);
  const baseCell = withOverlay(findCell(config.cells, base), base);
  const modelName = resolveModelName(base);
  const derivedMap = {};
  if (baseCell) {
    for (const [axisId, handler] of Object.entries(AXIS_HANDLERS)) {
      const fc = pgFeatures[axisId];
      if (!fc || !handler.deriveFromBase) continue;
      derivedMap[axisId] = handler.deriveFromBase(baseCell, fc, helpers);
    }
  }
  const attnDelta = deltas.attention || ({});
  const attnDerived = derivedMap.attention || ({});
  const attnKnobs = (pgFeatures.attention || ({})).knobs || [];
  const effTp = attnDelta.tp !== null && attnDelta.tp !== undefined ? attnDelta.tp : attnDerived.tp !== undefined ? attnDerived.tp : null;
  const staleExplicit = (knobId, picked) => {
    const knob = attnKnobs.find(k => k.id === knobId);
    const e = knob ? findEntry(knob.values || [], picked) : null;
    return !!(e !== null && e !== undefined && evaluateChip(e, {
      ...base,
      effTp
    }).disabled);
  };
  const effDpAttn = attnDelta.dpAttn !== null && attnDelta.dpAttn !== undefined ? staleExplicit("dpAttn", attnDelta.dpAttn) ? null : attnDelta.dpAttn : attnDerived.dpAttn !== undefined ? attnDerived.dpAttn : null;
  const dpAttnOn = effDpAttn === true || typeof effDpAttn === "number" && effDpAttn > 0;
  const dpDegEff = typeof effDpAttn === "number" && effDpAttn > 0 ? effDpAttn : 1;
  const cpKnobFreeSize = !!(attnKnobs.find(k => k.id === "cp") || ({})).freeSize;
  const cpSizeTarget = !cpKnobFreeSize && dpDegEff === 1 && typeof effTp === "number" && effTp > 0 ? effTp : null;
  const cpSizeStale = v => typeof v === "number" && v > 1 && cpSizeTarget !== null && v !== cpSizeTarget;
  const effCp = attnDelta.cp !== null && attnDelta.cp !== undefined ? staleExplicit("cp", attnDelta.cp) || cpSizeStale(attnDelta.cp) ? null : attnDelta.cp : attnDerived.cp !== undefined ? attnDerived.cp : null;
  const cpOn = typeof effCp === "number" && effCp > 1;
  const cpStrategy = (attnDelta.cpStrategy && !staleExplicit("cpStrategy", attnDelta.cpStrategy) ? attnDelta.cpStrategy : attnDerived.cpStrategy !== undefined ? attnDerived.cpStrategy : null) || "interleave";
  const constraintEffective = baseCell ? applyAllDeltas(baseCell.flags, baseCell.env, deltas, base, derivedMap) : null;
  const pdCardOwnsMode = (pgFeatures.pdDisagg && pgFeatures.pdDisagg.modes || []).length > 0;
  const pdMode = pdCardOwnsMode ? constraintEffective && constraintEffective.pdMode || "off" : base.pdMode || "off";
  const specAlgorithm = constraintEffective ? (findFlagArg(constraintEffective.flags, "--speculative-algorithm") || "").toUpperCase() || null : null;
  const constraintBase = {
    ...base,
    dpAttnOn,
    cpOn,
    cpStrategy,
    cpSizeTarget,
    effTp,
    pdMode,
    specAlgorithm
  };
  let baseCommand = "";
  let playgroundCommand = "";
  let diffLines = [];
  let pgFlagsLatest = [];
  let pgEnvLatest = [];
  const withRatio = (fl, value) => {
    if (!value) return fl;
    if (fl.some(f => f.startsWith("--mamba-full-memory-ratio"))) return fl;
    const out = [...fl];
    const line = `--mamba-full-memory-ratio ${value}`;
    const i = out.findIndex(f => f.startsWith("--host"));
    if (i >= 0) out.splice(i, 0, line); else out.push(line);
    return out;
  };
  if (baseCell) {
    baseCommand = renderCommandLines(baseCell, withRatio(baseCell.flags, pgRatios.base), baseCell.env, base, env, null, runMode);
    const {flags: pgFlags, env: pgEnv, pdMode} = applyAllDeltas(baseCell.flags, baseCell.env, deltas, base, derivedMap);
    pgFlagsLatest = pgFlags;
    pgEnvLatest = pgEnv;
    playgroundCommand = renderCommandLines(baseCell, withRatio(pgFlags, pgRatios.eff), pgEnv, base, env, pdMode, runMode);
    diffLines = computeDiff(baseCommand, playgroundCommand);
  }
  const effectiveKey = pgFlagsLatest.join("\n") + " " + pgEnvLatest.join("\n") + " " + (baseCell ? baseCell.flags.join("\n") + " " + baseCell.env.join("\n") : "");
  useEffect(() => {
    if (typeof window === "undefined" || !baseCell) return;
    window.dispatchEvent(new CustomEvent("sglang-k3-effective-config", {
      detail: {
        flags: pgFlagsLatest,
        env: pgEnvLatest,
        baseFlags: baseCell.flags,
        baseEnv: baseCell.env
      }
    }));
  }, [effectiveKey]);
  const matchedCell = baseCell ? findMatchingCell(config.cells, base, pgEnvLatest, pgFlagsLatest) : null;
  const playgroundVerified = !!(matchedCell && matchedCell.verified);
  const matchedSiblingCell = matchedCell && DIMENSIONS.some(d => matchedCell.match[d] !== base[d]) ? matchedCell : null;
  const pgSpecAlgoFlag = pgFlagsLatest.find(f => f.split(/[\s=]/)[0] === "--speculative-algorithm");
  const pgSpecHint = !!pgSpecAlgoFlag && !pgFlagsLatest.some(f => f.split(/[\s=]/)[0] === "--max-running-requests");
  const specAlgoLabels = {
    EAGLE: "MTP",
    EAGLE3: "MTP",
    FROZEN_KV_MTP: "MTP",
    DSPARK: "DSpark",
    DFLASH: "DFlash",
    NGRAM: "N-gram",
    STANDALONE: "standalone draft"
  };
  const pgSpecAlgoValue = pgSpecAlgoFlag ? pgSpecAlgoFlag.split(/[\s=]/).filter(Boolean)[1] || "" : "";
  const pgSpecAlgoName = specAlgoLabels[pgSpecAlgoValue.toUpperCase()] || pgSpecAlgoValue || "MTP";
  const pgCpDpHint = cpEnabledIn(pgFlagsLatest) && (bakedCpStrategy(pgFlagsLatest) || "interleave") === "interleave" && pgFlagsLatest.some(f => f.split(/[\s=]/)[0] === "--enable-dp-attention");
  const proposedCellSnippet = baseCell ? serializeCell(base, pgEnvLatest, pgFlagsLatest) : "";
  const existingCellSnippet = baseCell ? serializeCell(base, baseCell.env || [], baseCell.flags) : "";
  const submitUrl = baseCell ? buildSubmitUrl(base, {
    cellSnippet: proposedCellSnippet,
    existingCell: existingCellSnippet,
    sglangVersion: submitDraft.sglangVersion,
    benchResult: submitDraft.benchResult,
    notes: submitDraft.notes
  }) : "";
  const submitReady = submitAttest.ranCommand && submitAttest.reachedReady && submitAttest.outputCorrect && submitDraft.sglangVersion.trim().length > 0;
  const pdRouter = pdMode !== "off" && config.playgroundFeatures && config.playgroundFeatures.pdDisagg && config.playgroundFeatures.pdDisagg.router || null;
  const curlEnv = pdRouter && pdRouter.port != null ? {
    ...env,
    CURL_PORT: String(pdRouter.port)
  } : env;
  const curlText = interpolate(config.curl || "", curlEnv, modelName);
  const routerText = pdRouter && pdRouter.command ? interpolate(pdRouter.command, {
    ...env,
    PREFILL_PORT: PD_PORTS.prefill.serve,
    DECODE_PORT: PD_PORTS.decode.serve,
    ROUTER_PORT: pdRouter.port
  }, modelName) : "";
  const resetAll = () => setDeltas(initialDeltas());
  const placeholderGroups = (() => {
    const out = {
      command: [],
      curl: []
    };
    for (const [key, meta] of Object.entries(config.placeholders || ({}))) {
      (out[meta.target] || (out[meta.target] = [])).push({
        key,
        ...meta
      });
    }
    return out;
  })();
  const handleCopy = () => {
    navigator.clipboard.writeText(playgroundCommand);
    setCopied(true);
    setTimeout(() => setCopied(false), 1200);
  };
  const copyCurl = () => {
    navigator.clipboard.writeText(curlText);
    setCurlCopied(true);
    setTimeout(() => setCurlCopied(false), 1200);
  };
  const baseSummary = baseCell ? Object.entries(base).filter(([, v]) => v !== undefined && v !== "").map(([k, v]) => k === "hw" ? String(v).toUpperCase() : String(v)).join(" · ") : "(no verified cell at the current Deploy selection — showing playground only)";
  const renderChip = (label, current, value, onPick, opts = {}) => {
    const checked = current === value;
    const disabled = !!opts.disabled;
    return <span key={`${label}-${value === null ? "auto" : value}`} style={{
      ...s.chip,
      ...checked ? s.chipChecked : {},
      ...disabled ? s.chipDisabled : {}
    }} title={disabled ? opts.disabledReason || "Not available" : ""} onClick={() => {
      if (!disabled) onPick(value);
    }}>
        {label}
      </span>;
  };
  const renderSelect = (current, entries, onPick, base, labelFor, opts = {}) => {
    const hideSet = new Set(opts.hideValues || []);
    const items = [];
    for (const entry of entries || []) {
      const c = helpers.evaluateChip(entry, base);
      if (c.hidden) continue;
      if (hideSet.has(c.value)) continue;
      const lbl = labelFor ? labelFor(c) : c.label !== undefined ? c.label : c.value === null ? "Auto" : String(c.value);
      items.push({
        ...c,
        label: lbl
      });
    }
    let idx = items.findIndex(c => c.value === current);
    if (idx === -1) idx = 0;
    return <select style={{
      ...s.select,
      ...opts.disabled ? s.chipDisabled : {}
    }} disabled={!!opts.disabled} title={opts.disabled ? opts.disabledReason || "Not available" : ""} value={idx} onChange={e => {
      const next = items[parseInt(e.target.value, 10)];
      if (next && !next.disabled) onPick(next.value);
    }}>
        {items.map((c, i) => <option key={i} value={i} disabled={c.disabled}>
            {c.label}{c.disabled ? " (n/a)" : ""}
          </option>)}
      </select>;
  };
  return <div style={s.container} className="not-prose">
      {}
      <div style={s.baseStrip}>
        <span style={{
    fontWeight: 600
  }}>Inherited base from Deployment:</span>
        <code style={{
    fontFamily: "Menlo, monospace"
  }}>{baseSummary}</code>
        {}
        <button type="button" style={s.switchBaseBtn} onClick={() => {
    const el = document.getElementById(DEPLOYMENT_COMPONENT_ID) || document.getElementById("deployment") || document.getElementById("deploy");
    if (el) el.scrollIntoView({
      behavior: "smooth",
      block: "start"
    });
  }}>
          ↑ Switch base
        </button>
        <button style={s.resetBtn} onClick={resetAll}>Reset all overrides</button>
      </div>

      {}
      {Object.entries(AXIS_HANDLERS).map(([axisId, handler]) => {
    const fc = pgFeatures[axisId];
    if (!fc) return null;
    if (typeof fc.showWhen === "function" && !fc.showWhen(constraintBase)) return null;
    const setValue = next => setDeltas(d => ({
      ...d,
      [axisId]: next
    }));
    return handler.render({
      axisId,
      value: deltas[axisId],
      setValue,
      fc,
      base: constraintBase,
      s,
      h: helpers,
      renderChip,
      renderSelect,
      derived: derivedMap[axisId] || null
    });
  })}

      {}
      <div style={s.card}>
        <div style={s.title}>Playground Command (compare with base)</div>
        <div style={s.commandWrap}>
          <div style={s.commandHeader}>
            <div style={s.headerLeft}>
              <div style={s.badge(playgroundVerified)}>
                <span style={s.badgeDot(playgroundVerified)} />
                {playgroundVerified ? "Verified" : "Not Verified"}
              </div>
              {}
              {matchedSiblingCell && <span style={s.matchedHint}>
                  matches <code style={{
    fontFamily: "Menlo, monospace"
  }}>
                    {matchedSiblingCell.match.strategy}
                  </code>
                  <button type="button" style={s.matchedSwitchBtn} onClick={() => {
    const m = matchedSiblingCell.match;
    setDeltas(initialDeltas());
    const hash = new URLSearchParams(m).toString();
    window.location.hash = hash;
    window.dispatchEvent(new CustomEvent("sglang-deploy-sel", {
      detail: m
    }));
  }}>
                    switch base →
                  </button>
                </span>}
              <div style={s.runModeWrap} role="tablist" aria-label="Output format">
                <span style={s.runModeChip(runMode === "python")} onClick={() => setRunMode("python")} role="tab" aria-selected={runMode === "python"}>
                  Python
                </span>
                <span style={s.runModeChipLast(runMode === "docker")} onClick={() => setRunMode("docker")} role="tab" aria-selected={runMode === "docker"}>
                  Docker
                </span>
              </div>
            </div>
            <div style={s.iconRow}>
              <button style={s.iconButton} onClick={handleCopy}>
                {copied ? "✓ Copied" : "⧉ Copy"}
              </button>
              <button style={s.iconButton} onClick={() => setModal("curl")}>$ cURL</button>
              <button style={s.iconButton} onClick={() => setModal("env")}>⚙ Env</button>
              {}
              {!playgroundVerified && baseCell && <button style={{
    ...s.iconButton,
    borderColor: isDark ? "#FDBA74" : "#FB923C",
    color: isDark ? "#FDBA74" : "#C2410C",
    fontWeight: 600
  }} onClick={() => setModal("submit")} title="I verified this command on my hardware — open a pre-filled GitHub issue to land it as a cookbook cell.">
                  Submit ↗
                </button>}
            </div>
          </div>
          <pre style={s.commandPre}>
            {baseCell ? diffLines.map((d, i) => <span key={i} style={d.kind === "added" ? s.diffLineAdded : d.kind === "removed" ? s.diffLineRemoved : s.diffLineUnchanged}>
                {d.kind === "added" ? "+ " : d.kind === "removed" ? "- " : "  "}
                {d.line}{"\n"}
              </span>) : "# No verified base cell at the current Deployment selection.\n# Pick a supported hardware/variant in the Deployment panel to populate the playground base."}
          </pre>
          {pgSpecHint && <div style={s.mtpWarn}>
              ⚠️ Speculative decoding ({pgSpecAlgoName}) is on — SGLang resets <code>--max-running-requests</code> to <strong>48</strong> when it isn't set. Add <code>--max-running-requests &lt;N&gt;</code> sized for your target concurrency.
            </div>}
          {pgCpDpHint && <div style={s.mtpWarn}>
              ⚠️ Interleave prefill-CP together with DP-Attention: current SGLang releases assert <code>dp_size == 1</code> for the interleave layout, so this command fails at startup. Combined CP + DP-Attention support is planned upstream — keep one of the two off until it lands.
            </div>}
        </div>
      </div>

      {}
      {pdRouter && routerText && <div style={s.card}>
          <div style={s.title}>Router</div>
          <div style={{
    fontSize: 11,
    opacity: 0.7,
    margin: "0 0 6px"
  }}>
            Run after both roles are up. Substitute <code>{"<prefill-host>"}</code> /{" "}
            <code>{"<decode-host>"}</code> with reachable hosts (both <code>127.0.0.1</code>{" "}
            on a same-host deployment). Client traffic (cURL) targets this router.
          </div>
          <div style={s.commandWrap}>
            <div style={s.commandHeader}>
              <div style={{
    fontSize: 11,
    opacity: 0.7
  }}>port {pdRouter.port}</div>
              <button style={s.iconButton} onClick={() => {
    navigator.clipboard.writeText(routerText);
    setRouterCopied(true);
    setTimeout(() => setRouterCopied(false), 1200);
  }}>
                {routerCopied ? "✓ Copied" : "⧉ Copy"}
              </button>
            </div>
            <pre style={s.commandPre}>{routerText}</pre>
          </div>
        </div>}

      {}
      {modal === "curl" && <dialog ref={openDialog} style={s.dialog} onClose={() => setModal(null)} onClick={onDialogClick}>
          <div style={s.modalHeader}>
            <div style={s.modalTitle}>cURL example</div>
            <button style={s.modalCloseBtn} onClick={() => setModal(null)} aria-label="Close">×</button>
          </div>
          <div style={s.commandWrap}>
            <div style={s.commandHeader}>
              <div style={{
    fontSize: 11,
    opacity: 0.7
  }}>
                Model: <code>{modelName || "(unresolved)"}</code>
              </div>
              <button style={s.iconButton} onClick={copyCurl}>
                {curlCopied ? "✓ Copied" : "⧉ Copy"}
              </button>
            </div>
            <pre style={s.commandPre}>{curlText}</pre>
          </div>
          {pdRouter && <p style={{
    fontSize: 11,
    opacity: 0.85,
    marginTop: 8
  }}>
              <strong>PD-Disaggregation active</strong> — this targets the router on
              {" "}<code>:{pdRouter.port}</code>; client traffic must not hit the role
              servers directly.
            </p>}
          <p style={{
    fontSize: 11,
    opacity: 0.7,
    marginTop: 8
  }}>
            Edit <code>CURL_HOST</code> / <code>CURL_PORT</code> in the Env panel.
          </p>
        </dialog>}

      {}
      {modal === "env" && <dialog ref={openDialog} style={s.dialog} onClose={() => setModal(null)} onClick={onDialogClick}>
          <div style={s.modalHeader}>
            <div style={s.modalTitle}>Env / placeholder values</div>
            <button style={s.modalCloseBtn} onClick={() => setModal(null)} aria-label="Close">×</button>
          </div>
            {placeholderGroups.curl.length > 0 && <div>
                <div style={s.sectionHeading}>cURL placeholders</div>
                {placeholderGroups.curl.map(({key, label}) => <div key={key} style={s.formField}>
                    <label style={s.formLabel}>
                      {label} <code style={{
    opacity: 0.6
  }}>{`{{${key}}}`}</code>
                    </label>
                    <input style={s.formInput} value={envDraft[key] ?? ""} onChange={e => setEnvDraft({
    ...envDraft,
    [key]: e.target.value
  })} />
                  </div>)}
              </div>}
            {placeholderGroups.command.length > 0 && <div>
                <div style={s.sectionHeading}>Command placeholders</div>
                {placeholderGroups.command.map(({key, label}) => <div key={key} style={s.formField}>
                    <label style={s.formLabel}>
                      {label} <code style={{
    opacity: 0.6
  }}>{`{{${key}}}`}</code>
                    </label>
                    <input style={s.formInput} value={envDraft[key] ?? ""} onChange={e => setEnvDraft({
    ...envDraft,
    [key]: e.target.value
  })} />
                  </div>)}
              </div>}
            <div style={{
    display: "flex",
    justifyContent: "flex-end",
    gap: 8,
    marginTop: 16
  }}>
              <button style={{
    ...s.iconButton,
    padding: "6px 14px"
  }} onClick={() => setModal(null)}>Cancel</button>
              <button style={s.primaryBtn} onClick={() => {
    saveEnv(envDraft);
    setModal(null);
  }}>Save</button>
            </div>
          <p style={{
    fontSize: 11,
    opacity: 0.7,
    marginTop: 10
  }}>
            Values persist in localStorage and are shared with the Deployment panel.
          </p>
        </dialog>}

      {}
      {modal === "submit" && <dialog ref={openDialog} style={s.dialog} onClose={() => setModal(null)} onClick={onDialogClick}>
            <div style={s.modalHeader}>
              <div style={s.modalTitle}>Submit verified cell</div>
              <button style={s.modalCloseBtn} onClick={() => setModal(null)} aria-label="Close">×</button>
            </div>
            <p style={{
    fontSize: 12,
    opacity: 0.85,
    marginTop: 0,
    marginBottom: 12
  }}>
              You've put together a combination that isn't in the verified
              catalog yet. After you've run the command end-to-end on the
              target hardware, this submits a pre-filled GitHub Issue that a
              maintainer can convert into a PR.
            </p>

            <div style={s.sectionHeading}>Combination</div>
            <code style={{
    fontFamily: "Menlo, monospace",
    fontSize: 12
  }}>
              {base.hw} / {base.variant} / {base.quant} / {base.strategy} / {base.nodes}
            </code>
            {}
            {(() => {
    const adds = diffLines.filter(d => d.kind === "added");
    const rems = diffLines.filter(d => d.kind === "removed");
    if (adds.length === 0 && rems.length === 0) return null;
    return <>
                  <div style={{
      ...s.sectionHeading,
      marginTop: 10
    }}>
                    Overrides vs base ({adds.length} added · {rems.length} removed)
                  </div>
                  <pre style={{
      margin: 0,
      padding: "8px 10px",
      background: isDark ? "#111827" : "#f5f5f5",
      border: `1px solid ${isDark ? "#374151" : "#e5e7eb"}`,
      borderRadius: 4,
      fontFamily: "'Menlo', 'Monaco', 'Courier New', monospace",
      fontSize: 12,
      lineHeight: 1.4,
      maxHeight: 160,
      overflowY: "auto",
      whiteSpace: "pre-wrap"
    }}>
                    {[...rems, ...adds].map((d, i) => <div key={i} style={d.kind === "added" ? s.diffLineAdded : s.diffLineRemoved}>
                        {d.kind === "added" ? "+ " : "- "}
                        {d.line.replace(/^\s*/, "")}
                      </div>)}
                  </pre>
                </>;
  })()}

            <div style={{
    ...s.sectionHeading,
    marginTop: 14
  }}>Attestation (all required)</div>
            <div style={s.formField}>
              <label style={{
    fontSize: 12,
    display: "flex",
    alignItems: "flex-start",
    gap: 6
  }}>
                <input type="checkbox" checked={submitAttest.ranCommand} onChange={e => setSubmitAttest({
    ...submitAttest,
    ranCommand: e.target.checked
  })} />
                I ran this exact command on the listed hardware.
              </label>
              <label style={{
    fontSize: 12,
    display: "flex",
    alignItems: "flex-start",
    gap: 6
  }}>
                <input type="checkbox" checked={submitAttest.reachedReady} onChange={e => setSubmitAttest({
    ...submitAttest,
    reachedReady: e.target.checked
  })} />
                The server reached READY and answered a cURL request successfully.
              </label>
              <label style={{
    fontSize: 12,
    display: "flex",
    alignItems: "flex-start",
    gap: 6
  }}>
                <input type="checkbox" checked={submitAttest.outputCorrect} onChange={e => setSubmitAttest({
    ...submitAttest,
    outputCorrect: e.target.checked
  })} />
                Output looked correct on at least one prompt.
              </label>
            </div>

            <div style={{
    ...s.sectionHeading,
    marginTop: 14
  }}>SGLang version (required)</div>
            <input style={{
    ...s.formInput,
    width: "100%",
    boxSizing: "border-box"
  }} placeholder="sglang==0.5.4  (or git SHA abc1234)" value={submitDraft.sglangVersion} onChange={e => setSubmitDraft({
    ...submitDraft,
    sglangVersion: e.target.value
  })} />

            <div style={{
    ...s.sectionHeading,
    marginTop: 14
  }}>Benchmark result (optional)</div>
            <input style={{
    ...s.formInput,
    width: "100%",
    boxSizing: "border-box"
  }} placeholder="TTFT 95 ms / TPOT 18 ms / 1820 tok/s @ bs=64" value={submitDraft.benchResult} onChange={e => setSubmitDraft({
    ...submitDraft,
    benchResult: e.target.value
  })} />

            <div style={{
    ...s.sectionHeading,
    marginTop: 14
  }}>Notes / caveats (optional)</div>
            <textarea style={{
    ...s.formInput,
    width: "100%",
    boxSizing: "border-box",
    minHeight: 110,
    resize: "vertical",
    fontFamily: "inherit"
  }} placeholder="Cluster config, env-var quirks, NIC mappings, multi-node bootstrap details, …" value={submitDraft.notes} onChange={e => setSubmitDraft({
    ...submitDraft,
    notes: e.target.value
  })} />

            <div style={{
    display: "flex",
    justifyContent: "flex-end",
    gap: 8,
    marginTop: 16,
    alignItems: "center"
  }}>
              {!submitReady && <span style={{
    fontSize: 11,
    opacity: 0.7,
    marginRight: "auto"
  }}>
                  Tick all attestations and fill SGLang version to enable submit.
                </span>}
              <button style={{
    ...s.iconButton,
    padding: "6px 14px"
  }} onClick={() => setModal(null)}>Cancel</button>
              <a href={submitReady ? submitUrl : undefined} target="_blank" rel="noopener noreferrer" onClick={e => {
    if (!submitReady) e.preventDefault(); else setModal(null);
  }} style={{
    ...s.primaryBtn,
    textDecoration: "none",
    display: "inline-flex",
    alignItems: "center",
    opacity: submitReady ? 1 : 0.4,
    cursor: submitReady ? "pointer" : "not-allowed"
  }}>
                Open submission on GitHub →
              </a>
            </div>
          <p style={{
    fontSize: 11,
    opacity: 0.7,
    marginTop: 10
  }}>
            The CTA opens a pre-filled GitHub Issue using the
            <code> 3-playground-verified-cell.yml</code> template. A
            maintainer with the listed hardware will review and convert it
            into a cookbook PR.
          </p>
        </dialog>}
    </div>;
};

export const KimiK3MambaRatioCalculator = () => {
  const [isDark, setIsDark] = useState(false);
  const [requestLength, setRequestLength] = useState("11264");
  const [copied, setCopied] = useState(false);
  const [cfg, setCfg] = useState({
    flags: [],
    env: [],
    baseFlags: [],
    baseEnv: []
  });
  useEffect(() => {
    const checkTheme = () => {
      const html = document.documentElement;
      setIsDark(html.classList.contains("dark") || html.getAttribute("data-theme") === "dark" || html.style.colorScheme === "dark");
    };
    checkTheme();
    const observer = new MutationObserver(checkTheme);
    observer.observe(document.documentElement, {
      attributes: true,
      attributeFilter: ["class", "data-theme", "style"]
    });
    return () => observer.disconnect();
  }, []);
  useEffect(() => {
    const onCfg = e => setCfg({
      flags: e.detail && e.detail.flags || [],
      env: e.detail && e.detail.env || [],
      baseFlags: e.detail && e.detail.baseFlags || [],
      baseEnv: e.detail && e.detail.baseEnv || []
    });
    window.addEventListener("sglang-k3-effective-config", onCfg);
    return () => window.removeEventListener("sglang-k3-effective-config", onCfg);
  }, []);
  const length = Number.parseFloat(requestLength);
  const derive = (flags, env) => {
    const flagArg = name => {
      for (const f of flags) {
        const parts = f.split(/\s+/);
        if (parts[0] === name) return parts[1];
      }
      return null;
    };
    const hasFlag = name => flags.some(f => f.split(/[\s=]/)[0] === name);
    const tp = Number(flagArg("--tp-size")) || 8;
    const dp = hasFlag("--enable-dp-attention") ? Number(flagArg("--dp-size")) || 1 : 1;
    const attnTp = Math.max(1, Math.round(tp / dp));
    const dcp = Number(flagArg("--dcp-size")) || 1;
    const kvDtype = flagArg("--kv-cache-dtype") === "fp8_e4m3" ? "fp8_e4m3" : "bfloat16";
    const specOn = hasFlag("--speculative-algorithm");
    const replaySpec = hasFlag("--enable-linear-replayssm-spec");
    const ssmFlag = flagArg("--mamba-ssm-dtype");
    const ssmDtype = ssmFlag === "bfloat16" || ssmFlag === "float16" ? ssmFlag : "float32";
    const radixOff = hasFlag("--disable-radix-cache");
    const strategyFlag = flagArg("--mamba-radix-cache-strategy");
    const strategy = strategyFlag === "no_buffer" || strategyFlag === "extra_buffer_lazy" ? strategyFlag : "extra_buffer";
    const skipLock = env.some(e => e.startsWith("SGLANG_OPT_MAMBA_SKIP_DECODE_LOCK=1"));
    const pdRole = flagArg("--disaggregation-mode");
    const overlapOff = hasFlag("--disable-overlap-schedule") || (Number(flagArg("--pp-size")) || 1) > 1;
    const slots = pdRole === "decode" ? 1 : radixOff ? 1 : strategy === "no_buffer" ? 3 : 3 - (skipLock ? 1 : 0) + (overlapOff || strategy === "extra_buffer_lazy" ? 1 : 2);
    const block = Number(flagArg("--speculative-dspark-block-size")) || 7;
    const drafts = specOn && !replaySpec && pdRole !== "prefill" ? block + 1 : 0;
    const ssmBytes = ssmDtype === "float32" ? 4 : 2;
    const kvBytes = kvDtype === "fp8_e4m3" ? 1 : 2;
    const stateBytesPerSlot = 69 * (96 / attnTp * 128 * 128 * ssmBytes + 3 * 3 * (96 / attnTp) * 128 * 2);
    const kvBytesPerToken = 24 * (512 + 64) * kvBytes;
    const draftKvBytesPerToken = specOn ? 1400 : 0;
    const kvBytesPerTokenPerRank = kvBytesPerToken / dcp + draftKvBytesPerToken;
    const ratio = (slots + drafts) * stateBytesPerSlot / (kvBytesPerTokenPerRank * length);
    return {
      ratio,
      tp,
      dp,
      attnTp,
      dcp,
      kvDtype,
      ssmDtype,
      radixOff,
      strategy,
      skipLock,
      slots,
      specOn,
      replaySpec,
      block,
      pdRole
    };
  };
  const eff = derive(cfg.flags, cfg.env);
  const bs = derive(cfg.baseFlags.length ? cfg.baseFlags : cfg.flags, cfg.baseFlags.length ? cfg.baseEnv : cfg.env);
  const {ratio, tp, dp, attnTp, dcp, kvDtype, ssmDtype, radixOff, strategy, skipLock, slots, specOn, replaySpec, block, pdRole} = eff;
  const valid = Number.isFinite(ratio) && ratio > 0 && length > 0 && 96 % attnTp === 0;
  const baseValid = Number.isFinite(bs.ratio) && bs.ratio > 0 && length > 0;
  const formatRatio = value => {
    if (!Number.isFinite(value)) return "—";
    if (value >= 10) return value.toFixed(1).replace(/\.0$/, "");
    if (value >= 1) return value.toFixed(2).replace(/\.?0+$/, "");
    return Number(value.toPrecision(2)).toString();
  };
  const result = valid ? formatRatio(ratio) : "—";
  const baseResult = baseValid ? formatRatio(bs.ratio) : "—";
  const cliFlag = valid ? `--mamba-full-memory-ratio ${result}` : "";
  useEffect(() => {
    window.dispatchEvent(new CustomEvent("sglang-k3-mamba-ratio", {
      detail: {
        ratio: valid ? result : null,
        baseRatio: baseValid ? baseResult : null
      }
    }));
  }, [result, valid, baseResult, baseValid]);
  const copyFlag = () => {
    if (!cliFlag || typeof navigator === "undefined" || !navigator.clipboard) return;
    navigator.clipboard.writeText(cliFlag);
    setCopied(true);
    window.setTimeout(() => setCopied(false), 1600);
  };
  const colors = {
    border: isDark ? "#374151" : "#e5e7eb",
    panel: isDark ? "#1f2937" : "#ffffff",
    input: isDark ? "#111827" : "#f8fafc",
    text: isDark ? "#e5e7eb" : "#1f2937",
    muted: isDark ? "#9ca3af" : "#64748b",
    accent: isDark ? "#E85D4D" : "#D45D44",
    error: isDark ? "#fca5a5" : "#b91c1c"
  };
  const inputStyle = {
    width: "100%",
    boxSizing: "border-box",
    padding: "8px 10px",
    border: `1px solid ${colors.border}`,
    borderRadius: "5px",
    background: colors.input,
    color: colors.text,
    fontSize: "13px"
  };
  const labelStyle = {
    display: "flex",
    flexDirection: "column",
    gap: "5px",
    fontSize: "12px",
    fontWeight: 600
  };
  const chipStyle = {
    padding: "3px 9px",
    border: `1px solid ${colors.border}`,
    borderRadius: "999px",
    background: colors.input,
    color: colors.text,
    fontSize: "12px",
    whiteSpace: "nowrap"
  };
  const specLabel = !specOn ? "NOSPEC" : replaySpec ? "DSPARK + ReplaySSM (D folded)" : `DSPARK (D = ${block + 1})`;
  const derivedChips = [dp > 1 ? `${tp} GPUs = DP ${dp} × Attention TP ${attnTp}` : `Attention TP ${attnTp}`, `DCP ${dcp}`, `KV ${kvDtype === "fp8_e4m3" ? "FP8" : "BF16"}`, `State ${ssmDtype === "float32" ? "FP32" : ssmDtype === "bfloat16" ? "BF16" : "FP16"}`, pdRole === "decode" ? "PD decode: chunk cache (S = 1)" : radixOff ? "Radix off (S = 1)" : `${strategy}${skipLock ? " + slot saving" : ""} (S = ${slots})`, pdRole === "prefill" ? "PD prefill (no verify states)" : null, specLabel].filter(Boolean);
  return <div className="not-prose" style={{
    display: "grid",
    gap: "12px",
    padding: "14px",
    border: `1px solid ${colors.border}`,
    borderRadius: "8px",
    background: colors.panel,
    color: colors.text
  }}>
      <div style={{
    display: "grid",
    gridTemplateColumns: "minmax(180px, 260px) 1fr",
    gap: "14px",
    alignItems: "start"
  }}>
        <label htmlFor="k3-ratio-length" style={labelStyle}>
          Average request length
          <input id="k3-ratio-length" type="number" min="1" step="1" value={requestLength} onChange={event => setRequestLength(event.target.value)} style={inputStyle} />
          <span style={{
    color: colors.muted,
    fontSize: "11px",
    fontWeight: 400
  }}>
            Input + output tokens — the only free parameter
          </span>
        </label>

        <div style={{
    display: "flex",
    flexDirection: "column",
    gap: "6px"
  }}>
          <span style={{
    fontSize: "12px",
    fontWeight: 600
  }}>
            Serving configuration (follows the Deploy panel and Playground)
          </span>
          <div style={{
    display: "flex",
    flexWrap: "wrap",
    gap: "6px"
  }}>
            {derivedChips.map(c => <span key={c} style={chipStyle}>{c}</span>)}
          </div>
        </div>
      </div>

      {!valid ? <div style={{
    color: colors.error,
    fontSize: "12px"
  }}>
          Enter a valid request length.
        </div> : <div style={{
    display: "flex",
    alignItems: "center",
    gap: "12px",
    paddingTop: "12px",
    borderTop: `1px solid ${colors.border}`,
    flexWrap: "wrap"
  }}>
          <div>
            <div style={{
    color: colors.muted,
    fontSize: "11px"
  }}>
              Balanced ratio — pinned into the commands above
            </div>
            <div style={{
    fontSize: "26px",
    fontWeight: 700
  }}>{result}</div>
            {baseResult !== result ? <div style={{
    color: colors.muted,
    fontSize: "11px"
  }}>
                Deploy command (without Playground overrides): {baseResult}
              </div> : null}
          </div>
          <code style={{
    flex: 1,
    minWidth: "240px",
    color: colors.text
  }}>
            {cliFlag}
          </code>
          <button type="button" onClick={copyFlag} style={{
    padding: "7px 11px",
    border: 0,
    borderRadius: "5px",
    background: colors.accent,
    color: "#ffffff",
    fontSize: "12px",
    fontWeight: 600,
    cursor: "pointer"
  }}>
            {copied ? "Copied" : "Copy flag"}
          </button>
        </div>}
    </div>;
};

export const benchmarks = [{
  match: {
    hw: "b300",
    pdMode: "unified",
    strategy: "balanced"
  }
}, {
  match: {
    hw: "b300",
    pdMode: "unified",
    strategy: "low-latency"
  }
}, {
  match: {
    hw: "b300",
    pdMode: "unified",
    strategy: "high-throughput"
  }
}, {
  match: {
    hw: "b200",
    pdMode: "unified",
    strategy: "low-latency"
  }
}, {
  match: {
    hw: "b200",
    pdMode: "unified",
    strategy: "balanced"
  }
}, {
  match: {
    hw: "b200",
    pdMode: "unified",
    strategy: "high-throughput"
  }
}, {
  match: {
    hw: "mi350x",
    pdMode: "unified",
    strategy: "balanced"
  }
}, {
  match: {
    hw: "mi355x",
    pdMode: "unified",
    strategy: "balanced"
  }
}, {
  match: {
    hw: "h100",
    pdMode: "unified",
    strategy: "low-latency"
  }
}, {
  match: {
    hw: "h100",
    pdMode: "unified",
    strategy: "balanced"
  }
}, {
  match: {
    hw: "h100",
    pdMode: "unified",
    strategy: "high-throughput"
  }
}, {
  match: {
    hw: "h200",
    pdMode: "unified",
    strategy: "low-latency"
  }
}, {
  match: {
    hw: "h200",
    pdMode: "unified",
    strategy: "balanced"
  }
}, {
  match: {
    hw: "h200",
    pdMode: "unified",
    strategy: "high-throughput"
  }
}, {
  match: {
    hw: "gb300",
    pdMode: "unified",
    strategy: "low-latency"
  }
}, {
  match: {
    hw: "gb300",
    pdMode: "unified",
    strategy: "balanced"
  }
}, {
  match: {
    hw: "gb300",
    pdMode: "unified",
    strategy: "high-throughput"
  }
}, {
  match: {
    hw: "gb200",
    pdMode: "unified",
    strategy: "low-latency"
  }
}, {
  match: {
    hw: "gb200",
    pdMode: "unified",
    strategy: "balanced"
  }
}, {
  match: {
    hw: "gb200",
    pdMode: "unified",
    strategy: "high-throughput"
  }
}];

export const config = {
  modelName: "Kimi-K3",
  supportedHardware: ["b300", "gb300", "b200", "gb200", "h200", "h100", "mi350x", "mi355x"],
  cellFor(s) {
    return (config.cells || []).find(c => c.match.hw === s.hw && c.match.pdMode === s.pdMode && c.match.strategy === s.strategy);
  },
  flagOf(cell, name) {
    return ((cell || ({})).flags || []).find(f => f.split(/[\s=]/)[0] === name);
  },
  sizeOf(cell, name) {
    const f = config.flagOf(cell, name);
    return f ? Number(f.split(/[\s=]/)[1]) || 1 : 1;
  },
  hasDcp(s) {
    return !!config.flagOf(config.cellFor(s), "--dcp-size");
  },
  isPipelined(s) {
    return config.sizeOf(config.cellFor(s), "--pp-size") > 1;
  },
  specCollapses(s) {
    return config.isPipelined(s) && !!(config.cellFor(s) || ({})).specCollapsePp;
  },
  get dcpStorageDisableRules() {
    const groups = new Map();
    for (const c of config.cells || []) {
      if (!config.flagOf(c, "--dcp-size")) continue;
      const k = `${c.match.hw}|${c.match.pdMode}`;
      if (!groups.has(k)) groups.set(k, new Set());
      groups.get(k).add(c.match.strategy);
    }
    return [...groups].map(([k, strategies]) => {
      const [hw, pdMode] = k.split("|");
      return {
        when: {
          hw: [hw],
          pdMode: [pdMode],
          strategy: [...strategies],
          hicache: ["l2"],
          spec: ["none"]
        },
        reason: "This recipe runs DCP, and a storage backend (L3) under DCP is rejected at startup. Switch HiCache to L3 in the Deploy panel (that drops DCP), or stay on L1+L2."
      };
    });
  },
  get pipelinedKnobDisableRules() {
    const groups = new Map();
    for (const c of config.cells || []) {
      if (config.sizeOf(c, "--pp-size") <= 1 || c.specCollapsePp) continue;
      const k = `${c.match.hw}|${c.match.pdMode}`;
      if (!groups.has(k)) groups.set(k, new Set());
      groups.get(k).add(c.match.strategy);
    }
    return [...groups].map(([k, strategies]) => {
      const [hw, pdMode] = k.split("|");
      return {
        when: {
          hw: [hw],
          pdMode: [pdMode],
          strategy: [...strategies]
        },
        reason: "This recipe spends its ranks on pipeline stages (--pp-size > 1 with a small --tp-size), so widening the attention parallelism would need more GPUs than the deployment has. Pick a flat recipe to change TP or DP-Attention."
      };
    });
  },
  specCollapsedFlags(s) {
    const cell = config.cellFor(s);
    const pp = config.sizeOf(cell, "--pp-size");
    const out = [`--tp-size ${config.sizeOf(cell, "--tp-size") * pp}`];
    if (config.flagOf(cell, "--dcp-size") && s.hicache !== "l2" && s.hicache !== "l3") {
      out.push(`--dcp-size ${config.sizeOf(cell, "--dcp-size") * pp}`);
    }
    if (config.flagOf(cell, "--ep-size")) {
      out.push(`--ep-size ${config.sizeOf(cell, "--ep-size") * pp}`);
    }
    return out;
  },
  matchDims: [{
    id: "pdMode",
    title: "PD Mode",
    options: [{
      id: "unified",
      label: "Unified"
    }, {
      id: "prefill",
      label: "Prefill"
    }, {
      id: "decode",
      label: "Decode"
    }]
  }, {
    id: "strategy",
    title: "Strategy",
    options: [{
      id: "low-latency",
      label: "Low-Latency",
      showWhen: s => s.pdMode !== "prefill"
    }, {
      id: "balanced",
      label: "Balanced",
      showWhen: s => s.pdMode !== "prefill"
    }, {
      id: "high-throughput",
      label: "High-Throughput",
      showWhen: s => s.pdMode !== "prefill"
    }, {
      id: "default",
      label: "Default",
      showWhen: s => s.pdMode === "prefill"
    }, {
      id: "long-context",
      label: "Long-Context",
      showWhen: s => s.pdMode === "prefill"
    }]
  }],
  overlayDims: [{
    id: "quant",
    title: "Quantization",
    default: "mxfp4",
    options: [{
      id: "mxfp4",
      label: "MXFP4",
      subtitle: "Moonshot AI checkpoint"
    }, {
      id: "nvfp4",
      label: "NVFP4",
      subtitle: "NVIDIA checkpoint",
      disabled: s => !["b200", "gb200", "b300", "gb300"].includes(s.hw),
      disableReason: "The nvidia/Kimi-K3-NVFP4 checkpoint needs Blackwell: its routed experts run on FlashInfer TRT-LLM NVFP4 kernels (SiTU), which do not exist for Hopper or AMD.",
      stripPrefixes: ["--moe-runner-backend"],
      flags: ["--moe-runner-backend flashinfer_trtllm"],
      hints: ["Use docker image lmsysorg/sglang:dev-dev-kimi-k3-nvfp4 (CUDA 13)."]
    }]
  }, {
    id: "mmTransport",
    title: "VLM Transport",
    default: "auto",
    showWhen: s => s.pdMode !== "decode",
    options: [{
      id: "auto",
      label: "Auto (topology-aware)",
      hints: s => {
        if (s.pdMode !== "unified") {
          return ["VLM transport: Auto -> CPU for PD; KV/KDA transfer is separate."];
        }
        if (s.hw === "b300") {
          return ["VLM transport: Auto -> CUDA IPC (up to 1 GiB HBM; CPU fallback when full)."];
        }
        if (["gb200", "gb300"].includes(s.hw)) {
          return ["VLM transport: Auto -> CUDA VMM with IMEX, otherwise CPU (up to 1 GiB HBM)."];
        }
        return ["VLM transport: Auto -> CPU on this topology."];
      }
    }, {
      id: "cpu",
      label: "CPU (save HBM)",
      flags: ["--mm-feature-transport cpu"],
      hints: ["VLM transport: CPU; no GPU feature pool."]
    }]
  }, {
    id: "spec",
    title: "Spec Decode",
    default: "dspark",
    options: [{
      id: "none",
      label: "Non-Spec",
      env: s => ["mi350x", "mi355x"].includes(s.hw) ? ["SGLANG_MLA_DECODE_TUNE=1"] : []
    }, {
      id: "dspark",
      label: "DSPARK",
      disabled: s => config.isPipelined(s) && !config.specCollapses(s),
      disableReason: "This recipe is pipelined (--pp-size > 1) and DSPARK requires pp_size == 1. Pick a recipe that runs a single pipeline stage, or run this one NOSPEC.",
      stripPrefixes: s => config.specCollapses(s) ? ["--tp-size", "--pp-size", "--dcp-size", "--ep-size"] : [],
      flags: s => [...config.specCollapses(s) ? config.specCollapsedFlags(s) : [], "--speculative-algorithm DSPARK", "--speculative-draft-model-path RadixArk/Kimi-K3-DSpark", "--speculative-dspark-block-size 7", ...s.pdMode === "prefill" ? [] : ["--enable-linear-replayssm-spec"]]
    }, {
      id: "dflash",
      label: "DFLASH",
      disabled: true,
      disableReason: "No K3 DFLASH draft checkpoint published yet — DSPARK is the available speculative path.",
      flags: ["--speculative-algorithm DFLASH", "--speculative-draft-model-path <dflash-draft>"]
    }]
  }, {
    id: "hicache",
    title: "HiCache",
    default: "off",
    options: [{
      id: "off",
      label: "Off"
    }, {
      id: "l2",
      label: "L1+L2 (host)",
      flags: ["--enable-hierarchical-cache"],
      stripPrefixes: s => s.spec !== "none" && config.hasDcp(s) ? ["--dcp-size", "--dcp-comm-backend"] : [],
      hints: s => s.spec !== "none" && config.hasDcp(s) ? ["HiCache under DCP rejects speculative decoding, so this recipe drops DCP", "and serves the MLA KV TP-replicated (any PP/EP in the cell stays).", "Per-request context is far shorter than the DCP", "version — DCP is what buys KV capacity. Run the cell NOSPEC to keep DCP."] : []
    }, {
      id: "l3",
      label: "+ L3 (Mooncake)",
      flags: ["--enable-hierarchical-cache", "--hicache-storage-backend mooncake"],
      env: ["SGLANG_HICACHE_MOONCAKE_CONFIG_PATH={{MOONCAKE_CONFIG}}"],
      stripPrefixes: s => config.hasDcp(s) ? ["--dcp-size", "--dcp-comm-backend"] : [],
      hints: s => ["L3 also needs a mooncake_master process on rank 0 and the config file", "above present on every rank — the launch command alone is not enough.", ...config.hasDcp(s) ? ["L3 storage keys are not dcp_rank-aware yet, so this recipe drops DCP", "and serves the MLA KV TP-replicated (any PP/EP in the cell stays).", "Concurrency lands on a similar target, but", "per-request context is far shorter than the DCP version — DCP is", "what buys KV capacity."] : []]
    }]
  }],
  modelNames: {
    default: "moonshotai/Kimi-K3",
    nvfp4: "nvidia/Kimi-K3-NVFP4"
  },
  placeholders: {
    HOST_IP: {
      target: "command",
      label: "Bind host",
      default: "0.0.0.0"
    },
    PORT: {
      target: "command",
      label: "Bind port",
      default: "30000"
    },
    NODE0_IP: {
      target: "command",
      label: "Head node IP",
      default: "<node0-ip>"
    },
    NODE_RANK: {
      target: "command",
      label: "This node rank",
      default: "<node-rank>"
    },
    LOCAL_IP: {
      target: "command",
      label: "This node IP",
      default: "<this-node-ip>"
    },
    NETWORK_IFACE: {
      target: "command",
      label: "Cross-node NIC",
      default: "<your-nic>"
    },
    HF_TOKEN: {
      target: "command",
      label: "HF token (Docker)",
      default: "<your-hf-token>"
    },
    MOONCAKE_CONFIG: {
      target: "command",
      label: "Mooncake config path",
      default: "<mooncake.json>"
    },
    CURL_HOST: {
      target: "curl",
      label: "Server host",
      default: "localhost"
    },
    CURL_PORT: {
      target: "curl",
      label: "Server port",
      default: "30000"
    }
  },
  curl: `curl http://{{CURL_HOST}}:{{CURL_PORT}}/v1/chat/completions \\
-H 'Content-Type: application/json' \\
-d '{ "model": "{{MODEL_NAME}}", "messages": [{"role":"user","content":"Hello"}] }'`,
  benchmarkCommands: {
    speed: `python3 -m sglang.bench_serving \\
  --backend sglang \\
  --host {{CURL_HOST}} --port {{CURL_PORT}} \\
  --model {{MODEL_NAME}} \\
  --dataset-name {{DATASET}} \\
  --random-input-len {{ISL}} --random-output-len {{OSL}} --random-range-ratio 1.0 \\
  --num-prompts {{NUM_PROMPTS}} --max-concurrency {{MAX_CONCURRENCY}} \\
  --flush-cache`,
    numPromptsByConc: {
      1: 16,
      16: 80,
      64: 320,
      256: 1280,
      1024: 5120
    }
  },
  dockerImages: {
    h100: "lmsysorg/sglang:kimi-k3",
    h200: "lmsysorg/sglang:kimi-k3",
    b300: "lmsysorg/sglang:kimi-k3",
    gb300: "lmsysorg/sglang:kimi-k3",
    b200: "lmsysorg/sglang:kimi-k3",
    gb200: "lmsysorg/sglang:kimi-k3",
    mi350x: "lmsysorg/sglang-rocm:v0.5.17-rocm720-mi35x-20260817",
    mi355x: "lmsysorg/sglang-rocm:v0.5.17-rocm720-mi35x-20260817",
    "b300|nvfp4": "lmsysorg/sglang:dev-dev-kimi-k3-nvfp4",
    "gb300|nvfp4": "lmsysorg/sglang:dev-dev-kimi-k3-nvfp4",
    "b200|nvfp4": "lmsysorg/sglang:dev-dev-kimi-k3-nvfp4",
    "gb200|nvfp4": "lmsysorg/sglang:dev-dev-kimi-k3-nvfp4"
  },
  github: {
    cookbookModel: "moonshotai/kimi-k3"
  },
  playgroundFeatures: {
    attention: {
      knobs: [{
        id: "tp",
        label: "TP",
        values: [null, 8, {
          value: 16,
          get disable() {
            return [{
              when: {
                hw: ["b300", "gb300"]
              },
              reason: "TP=16 needs 16 ranks; the B300 and GB300 recipes have 8 ranks."
            }, {
              when: {
                hw: ["b200"],
                pdMode: ["unified"],
                spec: ["none"]
              },
              reason: "With Spec Decode off, the B200 Unified recipes already use all 16 GPUs as TP8 × PP2, so changing TP to 16 would require 32 ranks. Switch Spec Decode to DSPARK — it drops the pipeline and re-lays the same GPUs as flat TP16."
            }, ...config.pipelinedKnobDisableRules];
          }
        }]
      }, {
        id: "dpAttn",
        label: "DP-Attention",
        values: [null, false, 2, 4, {
          value: 8,
          get disable() {
            return [{
              when: {
                hw: ["b300", "gb300"]
              },
              reason: "On an 8-rank deployment (B300 1×8, GB300 2×4) dp=8 leaves attn_tp=1, so each rank holds the full unsharded MLA KV and OOMs — prefer dp=2/attn_tp=4."
            }, {
              when: {
                hw: ["b200"],
                pdMode: ["unified"],
                spec: ["none"]
              },
              reason: "With Spec Decode off, the B200 Unified recipes run TP8 within each PP2 stage, so dp=8 leaves attn_tp=1 and each rank holds the full unsharded MLA KV — prefer dp=2/attn_tp=4, or switch Spec Decode to DSPARK for the flat TP16 shape."
            }, ...config.pipelinedKnobDisableRules];
          }
        }, {
          value: 16,
          get disable() {
            return [{
              when: {
                hw: ["b300", "gb300"]
              },
              reason: "DP-Attention=16 needs 16 TP ranks; the B300 and GB300 recipes have 8."
            }, {
              when: {
                hw: ["b200"],
                pdMode: ["unified"],
                spec: ["none"]
              },
              reason: "With Spec Decode off, the B200 Unified recipes use TP8 within each PP2 stage, so DP-Attention cannot exceed 8. Switch Spec Decode to DSPARK for the flat TP16 shape."
            }, ...config.pipelinedKnobDisableRules];
          }
        }],
        labels: {
          "auto": "Auto",
          "false": "Off"
        }
      }]
    },
    moe: {
      backend: {
        options: [{
          id: null,
          label: "Inherited"
        }, {
          id: "deepep",
          label: "DeepEP",
          flags: ["--moe-a2a-backend deepep"]
        }, {
          id: "megamoe",
          label: "MegaMoE",
          flags: ["--moe-a2a-backend megamoe"],
          requiresHw: ["b200", "b300", "gb200", "gb300"]
        }, {
          id: "flashinfer_mxfp4",
          label: "FlashInfer (MXFP4)",
          flags: ["--moe-runner-backend flashinfer_mxfp4"],
          requiresHw: ["b200", "b300", "gb200", "gb300"]
        }, {
          id: "marlin",
          label: "Marlin (W4A16)",
          flags: ["--moe-runner-backend marlin"]
        }]
      },
      megamoeQuant: {
        stripEnv: ["SGLANG_DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK"],
        options: [{
          id: "w4a8",
          label: "W4A8",
          env: ["SGLANG_OPT_DEEPGEMM_MEGA_MOE_NUM_MAX_TOKENS_PER_RANK=8320"]
        }, {
          id: "w4a4",
          label: "W4A4",
          env: ["SGLANG_OPT_DEEPGEMM_MEGA_MOE_NUM_MAX_TOKENS_PER_RANK=8320", "SGLANG_OPT_DEEPGEMM_MEGA_MOE_USE_FP4_ACTS=1", "SGLANG_OPT_DEEPGEMM_MEGA_MOE_USE_MXF4_KIND=1"]
        }]
      },
      ep: {
        label: "EP",
        values: [null, 1, 2, 4, 8, {
          value: 16,
          get disable() {
            return [{
              when: {
                hw: ["b300", "gb300"]
              },
              reason: "EP=16 needs 16 TP ranks; the B300 and GB300 recipes have 8."
            }, {
              when: {
                hw: ["b200"],
                pdMode: ["unified"],
                spec: ["none"]
              },
              reason: "With Spec Decode off, the B200 Unified recipes use TP8 within each PP2 stage, so EP cannot exceed 8. Switch Spec Decode to DSPARK for the flat TP16 shape."
            }, ...config.pipelinedKnobDisableRules];
          }
        }]
      }
    },
    parsers: {
      items: [{
        id: "reasoning",
        label: "Reasoning Parser",
        flag: "--reasoning-parser kimi_k3"
      }, {
        id: "toolCall",
        label: "Tool Call Parser",
        flag: "--tool-call-parser kimi_k3"
      }]
    },
    pdDisagg: {
      showWhen: b => b.pdMode === "prefill" || b.pdMode === "decode",
      transferBackends: [{
        id: "nixl",
        label: "NiXL"
      }, {
        id: "mooncake",
        label: "Mooncake"
      }],
      ibDevices: [{
        id: "auto",
        label: "Auto"
      }, "mlx5_0"],
      router: {
        port: 8000,
        command: `python3 -m sglang_router.launch_router \\
  --pd-disaggregation \\
  --prefill http://<prefill-host>:{{PREFILL_PORT}} 8998 \\
  --decode http://<decode-host>:{{DECODE_PORT}} \\
  --host 0.0.0.0 --port {{ROUTER_PORT}} \\
  --disable-circuit-breaker \\
  --health-check-interval-secs 999999`
      }
    },
    hicache: {
      showWhen: b => b.hicache !== undefined && b.hicache !== "off",
      backends: [{
        id: null,
        label: "Auto"
      }, {
        id: "file",
        label: "File",
        get disable() {
          return config.dcpStorageDisableRules;
        }
      }, {
        id: "mooncake",
        label: "Mooncake",
        get disable() {
          return config.dcpStorageDisableRules;
        }
      }, {
        id: "hf3fs",
        label: "HF3FS",
        get disable() {
          return config.dcpStorageDisableRules;
        }
      }, {
        id: "nixl",
        label: "NiXL",
        get disable() {
          return config.dcpStorageDisableRules;
        }
      }],
      writePolicies: [{
        id: "auto",
        label: "Auto"
      }, {
        id: "write_through",
        label: "Write-through"
      }, {
        id: "write_back",
        label: "Write-back"
      }, {
        id: "write_through_selective",
        label: "Write-through (selective)"
      }]
    },
    flagSelects: [{
      id: "proposedDraftTokens",
      title: "Proposed Draft Tokens",
      showWhen: b => b.spec === "dspark",
      control: "slider",
      stripPrefixes: ["--speculative-dspark-block-size", "--speculative-dflash-block-size", "--speculative-num-steps"],
      options: [{
        id: "1",
        label: "1",
        flags: ["--speculative-dspark-block-size 1"]
      }, {
        id: "2",
        label: "2",
        flags: ["--speculative-dspark-block-size 2"]
      }, {
        id: "3",
        label: "3",
        flags: ["--speculative-dspark-block-size 3"]
      }, {
        id: "4",
        label: "4",
        flags: ["--speculative-dspark-block-size 4"]
      }, {
        id: "5",
        label: "5",
        flags: ["--speculative-dspark-block-size 5"]
      }, {
        id: "6",
        label: "6",
        flags: ["--speculative-dspark-block-size 6"]
      }, {
        id: "7",
        label: "7",
        flags: ["--speculative-dspark-block-size 7"]
      }]
    }, {
      id: "replaySsm",
      title: "ReplaySSM (spec)",
      showWhen: b => b.spec === "dspark",
      stripPrefixes: ["--enable-linear-replayssm-spec"],
      options: [{
        id: "off",
        label: "Off"
      }, {
        id: "on",
        label: "On",
        disable: {
          pdMode: ["prefill"]
        },
        disableReason: "A PD prefill server never runs speculative verify, so --enable-linear-replayssm-spec is rejected at startup.",
        flags: ["--enable-linear-replayssm-spec"]
      }]
    }, {
      id: "raggedVerify",
      title: "Ragged Verify Mode (spec)",
      showWhen: b => b.spec === "dspark",
      stripEnv: ["SGLANG_RAGGED_VERIFY_MODE"],
      options: [{
        id: "static",
        label: "Auto (static)"
      }, {
        id: "compact",
        label: "Compact (requires SPS table)",
        env: ["SGLANG_RAGGED_VERIFY_MODE=compact"]
      }]
    }, {
      id: "kvCacheDtype",
      title: "KV Cache Precision",
      stripPrefixes: ["--kv-cache-dtype"],
      options: [{
        id: "auto",
        label: "Auto (BF16)"
      }, {
        id: "fp8",
        label: "FP8 (E4M3) — halves KV memory",
        flags: ["--kv-cache-dtype fp8_e4m3"]
      }]
    }, {
      id: "mambaSsmDtype",
      title: "KDA State Precision",
      stripPrefixes: ["--mamba-ssm-dtype"],
      options: [{
        id: "auto",
        label: "Auto (FP32)"
      }, {
        id: "bf16",
        label: "BFloat16 — halves state memory",
        flags: ["--mamba-ssm-dtype bfloat16"]
      }, {
        id: "fp16",
        label: "Float16 — stochastic-rounding capable",
        flags: ["--mamba-ssm-dtype float16"]
      }]
    }, {
      id: "prefixCache",
      title: "Prefix Cache",
      stripPrefixes: ["--disable-radix-cache"],
      options: [{
        id: "on",
        label: "On"
      }, {
        id: "off",
        label: "Off",
        flags: ["--disable-radix-cache"]
      }]
    }, {
      id: "mambaRadix",
      title: "KDA Radix Cache Strategy",
      showWhen: (b, v, d) => ((v && v.prefixCache) ?? (d && d.prefixCache)) !== "off",
      stripPrefixes: ["--mamba-radix-cache-strategy"],
      options: [{
        id: "auto",
        label: "Auto (extra_buffer)"
      }, {
        id: "lazy",
        label: "extra_buffer_lazy",
        flags: ["--mamba-radix-cache-strategy extra_buffer_lazy"]
      }, {
        id: "nobuf",
        label: "no_buffer",
        flags: ["--mamba-radix-cache-strategy no_buffer"]
      }]
    }, {
      id: "mambaSlotSaving",
      title: "KDA Slot Saving (experimental)",
      stripEnv: ["SGLANG_OPT_MAMBA_SKIP_DECODE_LOCK"],
      options: [{
        id: "off",
        label: "Off"
      }, {
        id: "on",
        label: "On",
        env: ["SGLANG_OPT_MAMBA_SKIP_DECODE_LOCK=1"]
      }]
    }, {
      id: "eplb",
      title: "Expert Rebalancing (EPLB)",
      stripPrefixes: ["--enable-eplb"],
      options: [{
        id: "off",
        label: "Off"
      }, {
        id: "on",
        label: "On (requires EP a2a)",
        flags: ["--enable-eplb"]
      }]
    }, {
      id: "prefillGraph",
      title: "Prefill CUDA Graph",
      stripPrefixes: ["--cuda-graph-backend-prefill"],
      options: [{
        id: "auto",
        label: "Auto (off)"
      }, {
        id: "bcg",
        label: "Breakable (BCG)",
        flags: ["--cuda-graph-backend-prefill breakable"]
      }]
    }, {
      id: "pdDecodeRadix",
      title: "PD Decode Radix Cache",
      showWhen: b => b.pdMode === "decode",
      stripPrefixes: ["--disaggregation-decode-enable-radix-cache"],
      options: [{
        id: "off",
        label: "Off (chunk cache)"
      }, {
        id: "on",
        label: "On",
        flags: ["--disaggregation-decode-enable-radix-cache"]
      }]
    }, {
      id: "lsGpus",
      title: "Cluster Size (large-scale)",
      showWhen: b => b.pdMode === undefined || b.pdMode === "unified",
      default: b => ({
        b300: "8",
        gb300: "8",
        b200: "16",
        gb200: "16",
        h200: "16",
        h100: "32",
        mi350x: "8",
        mi355x: "8"
      })[(b || ({})).hw] || "32",
      stripPrefixes: [],
      options: [{
        id: "8",
        label: "8 GPUs"
      }, {
        id: "16",
        label: "16 GPUs"
      }, {
        id: "32",
        label: "32 GPUs"
      }, {
        id: "64",
        label: "64 GPUs"
      }]
    }, {
      id: "lsPreset",
      title: "Large-Scale Preset",
      showWhen: b => b.pdMode === undefined || b.pdMode === "unified",
      stripPrefixes: ["--tp-size", "--tp", "--tensor-parallel-size", "--ep-size", "--ep", "--expert-parallel-size", "--enable-dp-attention", "--dp-size", "--enable-dp-lm-head", "--dcp-size", "--dcp-comm-backend", "--pp-size", "--pipeline-parallel-size", "--moe-a2a-backend", "--moe-runner-backend", "--kv-cache-dtype", "--mamba-ssm-dtype", "--mamba-radix-cache-strategy", "--mem-fraction-static", "--disable-radix-cache", "--enable-symm-mem"],
      stripEnv: ["SGLANG_OPT_DEEPGEMM_MEGA_MOE_NUM_MAX_TOKENS_PER_RANK"],
      options: [{
        id: "off",
        label: "Off",
        flags: () => null
      }, {
        id: "serving",
        label: "Peak Throughput",
        disable: {
          hw: ["h100", "h200", "mi350x", "mi355x"]
        },
        disableReason: "The large-scale presets ride the MegaMoE a2a lane (SM100/SM103) — Blackwell only.",
        env: ["SGLANG_OPT_DEEPGEMM_MEGA_MOE_NUM_MAX_TOKENS_PER_RANK=20480"],
        flags: (v, b) => {
          const n = Number(v.lsGpus) || 32;
          const dp = n / 8;
          const gpusPerNode = ["gb200", "gb300"].includes(b.hw) ? 4 : 8;
          const nnodes = n / gpusPerNode;
          return [`--tp-size ${n}`, `--ep-size ${n}`, ...dp > 1 ? ["--enable-dp-attention", `--dp-size ${dp}`, "--enable-dp-lm-head"] : [], ...nnodes > 1 ? [`--nnodes ${nnodes}`, "--node-rank {{NODE_RANK}}", "--dist-init-addr {{NODE0_IP}}:20000"] : [], "--moe-a2a-backend megamoe", "--moe-runner-backend deep_gemm", "--kv-cache-dtype fp8_e4m3", "--mamba-ssm-dtype bfloat16", "--mamba-radix-cache-strategy extra_buffer_lazy", "--mem-fraction-static 0.92"];
        }
      }, {
        id: "capacity",
        label: "Peak Capacity (+DCP8)",
        disable: [{
          when: {
            hw: ["h100", "h200", "mi350x", "mi355x"]
          },
          reason: "The large-scale presets ride the MegaMoE a2a lane (SM100/SM103) — Blackwell only."
        }, {
          when: {
            hicache: ["l3"]
          },
          reason: "L3 storage keys are not dcp_rank-aware, so DCP and L3 cannot run together. Use Peak Throughput, or switch HiCache to L1+L2."
        }, {
          when: {
            hicache: ["l2"],
            spec: ["dspark"]
          },
          reason: "HiCache under DCP rejects speculative decoding, so this preset cannot add DCP here. Use Peak Throughput, or run the cell NOSPEC."
        }],
        env: ["SGLANG_OPT_DEEPGEMM_MEGA_MOE_NUM_MAX_TOKENS_PER_RANK=20480"],
        flags: (v, b) => {
          const n = Number(v.lsGpus) || 32;
          const dp = n / 8;
          const gpusPerNode = ["gb200", "gb300"].includes(b.hw) ? 4 : 8;
          const nnodes = n / gpusPerNode;
          return [`--tp-size ${n}`, `--ep-size ${n}`, ...dp > 1 ? ["--enable-dp-attention", `--dp-size ${dp}`, "--enable-dp-lm-head"] : [], "--dcp-size 8", ...nnodes > 1 ? [`--nnodes ${nnodes}`, "--node-rank {{NODE_RANK}}", "--dist-init-addr {{NODE0_IP}}:20000"] : [], "--moe-a2a-backend megamoe", "--moe-runner-backend deep_gemm", "--kv-cache-dtype fp8_e4m3", "--mamba-ssm-dtype bfloat16", "--mamba-radix-cache-strategy extra_buffer_lazy", "--mem-fraction-static 0.92"];
        }
      }]
    }]
  },
  cells: [{
    match: {
      hw: "b300",
      pdMode: "unified",
      strategy: "low-latency"
    },
    nnodes: 1,
    verified: false,
    verificationStatus: "in-progress",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--mem-fraction-static 0.85", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "b300",
      pdMode: "unified",
      strategy: "balanced"
    },
    nnodes: 1,
    verified: false,
    verificationStatus: "in-progress",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--dcp-size 8", "--mem-fraction-static 0.85", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "b300",
      pdMode: "unified",
      strategy: "high-throughput"
    },
    nnodes: 1,
    verified: false,
    verificationStatus: "in-progress",
    redirect: true,
    warn: "High-Throughput is the large-scale lane: pick a Cluster Size and a Large-Scale Preset in the [Playground](#playground) to compose the DP x EP command on top of this hardware's Balanced recipe.",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--dcp-size 8", "--disable-custom-all-reduce", "--mem-fraction-static 0.85", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "b200",
      pdMode: "unified",
      strategy: "low-latency"
    },
    nnodes: 2,
    specCollapsePp: true,
    verified: false,
    verificationStatus: "in-progress",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--pp-size 2", "--mem-fraction-static 0.85", "--disable-flashinfer-autotune", "--watchdog-timeout 3600", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--model-loader-extra-config '{\"enable_multithread_load\": true}'", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "b200",
      pdMode: "unified",
      strategy: "balanced"
    },
    nnodes: 2,
    specCollapsePp: true,
    verified: false,
    verificationStatus: "in-progress",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--pp-size 2", "--dcp-size 8", "--ep-size 8", "--moe-runner-backend flashinfer_mxfp4", "--decode-attention-backend cutedsl_mla", "--mem-fraction-static 0.85", "--chunked-prefill-size 8192", "--disable-flashinfer-autotune", "--watchdog-timeout 3600", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--model-loader-extra-config '{\"enable_multithread_load\": true}'", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "b200",
      pdMode: "unified",
      strategy: "high-throughput"
    },
    nnodes: 2,
    specCollapsePp: true,
    verified: false,
    verificationStatus: "in-progress",
    redirect: true,
    warn: "High-Throughput is the large-scale lane: pick a Cluster Size and a Large-Scale Preset in the [Playground](#playground) to compose the DP x EP command on top of this hardware's Balanced recipe.",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--pp-size 2", "--dcp-size 8", "--ep-size 8", "--moe-runner-backend flashinfer_mxfp4", "--decode-attention-backend cutedsl_mla", "--mem-fraction-static 0.85", "--chunked-prefill-size 8192", "--disable-flashinfer-autotune", "--watchdog-timeout 3600", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--model-loader-extra-config '{\"enable_multithread_load\": true}'", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "mi350x",
      pdMode: "unified",
      strategy: "balanced"
    },
    nnodes: 1,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_USE_AITER=1", "SGLANG_AITER_K3_OPT=1", "AITER_FLYDSL_FORCE=1", "AITER_SITUV2_A8W4=1"],
    flags: ["--model-path {{MODEL_NAME}}", "--trust-remote-code", "--tp-size 8", "--attention-backend triton", "--kv-cache-dtype fp8_e4m3", "--dtype bfloat16", "--mem-fraction-static 0.85", "--cuda-graph-max-bs 256", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "mi355x",
      pdMode: "unified",
      strategy: "balanced"
    },
    nnodes: 1,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_USE_AITER=1", "SGLANG_AITER_K3_OPT=1", "AITER_FLYDSL_FORCE=1", "AITER_SITUV2_A8W4=1"],
    flags: ["--model-path {{MODEL_NAME}}", "--trust-remote-code", "--tp-size 8", "--attention-backend triton", "--kv-cache-dtype fp8_e4m3", "--dtype bfloat16", "--mem-fraction-static 0.85", "--cuda-graph-max-bs 256", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "h100",
      pdMode: "unified",
      strategy: "low-latency"
    },
    nnodes: 4,
    verified: false,
    verificationStatus: "in-progress",
    env: ["NCCL_CUMEM_ENABLE=1", "PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True", "SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0", "SGLANG_K3_ATTN_RES_MODE=jit", "SGLANG_MOE_FUSED_GATE_RADIX=1", "SGLANG_HOST_IP={{LOCAL_IP}}", "NCCL_SOCKET_IFNAME={{NETWORK_IFACE}}", "GLOO_SOCKET_IFNAME={{NETWORK_IFACE}}"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 32", "--ep-size 32", "--moe-runner-backend marlin", "--decode-attention-backend flashmla", "--mem-fraction-static 0.85", "--dist-timeout 3600", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "h100",
      pdMode: "unified",
      strategy: "balanced"
    },
    nnodes: 4,
    verified: false,
    verificationStatus: "in-progress",
    env: ["NCCL_CUMEM_ENABLE=1", "PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True", "SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0", "SGLANG_K3_ATTN_RES_MODE=jit", "SGLANG_MOE_FUSED_GATE_RADIX=1", "SGLANG_HOST_IP={{LOCAL_IP}}", "NCCL_SOCKET_IFNAME={{NETWORK_IFACE}}", "GLOO_SOCKET_IFNAME={{NETWORK_IFACE}}"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 32", "--ep-size 32", "--moe-runner-backend marlin", "--decode-attention-backend flashmla", "--mem-fraction-static 0.85", "--dist-timeout 3600", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "h100",
      pdMode: "unified",
      strategy: "high-throughput"
    },
    nnodes: 4,
    verified: false,
    verificationStatus: "in-progress",
    env: ["NCCL_CUMEM_ENABLE=1", "PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True", "SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0", "SGLANG_K3_ATTN_RES_MODE=jit", "SGLANG_MOE_FUSED_GATE_RADIX=1", "SGLANG_HOST_IP={{LOCAL_IP}}", "NCCL_SOCKET_IFNAME={{NETWORK_IFACE}}", "GLOO_SOCKET_IFNAME={{NETWORK_IFACE}}"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 32", "--ep-size 32", "--moe-runner-backend marlin", "--decode-attention-backend flashmla", "--mem-fraction-static 0.85", "--mamba-radix-cache-strategy extra_buffer_lazy", "--dist-timeout 3600", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "h200",
      pdMode: "unified",
      strategy: "low-latency"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: ["NCCL_MNNVL_ENABLE=1", "NCCL_CUMEM_ENABLE=1", "SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 16", "--ep-size 16", "--moe-runner-backend marlin", "--decode-attention-backend flashmla", "--enable-symm-mem", "--mem-fraction-static 0.85", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "h200",
      pdMode: "unified",
      strategy: "balanced"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: ["NCCL_MNNVL_ENABLE=1", "NCCL_CUMEM_ENABLE=1", "SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 16", "--ep-size 16", "--moe-runner-backend marlin", "--decode-attention-backend flashmla", "--enable-symm-mem", "--mem-fraction-static 0.85", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "h200",
      pdMode: "unified",
      strategy: "high-throughput"
    },
    nnodes: 4,
    verified: false,
    verificationStatus: "in-progress",
    env: ["NCCL_MNNVL_ENABLE=1", "NCCL_CUMEM_ENABLE=1", "PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True", "SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0", "SGLANG_K3_ATTN_RES_MODE=jit", "SGLANG_MOE_FUSED_GATE_RADIX=1", "SGLANG_HOST_IP={{LOCAL_IP}}", "NCCL_SOCKET_IFNAME={{NETWORK_IFACE}}", "GLOO_SOCKET_IFNAME={{NETWORK_IFACE}}"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 32", "--ep-size 32", "--moe-runner-backend marlin", "--decode-attention-backend flashmla", "--enable-symm-mem", "--mem-fraction-static 0.90", "--mamba-radix-cache-strategy extra_buffer_lazy", "--dist-timeout 3600", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb300",
      pdMode: "unified",
      strategy: "low-latency"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--mem-fraction-static 0.85", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb300",
      pdMode: "unified",
      strategy: "balanced"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--dcp-size 8", "--mem-fraction-static 0.85", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb300",
      pdMode: "unified",
      strategy: "high-throughput"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    redirect: true,
    warn: "High-Throughput is the large-scale lane: pick a Cluster Size and a Large-Scale Preset in the [Playground](#playground) to compose the DP x EP command on top of this hardware's Balanced recipe.",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--dcp-size 8", "--mem-fraction-static 0.85", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb200",
      pdMode: "unified",
      strategy: "low-latency"
    },
    nnodes: 4,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 16", "--mem-fraction-static 0.85", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb200",
      pdMode: "unified",
      strategy: "balanced"
    },
    nnodes: 4,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 16", "--dcp-size 16", "--mem-fraction-static 0.85", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb200",
      pdMode: "unified",
      strategy: "high-throughput"
    },
    nnodes: 4,
    verified: false,
    verificationStatus: "in-progress",
    redirect: true,
    warn: "High-Throughput is the large-scale lane: pick a Cluster Size and a Large-Scale Preset in the [Playground](#playground) to compose the DP x EP command on top of this hardware's Balanced recipe.",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 16", "--dcp-size 16", "--mem-fraction-static 0.85", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "b300",
      pdMode: "prefill",
      strategy: "default"
    },
    nnodes: 1,
    verified: false,
    verificationStatus: "in-progress",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--disable-custom-all-reduce", "--enable-symm-mem", "--mem-fraction-static 0.85", "--chunked-prefill-size 16384", "--max-prefill-tokens 16384", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode prefill", "--disaggregation-transfer-backend nixl", "--disaggregation-bootstrap-port 8998", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "b300",
      pdMode: "prefill",
      strategy: "long-context"
    },
    nnodes: 1,
    verified: false,
    verificationStatus: "in-progress",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 1", "--pp-size 8", "--disable-custom-all-reduce", "--mem-fraction-static 0.90", "--chunked-prefill-size 16384", "--max-prefill-tokens 16384", "--disable-flashinfer-autotune", "--weight-loader-prefetch-checkpoints", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode prefill", "--disaggregation-transfer-backend nixl", "--disaggregation-bootstrap-port 8998", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb300",
      pdMode: "prefill",
      strategy: "default"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--mem-fraction-static 0.85", "--chunked-prefill-size 16384", "--max-prefill-tokens 16384", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode prefill", "--disaggregation-transfer-backend nixl", "--disaggregation-bootstrap-port 8998", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb300",
      pdMode: "prefill",
      strategy: "long-context"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 1", "--pp-size 8", "--mem-fraction-static 0.90", "--chunked-prefill-size 16384", "--max-prefill-tokens 16384", "--disable-flashinfer-autotune", "--weight-loader-prefetch-checkpoints", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode prefill", "--disaggregation-transfer-backend nixl", "--disaggregation-bootstrap-port 8998", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb200",
      pdMode: "prefill",
      strategy: "default"
    },
    nnodes: 4,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 1", "--pp-size 16", "--mem-fraction-static 0.85", "--chunked-prefill-size 16384", "--max-prefill-tokens 16384", "--disable-flashinfer-autotune", "--weight-loader-prefetch-checkpoints", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode prefill", "--disaggregation-transfer-backend nixl", "--disaggregation-bootstrap-port 8998", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb200",
      pdMode: "prefill",
      strategy: "long-context"
    },
    nnodes: 4,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 1", "--pp-size 16", "--mem-fraction-static 0.90", "--chunked-prefill-size 16384", "--max-prefill-tokens 16384", "--disable-flashinfer-autotune", "--weight-loader-prefetch-checkpoints", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode prefill", "--disaggregation-transfer-backend nixl", "--disaggregation-bootstrap-port 8998", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "b200",
      pdMode: "prefill",
      strategy: "default"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 1", "--pp-size 16", "--mem-fraction-static 0.85", "--chunked-prefill-size 16384", "--max-prefill-tokens 16384", "--disable-flashinfer-autotune", "--weight-loader-prefetch-checkpoints", "--watchdog-timeout 3600", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--model-loader-extra-config '{\"enable_multithread_load\": true}'", "--disaggregation-mode prefill", "--disaggregation-transfer-backend nixl", "--disaggregation-bootstrap-port 8998", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "b200",
      pdMode: "prefill",
      strategy: "long-context"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 1", "--pp-size 16", "--mem-fraction-static 0.90", "--chunked-prefill-size 16384", "--max-prefill-tokens 16384", "--disable-flashinfer-autotune", "--weight-loader-prefetch-checkpoints", "--watchdog-timeout 3600", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--model-loader-extra-config '{\"enable_multithread_load\": true}'", "--disaggregation-mode prefill", "--disaggregation-transfer-backend nixl", "--disaggregation-bootstrap-port 8998", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "b300",
      pdMode: "decode",
      strategy: "balanced"
    },
    nnodes: 1,
    verified: false,
    verificationStatus: "in-progress",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--dcp-size 8", "--disable-custom-all-reduce", "--mem-fraction-static 0.85", "--disaggregation-decode-extra-slots 16", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "b300",
      pdMode: "decode",
      strategy: "low-latency"
    },
    nnodes: 1,
    verified: false,
    verificationStatus: "in-progress",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--disable-custom-all-reduce", "--enable-symm-mem", "--mem-fraction-static 0.85", "--disaggregation-decode-extra-slots 16", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "b300",
      pdMode: "decode",
      strategy: "high-throughput"
    },
    nnodes: 1,
    verified: false,
    verificationStatus: "in-progress",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--dcp-size 8", "--disable-custom-all-reduce", "--mem-fraction-static 0.92", "--disaggregation-decode-extra-slots 16", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "b200",
      pdMode: "decode",
      strategy: "low-latency"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 16", "--mem-fraction-static 0.85", "--disaggregation-decode-extra-slots 16", "--disable-flashinfer-autotune", "--watchdog-timeout 3600", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--model-loader-extra-config '{\"enable_multithread_load\": true}'", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "b200",
      pdMode: "decode",
      strategy: "balanced"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 16", "--dcp-size 16", "--mem-fraction-static 0.85", "--disaggregation-decode-extra-slots 16", "--disable-flashinfer-autotune", "--watchdog-timeout 3600", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--model-loader-extra-config '{\"enable_multithread_load\": true}'", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "b200",
      pdMode: "decode",
      strategy: "high-throughput"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: [],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 16", "--dcp-size 16", "--mem-fraction-static 0.92", "--disaggregation-decode-extra-slots 16", "--disable-flashinfer-autotune", "--watchdog-timeout 3600", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--model-loader-extra-config '{\"enable_multithread_load\": true}'", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "mi350x",
      pdMode: "decode",
      strategy: "balanced"
    },
    nnodes: 1,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_USE_AITER=1", "SGLANG_AITER_K3_OPT=1", "AITER_FLYDSL_FORCE=1", "AITER_SITUV2_A8W4=1"],
    flags: ["--model-path {{MODEL_NAME}}", "--trust-remote-code", "--tp-size 8", "--attention-backend triton", "--kv-cache-dtype fp8_e4m3", "--dtype bfloat16", "--mem-fraction-static 0.85", "--cuda-graph-max-bs 256", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "mi355x",
      pdMode: "decode",
      strategy: "balanced"
    },
    nnodes: 1,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_USE_AITER=1", "SGLANG_AITER_K3_OPT=1", "AITER_FLYDSL_FORCE=1", "AITER_SITUV2_A8W4=1"],
    flags: ["--model-path {{MODEL_NAME}}", "--trust-remote-code", "--tp-size 8", "--attention-backend triton", "--kv-cache-dtype fp8_e4m3", "--dtype bfloat16", "--mem-fraction-static 0.85", "--cuda-graph-max-bs 256", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "h100",
      pdMode: "decode",
      strategy: "low-latency"
    },
    nnodes: 4,
    verified: false,
    verificationStatus: "in-progress",
    env: ["NCCL_CUMEM_ENABLE=1", "PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True", "SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0", "SGLANG_K3_ATTN_RES_MODE=jit", "SGLANG_MOE_FUSED_GATE_RADIX=1", "SGLANG_HOST_IP={{LOCAL_IP}}", "NCCL_SOCKET_IFNAME={{NETWORK_IFACE}}", "GLOO_SOCKET_IFNAME={{NETWORK_IFACE}}"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 32", "--ep-size 32", "--moe-runner-backend marlin", "--decode-attention-backend flashmla", "--mem-fraction-static 0.85", "--dist-timeout 3600", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "h100",
      pdMode: "decode",
      strategy: "balanced"
    },
    nnodes: 4,
    verified: false,
    verificationStatus: "in-progress",
    env: ["NCCL_CUMEM_ENABLE=1", "PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True", "SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0", "SGLANG_K3_ATTN_RES_MODE=jit", "SGLANG_MOE_FUSED_GATE_RADIX=1", "SGLANG_HOST_IP={{LOCAL_IP}}", "NCCL_SOCKET_IFNAME={{NETWORK_IFACE}}", "GLOO_SOCKET_IFNAME={{NETWORK_IFACE}}"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 32", "--ep-size 32", "--moe-runner-backend marlin", "--decode-attention-backend flashmla", "--mem-fraction-static 0.85", "--dist-timeout 3600", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "h100",
      pdMode: "decode",
      strategy: "high-throughput"
    },
    nnodes: 4,
    verified: false,
    verificationStatus: "in-progress",
    env: ["NCCL_CUMEM_ENABLE=1", "PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True", "SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0", "SGLANG_K3_ATTN_RES_MODE=jit", "SGLANG_MOE_FUSED_GATE_RADIX=1", "SGLANG_HOST_IP={{LOCAL_IP}}", "NCCL_SOCKET_IFNAME={{NETWORK_IFACE}}", "GLOO_SOCKET_IFNAME={{NETWORK_IFACE}}"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 32", "--ep-size 32", "--moe-runner-backend marlin", "--decode-attention-backend flashmla", "--mem-fraction-static 0.85", "--dist-timeout 3600", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "h200",
      pdMode: "decode",
      strategy: "low-latency"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: ["NCCL_MNNVL_ENABLE=1", "NCCL_CUMEM_ENABLE=1", "SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 16", "--ep-size 16", "--moe-runner-backend marlin", "--decode-attention-backend flashmla", "--enable-symm-mem", "--mem-fraction-static 0.85", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "h200",
      pdMode: "decode",
      strategy: "balanced"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: ["NCCL_MNNVL_ENABLE=1", "NCCL_CUMEM_ENABLE=1", "SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 16", "--ep-size 16", "--moe-runner-backend marlin", "--decode-attention-backend flashmla", "--enable-symm-mem", "--mem-fraction-static 0.85", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "h200",
      pdMode: "decode",
      strategy: "high-throughput"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: ["NCCL_MNNVL_ENABLE=1", "NCCL_CUMEM_ENABLE=1", "SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 16", "--ep-size 16", "--moe-runner-backend marlin", "--decode-attention-backend flashmla", "--enable-symm-mem", "--mem-fraction-static 0.90", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb300",
      pdMode: "decode",
      strategy: "low-latency"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--mem-fraction-static 0.85", "--disaggregation-decode-extra-slots 16", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb300",
      pdMode: "decode",
      strategy: "balanced"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--dcp-size 8", "--mem-fraction-static 0.85", "--disaggregation-decode-extra-slots 16", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb300",
      pdMode: "decode",
      strategy: "high-throughput"
    },
    nnodes: 2,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--dcp-size 8", "--mem-fraction-static 0.92", "--disaggregation-decode-extra-slots 16", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb200",
      pdMode: "decode",
      strategy: "low-latency"
    },
    nnodes: 4,
    verified: false,
    verificationStatus: "in-progress",
    warn: "SGLang requires `decode pp_size == prefill pp_size or 1`, so this cell must be paired with a PP2 x TP8 prefill (`--tp-size 8 --pp-size 2`) rather than the PP16 x TP1 Prefill recipe. That prefill delivers 2919 prefill tok/s/GPU against PP16's 4550, which is the trade for the decode-side latency.",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 8", "--pp-size 2", "--mem-fraction-static 0.85", "--disaggregation-decode-extra-slots 16", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb200",
      pdMode: "decode",
      strategy: "balanced"
    },
    nnodes: 4,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 16", "--dcp-size 16", "--ep-size 16", "--mem-fraction-static 0.85", "--disaggregation-decode-extra-slots 16", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }, {
    match: {
      hw: "gb200",
      pdMode: "decode",
      strategy: "high-throughput"
    },
    nnodes: 4,
    verified: false,
    verificationStatus: "in-progress",
    env: ["SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0"],
    flags: ["--trust-remote-code", "--model-path {{MODEL_NAME}}", "--tp-size 16", "--dcp-size 8", "--dp-size 2", "--enable-dp-attention", "--ep-size 16", "--mem-fraction-static 0.85", "--disaggregation-decode-extra-slots 16", "--reasoning-parser kimi_k3", "--tool-call-parser kimi_k3", "--disaggregation-mode decode", "--disaggregation-transfer-backend nixl", "--host {{HOST_IP}}", "--port {{PORT}}"]
  }],
  multiNodeHints: {
    b200: ["Unified with Spec Decode off runs TP8 within a node and PP2 across the two (+DCP8/EP8 on Balanced and High-Throughput); with DSPARK (pp_size == 1) it runs TP16 across both nodes instead.", "Prefill is TP1 × PP16 — one pipeline stage per GPU, non-speculative only. Decode is flat TP16 (+DCP16 on Balanced and High-Throughput).", "Multi-node K3 needs the cross-node NIC pinned on BOTH ranks:", "  GLOO_SOCKET_IFNAME=<your-nic>   # bootstrap interface", "  NCCL_SOCKET_IFNAME=<your-nic>   # force NCCL off kube-ipvs0", "  SGLANG_HOST_IP=<this-node-ip>", "  NCCL_IB_HCA=<hca0,hca1,...>     # RDMA fabrics only"],
    gb200: ["Allocate all four nodes within a single NVL72 domain.", "MNNVL is off by default — set on every rank:", "  NCCL_MNNVL_ENABLE=1", "  NCCL_CUMEM_ENABLE=1", "Point the JIT caches at GB200-only paths; GB200 is SM100 and GB300 is SM103,", "so the two architectures need separate caches:", "  TORCH_EXTENSIONS_DIR / TRITON_CACHE_DIR / TVM_FFI_CACHE_DIR"],
    h100: ["Set This node IP separately on each node; use the same cross-node NIC name on all four nodes."],
    h200: ["Low-Latency and Balanced run TP16/EP16 across 2 nodes; Unified High-Throughput widens to TP32/EP32 across 4.", "Multi-node K3 needs the cross-node NIC pinned on EVERY node:", "  GLOO_SOCKET_IFNAME=<your-nic>   # e.g. bond0", "  NCCL_SOCKET_IFNAME=<your-nic>   # force NCCL off kube-ipvs0", "  SGLANG_HOST_IP=<this-node-ip>"]
  }
};

export const Deployment = ({config, benchmarks}) => {
  if (!config) {
    return <div style={{
      padding: 12,
      color: "#b91c1c"
    }}>Deployment: missing <code>config</code> prop</div>;
  }
  const HARDWARE_CATALOG = {
    blackwell: [{
      id: "b300",
      label: "B300",
      vram: "288GB"
    }, {
      id: "gb300",
      label: "GB300",
      vram: "288GB"
    }, {
      id: "b200",
      label: "B200",
      vram: "192GB"
    }, {
      id: "gb200",
      label: "GB200",
      vram: "192GB"
    }, {
      id: "dgx-spark",
      label: "DGX Spark",
      vram: "128GB",
      multiNodeDockerFlags: ["--ulimit memlock=-1:-1", "--cap-add IPC_LOCK", "--device /dev/infiniband"]
    }],
    hopper: [{
      id: "h200",
      label: "H200",
      vram: "141GB"
    }, {
      id: "h100",
      label: "H100",
      vram: "80GB"
    }, {
      id: "h20-3e",
      label: "H20-3e",
      vram: "141GB"
    }, {
      id: "h800",
      label: "H800",
      vram: "80GB"
    }],
    amd: [{
      id: "mi300x",
      label: "MI300X",
      vram: "192GB"
    }, {
      id: "mi325x",
      label: "MI325X",
      vram: "256GB"
    }, {
      id: "mi350x",
      label: "MI350X",
      vram: "288GB"
    }, {
      id: "mi355x",
      label: "MI355X",
      vram: "288GB"
    }]
  };
  const makeStyles = isDark => ({
    container: {
      maxWidth: "900px",
      margin: "0 auto",
      display: "flex",
      flexDirection: "column",
      gap: "3px"
    },
    card: {
      padding: "5px 10px",
      border: `1px solid ${isDark ? "#374151" : "#e5e7eb"}`,
      borderLeft: `3px solid ${isDark ? "#E85D4D" : "#D45D44"}`,
      borderRadius: "4px",
      display: "flex",
      alignItems: "center",
      gap: "10px",
      background: isDark ? "#1f2937" : "#fff"
    },
    cardColumn: {
      padding: "5px 10px",
      border: `1px solid ${isDark ? "#374151" : "#e5e7eb"}`,
      borderLeft: `3px solid ${isDark ? "#E85D4D" : "#D45D44"}`,
      borderRadius: "4px",
      display: "flex",
      flexDirection: "column",
      gap: "4px",
      background: isDark ? "#1f2937" : "#fff"
    },
    title: {
      fontSize: "12px",
      fontWeight: "600",
      minWidth: "108px",
      flexShrink: 0,
      color: isDark ? "#e5e7eb" : "inherit"
    },
    vendorRow: {
      display: "flex",
      alignItems: "center",
      gap: "6px"
    },
    vendorLabel: {
      fontSize: "10px",
      fontWeight: "600",
      color: isDark ? "#9ca3af" : "#6b7280",
      width: "68px",
      flexShrink: 0,
      textTransform: "uppercase",
      letterSpacing: "0.04em"
    },
    itemsGrid: () => ({
      display: "grid",
      gridTemplateColumns: "repeat(auto-fit, minmax(72px, 1fr))",
      gap: "4px",
      flex: 1
    }),
    labelBase: {
      padding: "2px 8px",
      border: `1px solid ${isDark ? "#9ca3af" : "#d1d5db"}`,
      borderRadius: "3px",
      cursor: "pointer",
      display: "inline-flex",
      flexDirection: "column",
      alignItems: "center",
      justifyContent: "center",
      fontWeight: "500",
      fontSize: "12px",
      transition: "all 0.2s",
      userSelect: "none",
      minHeight: "26px",
      textAlign: "center",
      background: isDark ? "#374151" : "#fff",
      color: isDark ? "#e5e7eb" : "inherit"
    },
    checked: {
      background: "#D45D44",
      color: "white",
      borderColor: "#D45D44"
    },
    disabled: {
      cursor: "not-allowed",
      opacity: 0.4
    },
    subtitle: {
      display: "block",
      fontSize: "9px",
      marginTop: "1px",
      lineHeight: "1.1",
      opacity: 0.7
    },
    commandWrap: {
      position: "relative",
      flex: 1,
      background: isDark ? "#111827" : "#f5f5f5",
      borderRadius: "6px",
      border: `1px solid ${isDark ? "#374151" : "#e5e7eb"}`,
      overflow: "hidden"
    },
    commandHeader: {
      display: "flex",
      flexWrap: "wrap",
      justifyContent: "space-between",
      alignItems: "center",
      gap: "6px 10px",
      padding: "6px 10px",
      borderBottom: `1px solid ${isDark ? "#374151" : "#e5e7eb"}`,
      background: isDark ? "#1f2937" : "#fafafa"
    },
    commandPre: {
      padding: "12px 16px",
      fontFamily: "'Menlo', 'Monaco', 'Courier New', monospace",
      fontSize: "12px",
      lineHeight: "1.5",
      color: isDark ? "#e5e7eb" : "#374151",
      whiteSpace: "pre-wrap",
      overflowX: "auto",
      margin: 0
    },
    mtpWarn: {
      margin: "8px 0 0",
      padding: "8px 12px",
      borderRadius: "8px",
      fontSize: "12px",
      lineHeight: "1.45",
      background: isDark ? "#78350f" : "#fef3c7",
      color: isDark ? "#fde68a" : "#92400e",
      border: `1px solid ${isDark ? "#92400e" : "#fcd34d"}`
    },
    badge: status => ({
      display: "inline-flex",
      alignItems: "center",
      gap: "6px",
      padding: "2px 8px",
      borderRadius: "10px",
      background: ({
        verified: isDark ? "#064e3b" : "#d1fae5",
        "in-progress": isDark ? "#1e3a8a" : "#dbeafe",
        unverified: isDark ? "#78350f" : "#fef3c7"
      })[verifyStatusOf(status)],
      color: ({
        verified: isDark ? "#a7f3d0" : "#065f46",
        "in-progress": isDark ? "#bfdbfe" : "#1e40af",
        unverified: isDark ? "#fde68a" : "#92400e"
      })[verifyStatusOf(status)],
      fontSize: "11px",
      fontWeight: 600,
      whiteSpace: "nowrap"
    }),
    badgeDot: status => ({
      width: "8px",
      height: "8px",
      borderRadius: "50%",
      background: ({
        verified: "#10b981",
        "in-progress": "#3b82f6",
        unverified: "#f59e0b"
      })[verifyStatusOf(status)]
    }),
    iconButton: {
      padding: "4px 10px",
      border: `1px solid ${isDark ? "#4b5563" : "#d1d5db"}`,
      borderRadius: "4px",
      background: isDark ? "#1f2937" : "#fff",
      color: isDark ? "#e5e7eb" : "#374151",
      fontSize: "11px",
      fontWeight: 500,
      cursor: "pointer",
      display: "inline-flex",
      alignItems: "center",
      gap: "4px"
    },
    iconRow: {
      display: "inline-flex",
      flexWrap: "wrap",
      gap: "6px"
    },
    runModeWrap: {
      display: "inline-flex",
      border: `1px solid ${isDark ? "#4b5563" : "#d1d5db"}`,
      borderRadius: "10px",
      overflow: "hidden",
      fontSize: "11px",
      fontWeight: 600,
      userSelect: "none"
    },
    runModeChip: active => ({
      padding: "2px 10px",
      cursor: "pointer",
      background: active ? isDark ? "#1f2937" : "#fff" : "transparent",
      color: active ? isDark ? "#e5e7eb" : "#111827" : isDark ? "#9ca3af" : "#6b7280",
      borderRight: `1px solid ${isDark ? "#4b5563" : "#d1d5db"}`
    }),
    runModeChipLast: active => ({
      padding: "2px 10px",
      cursor: "pointer",
      background: active ? isDark ? "#1f2937" : "#fff" : "transparent",
      color: active ? isDark ? "#e5e7eb" : "#111827" : isDark ? "#9ca3af" : "#6b7280"
    }),
    headerLeft: {
      display: "inline-flex",
      flexWrap: "wrap",
      alignItems: "center",
      gap: "8px"
    },
    modalBackdrop: {
      position: "fixed",
      inset: 0,
      background: "rgba(0,0,0,0.5)",
      display: "flex",
      alignItems: "center",
      justifyContent: "center",
      zIndex: 9999
    },
    modalBox: {
      background: isDark ? "#1f2937" : "#fff",
      color: isDark ? "#e5e7eb" : "#111827",
      borderRadius: "8px",
      padding: "20px",
      maxWidth: "720px",
      width: "92%",
      maxHeight: "85vh",
      overflowY: "auto",
      border: `1px solid ${isDark ? "#374151" : "#e5e7eb"}`,
      boxShadow: "0 10px 25px rgba(0,0,0,0.25)"
    },
    modalHeader: {
      display: "flex",
      justifyContent: "space-between",
      alignItems: "center",
      marginBottom: "12px"
    },
    modalTitle: {
      fontSize: "15px",
      fontWeight: 600
    },
    modalCloseBtn: {
      background: "transparent",
      border: "none",
      color: "inherit",
      fontSize: "20px",
      cursor: "pointer",
      padding: "0 6px",
      lineHeight: 1
    },
    formField: {
      display: "flex",
      flexDirection: "column",
      gap: "4px",
      marginBottom: "10px"
    },
    formLabel: {
      fontSize: "12px",
      fontWeight: 500,
      color: isDark ? "#9ca3af" : "#4b5563"
    },
    formInput: {
      padding: "6px 10px",
      fontSize: "13px",
      border: `1px solid ${isDark ? "#4b5563" : "#d1d5db"}`,
      borderRadius: "4px",
      background: isDark ? "#111827" : "#fff",
      color: isDark ? "#e5e7eb" : "#111827",
      fontFamily: "'Menlo', 'Monaco', 'Courier New', monospace"
    },
    sectionHeading: {
      fontSize: "12px",
      fontWeight: 600,
      textTransform: "uppercase",
      letterSpacing: "0.04em",
      color: isDark ? "#9ca3af" : "#6b7280",
      margin: "12px 0 6px 0"
    },
    primaryBtn: {
      padding: "6px 14px",
      background: "#D45D44",
      color: "white",
      border: "none",
      borderRadius: "4px",
      cursor: "pointer",
      fontSize: "13px",
      fontWeight: 500
    },
    benchCard: {
      padding: "8px 12px",
      border: `1px solid ${isDark ? "#374151" : "#e5e7eb"}`,
      borderLeft: `3px solid ${isDark ? "#E85D4D" : "#D45D44"}`,
      borderRadius: "4px",
      background: isDark ? "#1f2937" : "#fff",
      display: "flex",
      flexDirection: "column",
      gap: "8px"
    },
    benchHeader: {
      display: "flex",
      flexWrap: "wrap",
      alignItems: "baseline",
      justifyContent: "space-between",
      gap: "6px 12px"
    },
    benchTitle: {
      fontSize: "13px",
      fontWeight: 600,
      color: isDark ? "#e5e7eb" : "inherit"
    },
    benchVersion: {
      fontSize: "11px",
      color: isDark ? "#9ca3af" : "#6b7280"
    },
    benchHeaderRight: {
      display: "flex",
      flexWrap: "wrap",
      alignItems: "center",
      gap: "6px 10px",
      flexShrink: 0
    },
    benchChipRow: {
      display: "flex",
      alignItems: "center",
      gap: "6px",
      flexWrap: "wrap",
      margin: "2px 0 8px"
    },
    benchChip: {
      padding: "2px 10px",
      fontSize: "12px",
      cursor: "pointer",
      border: `1px solid ${isDark ? "#4b5563" : "#d1d5db"}`,
      borderRadius: "4px",
      background: isDark ? "#1f2937" : "#fff",
      color: isDark ? "#e5e7eb" : "#374151",
      fontFamily: "'Menlo', 'Monaco', 'Courier New', monospace"
    },
    benchChipActive: {
      background: "#D45D44",
      color: "white",
      borderColor: "#D45D44"
    },
    benchBlock: {
      border: `1px solid ${isDark ? "#374151" : "#e5e7eb"}`,
      borderRadius: "4px",
      padding: "8px 10px",
      background: isDark ? "#111827" : "#fafafa"
    },
    benchBlockTitle: {
      fontSize: "11px",
      fontWeight: 600,
      textTransform: "uppercase",
      letterSpacing: "0.04em",
      color: isDark ? "#9ca3af" : "#6b7280",
      marginBottom: "4px"
    },
    benchWorkload: {
      fontSize: "11px",
      fontStyle: "italic",
      color: isDark ? "#9ca3af" : "#6b7280",
      marginBottom: "6px",
      lineHeight: "1.3"
    },
    benchRow: {
      display: "flex",
      justifyContent: "space-between",
      fontSize: "12px",
      padding: "2px 0"
    },
    benchKey: {
      color: isDark ? "#9ca3af" : "#6b7280"
    },
    benchVal: {
      color: isDark ? "#e5e7eb" : "#111827",
      fontFamily: "'Menlo', 'Monaco', 'Courier New', monospace",
      fontWeight: 500
    },
    benchNotes: {
      fontSize: "11px",
      fontStyle: "italic",
      color: isDark ? "#9ca3af" : "#6b7280"
    },
    benchLegend: {
      fontSize: "10px",
      fontStyle: "italic",
      color: isDark ? "#6b7280" : "#9ca3af",
      marginTop: "6px",
      fontFamily: "'Menlo', 'Monaco', 'Courier New', monospace"
    },
    benchEmpty: {
      fontSize: "12px",
      fontStyle: "italic",
      color: isDark ? "#9ca3af" : "#6b7280"
    },
    benchTable: {
      display: "grid",
      columnGap: 0,
      rowGap: "3px",
      marginTop: "4px",
      alignItems: "baseline"
    },
    benchTableHead: {
      textAlign: "right",
      fontWeight: 500,
      fontSize: "11px",
      color: isDark ? "#9ca3af" : "#6b7280",
      paddingLeft: "16px",
      paddingBottom: "4px",
      whiteSpace: "nowrap"
    },
    benchTableCornerHead: {
      paddingBottom: "4px"
    },
    benchTableSeparator: {
      gridColumn: "1 / -1",
      height: "1px",
      background: isDark ? "#374151" : "#e5e7eb",
      marginTop: "-3px"
    },
    benchTableLabel: {
      textAlign: "left",
      fontSize: "12px",
      color: isDark ? "#9ca3af" : "#6b7280",
      whiteSpace: "nowrap"
    },
    benchTableValue: {
      textAlign: "right",
      fontSize: "12px",
      color: isDark ? "#e5e7eb" : "#111827",
      fontFamily: "'Menlo', 'Monaco', 'Courier New', monospace",
      fontWeight: 500,
      paddingLeft: "16px",
      whiteSpace: "nowrap"
    },
    benchTableValueMissing: {
      color: isDark ? "#6b7280" : "#9ca3af"
    }
  });
  const VERIFY_LABEL = {
    verified: "Verified",
    "in-progress": "Final Verification In Progress",
    unverified: "Not Verified"
  };
  const verifyStatusOf = v => typeof v === "string" ? VERIFY_LABEL[v] ? v : "unverified" : v ? "verified" : "unverified";
  const cellVerifyStatus = c => c ? verifyStatusOf(c.verificationStatus ?? c.verified) : "unverified";
  const LEGACY_MATCH_DIMS = [{
    id: "variant",
    title: "Model Variant",
    optionsKey: "variants"
  }, {
    id: "quant",
    title: "Quantization",
    optionsKey: "quantizations"
  }, {
    id: "strategy",
    title: "Strategy",
    optionsKey: "strategies"
  }, {
    id: "nodes",
    title: "Nodes",
    optionsKey: "nodesOptions"
  }];
  const matchDimSpecs = (config.matchDims || LEGACY_MATCH_DIMS).map(d => ({
    ...d,
    options: d.options || config[d.optionsKey] || []
  }));
  const overlayDimSpecs = config.overlayDims || [];
  const DIMENSIONS = ["hw", ...matchDimSpecs.map(d => d.id)];
  const optionVisible = (opt, sel) => typeof opt.showWhen !== "function" || opt.showWhen(sel);
  const optionDisabled = (opt, sel) => typeof opt.disabled === "function" ? opt.disabled(sel) : !!opt.disabled;
  const visibleOptions = (spec, sel) => (spec.options || []).filter(o => optionVisible(o, sel));
  const rowVisible = (spec, sel) => (typeof spec.showWhen !== "function" || spec.showWhen(sel)) && visibleOptions(spec, sel).length > 0;
  const overlayPick = sel => {
    const picked = [];
    for (const spec of config.overlayDims || []) {
      if (!rowVisible(spec, sel)) continue;
      const opt = (spec.options || []).find(o => o.id === sel[spec.id]);
      if (opt && !optionDisabled(opt, sel)) picked.push(opt);
    }
    return picked;
  };
  const overlayPart = (sel, key) => {
    const out = [];
    for (const opt of overlayPick(sel)) {
      const add = typeof opt[key] === "function" ? opt[key](sel) : opt[key];
      if (add) out.push(...add);
    }
    return out;
  };
  const overlayCompose = (cellFlags, sel) => {
    const strip = overlayPart(sel, "stripPrefixes");
    const add = overlayPart(sel, "flags");
    if (!strip.length) return [...cellFlags || [], ...add];
    const used = new Set();
    const replacementsFor = tok => {
      const out = [];
      add.forEach((f, i) => {
        if (used.has(i) || f.split(/[\s=]/)[0] !== tok) return;
        used.add(i);
        out.push(f);
      });
      return out;
    };
    const out = [];
    for (const f of cellFlags || []) {
      const tok = f.split(/[\s=]/)[0];
      if (!strip.includes(tok)) out.push(f); else out.push(...replacementsFor(tok));
    }
    add.forEach((f, i) => {
      if (!used.has(i)) out.push(f);
    });
    return out;
  };
  const findCell = (cells, sel) => cells.find(c => DIMENSIONS.every(d => c.match[d] === sel[d]));
  const findBenchmark = (list, sel) => (list || []).find(b => DIMENSIONS.every(d => b.match[d] === sel[d])) || null;
  const normalizeSpeed = speed => {
    if (!speed) return [];
    return Array.isArray(speed) ? speed : [speed];
  };
  const effectiveAccuracy = (entry, sel) => entry ? {
    ...config.defaultAccuracy && config.defaultAccuracy[sel.variant] || ({}),
    ...entry.accuracy || ({})
  } : {};
  const benchmarkIsEmpty = (entry, accuracy) => {
    for (const m of normalizeSpeed(entry && entry.speed)) {
      if (m && typeof m === "object") {
        for (const [key, v] of Object.entries(m)) {
          if (key === "workload") continue;
          if (v !== null && v !== undefined) return false;
        }
      }
    }
    if (accuracy && typeof accuracy === "object") {
      for (const v of Object.values(accuracy)) {
        if (v !== null && v !== undefined) return false;
      }
    }
    return true;
  };
  const isOptionAvailable = (cells, sel, dim, value) => {
    const idx = DIMENSIONS.indexOf(dim);
    const higher = DIMENSIONS.slice(0, idx);
    return cells.some(c => c.match[dim] === value && higher.every(d => c.match[d] === sel[d]));
  };
  const snapToValidCell = (cells, sel, dim, value) => {
    const idx = DIMENSIONS.indexOf(dim);
    const higher = DIMENSIONS.slice(0, idx);
    const lower = DIMENSIONS.slice(idx + 1);
    let best = null, bestLowerMatches = -1;
    for (const c of cells) {
      if (c.match[dim] !== value) continue;
      if (!higher.every(d => c.match[d] === sel[d])) continue;
      let s = 0;
      for (const d of lower) if (c.match[d] === sel[d]) s++;
      if (s > bestLowerMatches) {
        bestLowerMatches = s;
        best = c;
      }
    }
    if (!best) return sel;
    const next = {
      ...sel,
      [dim]: value
    };
    for (const d of lower) next[d] = best.match[d];
    return next;
  };
  const validateSelection = (cells, parsed) => {
    const valid = {};
    for (const dim of DIMENSIONS) {
      const want = parsed[dim];
      const works = cells.some(c => c.match[dim] === want && DIMENSIONS.slice(0, DIMENSIONS.indexOf(dim)).every(d => c.match[d] === valid[d]));
      if (works) {
        valid[dim] = want;
      } else {
        const fallback = cells.find(c => DIMENSIONS.slice(0, DIMENSIONS.indexOf(dim)).every(d => c.match[d] === valid[d]));
        valid[dim] = fallback ? fallback.match[dim] : want;
      }
    }
    for (const spec of overlayDimSpecs) {
      const want = parsed[spec.id];
      const opts = spec.options || [];
      valid[spec.id] = opts.some(o => o.id === want) ? want : (spec.default ?? (opts[0] && opts[0].id)) ?? "";
    }
    return valid;
  };
  const resolveModelName = sel => {
    const keys = [`${sel.hw}|${sel.variant}|${sel.quant}`, `${sel.variant}|${sel.quant}`, `${sel.hw}|${sel.quant}`, sel.quant, sel.hw, "default"];
    for (const k of keys) {
      const hit = config.modelNames[k];
      if (hit) return hit;
    }
    return "";
  };
  const interpolate = (text, env, modelName) => text.replace(/{{(\w+)}}/g, (_, key) => key === "MODEL_NAME" ? modelName : env[key] ?? `{{${key}}}`);
  const parseNnodes = id => {
    if (id === "single") return 1;
    const m = (/^multi-(\d+)$/).exec(id || "");
    return m ? parseInt(m[1], 10) : 1;
  };
  const cellNnodes = (cell, sel) => sel.nodes !== undefined ? parseNnodes(sel.nodes) : cell.nnodes || 1;
  const PD_SERVE_PORTS = {
    prefill: 30000,
    decode: 30100
  };
  const overlayEnv = sel => overlayPart(sel, "env");
  const overlayHints = sel => overlayPart(sel, "hints");
  const renderCommand = (cell, sel, envValues, mode = "python") => {
    if (!cell) return "# No command available for the current selection.";
    const modelName = resolveModelName(sel);
    const nnodes = cellNnodes(cell, sel);
    const multinode = nnodes > 1;
    const cellEnv = [...cell.env || [], ...overlayEnv(sel)];
    const flags = overlayCompose(cell.flags, sel);
    if (multinode) {
      const PARALLELISM_ANCHORS = ["--enable-dp-attention", "--dp", "--tp-size", "--tp"];
      let i = -1;
      for (const anchor of PARALLELISM_ANCHORS) {
        i = flags.findIndex(f => f.split(/[\s=]/)[0] === anchor);
        if (i !== -1) break;
      }
      if (i === -1) i = flags.findIndex(f => f.startsWith("--model-path"));
      flags.splice(i + 1, 0, `--nnodes ${nnodes}`, `--node-rank {{NODE_RANK}}`, `--dist-init-addr {{NODE0_IP}}:20000`);
    }
    const pdServePort = PD_SERVE_PORTS[sel.pdMode];
    if (pdServePort !== undefined) {
      for (let j = 0; j < flags.length; j++) {
        if (flags[j].split(/[\s=]/)[0] === "--port") {
          flags[j] = `--port ${pdServePort}`;
        }
      }
    }
    let cmd;
    if (mode === "docker") {
      const di = config.dockerImages || ({});
      const image = di[`${sel.hw}|${sel.quant}|${sel.strategy}`] || di[`${sel.hw}|${sel.quant}`] || di[sel.hw] || "lmsysorg/sglang:dev";
      const dockerRunCommand = typeof config.dockerRunCommand === "function" ? config.dockerRunCommand(sel) : config.dockerRunCommand || "sglang serve";
      const portFlag = flags.find(x => x.split(/[\s=]/)[0] === "--port");
      const servePort = portFlag ? portFlag.slice(("--port").length).trim() : "{{PORT}}";
      const hostNetwork = multinode || typeof config.dockerHostNetworkWhen === "function" && config.dockerHostNetworkWhen(sel, {
        flags,
        env: cellEnv
      });
      const vendorOf = hwId => {
        for (const [vendor, list] of Object.entries(HARDWARE_CATALOG)) {
          if (list.some(h => h.id === hwId)) return vendor;
        }
        const extra = (config.hardware || []).find(h => h.id === hwId);
        return extra && extra.vendor || "nvidia";
      };
      const fabricFlagsOf = hwId => {
        const extra = (config.hardware || []).find(h => h.id === hwId);
        if (extra) return extra.multiNodeDockerFlags || [];
        for (const list of Object.values(HARDWARE_CATALOG)) {
          const hit = list.find(h => h.id === hwId);
          if (hit) return hit.multiNodeDockerFlags || [];
        }
        return [];
      };
      const gpuAccessLines = vendorOf(sel.hw) === "amd" ? ["docker run", "  --device=/dev/kfd --device=/dev/dri", "  --group-add video", "  --cap-add=SYS_PTRACE --security-opt seccomp=unconfined", "  --shm-size 32g"] : ["docker run --gpus all", "  --shm-size 32g"];
      const dockerLines = [...gpuAccessLines, hostNetwork ? "  --network host" : `  -p ${servePort}:${servePort}`, ...multinode ? fabricFlagsOf(sel.hw).map(f => "  " + f) : [], "  -v ~/.cache/huggingface:/root/.cache/huggingface", ...(config.dockerMounts || []).map(mount => `  -v ${mount}`), ...config.placeholders && config.placeholders.HF_TOKEN ? [`  --env "HF_TOKEN={{HF_TOKEN}}"`] : [], ...cellEnv.map(e => `  --env ${e}`), "  --ipc=host", `  ${image}`, `  ${dockerRunCommand}`, ...flags.map(f => "    " + f)];
      cmd = dockerLines.join(" \\\n");
    } else {
      const flagBlock = flags.map(f => "  " + f).join(" \\\n");
      const envBlock = cellEnv.length ? cellEnv.join(" \\\n") + " \\\n" : "";
      cmd = `${envBlock}sglang serve \\\n${flagBlock}`;
    }
    const hintLines = [...overlayHints(sel), ...multinode && config.multiNodeHints && config.multiNodeHints[sel.hw] ? config.multiNodeHints[sel.hw] : []];
    if (hintLines.length) {
      const hint = hintLines.map(line => line.length ? "# " + line : "#").join("\n");
      cmd = `${hint}\n${cmd}`;
    }
    cmd = interpolate(cmd, envValues, modelName);
    if (multinode) {
      const header = `# Multi-node (${nnodes} nodes). Run the same command on every node with:\n` + `#   <node-rank> = 0 on the head node, 1..${nnodes - 1} on the others\n` + `#   <node0-ip>  = IP of the head node (reachable from all others)`;
      cmd = `${header}\n${cmd}`;
    }
    return cmd;
  };
  const ACCURACY_LABELS = config.accuracyLabels || [];
  const renderBenchmarkCard = entry => {
    const pct = entry && entry.latencyPercentile || config.latencyPercentile || "P50";
    const SPEED_LABELS = [["ttft_ms", `TTFT (${pct})`, "ms"], ["tpot_ms", `TPOT (${pct})`, "ms"], ["tokens_per_sec_per_gpu", "throughput per gpu", "tok/s"], ["interactivity", "interactivity", "tokens/s/user", m => m.tpot_ms != null && m.tpot_ms !== 0 ? Math.round(1000 / m.tpot_ms * 10) / 10 : null]];
    const WORKLOAD_KEYS = ["dataset", "isl", "osl", "max_concurrency"];
    const fmt = (val, unit) => {
      if (val === null || val === undefined) return null;
      return `${val}${unit ? " " + unit : ""}`;
    };
    const formatWorkloadParts = (workload, keys) => {
      if (!workload) return "";
      const parts = [];
      if (keys.has("dataset") && workload.dataset) parts.push(workload.dataset);
      if (keys.has("isl") || keys.has("osl")) {
        if (workload.isl != null || workload.osl != null) {
          parts.push(`in/out=${workload.isl != null ? workload.isl : "?"}/${workload.osl != null ? workload.osl : "?"}`);
        }
      }
      if (keys.has("max_concurrency") && workload.max_concurrency != null) {
        parts.push(`max-concurrency=${workload.max_concurrency}`);
      }
      return parts.join(", ");
    };
    const ALWAYS_PER_COLUMN = new Set(["max_concurrency"]);
    const partitionWorkload = measurements => {
      const shared = new Set();
      const differing = new Set();
      for (const k of WORKLOAD_KEYS) {
        const seen = new Set();
        let anyPresent = false;
        for (const m of measurements) {
          const v = m && m.workload ? m.workload[k] : undefined;
          if (v != null) anyPresent = true;
          seen.add(v);
        }
        if (!anyPresent) continue;
        if (ALWAYS_PER_COLUMN.has(k) || seen.size > 1) differing.add(k); else shared.add(k);
      }
      return {
        shared,
        differing
      };
    };
    const renderBenchTable = ({title, sharedText, colHeaders, rows, colCount, legend}) => {
      if (rows.length === 0) return null;
      const showColHeaders = colHeaders.length > 0 && colHeaders.some(h => h !== "");
      return <div style={s.benchBlock}>
          <div style={s.benchBlockTitle}>{title}</div>
          {sharedText && <div style={s.benchWorkload}>{sharedText}</div>}
          <div style={{
        ...s.benchTable,
        gridTemplateColumns: `max-content repeat(${colCount}, minmax(0, 1fr))`
      }}>
            {showColHeaders && <div key="corner" style={s.benchTableCornerHead}></div>}
            {showColHeaders && colHeaders.map((h, i) => <div key={`hdr-${i}`} style={s.benchTableHead}>{h}</div>)}
            {showColHeaders && <div key="sep" style={s.benchTableSeparator}></div>}
            {rows.map(r => [<div key={`lbl-${r.label}`} style={s.benchTableLabel}>{r.label}</div>, ...r.values.map((v, i) => <div key={`val-${r.label}-${i}`} style={v === null ? {
        ...s.benchTableValue,
        ...s.benchTableValueMissing
      } : s.benchTableValue}>
                  {v !== null ? v : "—"}
                </div>)])}
          </div>
          {legend && <div style={s.benchLegend}>
              {(Array.isArray(legend) ? legend : [legend]).map((line, i) => <div key={`legend-${i}`}>{line}</div>)}
            </div>}
        </div>;
    };
    const buildSpeedTable = measurements => {
      if (measurements.length === 0) return null;
      const {shared, differing} = partitionWorkload(measurements);
      const sharedText = formatWorkloadParts(measurements[0] && measurements[0].workload, shared);
      const colHeaders = measurements.map(m => formatWorkloadParts(m && m.workload, differing));
      const rows = SPEED_LABELS.map(tup => {
        const [key, label, unit, compute] = tup;
        const values = measurements.map(m => {
          const raw = compute ? compute(m) : m[key];
          return fmt(raw, unit);
        });
        return {
          label,
          values
        };
      });
      return {
        title: "Speed",
        sharedText,
        colHeaders,
        rows,
        colCount: measurements.length,
        legend: [`throughput per gpu = (input+output tokens)/elapsed/GPU`, `interactivity = 1000/TPOT(ms) (tokens/s/user)`]
      };
    };
    const buildAccuracyTable = accuracy => {
      if (!accuracy) return null;
      const rows = ACCURACY_LABELS.map(([key, label, unit]) => {
        const v = fmt(accuracy[key], unit);
        if (v === null) return null;
        return {
          label,
          values: [v]
        };
      }).filter(r => r !== null);
      if (rows.length === 0) return null;
      return {
        title: "Accuracy",
        sharedText: null,
        colHeaders: [],
        rows,
        colCount: 1
      };
    };
    const accuracy = effectiveAccuracy(entry, sel);
    const isEmpty = benchmarkIsEmpty(entry, accuracy);
    const measurements = !isEmpty ? normalizeSpeed(entry && entry.speed) : [];
    const accuracyTable = !isEmpty ? buildAccuracyTable(accuracy) : null;
    const speedTable = !isEmpty ? buildSpeedTable(measurements) : null;
    const hasBenchCmds = !isEmpty && buildBenchCommands(entry, sel) !== null;
    return <div style={s.benchCard}>
        <div style={s.benchHeader}>
          <div style={s.benchTitle}>Benchmark</div>
          <div style={s.benchHeaderRight}>
            {!isEmpty && entry && entry.sglang_version && <div style={s.benchVersion}>measured on sglang <code>{entry.sglang_version}</code></div>}
            {hasBenchCmds && <button style={s.iconButton} onClick={() => setModal("bench")}>⚡ Reproduce</button>}
          </div>
        </div>
        {isEmpty ? <div style={s.benchEmpty}>
            Benchmark data pending for this combination — submit yours via the Playground's Submit ↗ button.
          </div> : <>
            {accuracyTable && renderBenchTable(accuracyTable)}
            {speedTable && renderBenchTable(speedTable)}
            {entry && entry.notes && <div style={s.benchNotes}>{entry.notes}</div>}
          </>}
      </div>;
  };
  const buildBenchCommands = (entry, sel) => {
    const bc = config.benchmarkCommands;
    if (!bc) return null;
    const acc = effectiveAccuracy(entry, sel);
    const accuracy = [];
    if (bc.accuracy) {
      for (const [key, label] of ACCURACY_LABELS) {
        if (acc[key] == null) continue;
        const tmpl = bc.accuracy[key];
        const resolved = typeof tmpl === "string" ? tmpl : tmpl && tmpl[sel.variant] || null;
        if (resolved) accuracy.push({
          key,
          label,
          template: resolved
        });
      }
    }
    let speed = null;
    if (bc.speed && entry) {
      const ms = normalizeSpeed(entry.speed).filter(m => m && m.workload && m.workload.max_concurrency != null);
      const concurrencies = [...new Set(ms.map(m => m.workload.max_concurrency))].sort((a, b) => a - b);
      if (concurrencies.length) {
        speed = {
          template: bc.speed,
          concurrencies,
          workload: ms[0].workload,
          numPromptsOf: c => {
            const m = ms.find(x => x.workload.max_concurrency === c);
            if (m && m.workload.num_prompts != null) return m.workload.num_prompts;
            const tbl = bc.numPromptsByConc;
            if (tbl && tbl[c] != null) return tbl[c];
            return Math.max(c * 2, 200);
          }
        };
      }
    }
    if (accuracy.length === 0 && !speed) return null;
    return {
      accuracy,
      speed
    };
  };
  const buildHardwareGroups = () => {
    const supported = new Set(config.supportedHardware);
    const catalog = {};
    for (const [vendor, list] of Object.entries(HARDWARE_CATALOG)) catalog[vendor] = [...list];
    for (const hw of config.hardware || []) {
      const vendor = hw.vendor || "nvidia";
      const list = catalog[vendor] || (catalog[vendor] = []);
      const entry = {
        id: hw.id,
        label: hw.label,
        vram: hw.vram
      };
      const i = list.findIndex(x => x.id === hw.id);
      if (i >= 0) list[i] = entry; else list.push(entry);
    }
    const groups = [];
    for (const [vendor, list] of Object.entries(catalog)) {
      const items = list.filter(hw => supported.has(hw.id)).map(hw => ({
        id: hw.id,
        label: hw.label,
        subtitle: hw.vram
      }));
      if (items.length) groups.push({
        label: vendor.toUpperCase(),
        items
      });
    }
    if (config.groupHardware === false) {
      return [{
        label: null,
        items: groups.flatMap(group => group.items)
      }];
    }
    return groups;
  };
  const initialSelectionFromCells = () => {
    const first = config.cells[0];
    const sel = Object.fromEntries(DIMENSIONS.map(d => [d, first ? first.match[d] : ""]));
    for (const spec of overlayDimSpecs) {
      const opts = spec.options || [];
      sel[spec.id] = (spec.default ?? (opts[0] && opts[0].id)) ?? "";
    }
    return sel;
  };
  const placeholderDefaults = schema => {
    const out = {};
    for (const [k, v] of Object.entries(schema || ({}))) out[k] = v.default ?? "";
    return out;
  };
  const [isDark, setIsDark] = useState(false);
  useEffect(() => {
    const check = () => {
      const html = document.documentElement;
      setIsDark(html.classList.contains("dark") || html.getAttribute("data-theme") === "dark" || html.style.colorScheme === "dark");
    };
    check();
    const observer = new MutationObserver(check);
    observer.observe(document.documentElement, {
      attributes: true,
      attributeFilter: ["class", "data-theme", "style"]
    });
    return () => observer.disconnect();
  }, []);
  const STORAGE_KEY = "sglang-deploy-env";
  const [env, setEnv] = useState(() => placeholderDefaults(config.placeholders));
  useEffect(() => {
    try {
      const raw = window.localStorage.getItem(STORAGE_KEY);
      if (raw) {
        const parsed = JSON.parse(raw);
        setEnv({
          ...placeholderDefaults(config.placeholders),
          ...parsed
        });
      }
    } catch {}
  }, []);
  const saveEnv = next => {
    setEnv(next);
    try {
      window.localStorage.setItem(STORAGE_KEY, JSON.stringify(next));
    } catch {}
  };
  const [sel, setSel] = useState(() => initialSelectionFromCells());
  const INTERNAL_HASH_STATE_KEY = "__sglangDeployInternalHash";
  const DEPLOYMENT_COMPONENT_ID = "deployment-configurator";
  useEffect(() => {
    const hydrate = () => {
      const raw = window.location.hash.replace(/^#/, "");
      if (!raw) return;
      const params = new URLSearchParams(raw);
      const initial = initialSelectionFromCells();
      const parsed = {
        ...initial
      };
      let touched = false;
      params.forEach((value, key) => {
        if ((key in parsed)) {
          parsed[key] = value;
          touched = true;
        }
      });
      if (!touched) return;
      setSel(validateSelection(config.cells, parsed));
      const historyState = window.history.state;
      const isInternalHash = historyState && typeof historyState === "object" && historyState[INTERNAL_HASH_STATE_KEY] === `#${raw}`;
      if (isInternalHash) return;
      const el = document.getElementById(DEPLOYMENT_COMPONENT_ID);
      if (el) el.scrollIntoView({
        behavior: "smooth",
        block: "start"
      });
    };
    hydrate();
    window.addEventListener("hashchange", hydrate);
    return () => window.removeEventListener("hashchange", hydrate);
  }, []);
  useEffect(() => {
    const target = "#" + new URLSearchParams(sel).toString();
    if (window.location.hash !== target) {
      const historyState = window.history.state && typeof window.history.state === "object" ? window.history.state : {};
      window.history.replaceState({
        ...historyState,
        [INTERNAL_HASH_STATE_KEY]: target
      }, "", target);
    }
    window.dispatchEvent(new CustomEvent("sglang-deploy-sel", {
      detail: sel
    }));
  }, [sel]);
  const [modal, setModal] = useState(null);
  useEffect(() => {
    if (modal === null) return;
    const onKey = e => {
      if (e.key === "Escape") setModal(null);
    };
    const prev = document.body.style.overflow;
    document.body.style.overflow = "hidden";
    window.addEventListener("keydown", onKey);
    return () => {
      window.removeEventListener("keydown", onKey);
      document.body.style.overflow = prev;
    };
  }, [modal]);
  const [copied, setCopied] = useState(false);
  const [curlCopied, setCurlCopied] = useState(false);
  const [envDraft, setEnvDraft] = useState(env);
  const [benchConc, setBenchConc] = useState(null);
  const [benchAcc, setBenchAcc] = useState(null);
  const [benchCopied, setBenchCopied] = useState(null);
  const configuredRunModes = typeof config.runModes === "function" ? config.runModes(sel) : config.runModes;
  const runModes = configuredRunModes || ["python", "docker"];
  const [runMode, setRunMode] = useState(runModes[0]);
  const hasRunMode = runModes.includes(runMode);
  const fallbackRunMode = runModes[0];
  const activeRunMode = hasRunMode ? runMode : fallbackRunMode;
  useEffect(() => {
    if (!hasRunMode) setRunMode(fallbackRunMode);
  }, [hasRunMode, fallbackRunMode]);
  useEffect(() => {
    if (modal === "env") setEnvDraft(env);
  }, [modal, env]);
  const [mambaRatio, setMambaRatio] = useState(null);
  useEffect(() => {
    const onRatio = e => setMambaRatio(e.detail && (e.detail.baseRatio || e.detail.ratio) || null);
    window.addEventListener("sglang-k3-mamba-ratio", onRatio);
    return () => window.removeEventListener("sglang-k3-mamba-ratio", onRatio);
  }, []);
  const s = makeStyles(isDark);
  const cell = findCell(config.cells, sel);
  const verifyStatus = cellVerifyStatus(cell);
  const cellWithRatio = (() => {
    if (!cell || !mambaRatio) return cell;
    if (cell.flags.some(f => f.startsWith("--mamba-full-memory-ratio"))) return cell;
    const flags = [...cell.flags];
    const line = `--mamba-full-memory-ratio ${mambaRatio}`;
    const i = flags.findIndex(f => f.startsWith("--host"));
    if (i >= 0) flags.splice(i, 0, line); else flags.push(line);
    return {
      ...cell,
      flags
    };
  })();
  const command = renderCommand(cellWithRatio, sel, env, activeRunMode);
  const effFlags = cell ? overlayCompose(cell.flags, sel) : [];
  const specAlgoFlag = effFlags.find(f => f.split(/[\s=]/)[0] === "--speculative-algorithm");
  const specMrrFlag = effFlags.find(f => f.split(/[\s=]/)[0] === "--max-running-requests");
  const mtpHint = !!specAlgoFlag && !specMrrFlag;
  const specPinnedHint = !!specAlgoFlag && !!specMrrFlag;
  const specMrrValue = specMrrFlag ? specMrrFlag.split(/[\s=]/).filter(Boolean)[1] || "" : "";
  const SPEC_ALGO_LABEL = {
    EAGLE: "MTP",
    EAGLE3: "MTP",
    FROZEN_KV_MTP: "MTP",
    DSPARK: "DSpark",
    DFLASH: "DFlash",
    NGRAM: "N-gram",
    STANDALONE: "standalone draft"
  };
  const specAlgoName = (() => {
    if (!specAlgoFlag) return "MTP";
    const v = specAlgoFlag.split(/[\s=]/).filter(Boolean)[1] || "";
    return SPEC_ALGO_LABEL[v.toUpperCase()] || v || "MTP";
  })();
  const renderWarn = text => {
    const out = [];
    const re = /\[([^\]]+)\]\(#([^)]+)\)/g;
    let last = 0;
    for (let m; m = re.exec(text); last = m.index + m[0].length) {
      if (m.index > last) out.push(text.slice(last, m.index));
      const anchor = m[2];
      out.push(<button key={m.index} type="button" onClick={() => {
        const el = document.getElementById(anchor);
        if (el) el.scrollIntoView({
          behavior: "smooth",
          block: "start"
        });
      }} style={{
        background: "transparent",
        border: "none",
        padding: 0,
        color: isDark ? "#FDBA74" : "#C2410C",
        cursor: "pointer",
        font: "inherit",
        fontWeight: 600,
        textDecoration: "underline",
        textUnderlineOffset: "2px"
      }}>
          {m[1]}
        </button>);
    }
    if (last < text.length) out.push(text.slice(last));
    return out;
  };
  const modelName = resolveModelName(sel);
  const curlTemplate = typeof config.curl === "function" ? config.curl(sel, cell) : config.curl;
  const curlText = interpolate(curlTemplate || "", env, modelName);
  const hwGroups = buildHardwareGroups();
  const benchEntry = benchmarks ? findBenchmark(benchmarks, sel) : null;
  const isOverlayDim = dim => overlayDimSpecs.some(d => d.id === dim);
  const findOption = (dim, value) => {
    const spec = [...matchDimSpecs, ...overlayDimSpecs].find(d => d.id === dim);
    return spec && (spec.options || []).find(o => o.id === value);
  };
  const isEnabled = (dim, value) => {
    const opt = findOption(dim, value);
    if (opt && optionDisabled(opt, sel)) return false;
    return isOverlayDim(dim) || isOptionAvailable(config.cells, sel, dim, value);
  };
  const reseatHiddenPicks = next => {
    let out = next;
    for (const spec of [...matchDimSpecs, ...overlayDimSpecs]) {
      const opts = visibleOptions(spec, out).filter(o => !optionDisabled(o, out));
      if (!opts.length) continue;
      if (!opts.some(o => o.id === out[spec.id])) {
        out = {
          ...out,
          [spec.id]: opts[0].id
        };
      }
    }
    return out;
  };
  const handleSelect = (dim, value) => {
    setSel(prev => reseatHiddenPicks(isOverlayDim(dim) ? {
      ...prev,
      [dim]: value
    } : snapToValidCell(config.cells, prev, dim, value)));
  };
  const handleCopy = () => {
    navigator.clipboard.writeText(command);
    setCopied(true);
    setTimeout(() => setCopied(false), 1200);
  };
  const copyCurl = () => {
    navigator.clipboard.writeText(curlText);
    setCurlCopied(true);
    setTimeout(() => setCurlCopied(false), 1200);
  };
  const copyBench = (key, text) => {
    navigator.clipboard.writeText(text);
    setBenchCopied(key);
    setTimeout(() => setBenchCopied(null), 1200);
  };
  const placeholderGroups = (() => {
    const out = {
      command: [],
      curl: []
    };
    for (const [key, meta] of Object.entries(config.placeholders || ({}))) {
      (out[meta.target] || (out[meta.target] = [])).push({
        key,
        ...meta
      });
    }
    return out;
  })();
  const renderButton = (item, dim, selectedId) => {
    const checked = selectedId === item.id;
    const disabled = !isEnabled(dim, item.id);
    return <label key={item.id} style={{
      ...s.labelBase,
      ...checked ? s.checked : {},
      ...disabled ? s.disabled : {}
    }} title={disabled ? item.disableReason || "Not supported for current selection" : ""} onClick={e => {
      if (disabled) {
        e.preventDefault();
        return;
      }
      handleSelect(dim, item.id);
    }}>
        <input type="radio" checked={checked} disabled={disabled} readOnly style={{
      display: "none"
    }} />
        <span>{item.label}</span>
        {item.subtitle && <small style={{
      ...s.subtitle,
      color: checked ? "rgba(255,255,255,0.85)" : "inherit"
    }}>
            {item.subtitle}
          </small>}
      </label>;
  };
  const renderFlatSection = (title, options, dim, selectedId) => <div style={s.card}>
      <div style={s.title}>{title}</div>
      <div style={s.itemsGrid(options.length)}>
        {options.map(item => renderButton(item, dim, selectedId))}
      </div>
    </div>;
  const maxHwCols = Math.max(...hwGroups.map(x => x.items.length));
  return <div id={DEPLOYMENT_COMPONENT_ID} style={{
    ...s.container,
    scrollMarginTop: "104px"
  }} className="not-prose">
      {}
      <div style={s.cardColumn}>
        <div style={{
    ...s.title,
    marginBottom: "2px"
  }}>Hardware Platform</div>
        {hwGroups.map(g => <div key={g.label || "hardware"} style={s.vendorRow}>
            {g.label && <div style={s.vendorLabel}>{g.label}</div>}
            <div style={s.itemsGrid(maxHwCols)}>
              {g.items.map(item => renderButton(item, "hw", sel.hw))}
              {Array.from({
    length: maxHwCols - g.items.length
  }).map((_, i) => <div key={`pad-${i}`} />)}
            </div>
          </div>)}
      </div>

      {matchDimSpecs.filter(d => rowVisible(d, sel)).map(d => <div key={d.id}>
            {renderFlatSection(d.title, visibleOptions(d, sel), d.id, sel[d.id])}
          </div>)}
      {overlayDimSpecs.filter(d => rowVisible(d, sel)).map(d => <div key={d.id}>
            {renderFlatSection(d.title, visibleOptions(d, sel), d.id, sel[d.id])}
          </div>)}

      {}
      <div style={s.card}>
        <div style={s.title}>Command:</div>
        <div style={s.commandWrap}>
          {cell && cell.redirect ? cell.warn && <div style={s.mtpWarn}>⚠️ {renderWarn(cell.warn)}</div> : <>
            <div style={s.commandHeader}>
              <div style={s.headerLeft}>
                <div style={s.badge(verifyStatus)}>
                  <span style={s.badgeDot(verifyStatus)} />
                  {VERIFY_LABEL[verifyStatus]}
                </div>
                <div style={s.runModeWrap} role="tablist" aria-label="Output format">
                  {runModes.map((mode, index) => <span key={mode} style={{
    ...index === runModes.length - 1 ? s.runModeChipLast(activeRunMode === mode) : s.runModeChip(activeRunMode === mode),
    ...runModes.length === 1 ? {
      borderRadius: 7
    } : {}
  }} onClick={() => setRunMode(mode)} role="tab" aria-selected={activeRunMode === mode}>
                      {mode === "docker" ? "Docker" : "Python"}
                    </span>)}
                </div>
              </div>
              <div style={s.iconRow}>
                <button style={s.iconButton} onClick={handleCopy}>
                  {copied ? "✓ Copied" : "⧉ Copy"}
                </button>
                <button style={s.iconButton} onClick={() => setModal("curl")}>$ cURL</button>
                <button style={s.iconButton} onClick={() => setModal("env")}>⚙ Env</button>
              </div>
            </div>
            <pre style={s.commandPre}>{command}</pre>
            {cell && cell.warn && <div style={s.mtpWarn}>⚠️ {renderWarn(cell.warn)}</div>}
            {mtpHint && <div style={s.mtpWarn}>
                ⚠️ Speculative decoding ({specAlgoName}) is on — SGLang resets <code>--max-running-requests</code> to <strong>48</strong> when it isn't set. Add <code>--max-running-requests &lt;N&gt;</code> sized for your target concurrency.
              </div>}
            {specPinnedHint && <div style={s.mtpWarn}>
                ℹ️ Speculative decoding ({specAlgoName}) is on and this recipe pins <code>--max-running-requests</code> to <strong>{specMrrValue}</strong>. Adjust it to match your target concurrency — if you remove the flag, SGLang falls back to <strong>48</strong>.
              </div>}
          </>}
        </div>
      </div>

      {}
      {benchmarks && cell && renderBenchmarkCard(benchEntry)}

      {}
      {config.showPlaygroundLink !== false && <div style={{
    padding: "6px 12px",
    fontSize: "12px",
    color: isDark ? "#9ca3af" : "#6b7280",
    display: "flex",
    alignItems: "center",
    gap: "6px"
  }}>
          <span>Need to go beyond the verified matrix?</span>
          <button type="button" onClick={() => {
    const el = document.getElementById("playground");
    if (el) el.scrollIntoView({
      behavior: "smooth",
      block: "start"
    });
  }} style={{
    background: "transparent",
    border: "none",
    padding: 0,
    color: isDark ? "#FDBA74" : "#C2410C",
    cursor: "pointer",
    fontSize: "12px",
    fontWeight: 600,
    textDecoration: "underline",
    textUnderlineOffset: "2px"
  }}>
            Open the Playground →
          </button>
        </div>}

      {}
      {modal === "curl" && <div style={s.modalBackdrop} onClick={() => setModal(null)}>
          <div style={s.modalBox} onClick={e => e.stopPropagation()}>
            <div style={s.modalHeader}>
              <div style={s.modalTitle}>cURL example</div>
              <button style={s.modalCloseBtn} onClick={() => setModal(null)} aria-label="Close">×</button>
            </div>
            <div style={s.commandWrap}>
              <div style={s.commandHeader}>
                <div style={{
    fontSize: 11,
    opacity: 0.7
  }}>
                  Model: <code>{modelName || "(unresolved)"}</code>
                </div>
                <button style={s.iconButton} onClick={copyCurl}>
                  {curlCopied ? "✓ Copied" : "⧉ Copy"}
                </button>
              </div>
              <pre style={s.commandPre}>{curlText}</pre>
            </div>
            <p style={{
    fontSize: 11,
    opacity: 0.7,
    marginTop: 8
  }}>
              Edit <code>CURL_HOST</code> / <code>CURL_PORT</code> in the Env panel.
            </p>
          </div>
        </div>}

      {}
      {modal === "env" && <div style={s.modalBackdrop} onClick={() => setModal(null)}>
          <div style={s.modalBox} onClick={e => e.stopPropagation()}>
            <div style={s.modalHeader}>
              <div style={s.modalTitle}>Env / placeholder values</div>
              <button style={s.modalCloseBtn} onClick={() => setModal(null)} aria-label="Close">×</button>
            </div>
            {placeholderGroups.curl.length > 0 && <div>
                <div style={s.sectionHeading}>cURL placeholders</div>
                {placeholderGroups.curl.map(({key, label}) => <div key={key} style={s.formField}>
                    <label style={s.formLabel}>
                      {label} <code style={{
    opacity: 0.6
  }}>{`{{${key}}}`}</code>
                    </label>
                    <input style={s.formInput} value={envDraft[key] ?? ""} onChange={e => setEnvDraft({
    ...envDraft,
    [key]: e.target.value
  })} />
                  </div>)}
              </div>}
            {placeholderGroups.command.length > 0 && <div>
                <div style={s.sectionHeading}>Command placeholders</div>
                {placeholderGroups.command.map(({key, label}) => <div key={key} style={s.formField}>
                    <label style={s.formLabel}>
                      {label} <code style={{
    opacity: 0.6
  }}>{`{{${key}}}`}</code>
                    </label>
                    <input style={s.formInput} value={envDraft[key] ?? ""} onChange={e => setEnvDraft({
    ...envDraft,
    [key]: e.target.value
  })} />
                  </div>)}
              </div>}
            <div style={{
    display: "flex",
    justifyContent: "flex-end",
    gap: 8,
    marginTop: 16
  }}>
              <button style={{
    ...s.iconButton,
    padding: "6px 14px"
  }} onClick={() => setModal(null)}>Cancel</button>
              <button style={s.primaryBtn} onClick={() => {
    saveEnv(envDraft);
    setModal(null);
  }}>Save</button>
            </div>
            <p style={{
    fontSize: 11,
    opacity: 0.7,
    marginTop: 10
  }}>
              Values persist in localStorage and are reused the next time you visit any cookbook.
            </p>
          </div>
        </div>}

      {}
      {modal === "bench" && benchEntry && (() => {
    const bc = buildBenchCommands(benchEntry, sel);
    if (!bc) return null;
    const selSummary = `${sel.hw.toUpperCase()} · ${sel.variant} · ${sel.quant.toUpperCase()} · ${sel.strategy} · ${sel.nodes}`;
    let selConc = null;
    let speedCmd = null;
    if (bc.speed) {
      selConc = bc.speed.concurrencies.includes(benchConc) ? benchConc : bc.speed.concurrencies[0];
      const w = bc.speed.workload;
      speedCmd = interpolate(bc.speed.template, {
        ...env,
        DATASET: w.dataset,
        ISL: w.isl,
        OSL: w.osl,
        MAX_CONCURRENCY: selConc,
        NUM_PROMPTS: bc.speed.numPromptsOf(selConc)
      }, modelName);
    }
    let selAcc = null;
    let accCmd = null;
    if (bc.accuracy.length > 0) {
      selAcc = bc.accuracy.find(a => a.key === benchAcc) || bc.accuracy[0];
      accCmd = interpolate(selAcc.template, env, modelName);
    }
    return <div style={s.modalBackdrop} onClick={() => setModal(null)}>
            <div style={s.modalBox} onClick={e => e.stopPropagation()}>
              <div style={s.modalHeader}>
                <div style={s.modalTitle}>Benchmark commands</div>
                <button style={s.modalCloseBtn} onClick={() => setModal(null)} aria-label="Close">×</button>
              </div>
              <p style={{
      fontSize: 11,
      opacity: 0.7,
      margin: "0 0 12px"
    }}>
                For <code>{selSummary}</code>. Start the server with the Deploy command above, then run these against it.
              </p>

              {selAcc && <div>
                  <div style={s.sectionHeading}>Accuracy</div>
                  {bc.accuracy.length > 1 && <div style={s.benchChipRow}>
                      <span style={{
      fontSize: 11,
      opacity: 0.7
    }}>benchmark:</span>
                      {bc.accuracy.map(a => <button key={a.key} style={{
      ...s.benchChip,
      ...a.key === selAcc.key ? s.benchChipActive : {}
    }} onClick={() => setBenchAcc(a.key)}>
                          {a.label}
                        </button>)}
                    </div>}
                  <div style={{
      ...s.commandWrap,
      marginBottom: 6
    }}>
                    <div style={s.commandHeader}>
                      <div style={{
      fontSize: 11,
      opacity: 0.7
    }}>{selAcc.label}</div>
                      <button style={s.iconButton} onClick={() => copyBench("acc", accCmd)}>
                        {benchCopied === "acc" ? "✓ Copied" : "⧉ Copy"}
                      </button>
                    </div>
                    <pre style={s.commandPre}>{accCmd}</pre>
                  </div>
                  {bc.accuracy.length > 1 && <p style={{
      fontSize: 11,
      opacity: 0.7,
      margin: "0 0 4px"
    }}>
                      Switch the benchmark chip to see each eval's command.
                    </p>}
                </div>}

              {bc.speed && <div>
                  <div style={s.sectionHeading}>Speed</div>
                  {bc.speed.concurrencies.length > 1 && <div style={s.benchChipRow}>
                      <span style={{
      fontSize: 11,
      opacity: 0.7
    }}>max-concurrency:</span>
                      {bc.speed.concurrencies.map(c => <button key={c} style={{
      ...s.benchChip,
      ...c === selConc ? s.benchChipActive : {}
    }} onClick={() => setBenchConc(c)}>
                          {c}
                        </button>)}
                    </div>}
                  <div style={{
      ...s.commandWrap,
      marginBottom: 6
    }}>
                    <div style={s.commandHeader}>
                      <div style={{
      fontSize: 11,
      opacity: 0.7
    }}>max-concurrency = {selConc}</div>
                      <button style={s.iconButton} onClick={() => copyBench("speed", speedCmd)}>
                        {benchCopied === "speed" ? "✓ Copied" : "⧉ Copy"}
                      </button>
                    </div>
                    <pre style={s.commandPre}>{speedCmd}</pre>
                  </div>
                  <p style={{
      fontSize: 11,
      opacity: 0.7,
      margin: "0 0 4px"
    }}>
                    One command — switch the concurrency chip (or edit <code>--max-concurrency</code>) to reproduce each Speed column.
                  </p>
                </div>}

              <p style={{
      fontSize: 11,
      opacity: 0.7,
      marginTop: 12
    }}>
                Edit <code>CURL_HOST</code> / <code>CURL_PORT</code> in the Env panel.
              </p>
            </div>
          </div>;
  })()}
    </div>;
};

## Deployment

<a id="install" />

<Accordion title="Install SGLang">
  For all methods and hardware platforms, see the [official SGLang installation guide](../../../docs/get-started/install). The two paths below match the **Python / Docker** toggle in the command panel.

  <Tabs>
    <Tab title="Python (pip / uv)">
      ```bash Command theme={null}
      pip install --upgrade pip
      pip install uv
      uv pip install sglang
      ```

      Then run the **Python** output of the command panel below in that environment.
    </Tab>

    <Tab title="Docker">
      ```bash Command theme={null}
      docker pull lmsysorg/sglang:latest                                  # NVIDIA (CUDA)
      docker pull lmsysorg/sglang-rocm:v0.5.17-rocm720-mi35x-20260817     # AMD MI350X / MI355X (ROCm)
      ```

      For how to launch the image, see [Install → Method 3: Using Docker](../../../docs/get-started/install#method-3-using-docker). Substitute the inner `sglang serve ...` with what the command generator below produces.
    </Tab>
  </Tabs>
</Accordion>

Pick your hardware, then the deployment shape and operating point. Node count follows the hardware recipe (B200 2×8, GB200 4×4, H100 4×8, B300 1×8, H200 2×8 — 4×8 on Unified High-Throughput, GB300 2×4, MI350X/MI355X 1×8), so it is not a separate choice. If you serve the NVFP4 checkpoint (`nvidia/Kimi-K3-NVFP4`, the **Quantization** row in the panel below), use the `lmsysorg/sglang:dev-dev-kimi-k3-nvfp4` image.

**PD Mode** — `Unified` serves prefill and decode together. `Prefill` / `Decode` split them into dedicated pools (see [PD disaggregation](#3-4-pd-disaggregation)); `Prefill` ships two strategies, both chunked at 16k. On the 8-GPU platforms (B300 1×8, GB300 2×4), `Default` is TP8 and `Long-Context` is `--pp-size 8 --tp-size 1`. On the 16-GPU platforms (B200 2×8, GB200 4×4), both are `--pp-size 16 --tp-size 1` and differ only in `--mem-fraction-static` (0.85 vs 0.90) — deep PP is the throughput shape there, not just the long-context one (see [Deep PP](#deep-pp-for-prefill)).

**Strategy** — the operating point within that shape:

* **Low-Latency** — no DCP, so the MLA KV stays TP-replicated. For chat. B200 splits its two nodes into PP2 × TP8; every other platform is flat TP.
* **Balanced** — the accuracy-preserving default: PP2 × DCPEP8 on B200 (the two pipeline stages and DCP8 split KV and KDA state), TP16/DCP16 on GB200, TP8/DCP8 on B300/GB300, TP8 ROCm/AITER on MI35x.
* **High-Throughput** — the large-scale lane: pick a **Cluster Size** and **Large-Scale Preset** in the Playground ([details](#large-scale-presets)). The cell itself is Balanced, except on H100 (plus `extra_buffer_lazy`) and H200 (widens to 4×8 TP32/EP32 at `--mem-fraction-static 0.90`).

`Long-Context` appears only under the `Prefill` PD mode; for long-context unified serving on B200, start from High-Throughput and raise `--context-length`.

**Spec Decode** — layers onto the strategy without changing it, on every platform except B200. DSPARK proposes 7 draft tokens per step (tune in the Playground) and requires `pp_size == 1`, so on B200 it also drops the pipeline and re-lays the same 16 GPUs flat: PP2 × TP8 → TP16, PP2 × DCPEP8 → DCPEP16. DFLASH has no published draft checkpoint. The win is largest on short interactive traffic and fades as the prompt grows.

<Note>
  `--mamba-full-memory-ratio` is the one sizing flag, computed live: set your average request length in the [Mamba ratio calculator](#mamba-ratio-calculator); everything else follows the panels, and the result is pinned into the command.
</Note>

<Deployment config={config} benchmarks={benchmarks} />

### Mamba ratio calculator

<KimiK3MambaRatioCalculator />

<Accordion title="How --mamba-full-memory-ratio is calculated">
  `--mamba-full-memory-ratio` is the ratio between the KDA state pool and the MLA KV pool. Every parameter below except `L` is read live from the Deploy panel and Playground selection; the balanced value is the per-request cost ratio:

  ```text theme={null}
  ratio = (S + D) x state_bytes / (L x (mla_kv_bytes / DCP + draft_kv_bytes))
  ```

  * `S` — KDA state slots per request: `extra_buffer=5`, `extra_buffer_lazy=4`, `no_buffer=3`, disabled radix cache `=1`. `SGLANG_OPT_MAMBA_SKIP_DECODE_LOCK` frees one slot on the extra-buffer strategies; with the overlap scheduler off (or `pp > 1`, which disables it) the track buffer costs one slot instead of two.
  * `D` — verify intermediate states under speculative decoding: `0` when disabled, otherwise DSPARK block size + 1 (`8` at the default 7). ReplaySSM (`--enable-linear-replayssm-spec`) folds them into a per-slot ring, returning `D` to `0`.
  * `state_bytes` — one state slot's bytes, from K3's fixed geometry, the attention-TP width, and the SSM dtype.
  * `mla_kv_bytes` — one token's MLA latent KV bytes (KV-dtype dependent); DCP shards it across its ranks. The DSPARK draft model's KV (\~1.4 KB per token) is replicated on every rank, so it enters flat — negligible without DCP, the same order as the sharded MLA share under DCP8.
  * `L` — average total request length in tokens: input + output.
</Accordion>

<a id="playground" style={{ scrollMarginTop: "96px" }} />

## Advanced Features Playground

The Playground is where you experiment with **SGLang features beyond the deployment matrix**. The Deploy panel above emits the recipes the SGLang team is converging on; the Playground lets you turn on additional knobs on top of whichever cell the Deploy panel is currently showing.

<Playground config={config} />

## 1. Model Introduction

**Kimi-K3** is Moonshot AI's flagship hybrid MoE vision-language model: **2.8 trillion parameters**, **16 of 896 experts** active per token, roughly **2.5× the scaling efficiency of Kimi-K2**. The backbone interleaves **Kimi Delta Attention (KDA)** with MLA across 93 layers (plus Attention Residuals and Stable LatentMoE); serving supports image input and a **1M-token** window with prefix caching. Weights ship in **MXFP4**: the FlashInfer MXFP4 (trtllm-gen SiTU) runner serves them on Blackwell, Marlin (W4A16) elsewhere, MegaMoE for short-context batch throughput.

K3 **always runs with thinking enabled**, with reasoning depth controlled by `reasoning_effort` (`low` / `high` / `max`; default `max`).

<Note>
  Kimi-K3 is Moonshot AI's first open-source model in the trillion-plus class; **full model weights
  are scheduled to release by July 27, 2026**. The recipes on this page were validated on the public
  [`sgl-project/sglang` `kimi-k3` branch](https://github.com/sgl-project/sglang/tree/kimi-k3) — the HuggingFace
  repository (`moonshotai/Kimi-K3`) and a public `lmsysorg/sglang` image with K3 support will be
  available at launch.

  Every cell in the Deploy panel above is currently marked **Final Verification In Progress**: the
  recipe runs, but its serving round on the final weights and current code is still open. Re-measure
  throughput and accuracy before you rely on any of them.
</Note>

**Recommended generation:** `temperature=1.0`, `top_p=0.95`, `presence_penalty=0`, `frequency_penalty=0` (fixed by the model; informational — do not hardcode in sample code).

**Resources:** [HuggingFace](https://huggingface.co/moonshotai/Kimi-K3) · [Kimi-K3 Quickstart](https://platform.kimi.ai/docs/guide/kimi-k3-quickstart).

## 2. Configuration Tips

**Memory: two pools, one flag.** K3 splits static memory into a worst-case-reserved **KDA state pool** (it sets the concurrency ceiling) and a paged **MLA KV pool**, divided by `--mamba-full-memory-ratio`. The command panel pins that flag to the [calculator](#mamba-ratio-calculator)'s output — set your average request length there; every other calculator input follows the panels. After boot, read back `max_total_num_tokens` (the KV side) and the admitted-request cap (the state side).

Capacity levers, all in the Playground. Each trades precision or cache behavior for capacity — re-verify accuracy on your workload:

| Lever                                            | Effect                                                                                          |
| ------------------------------------------------ | ----------------------------------------------------------------------------------------------- |
| `--mamba-radix-cache-strategy extra_buffer_lazy` | 4 state slots per request instead of 5                                                          |
| `--mamba-ssm-dtype bfloat16`                     | \~halves state bytes; with spec on, KDA verification falls back from the fused kernel to Triton |
| `--kv-cache-dtype fp8_e4m3`                      | halves KV bytes per token; under PD both roles must match at connect                            |
| `--mem-fraction-static` 0.90–0.92                | cheapest first win when the boot log shows a large idle `avail mem`                             |
| `SGLANG_OPT_MAMBA_SKIP_DECODE_LOCK=1`            | frees one more slot per request (experimental, under validation)                                |

Speculation: DSPARK holds block size + 1 (= 8) intermediate states per request — the calculator folds this in — and an unset `--max-running-requests` resets to 48 under spec (the command panel reminds you; set it explicitly to raise).

**MoE runner.** Leave `--moe-runner-backend` unset on Blackwell: FlashInfer MXFP4 (W4A8, official trtllm-gen SiTU kernels) is selected with the pinned FlashInfer 0.6.17 dependency; H100/H200 pin Marlin. The B200 Balanced and High-Throughput cells pin `flashinfer_mxfp4` explicitly because that is the shape they were brought up on. The published Docker images install the matching official `flashinfer-python`, `flashinfer-cubin`, and `flashinfer-jit-cache` packages.

**Attention backend.** Leave all three attention knobs unset on Blackwell: K3 resolves prefill, decode, and — under DSPARK — verification as a set (`trtllm_mla` across the board; `cutedsl_mla` takes decode and verification under DCP). On the non-DCP recipes, setting any one of the three cancels the auto-resolution for the others. The B200 Balanced and High-Throughput cells pin `--decode-attention-backend cutedsl_mla`, which is what auto-resolution picks for those DCP recipes anyway — it is written out because it is the shape they were brought up on, not because it changes the resolution. H100/H200 pin `flashmla` for decode.

**Context length.** `--context-length` bounds the longest accepted request plus some context-scaled buffers; it does not size the KV pool. For long context the lever that adds capacity is `fp8_e4m3` KV.

**DSPARK.** Adds `--speculative-algorithm DSPARK` plus the draft checkpoint on top of the showing strategy. Leave `--speculative-draft-attention-backend` unset. No serving round on the final draft checkpoint has landed — measure against the same recipe running NOSPEC before adopting.

**Per-platform notes:**

| Platform                                  | Topology                                                                                                                                                    | Notes                                                                                                                                                               |
| ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| B300 1×8                                  | TP8 (+DCP8)                                                                                                                                                 | accuracy-first defaults on Low-Latency and Balanced                                                                                                                 |
| GB300 2×4                                 | TP8/DCP8                                                                                                                                                    | MNNVL transport and cuMem auto-detected                                                                                                                             |
| B200 2×8                                  | PP2 × TP8 on Low-Latency, PP2 × DCPEP8 on Balanced and High-Throughput. DSPARK re-lays the same 16 GPUs as TP16 / TP16+DCP16+EP16. PD prefill is TP1 × PP16 | Unified serves all three operating points; `Long-Context` is a `Prefill`-only strategy                                                                              |
| GB200 4×4                                 | TP16/DCP16                                                                                                                                                  | MNNVL auto-detected                                                                                                                                                 |
| H200 2×8 (4×8 on Unified High-Throughput) | TP16/EP16 + symm-mem, Marlin + FlashMLA; High-Throughput widens to TP32/EP32 over 4 nodes at mem-frac 0.90 with `extra_buffer_lazy`                         | same block on every node; export the cross-node NIC (`GLOO_SOCKET_IFNAME` / `NCCL_SOCKET_IFNAME`, `SGLANG_HOST_IP`); keep `NCCL_MNNVL_ENABLE=1 NCCL_CUMEM_ENABLE=1` |
| H100 4×8                                  | TP32/EP32, Marlin + FlashMLA                                                                                                                                | SM90a build of the K3 image; pin NCCL/Gloo to the same NIC on all nodes; least post-weight headroom (80 GB)                                                         |
| MI350X/MI355X 1×8                         | TP8 ROCm/AITER                                                                                                                                              | AITER A8W4 FlyDSL MoE, Triton attention (`SGLANG_MLA_DECODE_TUNE=1` for gfx950 MLA decode geometry), graph bs up to 256, fp8 kvcache; DSPARK supported              |

**DCP notes** — the DCP cells are Balanced and High-Throughput on every Blackwell platform, in both the `Unified` and `Decode` roles:

* DCP is the only axis that shards the TP-replicated MLA KV; Low-Latency skips it.
* Leave `--dcp-comm-backend` unset (fabric-resolved: `fi_a2a` on GB200/GB300, `a2a` on B200/B300).
* No `--enable-symm-mem` under DCP (force-disabled for decode-graph correctness).
* Explicit `tokenspeed_mla` force-rewrites `--kv-cache-dtype` to fp8; the default `cutedsl_mla` serves either dtype.
* Calculator ratios run well above 1 here (`r > 1` is legal): `bfloat16` state buys admission, `fp8` KV buys context.
* Don't use EP with an a2a backend: a2a buffers reclaim the KV that DCP buys. Compose only to measure. a2a backend is set when `--moe-a2a-backend` is set.

No cell has a serving round in this exact shape — treat them as starting points to verify.

## 3. Advanced Usage

### 3.1 Reasoning

K3 always thinks; the `kimi_k3` reasoning parser (toggle **Reasoning Parser** in the **Parsers** card of the [Playground above](#playground)) separates that thinking from the final answer — thinking lands in `message.reasoning_content`, the answer in `message.content`. Control the reasoning depth with `reasoning_effort` (`low` / `high` / `max`; default `max`).

<Accordion title="Reasoning Example (Python)">
  ```python Example theme={null}
  from openai import OpenAI

  client = OpenAI(base_url="http://localhost:30000/v1", api_key="EMPTY")
  resp = client.chat.completions.create(
      model="moonshotai/Kimi-K3",
      messages=[{"role": "user", "content": "What is 15% of 240?"}],
      reasoning_effort="high",  # "low" | "high" | "max" (default max)
  )
  msg = resp.choices[0].message
  print("Reasoning:", getattr(msg, "reasoning_content", None))
  print("Answer:", msg.content)
  ```
</Accordion>

<Accordion title="Example Output">
  ```text Output theme={null}
  Pending update...
  ```
</Accordion>

### 3.2 Tool Calling

Enable the `kimi_k3` tool-call parser (toggle **Tool Call Parser** in the **Parsers** card of the [Playground above](#playground)) to surface structured tool calls via `message.tool_calls`. Because K3 is a thinking model, the follow-up turn may put text in `reasoning_content` as well as `content` — print both.

<Accordion title="Tool Calling Example (Python)">
  ```python Example theme={null}
  from openai import OpenAI

  client = OpenAI(base_url="http://localhost:30000/v1", api_key="EMPTY")
  tools = [{
      "type": "function",
      "function": {
          "name": "get_weather",
          "description": "Get the current weather for a city",
          "parameters": {
              "type": "object",
              "properties": {"city": {"type": "string"}},
              "required": ["city"],
          },
      },
  }]
  resp = client.chat.completions.create(
      model="moonshotai/Kimi-K3",
      messages=[{"role": "user", "content": "What's the weather in Beijing?"}],
      tools=tools,
  )
  msg = resp.choices[0].message
  print("Reasoning:", getattr(msg, "reasoning_content", None))
  print("Tool calls:", msg.tool_calls)
  ```
</Accordion>

<Accordion title="Example Output">
  ```text Output theme={null}
  Pending update...
  ```
</Accordion>

### 3.3 HiCache (Hierarchical KV Caching)

K3's hybrid HiCache tiers the paged MLA KV **and** the KDA/mamba state across L1 (GPU) / L2 (host) / L3 (Mooncake) — enable it from the **HiCache** card in the [Playground above](#playground) for long multi-turn workloads.

* On the DCP recipes (Blackwell Balanced / High-Throughput, in both the `Unified` and `Decode` roles), the host tiers are not fully DCP-aware yet: **L3 always, and L1+L2 with Spec Decode on, drop the DCP flags** (the command hints call it out — per-request KV capacity shrinks accordingly). L1+L2 with Spec Decode off keeps DCP. Only DCP goes: the MLA KV reverts to TP-replicated, but the cell's other parallelism stays, so B300/GB300/GB200 land on plain TP while B200 Unified keeps its `--pp-size 2` / `--ep-size`.
* Low-Latency and the Hopper recipes take all tiers unchanged.

<a id="pd-disaggregation" />

### 3.4 PD Disaggregation

PD splits prefill and decode into separate server groups; because K3 is hybrid, the transfer moves **both** the paged MLA KV and the KDA recurrent state.

* **Transfer**: the cells emit **NiXL** (RDMA); Mooncake stays selectable in the Playground.
* **Ports**: prefill `30000`, decode `30100` (derived ZMQ/dist ranges must not collide on a shared host). The positional `8998` after `--prefill` must match `--disaggregation-bootstrap-port`, or only the decode worker registers.
* **Decode state pool**: chunk cache — one slot per request; `--mamba-radix-cache-strategy` is inert. Keep `--disaggregation-decode-extra-slots` pinned: unpinned it defaults to twice the batch below 32 requests and **zero** above.

#### Deep PP for prefill

Deep PP is `--tp-size 1` with one pipeline stage per GPU — `--pp-size 8` on B300/GB300, `--pp-size 16` on B200/GB200. Pipeline P2P overlaps the next microbatch's compute, unlike TP/EP collectives, and each stage owns whole layers (a clean slice of KV and state). `--tp-size 1` is also what buys context: above TP1 the MLA KV is replicated across the TP ranks, so TP2 × PP8 holds roughly half the tokens of TP1 × PP16 for the same memory.

* Use one stage per GPU; a shallow split still pays the in-stage all-reduce and can lose to flat TP.
* Pays only with several requests in flight. On the 8-GPU platforms that is why `Default` stays TP8; on the 16-GPU platforms deep PP wins at the Default operating point too, so both strategies use it — measured on GB200 at ISL 8192 / concurrency 32, PP16 × TP1 reached 4550 prefill tok/s/GPU vs 3596 (PP8 × TP2), 2407 (TEP16), and 1652 (TP16). Below concurrency \~8 the pipeline cannot fill and TEP16 leads instead (1947 vs 1227) — use `--tp-size 16 --ep-size 16` there.
* DSPARK off (`pp_size == 1` required) — on B200/GB200 that applies to `Default` as well.
* Fan one prefill role out to several decode roles; budget for in-transfer KV on the decode side.

<Accordion title="Router">
  ```bash Command theme={null}
  python3 -m sglang_router.launch_router \
    --pd-disaggregation \
    --prefill http://<prefill-host>:30000 8998 \
    --decode http://<decode-host>:30100 \
    --host 0.0.0.0 --port 8000 \
    --disable-circuit-breaker \
    --health-check-interval-secs 999999
  ```
</Accordion>

Clients then send requests to the router (`:8000`) instead of an individual role server.

### 3.5 VLM Serving Profiles

The open-source K3 serving contract currently supports **image input only** — its
processor rejects video and audio input.

#### VLM feature transport

Use **VLM Transport** in the command picker. `Auto` is a topology-aware starting
point, not a claim that one configuration is fastest for every workload.

| Picker selection                | Processor-to-scheduler feature path            |
| ------------------------------- | ---------------------------------------------- |
| Auto · single-node Unified CUDA | CUDA IPC                                       |
| Auto · Unified GB200/GB300      | CUDA VMM when IMEX is available; CPU otherwise |
| Auto · PD or other topologies   | CPU                                            |
| CPU                             | CPU, with no GPU feature pool                  |

CUDA IPC and CUDA VMM reserve up to `SGLANG_MM_FEATURE_CACHE_MB` (1 GiB by
default) on the base GPU and fall back to CPU per tensor when full. This setting
does not control EPD encoder output or PD KV/KDA transfer. K3 already defaults to
2 processor workers and 16 I/O workers; leave those flags unset unless tuning.

#### VLM compatibility

| Feature              | K3 behavior                                                                                                                                                                                                                           |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| PD                   | Supported. Image processing and ViT run on prefill; the PD transfer then moves both paged MLA KV and KDA recurrent state as described in [PD disaggregation](#pd-disaggregation).                                                     |
| EPD                  | Supported on the public `kimi-k3` branch. Use an `--encoder-only` vision role and a `--language-only` prefill role; add the normal decode role for full EPD. See the [EPD guide](../../../docs/advanced_features/epd_disaggregation). |
| MM encoder DP        | Built in. K3 shards complete images across TP ranks, so leave `--mm-enable-dp-encoder` unset in unified, PD-prefill, and encoder-only roles.                                                                                          |
| MM feature transport | Processor-to-scheduler features only. EPD encoder output and PD KV/KDA transfer use their own backends.                                                                                                                               |
| ViT BCG              | Compatible with unified and encoder-only roles, but recommended only for repeated encoder shapes after measuring the HBM trade-off below.                                                                                             |

#### Should ViT BCG be enabled?

Keep ViT BCG **off** for general serving; enable `SGLANG_VIT_ENABLE_CUDA_GRAPH=1` only for ViT-only / EPD encoder workloads with recurring image shapes and spare HBM.

* The win is confined to the encoder — no reliable end-to-end TTFT/TPOT gain in full-model serving.
* Each captured graph retains HBM (graph + per-entry metadata); measure on your own shapes.
* The default cache captures after two hits and falls back to eager above 6,144 tokens; do not enlarge it without measuring.

#### Low-HBM VLM

Use this profile when keeping HBM headroom matters more than peak concurrency.
It removes the GPU feature pool, keeps ViT BCG disabled, halves the context
window, caps concurrency, and lowers the static-memory target:

```bash Command theme={null}
sglang serve \
  --trust-remote-code \
  --model-path moonshotai/Kimi-K3 \
  --tp-size 8 \
  --context-length 65536 \
  --enable-symm-mem \
  --mem-fraction-static 0.82 \
  --mm-feature-transport cpu \
  --reasoning-parser kimi_k3 \
  --tool-call-parser kimi_k3 \
  --host 0.0.0.0 \
  --port 30000
```

`--mem-fraction-static 0.82` is a conservative B300 starting point, not a portable minimum: raise it toward `0.85` if startup reports insufficient memory; if HBM must go back to other workloads, reduce context/concurrency first. The precision levers (`fp8_e4m3` KV, `bfloat16` SSM state) save far more but stay accuracy-gated.

<a id="large-scale-presets" />

### 3.6 Large-Scale Serving Presets (16–64 GPUs, Blackwell)

**The KDA state pool is the concurrency ceiling** — DP, EP, and DCP do not shard it; only attention-TP width, SSM dtype, and cache strategy change the per-GPU bill. The MLA KV is cheap to shrink (fp8) or deduplicate (DCP).

Two presets come out of this, at `N = 8k` GPUs:

| Preset                                                | What it trades                                                                                                                                                                                                                       | Pick it for                                            |
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------ |
| **Peak Throughput** — `dp = k`, attention-TP 8        | State shards 8-way. The per-step KDA all-reduce stays within one 8-GPU B200/B300 node, or spans two 4-GPU GB200/GB300 nodes over MNNVL. `--kv-cache-dtype fp8_e4m3` is load-bearing — bf16 KV does not fit 128 requests per replica. | Maximum sustained TPS — the default large-scale shape. |
| **Peak Capacity (+DCP8)** — `dp = k` + `--dcp-size 8` | Deduplicates the attention-TP group's MLA KV: concurrency ceiling +72% at the same engine throughput, \~1.8× ITL.                                                                                                                    | Context ≥ \~16K, or per-replica concurrency past 128.  |

* **Radix cache** is independent of the preset: for prefix-free traffic (offline batch, evals) switch it off (Playground's **Prefix Cache** card) — one state slot per request instead of 4–5.
* The fully data-parallel extreme (`--dp-size` = GPU count, attention-TP 1) — the shape behind the 64-GPU sweep's \~3K tok/s per GPU — is not a preset: 288 GB GPUs only, radix forced off, no head-to-head against the preset shape.

The Peak Throughput preset at 32 GPUs on B200/B300 (4 nodes × 8; every node runs the same command with its own `--node-rank`). On GB200/GB300 the same 32-GPU shape uses 8 nodes × 4, and the Playground emits `--nnodes 8`:

```bash Command theme={null}
SGLANG_OPT_DEEPGEMM_MEGA_MOE_NUM_MAX_TOKENS_PER_RANK=20480 \
sglang serve \
  --trust-remote-code \
  --model-path moonshotai/Kimi-K3 \
  --tp-size 32 --ep-size 32 \
  --enable-dp-attention --dp-size 4 --enable-dp-lm-head \
  --nnodes 4 --node-rank <rank> --dist-init-addr <node0-ip>:20000 \
  --moe-a2a-backend megamoe --moe-runner-backend deep_gemm \
  --kv-cache-dtype fp8_e4m3 \
  --mamba-ssm-dtype bfloat16 \
  --mamba-radix-cache-strategy extra_buffer_lazy \
  --mem-fraction-static 0.92 \
  --reasoning-parser kimi_k3 --tool-call-parser kimi_k3 \
  --host 0.0.0.0 --port 30000
```

Scale by holding the per-replica shape fixed and moving only the replica count; pool sizing rides the calculator-driven `--mamba-full-memory-ratio`, which folds in DP, DCP, precision, and speculation:

| GPUs | B200/B300 nodes | GB200/GB300 nodes | `--tp-size` / `--ep-size` | `--dp-size` |
| ---- | --------------- | ----------------- | ------------------------- | ----------- |
| 16   | 2×8             | 4×4               | 16                        | 2           |
| 32   | 4×8             | 8×4               | 32                        | 4           |
| 64   | 8×8             | 16×4              | 64                        | 8           |

For Peak Capacity, add `--dcp-size 8` and re-derive the pool split with the [Mamba ratio calculator](#mamba-ratio-calculator).

Both presets are one click away in the [Playground above](#playground): pick a **Cluster Size** and a **Large-Scale Preset** and the full command composes onto whichever cell is showing.

Decisions the preset already makes:

* **MegaMoE + `deep_gemm`** — the fused DeepGEMM all-to-all/MoE path used by these large-scale DP/EP throughput presets, with K3's SiTU activation.
* **SP-MoE and shared-expert overlap** engage automatically under EP a2a; the K3 all-reduce fusion does not.
* **Spec Decode follows the Deploy knob.** Acceptance thins at large batch; spec × EP × DP-attention is validated only at 8-GPU EP8 × DP2 (full GSM8K) — experimental at these scales.

<Note>
  No preset has a full serving round on final weights; the constants derive from measured single- and dual-node rounds plus a 64-GPU sweep. Validate throughput and accuracy on your workload before committing a fleet.
</Note>
