Navigation
📐 Foundations· 12 min read

Full Lifecycle Cost

From pre-training investment through fine-tuning to serving — estimating the total cost of bringing a model from scratch to production.

costpre-trainingfine-tuninginferencetcogpu-hours

AI infrastructure decisions are ultimately economic decisions. This chapter builds the complete cost picture — from the initial training investment through fine-tuning to the ongoing cost of serving — so you can make informed tradeoffs.


1. The Three Cost Phases

Lifecycle Cost

PhaseWhenDurationCost driverTypical share
Pre-trainingOnceWeeks–monthsGPU-hours × price/hour5–20% of lifetime cost
Fine-tuningPer adaptationHours–daysMuch smaller than pre-training<1%
InferenceOngoingForeverTokens served × cost/token80–95% of lifetime cost

The key insight: inference dominates total cost. A model trained once serves billions of requests. Every 10% inference cost reduction saves more than a 50% training cost reduction.


2. Pre-Training Cost

Compute Cost Formula

Costtrain=CFLOPS/GPU×MFU×price/GPU-hour3600\text{Cost}_{\text{train}} = \frac{C}{\text{FLOPS/GPU} \times \text{MFU}} \times \frac{\text{price/GPU-hour}}{3600}

Where C≈6NDC \approx 6ND (total FLOPs for NN parameters, DD tokens).

Cost Estimates by Model Size

ModelParamsTokensFLOPsH100-hoursCost ($2/hr)
7B7B2T8.4×10228.4 \times 10^{22}~53K~$106K
13B13B2T1.6×10231.6 \times 10^{23}~100K~$200K
70B70B15T6.3×10246.3 \times 10^{24}~4M~$8M
405B405B15T3.6×10253.6 \times 10^{25}~23M~$46M

Assumptions: H100 at 989 TFLOPS FP16, 40% MFU, $2/GPU-hour (cloud spot pricing)

Hidden Pre-Training Costs

The GPU compute cost is only part of the picture:

Cost componentTypical multiplierNotes
GPU compute1.0× (baseline)The number above
Failed runs / restarts1.2–2.0×Hyperparameter search, loss spikes, hardware failures
Data preparation0.1–0.3×Crawling, cleaning, deduplication, tokenization
Engineering team0.5–2.0×6–12 months of 5–20 engineers
Storage0.05–0.1×Checkpoints (TB-scale), training data
Networking / infrastructure0.1–0.2×InfiniBand, cluster management

Rule of thumb: multiply raw GPU cost by 2.5–4× for total pre-training cost.


GPU Cloud Pricing Reference (as of mid-2026)

