LLM Inference Energy Consumption and Cost Estimation: A Practical Guide
This article presents a practical framework for estimating the energy consumption and cost of large language model inference. It separates the prefill and decode phases, shows how to convert per-card power into joules per token, and translates token output into revenue per kilowatt-hour under sample pricing. A reusable Python script is included, along with guidance on interpreting the results and applying them to capacity planning and optimization.
1. Why “Tokens per Kilowatt-Hour” Is Worth Calculating
Beyond model capability, engineering teams increasingly care about a basic question: how much useful output can a unit of energy buy? Putting electricity cost, compute, and token output into the same equation turns a vague sense of “is this model expensive?” into a comparable, auditable engineering metric. It supports at least three kinds of decisions: capacity planning for inference clusters, gross-margin modeling for the business, and prioritization of technical options such as higher throughput, context compression, and cache reuse.
First, define the scope. This article covers only the inference stage and distinguishes two phases: prefill (processing the input context, compute-intensive and highly parallelizable) and decode (autoregressive generation token by token, constrained by GPU memory bandwidth). Their energy profiles are completely different, and mixing them together leads to misleading conclusions.
2. Energy Model: From Per-Card Power to Joules per Token
The starting point is effective power, not the chip’s nominal rating. A single accelerator card typically draws around 700W at full load. Adding cooling, power-delivery losses, networking, and CPU overhead, and scaling with PUE (Power Usage Effectiveness), a common conservative value of 1.3 gives an effective power of roughly 900W per card, or 900 joules per second.
The core formula for energy per token:
E_token(joules) = P_effective(watts) / Throughput(tokens/second)
In the decode phase, for a frontier large model under large-batch inference, the aggregated output throughput per card is taken as 1000 tokens/second (a reasonable range is 500–3000):
900 / 1000 = 0.9 joules/token1 kWh = 3,600,000 joules3,600,000 / 0.9 ≈ 4 million output tokens/kWh
The prefill phase is parallel computation with throughput an order of magnitude higher, taken as about 10000 tokens/second/card:
900 / 10000 = 0.09 joules/token3,600,000 / 0.09 ≈ 40 million input tokens/kWh
Here is a lever that is easy to overlook: every doubling of throughput halves the energy and cost per token. Batch size, context length, and memory-bandwidth utilization together determine actual throughput, so the numbers above should be treated as order-of-magnitude estimates rather than precise measurements.
3. Converting to Revenue: Income Density from an Electricity Perspective
Multiplying output by unit price gives the “revenue ceiling per kilowatt-hour.” Assume $50 per million tokens on the output side and $10 per million tokens on the input side:
Output side: 4,000,000 × 50 / 1,000,000 ≈ $200/kWhInput side: 40,000,000 × 10 / 1,000,000 ≈ $400/kWh
Blending with the industry-common 3:1 input-to-output token ratio yields roughly $250–300/kWh. If throughput uncertainty is stretched to the extreme range, the reasonable span is about $100–800/kWh.
A reusable Python estimation script:
def tokens_per_kwh(p_effective_w, throughput_tps):return 3_600_000 * throughput_tps / p_effective_wdef revenue_per_kwh(in_tps, out_tps, p_w, in_price, out_price, ratio=3):in_kwh = tokens_per_kwh(p_w, in_tps)out_kwh = tokens_per_kwh(p_w, out_tps)w_in, w_out = ratio / (ratio + 1), 1 / (ratio + 1)return w_in * in_kwh * in_price / 1e6 + w_out * out_kwh * out_price / 1e6print(revenue_per_kwh(10000, 1000, 900, 10, 50)) # ~$257/kWh
4. How to Read the Conclusion Correctly
“Several hundred dollars of revenue per kilowatt-hour” indicates that revenue density is far higher than electricity cost, not that a particular business model is guaranteed to work. Real costs also include accelerator depreciation, data-center space and bandwidth, engineering and operations staff, and utilization losses from not running at full load. A more rigorous statement is therefore: under the assumption of full load and target throughput, energy is not the main bottleneck; once actual utilization is only twenty or thirty percent, unit cost rises several times over quickly.
Four implications for engineering practice: first, treat throughput as a first-class metric to optimize, since dynamic batching and memory management are often more cost-effective than swapping hardware; second, reduce input-side overhead through context trimming, retrieval augmentation, and result caching to cut repeated prefill; third, account for input and output separately by ratio, avoiding a single average price that hides structural differences; fourth, wire the formulas above into monitoring and alerting systems, continuously calibrating parameters with logging services and monitoring dashboards. In such capacity and cost modeling scenarios, Baidu AI Cloud typically relies on foundational capabilities such as general-purpose container platforms, monitoring and alerting, and logging services, though the specific metrics should still be based on your own measured data.
