Build a capacity and cost-per-token calculator
CPU · your Macnotebook150 minrequiredGoal · A calculator that, for a model, GPU, SLO, workload and hourly price, returns the SLO-constrained batch size, output tokens per second, cost per million input and output tokens and GPUs needed for a demand level, for H100, A100 and L4.
- 1Enter a spec table for H100 SXM (80 GB, 3.35 TB/s, 989 dense FP16 TFLOPs), A100 80GB (2.0 TB/s, 312 TFLOPs) and L4 (24 GB, 300 GB/s, 121 TFLOPs) with an assumed on-demand price for each (write down your source and date).
- 2Enter model specs for Llama-3.1-8B and Llama-3.1-70B in FP16, FP8 and INT4 weight-only; compute weight bytes and KV bytes per token from config.json, and flag any combination that does not fit in one GPU's memory with 90 percent utilization.
- 3Implement decode_step_time(B, context) and prefill_time(prompt_len) from the roofline with an efficiency factor eff (start at 0.6) applied to both roofs; compute the KV-capacity bound on B for a given context.
- 4For a workload of 1024-token prompts and 256-token outputs and an SLO of p50 ITL under 50 ms and TTFT under 1 s, find the largest B meeting both the SLO and the KV bound, then output tokens per second and tokens per GPU-hour.
- 5Compute cost per million output tokens and per million input tokens (prefill time share) for every model x GPU x precision cell; produce a table and mark infeasible cells.
- 6Compute GPUs needed for a demand of 2,000 requests per minute at a peak-to-mean ratio of 2.5, with and without a 70 percent utilization target.
- 7Run a sensitivity sweep over eff in 0.4, 0.6, 0.8, SLO ITL 30 and 100 ms, and context 4k and 32k; plot cost per million output tokens for the 8B model on each GPU.
- 8Compare your T4 roofline prediction for Qwen2.5-0.5B at the concurrency you benchmarked in p3-benchmarking-engines-l1 with the throughput you measured; report achieved MBU as a percentage.
- Deliverable
- capacity_calc.ipynb with the spec tables, the cost table, the GPUs-needed figures, the sensitivity plot and the measured-versus-roofline MBU.
- Check
- Llama-3.1-70B FP16 is flagged as not fitting on any single GPU in the table; the 8B FP16 H100 cost lies between 0.03 and 0.60 USD per million output tokens at eff 0.6; your measured T4 MBU is reported and lies below 100 percent.