做模型专题How models are made 训练管线 · 第 8 站training pipeline · stage 8
GPU 事实与成本数学:跑模型的硬件账GPU facts and cost math: the hardware bill for running a model从业者视角的方法论 · 关键事实挂官方出处practitioner-perspective methodology · key facts carry official sources
从可用内存拆解驻留权重、上下文缓存、并发与运行时;区分理想化带宽算式和实际吞吐,附可填写预算,不存单价或购卡建议。Separate resident weights, context cache, concurrency and runtime; distinguish idealized bandwidth arithmetic from actual throughput, with an editable budget and no stored prices or purchase advice.
这一篇讲什么What this guide covers
预算先拆成驻留权重、缓存、运行时与预留,再和任务实际可用内存比较。文件能下载不等于能加载;小于预算也不等于运行器支持或输出合格。
本站不存卡价、租用单价或购卡建议。原硬件来源日期保留为 2026-10-21;2026-11-04 仅新增缓存方法说明与本地预算算式,未重新核验旧硬件规格。
Split memory into resident weights, cache, runtime and reserve, then compare with task-available memory. Downloading is not loading; a lower estimate does not establish runtime support or output quality.
This site stores no card/rental prices or purchase recommendations. Original hardware-source dates remain 2026-10-21. The 2026-11-04 addition covers cache methodology and browser-local arithmetic, not a fresh hardware-spec check.
核对容量、带宽与可用量Check capacity, bandwidth and available memory
硬件官方规格页可用于核对容量、带宽和型号,但不能直接给出某个任务的速度或可用内存。驱动、后端、共享内存、系统占用和模型布局都需另外核对。
下列来源保留原快照日期。本文不把某张卡或某台机器的标称总容量当作当前任务可用量,也不把两张卡的容量简单视作一个连续内存池。使用预算工具时填写已核对的可用 GiB;十进制 GB 先换单位。
Official hardware pages establish published capacity, bandwidth and SKU, not task speed or available memory. Check drivers, backend, sharing, system use and loaded model layout separately.
Sources retain original snapshot dates. Nominal device capacity is not task-available memory, and two cards are not automatically one contiguous pool. Enter checked available GiB in the budget tool, converting decimal GB first.
带宽算式的假设与边界Assumptions and limits of bandwidth arithmetic
对简化的稠密模型单请求 decode,可用峰值内存带宽 ÷ 每步需从该层级读取的字节量做理想化估计。只有在假设每步从该内存层级完整读取权重时,才能把权重体积放进分母;MoE 激活专家、缓存复用、批处理和卸载会改变口径。
例如假设每步需读 16 GB、带宽为 3.35 TB/s,忽略其他开销时约为 209 次读取/秒。这是教学算式,不是 token/s 测试结果。减小权重文件不保证速度按相同比例增加。
prefill 和 decode 的瓶颈会随批量、序列长度、算子实现与硬件变化,不能一概写成“一个只看算力,另一个只看带宽”。
For a simplified single-request dense-model decode, peak memory bandwidth divided by bytes read per step gives an idealized estimate. Weight size belongs in that denominator only if each step reads all weights from that memory level. Active MoE experts, cache reuse, batching and offload change the assumptions.
For example, assumed reads of 16 GB per step at 3.35 TB/s give about 209 reads/second before other overhead. This is teaching arithmetic, not measured tokens/second. Smaller files do not guarantee proportionally higher speed.
Prefill/decode bottlenecks vary with batch, sequence length, kernels and hardware; neither can universally be reduced to compute-only or bandwidth-only.
成本数学:讲构成,不存单价Cost math: composition, not unit prices
每 token 硬件分摊成本 = 同一统计期间内计入的硬件费用 ÷ 同期间实际产出的 tokens。写清输入/输出口径、缓存、空闲、失败重试和服务量,避免拿峰值理论吞吐当实际交付。
容量预算回答“按这些假设占多少内存”,不回答“每小时能产多少”。吞吐需在自己的授权环境按固定任务观察;本站没有运行模型测试或保存单价。需要记录费用构成,使用 成本计算器。
Allocated hardware cost per token equals included hardware cost divided by actual tokens produced in the same period. Define input/output, caching, idle time, failed retries and service volume; theoretical peak throughput is not delivered output.
A capacity budget estimates memory under assumptions, not hourly production. Observe throughput only in your own authorized fixed-task environment; this site ran no model benchmark and stores no prices. Record cost components with the cost calculator.
和本站其他资产的关系How this fits the rest of the site
系列页 B 区按发布文件体积 × 1.15 初筛候选。该固定示意比例不是 KV 缓存估算,也不保证能运行。用本文下方的工具把缓存长度、并发和运行时预留分别列出;编码器、MLA、混合或滑动窗口模型另查架构方法。
Series-page block B filters candidates by published file size × 1.15. That fixed illustration neither estimates KV cache nor guarantees execution. Use the tool below to separate cached length, concurrency and runtime reserve; encoders, MLA, hybrid and sliding-window models require architecture-specific methods.
和学 AI 站的分工How this differs from the Learn site
学 AI 站的 显存 与
量化 是使用者视角的一页科普;
这一篇给硬件事实表与成本数学的构成方法。
同一个概念在两处深度不同,互链不重复。
KV 缓存与批处理机制见上一篇「跑起来深水」。
The Learn site's VRAM and
quantisation pages are user-perspective explainers;
this guide gives the hardware fact table and the composition method for the cost math.
Same concept, different depth on each side, cross-linked without duplication.
For the KV cache and batching mechanics see the previous guide, “Serving deep dive”.
完整例子:10 GiB 预算如何分配Worked example: allocating a 10 GiB budget
下面是假设的容量练习,不对应具体模型,也不是本站运行结果。GiB 按 2 的 30 次方字节计算;不要把十进制 GB 直接当成相同数值的 GiB。
设可用于任务的预算为 10 GiB,候选权重占 6 GiB。先按 2 GiB 缓存、1 GiB 运行时占用估算,合计 9 GiB,另留 1 GiB 余量。这些缓存与运行时数字只是练习假设;真实数值随模型、精度、上下文和并发变化。
接着核对文件体积、运行器支持和实际可用内存。用短输入启动后记录占用,再增加上下文。若缓存超过预算,可以缩短输入、调整并发或评估其他档位;卸载能力需查运行器文档。
容量预算不能预测生成速度,也不能证明质量足够。对比方案时,再用相同任务记录耗时、错误和用量;本例不给出性能承诺或硬件购买建议。
This hypothetical capacity exercise is not a named model or a measured site result. A GiB is 2^30 bytes; decimal GB and GiB are not numerically interchangeable.
Assume a 10 GiB available budget and 6 GiB of weights. With assumed cache use of 2 GiB and runtime use of 1 GiB, the estimate is 9 GiB, leaving 1 GiB headroom. Cache/runtime figures are exercise assumptions; actual use depends on model, precision, context and concurrency.
Check file size, runtime support and available memory. Start with short input, record use, then increase context. If cache exceeds budget, assess shorter input, different concurrency or other tiers. Check runtime documentation for offload support.
Capacity does not predict speed or establish quality. Compare equal tasks for latency, errors and usage. This example makes no performance guarantee or purchase recommendation.
Continue to the local-model workflow, or revisit quantization to separate bit width from quality.
上下文与并发:容量预算Context and concurrency: capacity budget
这是标准全注意力 MHA/GQA 解码器的简化预算,不读取硬件、不下载模型、不预测速度。所有输入都是待你核对的假设;驻留权重不等于下载文件体积。A simplified budget for standard full-attention MHA/GQA decoders. It does not inspect hardware, download models or predict speed. Inputs are assumptions to check; resident weights are not download-file size.
C 包括提示和已生成内容;N 假设各请求长度相同、缓存互不共享。8-bit 的比例因子等开销需加进预留。架构字段取模型配置,缓存精度取运行器配置,不能用参数总量猜。C includes prompt and generated content. N assumes equal lengths and no cache sharing. Add 8-bit scaling/metadata to reserve. Read architecture from model config and cache precision from runtime config; do not infer them from parameter count.
KV bytes = 2 × L × Hkv × D × B × C × N
KV GiB = KV bytes / 1,073,741,824
总预算 = 驻留权重 + KV + 运行时与预留Total = resident weights + KV + runtime/reserve
填写并核对适用范围后计算。Fill inputs and confirm the scope to calculate.
GB 与 GiB 换算(只换单位)GB and GiB conversion (units only)
1 GB = 1,000,000,000 bytes; 1 GiB = 1,073,741,824 bytes.
换算结果不会自动填进驻留权重;加载后的布局、精度转换和运行器分配可能不同。The conversion is not copied into resident weights: loaded layout, precision conversion and runtime allocation may differ.
未计入的项目、错误的驻留估计、多卡分配、前缀共享、缓存分页和多模态编码器都可能改变结果。此算式不适用于所有架构;MLA、混合状态空间与各层不同的缓存需另算。Missing overhead, wrong residency estimates, multi-device allocation, prefix sharing, paging and multimodal encoders can change the result. This formula is not universal: MLA, hybrid state-space models and differing per-layer caches need separate calculations.
Transformers: cache tensors · vLLM: memory controls · 容量不足排查Memory troubleshooting
出处Sources
- NVIDIA H100 官方规格页(SXM 80GB / NVL 94GB 与带宽口径,2026-10-21 直抓)NVIDIA H100 official spec page (SXM 80GB / NVL 94GB and bandwidth figures; fetched directly 2026-10-21):https://www.nvidia.com/en-us/data-center/h100/
- NVIDIA A100 官方规格页(80GB HBM2e 与带宽口径,2026-10-21 直抓)NVIDIA A100 official spec page (80GB HBM2e and bandwidth figures; fetched directly 2026-10-21):https://www.nvidia.com/en-us/data-center/a100/
- NVIDIA RTX 4090 官方规格页(24GB GDDR6X,2026-10-21 直抓)NVIDIA RTX 4090 official spec page (24GB GDDR6X; fetched directly 2026-10-21):https://www.nvidia.com/en-us/geforce/graphics-cards/40-series/rtx-4090/
- Apple MacBook Pro 官方规格页(统一内存容量口径,2026-10-21 直抓)Apple MacBook Pro official spec page (unified-memory capacity figures; fetched directly 2026-10-21):https://www.apple.com/macbook-pro/specs/
- PagedAttention 论文(arXiv 2309.06180,KV 缓存显存与吞吐关系,2026-10-21 直抓摘要页)PagedAttention paper (arXiv 2309.06180, KV-cache memory versus throughput; abstract page fetched directly 2026-10-21):https://arxiv.org/abs/2309.06180
- llama.cpp 官方仓库(GGUF 本地推理实现,2026-10-21 直抓 200)llama.cpp official repository (the GGUF local-inference implementation; fetched directly, HTTP 200, 2026-10-21):https://github.com/ggml-org/llama.cpp
- Transformers · 缓存张量结构(2026-11-04 单项核验)Transformers: cache tensor structure (item checked 2026-11-04):https://huggingface.co/docs/transformers/cache_explanation
- vLLM · 内存控制(2026-11-04 单项核验)vLLM: memory controls (item checked 2026-11-04):https://docs.vllm.ai/en/latest/configuration/conserving_memory/
基础来源快照:2026-10-21;单项补充与核验范围见正文和来源标签。请回原始说明核对规格、方法与适用条件。Base source snapshot: 2026-10-21; item-specific additions and check scope appear in the text and source labels. Check original specifications, methods and conditions.
这页出现在主题:This page appears in: 用 AI 做游戏Make games with AI