ProviderGPUOn-demand ($/hr)Spot/preemptible ($/hr)Reserved 1yr ($/hr)
AWSH100 (p5.48xlarge, 8 GPUs)~32/hr(32/hr (4/GPU)~12/hr(12/hr (1.50/GPU)~22/hr(22/hr (2.75/GPU)
GCPH100 (a3-highgpu-8g)~30/hr(30/hr (3.75/GPU)~10/hr(10/hr (1.25/GPU)~20/hr(20/hr (2.50/GPU)
AzureH100 (ND H100 v5)~28/hr(28/hr (3.50/GPU)~8/hr(8/hr (1.00/GPU)~19/hr(19/hr (2.40/GPU)
CoreWeaveH100 SXM~$2.50/GPU/hr—~$2.00/GPU/hr
Lambda LabsH100 SXM~$2.50/GPU/hr—~$1.90/GPU/hr

Prices change frequently. Hyperscalers bundle GPUs in fixed node sizes (typically 8 GPUs). GPU cloud providers (CoreWeave, Lambda) often offer lower per-GPU pricing but less managed infrastructure.


3. Fine-Tuning Cost

Full Fine-Tuning

Same as pre-training but on much less data:

ConfigDataComputeCost (H100)
7B, 100K examples~50M tokens~2×10182 \times 10^{18} FLOPs~$3
7B, 1M examples~500M tokens~2×10192 \times 10^{19} FLOPs~$30
70B, 100K examples~50M tokens~2×10192 \times 10^{19} FLOPs~$30
70B, 1M examples~500M tokens~2×10202 \times 10^{20} FLOPs~$300

LoRA Fine-Tuning

LoRA reduces trainable parameters by 100×+, but the forward/backward pass still processes the full model. Cost reduction is ~2–3× (not 100×), mainly from:

  • Smaller optimizer states (only LoRA params in FP32)
  • No gradient for frozen weights (but activations still computed)
  • Can use smaller batch sizes due to less memory pressure
ConfigFull FT costLoRA costSavings
7B, 1M examples~$30~$103×
70B, 1M examples~$300~$1003×

The Real Fine-Tuning Cost: Iteration

The compute cost per run is small. The real cost is iteration — running dozens of experiments with different data mixes, hyperparameters, and evaluation criteria. Budget for 10–50 runs per model adaptation.


4. Inference Cost

Cost Per Token

Cost/token=GPU cost/secondtokens/second\text{Cost/token} = \frac{\text{GPU cost/second}}{\text{tokens/second}}

Throughput depends on:

  • Model size (larger = fewer tokens/second)
  • Batch size (larger = better GPU utilization = more tokens/second)
  • Sequence length (longer = more KV cache = fewer concurrent requests)
  • Quantization (INT8/FP8 = ~2× throughput)
  • Hardware (H100 vs A100 vs consumer GPUs)

Throughput Estimates

ModelHardwareQuantizationThroughput (tokens/s)Cost per 1M tokens
7B1× H100FP16~3,000~$0.19
7B1× H100INT8~5,500~$0.10
70B8× H100 (TP=8)FP16~1,500~$3.00
70B4× H100FP8~2,000~$1.10
405B16× H100FP8~800~$11.00

Throughput varies significantly with batch size, sequence length, and serving engine optimization. These estimates assume moderate batch size (~32 concurrent requests), 2K average context, and optimized serving engine (vLLM or equivalent).

Inference at Scale: The Dominant Cost

For a popular AI service handling 10B tokens/month:

ModelCost/1M tokensMonthly inference costAnnual inference cost
7B (FP8)$0.10$1M$12M
70B (FP8)$1.10$11M$132M

Compare to training cost:

  • Training a 70B model: ~$8M (one-time)
  • Serving it for 1 year: ~$132M (16× training cost)

This is why inference optimization is the highest-leverage work in AI infrastructure.


5. Cost Optimization Levers

Training Cost Reduction

LeverSavingsTradeoff
Lower precision (FP8 training)1.5–2× throughputSlightly more complex training recipe
Better MFU (communication overlap, tuning)1.2–1.5×Engineering effort
Spot/preemptible instances2–3× cheaperNeed fault-tolerant training
Smaller model + more data (over-training)Save on inferenceMore training tokens needed

Inference Cost Reduction

LeverSavingsTradeoff
Quantization (FP8/INT8/INT4)2–4× throughputSmall quality loss
Batching optimization2–5× throughputHigher latency at low load
KV cache optimization (GQA, MLA, quantized KV)More concurrent requestsEngineering complexity
Speculative decoding2–3× decode speedExtra draft model compute
Prompt cachingSkip repeated prefillMemory for cache
Smaller model (from over-training)2–10×Quality depends on training
Model routing (small → large cascade)2–5× average costRouter quality matters

The Economic Formula

Total cost=Train(Ctrain)+FT(nexperiments×Cft)+Inference(Vtokens×Cper_token×Tlifetime)\text{Total cost} = \text{Train}(C_{\text{train}}) + \text{FT}(n_{\text{experiments}} \times C_{\text{ft}}) + \text{Inference}(V_{\text{tokens}} \times C_{\text{per\_token}} \times T_{\text{lifetime}})

For any model serving more than ~1M requests, inference dominates. Optimize inference first.

Caveat: cost optimization is meaningless without quality constraints. The cheapest option is always “don’t run the model.” Every cost decision must be evaluated against a quality threshold — the cost-quality Pareto frontier is what matters, not cost alone.


Self-Hosting TCO: A Worked Example

Should you self-host a 70B model or use an API?

Self-hosting (8× H100 DGX):

  • Hardware: ~300K(amortizedover3years=300K (amortized over 3 years = 100K/year)
  • Power + cooling: ~30K/year(8GPUs×700W×30K/year (8 GPUs × 700W × 0.10/kWh × 24/7)
  • Staff (0.5 FTE ops): ~$100K/year
  • Total: ~$230K/year
  • Throughput: ~2,000 tokens/s (FP8, optimized) = ~5.3B tokens/month
  • Cost: ~$0.043 per 1M tokens

API (GPT-4o-mini equivalent):

  • 0.15/1Minput+0.15/1M input + 0.60/1M output
  • Average: ~$0.30 per 1M tokens

Break-even: self-hosting wins at ~800M tokens/month (about $240K/year API spend). Below that, use APIs.


6. Cost Benchmarking: API Pricing as a Reference

Public API pricing reflects infrastructure costs (with margin). Prices as of mid-2026 — check provider websites for current rates:

ProviderModelInput (per 1M tokens)Output (per 1M tokens)
OpenAIGPT-4o$2.50$10.00
OpenAIGPT-4o-mini$0.15$0.60
AnthropicClaude Sonnet 4$3.00$15.00
DeepSeekDeepSeek-V3$0.27$1.10
GoogleGemini 2.0 Flash$0.10$0.40

Output tokens cost 2–5× more than input tokens because:

  • Input = prefill (compute-efficient, parallel)
  • Output = decode (memory-BW-bound, sequential, one at a time)

Self-hosting is cheaper than API at scale — the crossover is typically around 50–100M tokens/month, depending on model size and optimization level.


Self-Check

  • Explain why inference costs dominate total lifecycle cost
  • Estimate pre-training cost for a 7B model on 2T tokens
  • Explain hidden training costs beyond GPU compute (failure multiplier, data prep, engineering)
  • Explain why LoRA saves ~3× (not 100×) on fine-tuning cost
  • Calculate cost per 1M tokens given GPU price and throughput
  • Name 3 inference cost optimization levers and their tradeoffs
  • Explain why output tokens cost more than input tokens

References