Accelerator Memory Estimator
This is a doer: given a model and a config, you run the formulas in accelerator-memory-estimator-guide.md
to produce a numeric per-device memory estimate and a concrete fitting recommendation. Apply the
judgment of an engineer who has sized hundreds of training and serving jobs on GPU and TPU clusters.
Every number you produce is an estimate (±). Real memory depends on framework, kernels,
fragmentation, and version. Always tell the reader to confirm with nvidia-smi / a profiler / an OOM
test on a small slice before committing hardware.
How to use this skill
- Read
accelerator-memory-estimator-guide.md — the formulas and the step-by-step procedure.
Apply it end to end: collect inputs → compute each memory term → sum per device → compare to
capacity → recommend.
- For fully worked numeric estimates to imitate (full FT of a 7B on one 80GB GPU; 70B with ZeRO-3 on
8×H100; KV cache for a 70B with GQA), read
examples.md.
- State your assumptions explicitly (dtype, optimizer, batch, seq, device, count). Show
inputs → formula → number → recommendation. Label every result estimate, verify.
Essentials (full detail in accelerator-memory-estimator-guide.md)
- Full training ≈ 16·P bytes + activations + overhead. For P params with bf16 weights and
mixed-precision AdamW: weights 2·P + gradients 2·P + optimizer 12·P (fp32 master 4·P + m 4·P +
v 4·P) = 16·P before activations. Add ~5–15% framework/fragmentation overhead.
- 8-bit Adam cuts optimizer state ~12·P → ~6·P; fp8/8-bit weights/grads cut further. Note them
as levers, don't assume them silently.
- Activations dominate at large batch×seq. Roughly ∝ batch · seq · hidden · layers · (bytes).
Activation checkpointing trades compute for memory — store only layer boundaries, recompute the
rest: activation memory drops by roughly the per-layer factor (often 5–10×).
- Sharding divides by world size. FSDP / ZeRO-3 shard weights + gradients + optimizer by the
data-parallel size N (each ≈ 16·P/N). ZeRO-1 shards optimizer only; ZeRO-2 optimizer + grads.
Tensor parallel (TP=k) divides per-layer weights/activations by k (high comms, keep intra-node).
Pipeline parallel splits layers across stages (mind the bubble + in-flight microbatches).
- Inference ≈ weights + KV cache + workspace. Weights ≈ 2·P bf16 (≈1·P int8, ≈0.5·P int4).
- KV cache = 2 · layers · kv_heads · head_dim · seq_len · batch · dtype_bytes. GQA/MQA shrink
kv_heads (often 8 vs 64 query heads → ~8× smaller cache). KV cache, not weights, usually caps
serving concurrency and context length.
- Rules of thumb: full FT ≈ 16·P + activations; LoRA ≈ weights (frozen) + tiny adapter state;
QLoRA ≈ 4-bit weights (~0.5·P) + adapters → 7B fine-tunes on a single 24GB card; inference ≈
weights + KV.
- The procedure: inputs (P or dims, dtype, optimizer, batch, seq, devices, device HBM) → per-device
bytes → compare to capacity (leave ~10–20% headroom) → recommend the cheapest strategy that fits.
- Always state ± and verify. These estimates get you to the right hardware/parallelism class; the
exact fit is confirmed by a real run.
Related skills
[[training-frameworks]] — implement FSDP/ZeRO/TP/PP (DeepSpeed, Megatron, FSDP, NeMo) once you know
the strategy.
[[fine-tuning-peft]] — LoRA/QLoRA mechanics when the estimate says full FT won't fit.
[[ml-frameworks]] — PyTorch/JAX/XLA memory behavior, dtypes, activation checkpointing APIs.
[[serving-frameworks]] — vLLM/SGLang/TensorRT-LLM that turn the KV-cache budget into real concurrency.
[[inference-optimization]] — paged/quantized KV cache, chunked prefill, batching to use the budget.
[[ai-networking-collectives]] — interconnect (NVLink/IB) that decides whether TP/FSDP are viable.
[[gke-master]] — picking TPU/GPU node pools and accelerator SKUs once you know the memory class.
[[ai-research-science]] — scaling laws / architecture choices that set P, layers, hidden, heads.
1---2name: accelerator-memory-estimator3description: Use this to ESTIMATE GPU/TPU memory for an ML workload and DECIDE what fits and what parallelism is needed. Trigger whenever someone asks "will this model fit", "do I have enough VRAM/HBM", "OOM / CUDA out of memory", "how many H100s / how much TPU HBM do I need", "what batch size fits", "can I fine-tune a 7B/70B on one GPU", "how big is the KV cache". Performs the actual arithmetic: training memory (weights + gradients + optimizer states + activations + overhead), sharding math (FSDP/ZeRO-1/2/3, tensor parallel, pipeline parallel), and inference KV-cache memory (with GQA/MQA). Given a model + config, it computes per-device memory, compares to capacity (H100 80GB, A100 40/80GB, TPU v5e/v5p HBM), and RECOMMENDS a fitting strategy (fits / FSDP / TP=k / activation checkpointing / quantization / QLoRA). All outputs are ESTIMATES (±) — verify against a real run.4---56# Accelerator Memory Estimator78This is a **doer**: given a model and a config, you run the formulas in `accelerator-memory-estimator-guide.md`9to produce a **numeric per-device memory estimate** and a concrete fitting recommendation. Apply the10judgment of an engineer who has sized hundreds of training and serving jobs on GPU and TPU clusters.1112**Every number you produce is an estimate (±).** Real memory depends on framework, kernels,13fragmentation, and version. Always tell the reader to confirm with `nvidia-smi` / a profiler / an OOM14test on a small slice before committing hardware.1516## How to use this skill17181. **Read `accelerator-memory-estimator-guide.md`** — the formulas and the step-by-step procedure.19 Apply it end to end: collect inputs → compute each memory term → sum per device → compare to20 capacity → recommend.212. For fully worked numeric estimates to imitate (full FT of a 7B on one 80GB GPU; 70B with ZeRO-3 on22 8×H100; KV cache for a 70B with GQA), read **`examples.md`**.233. State your assumptions explicitly (dtype, optimizer, batch, seq, device, count). Show24 inputs → formula → number → recommendation. Label every result **estimate, verify**.2526## Essentials (full detail in `accelerator-memory-estimator-guide.md`)2728- **Full training ≈ 16·P bytes + activations + overhead.** For P params with bf16 weights and29 mixed-precision AdamW: weights 2·P + gradients 2·P + optimizer 12·P (fp32 master 4·P + m 4·P +30 v 4·P) = **16·P** before activations. Add ~5–15% framework/fragmentation overhead.31- **8-bit Adam** cuts optimizer state ~12·P → ~6·P; **fp8/8-bit** weights/grads cut further. Note them32 as levers, don't assume them silently.33- **Activations dominate at large batch×seq.** Roughly ∝ batch · seq · hidden · layers · (bytes).34 **Activation checkpointing** trades compute for memory — store only layer boundaries, recompute the35 rest: activation memory drops by roughly the per-layer factor (often 5–10×).36- **Sharding divides by world size.** FSDP / ZeRO-3 shard **weights + gradients + optimizer** by the37 data-parallel size N (each ≈ 16·P/N). ZeRO-1 shards optimizer only; ZeRO-2 optimizer + grads.38 **Tensor parallel (TP=k)** divides per-layer weights/activations by k (high comms, keep intra-node).39 **Pipeline parallel** splits layers across stages (mind the bubble + in-flight microbatches).40- **Inference ≈ weights + KV cache + workspace.** Weights ≈ 2·P bf16 (≈1·P int8, ≈0.5·P int4).41- **KV cache = 2 · layers · kv_heads · head_dim · seq_len · batch · dtype_bytes.** GQA/MQA shrink42 `kv_heads` (often 8 vs 64 query heads → ~8× smaller cache). KV cache, not weights, usually caps43 serving concurrency and context length.44- **Rules of thumb:** full FT ≈ 16·P + activations; LoRA ≈ weights (frozen) + tiny adapter state;45 **QLoRA ≈ 4-bit weights (~0.5·P) + adapters** → 7B fine-tunes on a single 24GB card; inference ≈46 weights + KV.47- **The procedure:** inputs (P or dims, dtype, optimizer, batch, seq, devices, device HBM) → per-device48 bytes → compare to capacity (leave ~10–20% headroom) → recommend the cheapest strategy that fits.49- **Always state ± and verify.** These estimates get you to the right hardware/parallelism class; the50 exact fit is confirmed by a real run.5152## Related skills5354- `[[training-frameworks]]` — implement FSDP/ZeRO/TP/PP (DeepSpeed, Megatron, FSDP, NeMo) once you know55 the strategy.56- `[[fine-tuning-peft]]` — LoRA/QLoRA mechanics when the estimate says full FT won't fit.57- `[[ml-frameworks]]` — PyTorch/JAX/XLA memory behavior, dtypes, activation checkpointing APIs.58- `[[serving-frameworks]]` — vLLM/SGLang/TensorRT-LLM that turn the KV-cache budget into real concurrency.59- `[[inference-optimization]]` — paged/quantized KV cache, chunked prefill, batching to use the budget.60- `[[ai-networking-collectives]]` — interconnect (NVLink/IB) that decides whether TP/FSDP are viable.61- `[[gke-master]]` — picking TPU/GPU node pools and accelerator SKUs once you know the memory class.62- `[[ai-research-science]]` — scaling laws / architecture choices that set P, layers, hidden, heads.