AI Skills AI技能 8d ago Updated 8d ago 更新于 8天前 48

Start Here: The Words Everyone Uses About LLM Inference 从这里开始:关于LLM推理每个人都在用的那些词

LLM inference is fundamentally constrained by memory bandwidth, not arithmetic speed; producing one token from a 70B model requires reading ~70GB of weights, making decode inherently bandwidth-bound Batching is the primary optimization: multiple requests share the same weight fetch, so arithmetic intensity in decode equals the batch size, but attention/KV cache remains per-user and cannot be batched Mixture-of-Experts (MoE) models reduce active parameters but do not solve the serving bandwidth p LLM推理的核心瓶颈是内存带宽而非算力,decode阶段每生成一个token需要读取全部模型权重(70B参数×2字节=140GB流量) GPU的ridge point(算术强度临界值)= 峰值算力÷内存带宽,H100约为296 ops/byte,prefill在此右侧(算力受限),decode在此左侧(带宽受限) Batching通过让多个请求共享同一次权重读取来摊薄内存访问成本,batch size直接决定decode阶段的算术强度 MoE模型虽减少单次推理的活跃参数,但所有专家仍需驻留显存,高并发时优势被稀释,decode仍受带宽约束 KV cache是per-user的独立内存访问,无法

65
Hot 热度
72
Quality 质量
68
Impact 影响力

Analysis 深度分析

TL;DR

  • LLM inference is fundamentally constrained by memory bandwidth, not arithmetic speed; producing one token from a 70B model requires reading ~70GB of weights, making decode inherently bandwidth-bound
  • Batching is the primary optimization: multiple requests share the same weight fetch, so arithmetic intensity in decode equals the batch size, but attention/KV cache remains per-user and cannot be batched
  • Mixture-of-Experts (MoE) models reduce active parameters but do not solve the serving bandwidth problem at scale, since all experts must reside in GPU memory and high concurrency reactivates full-weight traffic
  • The "ridge point" (arithmetic speed ÷ memory bandwidth) varies significantly by GPU: H100 = 296, A100 = 153, L40S = 419, meaning cheaper cards like L40S require larger batches to break even
  • KV cache is the critical bottleneck for long-context serving; optimizations must target cache size reduction rather than arithmetic speed, since cache traffic is inherently per-user and unbatchable

Why It Matters

This article provides the foundational mental model for understanding LLM serving performance, explaining why certain optimizations work and others don't. For AI practitioners, it clarifies that tokens-per-second metrics are meaningless without batch size context, and that hardware selection decisions must account for the arithmetic-to-bandwidth ratio, not just peak FLOPS or hourly cost.

Technical Details

  • Roofline model applied to inference: The ridge point (ops/byte ratio) determines whether a GPU is compute-bound or bandwidth-bound; prefill operates right of the ridge (compute-bound) while decode operates far left (bandwidth-bound)
  • Prefill vs. Decode asymmetry: Prefill processes all prompt tokens in parallel (one weight read for N tokens), while decode generates tokens sequentially (one full weight read per token), creating a fundamental performance imbalance
  • Batching mechanics: Weight matrices are request-agnostic, so a single 70GB fetch can serve up to 32+ concurrent requests; however, KV cache is conversation-specific and cannot be shared across requests
  • MoE serving dynamics: Active parameters scale with experts fired per token (e.g., 8/256 for Qwen3.6-35B-A3B), but total parameters still occupy GPU memory; batching recovers efficiency only at impractically large concurrency (~9,500 users)
  • Hardware-specific ridge points: H100 SXM = 296 ops/byte, A100 80GB = 153, L40S = 419; the L40S's low bandwidth-to-arithmetic ratio makes it harder to reach compute-bound operation despite lower cost

Industry Insight

  • When evaluating GPU hardware for LLM serving, prioritize the arithmetic-to-bandwidth ratio over peak FLOPS or hourly pricing; the L40S appears economical but requires significantly larger batches to achieve comparable efficiency to H100
  • Monitor actual running batch size (via vLLM metrics like num_requests_running) rather than configured limits; most production systems operate at 3-10% of available arithmetic capacity, indicating severe underutilization
  • For long-context features, invest in KV cache optimization (compression, eviction policies, quantization) rather than seeking arithmetic speedups, since cache traffic is the unbatchable bottleneck that batching cannot resolve

TL;DR

  • LLM推理的核心瓶颈是内存带宽而非算力,decode阶段每生成一个token需要读取全部模型权重(70B参数×2字节=140GB流量)
  • GPU的ridge point(算术强度临界值)= 峰值算力÷内存带宽,H100约为296 ops/byte,prefill在此右侧(算力受限),decode在此左侧(带宽受限)
  • Batching通过让多个请求共享同一次权重读取来摊薄内存访问成本,batch size直接决定decode阶段的算术强度
  • MoE模型虽减少单次推理的活跃参数,但所有专家仍需驻留显存,高并发时优势被稀释,decode仍受带宽约束
  • KV cache是per-user的独立内存访问,无法通过batching优化,是长上下文场景性能瓶颈的根本原因

为什么值得看

本文揭示了LLM推理系统各优化技术(KV cache、quantization、FlashInfer等)的共同底层逻辑——内存带宽约束,帮助从业者从"背诵术语"转向"理解机制"。对生产环境部署、硬件选型和性能调优具有直接指导价值,避免被表面指标误导。

技术解析

  • Ridge Point与Roofline模型:GPU的算术强度临界值由硬件规格决定(H100: 990 TFLOP/s ÷ 3.35 TB/s ≈ 296 ops/byte)。Prefill阶段因并行处理整个prompt,算术强度远高于ridge point,属于算力受限;decode阶段每token仅1次权重读取,算术强度≈batch size,远低于ridge point,属于带宽受限。
  • Batching的本质:不是队列等待,而是多个请求在同一轮权重读取中并行处理。batch=32时算术强度为32,batch=296时才能达到H100的ridge point。实际生产中batch size往往远低于此,导致大量算力闲置。
  • MoE模型的带宽特性:Qwen3.6-35B-A3B有350亿参数但每次仅激活约30亿(8/256专家),单请求带宽降低约32倍。但所有专家仍需驻留显存,高并发时所有专家被激活,带宽优势消失,仅适合单卡本地推理。
  • KV cache的不可批处理性:每个请求的KV cache独立存储,50个用户意味着50次独立读取,无法共享。多头注意力中多个query head共享同一KV pair(约8倍复用),但相对于296的ridge point仍微不足道。
  • 硬件选型陷阱:L40S单价低但带宽/算力比差(ridge point=419),需要更大batch才能摊薄成本;A100 ridge point=153。选卡不能只看小时租金,需计算实际batch size下的有效利用率。

行业启示

  • 性能指标必须绑定batch size:任何tokens/s数据若无batch size上下文均无意义。应监控vLLM的num_requests_running指标,而非仅看--max-num-seqs上限,避免为闲置算力付费。
  • 长上下文优化的正确方向:KV cache是per-user成本,无法通过batching解决,工程重点应放在压缩cache(quantization、eviction策略)而非单纯堆算力。
  • 硬件选型需计算真实ridge point:便宜GPU可能因带宽不足需要更大batch才能盈亏平衡,需结合业务并发特征评估,而非仅比较单价或峰值算力。

Disclaimer: The above content is generated by AI and is for reference only. 免责声明:以上内容由 AI 生成,仅供参考。

LLM 大模型 Inference 推理 Quantization 量化 Deployment 部署 GPU GPU