Estimate AI Inference Cost at Scale: A Guide
In this article
This guide explains how to estimate the cost of running AI inference at scale, covering the key factors that drive expenses and providing a step-by-step method to calculate a realistic budget. You'll learn how to account for hardware, usage patterns, and operational overhead, so you can plan for costs before you scale.
What You'll Need
- Details about your AI model: architecture (e.g., transformer), parameter count, and input/output sizes.
- Expected usage: number of requests per day, average tokens per request (if using a language model), or the size of images/video frames.
- Hardware options: cloud GPU/TPU pricing or on-premises server costs (per hour).
- Basic understanding of key metrics: tokens, FLOPs, latency, throughput, and utilization.
- A spreadsheet or simple calculator for arithmetic.
Step-by-Step
- Define your model's compute requirement. For transformer-based models, the compute per token is roughly 2 × (number of parameters) FLOPs. For example, a 7B parameter model requires about 14 billion FLOPs per token. For non-transformer models, use benchmark tools or vendor specifications to estimate FLOPs per inference.
- Estimate the average size of a single request. For text models, this is the total number of tokens (input + output). For image or video models, it's the number of pixels or frames processed. Be realistic: a chat request might be 500 tokens, while a document summarization could be 2,000.
- Calculate FLOPs per request. Multiply the compute per token (or per pixel) by the average request size. For a 7B model and 500 tokens, that's 14e9 × 500 = 7e12 FLOPs (7 TFLOPs).
- Determine your hardware's throughput. Look up the peak FLOPs for your chosen GPU/TPU (e.g., A100: 19.5 TFLOP/s FP32, 312 TFLOP/s TF32). Real-world utilization is typically 10-50% of peak. Use a conservative 20% for planning.
- Compute the time per request. Divide the FLOPs per request by the effective throughput (peak × utilization). For a 7 TFLOP request on an A100 at 20% utilization (62.4 TFLOP/s), that's ~0.11 seconds per request.
- Calculate the maximum requests per hour per GPU. Divide 3600 seconds by the time per request. With 0.11 seconds, that's about 32,700 requests per hour per GPU.
- Project your daily request volume. Estimate peak and average requests per day. For example, 1 million requests per day, with a peak of 2× average.
- Determine the number of GPUs needed. Divide your peak requests per hour by the requests per hour per GPU. If peak is 100,000 requests/hour, you need about 3 GPUs (100,000 / 32,700 ≈ 3.06).
- Calculate hardware cost. For cloud, multiply the number of GPUs by the hourly price and by the number of hours you run (e.g., 3 GPUs × $2/hour × 24 hours = $144/day). For on-premises, amortize the hardware cost over its useful life (e.g., $10,000 server / 3 years = ~$0.38/hour).
- Add operational costs. Include electricity (if on-prem), storage for model weights and logs, networking, and any managed service fees. A common rule of thumb is to add 20-30% on top of hardware cost.
- Sum up your total monthly cost. Multiply the daily hardware cost by 30, then add the operational overhead. This gives you a baseline estimate.
- Adjust for real-world factors. Add a buffer for retries, higher token counts, and model updates. Many teams double the estimate to be safe.
Common Mistakes
- Using theoretical peak FLOPs instead of real utilization. Real-world utilization is often 10-30% of peak due to memory bottlenecks and overhead.
- Underestimating token count. Users often send longer prompts than expected. Always test with real data.
- Ignoring batch effects. Batching multiple requests together increases throughput but also affects latency. Your cost model should reflect whether you can batch.
- Forgetting about the cost of serving infrastructure. Load balancers, API gateways, and logging add up.
- Assuming linear scaling. Doubling the number of GPUs doesn't always double throughput due to communication overhead.
Tips
- Start with a small pilot. Run a real workload on a single GPU to measure actual token counts and latency.
- Use auto-scaling. In the cloud, scale down to zero when idle to save costs.
- Optimize your model. Quantization (e.g., INT8) and pruning can reduce FLOPs and memory, cutting costs significantly.
- Consider serverless inference. For spiky workloads, serverless providers charge per request, which can be cheaper than dedicated GPUs.
- Monitor utilization. Use dashboards to track GPU utilization and adjust capacity accordingly.
Troubleshooting
- If your cost estimate is wildly high: Re-check your token count assumption. Often, the average token count is lower than you think. Also, consider using a smaller model or quantization.
- If latency is too high: Your utilization assumption may be too optimistic. Try a more powerful GPU or reduce the model size.
- If your actual costs are much higher than the estimate: Look for hidden costs like data transfer fees, storage, or idle GPU time. Use cloud cost management tools to identify them.
- If you can't meet SLAs: You may need to over-provision. In that case, re-estimate with a higher peak-to-average ratio.
Frequently Asked Questions
How accurate is a FLOP-based estimate?
It's a good starting point, but real-world performance varies. Use it for budgeting, then refine with actual benchmarks.
Does the cost differ between text and image models?
Yes. Image models process pixels, which are much larger than tokens, so they require more compute and memory.
Should I include training costs?
No, this guide is for inference only. Training is a separate, often one-time, cost.
How do I estimate the cost of a model I haven't deployed yet?
Use the model's parameter count and typical request size to estimate FLOPs, then follow the steps above.
Is it cheaper to run on-premises or in the cloud?
It depends on your utilization. If you run 24/7, on-prem can be cheaper. For variable workloads, cloud with auto-scaling is often more cost-effective.
What is a good rule of thumb for adding overhead?
Add 20-30% for operational costs. For a safety buffer, double the final number to account for unexpected spikes.