{
  "type": "formula",
  "id": "ascend-concurrency",
  "slug": "ascend-concurrency",
  "domain": "昇腾部署",
  "title": "昇腾服务并发上限估算器：KV Cache Block 算法（官方公式）",
  "h1": "并发上限估算器（KV Cache Block）",
  "question": "这台机器按我的上下文长度，最多能同时跑多少个请求（maxBatchSize 上限）？",
  "summary": "用官方的 KV Cache Block 算法把「显存」折算成「最大并发」：每个请求占几个 Block，总 Block 数除以它就是上限。总 Block 数（Total Block Num）必须在你自己的机器上实测取得，官方示例值是 817。",
  "keywords": "昇腾并发估算,maxBatchSize,KV Cache Block,cacheBlockSize,npuBlockNum,显存换算并发,MindIE 并发",
  "updated": "2026-11-19",
  "source": {
    "title": "G8 容量与成本（官方 KV Cache Block 算法）",
    "url": "/report-course-ascend-g8.html"
  },
  "inputs": [
    {
      "id": "blk",
      "label": "cacheBlockSize（每块多少 token）",
      "unit": "token",
      "default": "128",
      "step": "1",
      "hint": "官方默认 128；除非有特殊理由，不要改"
    },
    {
      "id": "tin_max",
      "label": "最大输入 token 数",
      "unit": "token",
      "default": "2048",
      "step": "1",
      "hint": "按你场景的最长输入填"
    },
    {
      "id": "tout_max",
      "label": "最大输出 token 数",
      "unit": "token",
      "default": "512",
      "step": "1",
      "hint": "按你场景的最长输出填"
    },
    {
      "id": "tin_avg",
      "label": "平均输入 token 数",
      "unit": "token",
      "default": "1024",
      "step": "1",
      "hint": "请求之间长度差距大时才有意义"
    },
    {
      "id": "tout_avg",
      "label": "平均输出 token 数",
      "unit": "token",
      "default": "256",
      "step": "1",
      "hint": "同上"
    },
    {
      "id": "total",
      "label": "Total Block Num（实测）",
      "unit": "块",
      "default": "817",
      "step": "1",
      "hint": "grep npuBlockNum 取最小值；817 只是官方示例，你的机器必须实测"
    }
  ],
  "outputs": [
    {
      "id": "blk_max",
      "label": "每请求最大 Block 数",
      "unit": "块",
      "expr": "Math.ceil(tin_max/blk)+Math.ceil(tout_max/blk)",
      "digits": 0
    },
    {
      "id": "batch_max",
      "label": "maxBatchSize 上限（按最大长度）",
      "unit": "并发",
      "expr": "Math.floor(total/(Math.ceil(tin_max/blk)+Math.ceil(tout_max/blk)))",
      "digits": 0
    },
    {
      "id": "blk_avg",
      "label": "每请求平均 Block 数",
      "unit": "块",
      "expr": "Math.ceil(tin_avg/blk)+Math.ceil(tout_avg/blk)",
      "digits": 0
    },
    {
      "id": "batch_avg",
      "label": "上限（按平均长度，可适当上浮）",
      "unit": "并发",
      "expr": "Math.floor(total/(Math.ceil(tin_avg/blk)+Math.ceil(tout_avg/blk)))",
      "digits": 0
    }
  ],
  "formulas": [
    {
      "name": "每请求最大 Block 数",
      "expr": "Ceil(最大输入Token数 ÷ cacheBlockSize) + Ceil(最大输出Token数 ÷ cacheBlockSize)",
      "note": "官方公式（G8 第 4 步）"
    },
    {
      "name": "每请求平均 Block 数",
      "expr": "Ceil(平均输入Token数 ÷ cacheBlockSize) + Ceil(平均输出Token数 ÷ cacheBlockSize)",
      "note": "请求长度差异大时用它，上限可适当提高"
    },
    {
      "name": "maxBatchSize 上限",
      "expr": "Floor(Total Block Num ÷ 每请求最大Block数)",
      "note": "官方：为保持最佳性能，maxBatchSize 一般不宜超过这个值"
    },
    {
      "name": "取 Total Block Num",
      "expr": "grep npuBlockNum <MindIE LLM Python 程序日志>，多个结果取最小值",
      "note": "必须先清空旧日志再 grep，否则拿到的是历史配置的旧值"
    }
  ],
  "notes": [
    "官方公式与默认值来自 G8《容量与成本》（MindIE 推理性能解决方案 · TopN 性能问题解决方案里的「服务化性能上限评估」）。",
    "Total Block Num 官方明确要求实测：grep npuBlockNum 取最小值；官方示例值 817（另一处示例 1747）只是示例，不是通用值。",
    "这是**显存维度**的上限。真实并发还会被性能上限（时延/吞吐）与 maxSeqLen 等参数压住，所以实测结果通常低于本估算。",
    "官方明确：不存在与场景无关的「一张卡能支持多少并发」的通用数字，必须按你的模型/精度/长度实测 + 按本公式估算。"
  ],
  "sourceUrl": "https://loudilaoshi.com/report-course-ascend-g8.html",
  "canonical": "https://loudilaoshi.com/tools/ascend-concurrency.html",
  "license": "转载或引用请注明作者「娄迪老师」与原文链接"
}