Skip to main content

The $9M Question

Chain-of-thought reasoning multiplies the serving bill, turning an algorithm choice into a capital decision.

ops
intermediate
Use InferenceScalingModel and EconomicsModel to quantify how chain-of-thought reasoning multiplies per-query latency, GPU fleet size, and annual infrastructure cost.

The Question

A team wants to add chain-of-thought (CoT) reasoning to its production serving pipeline. The accuracy improvement is clear: \(K=8\) reasoning steps (400 reasoning tokens vs. 50 tokens at \(K=1\)) measurably improve answer quality on hard queries. The open matter is what \(K=8\) costs, measured not in tokens but in dollars, GPUs, and annual infrastructure budget. Is this an algorithm decision or a capital expenditure decision?

NotePrerequisites

Complete Tutorial 2: Two Phases, One Request and Tutorial 3: The KV Cache Wall. This tutorial assumes familiarity with TTFT, ITL, and the two-phase serving model.

NoteLearning Objectives
  • Calculate per-query latency and energy cost across reasoning depths \(K=1\) to \(K=16\)
  • Compose InferenceScalingModel with EconomicsModel for annualized fleet cost
  • Quantify the cost multiplier of \(K=8\) reasoning at 100 QPS fleet scale
  • Evaluate a routing strategy that sends easy queries to a smaller model and hard queries to an expensive reasoning model
TipBackground: Inference-Time Compute Scaling

Standard LLM inference generates one answer directly: prefill the prompt (TTFT), then decode tokens one at a time (ITL). Chain-of-thought reasoning changes this: the model generates \(K\) intermediate “thinking” steps, each producing 50 tokens, before the final answer. The cost model becomes:

\[T_{\text{reason}} = \text{TTFT} + K \times T_{\text{step}}\]

where \(T_{\text{step}} = \text{tokens\_per\_step} \times \text{ITL}\). Each step is memory-bound (decoding), so the cost scales linearly with \(K\) at the decode rate, which belongs to the memory-bandwidth-limited phase. A seemingly algorithmic choice (add more reasoning) translates directly into GPU-hours and dollars.


1. Setup

import mlsysim
from mlsysim import Engine

2. Baseline Serving: Single-Query Cost

The baseline is GPT-4 (1,760B parameters) served on NVIDIA H100 at context length 2048 with no multi-step reasoning. It gives the per-query TTFT and ITL that everything else builds on.

from mlsysim import Models, Hardware
from mlsysim.solvers import ServingModel
from mlsysim.show import table, info

model = Models.Language.GPT4
hardware = Hardware.Cloud.H100

serving = ServingModel()
baseline = serving.solve(
    model=model, hardware=hardware,
    seq_len=2048, batch_size=1, precision="fp16"
)

info("Baseline Serving",
     Model=f"{model.name} ({model.parameters.to('Bparam').magnitude:.0f}B params)",
     Hardware=hardware.name,
     TTFT=baseline.ttft.to('ms'),
     ITL=baseline.itl.to('ms'),
     Memory_Used=f"{baseline.memory_utilization:.0%}",
     Feasible=f"{baseline.feasible}")
── Baseline Serving ────────────────────────
Model:        GPT-4 (1760B params)
Hardware:     NVIDIA H100
TTFT:         2,352.6 ms
ITL:          1,055.6 ms
Memory Used:  4117%
Feasible:     False

For GPT-4 on NVIDIA H100, prefill TTFT is 2,352.6 ms and per-token decode ITL is 1,055.6 ms (Feasible: False confirms that 1,760B FP16 weights exceed a single NVIDIA H100 and must be sharded across multi-GPU nodes in Section 4; here ServingModel gives the ideal per-GPU HBM bandwidth lower bound before sharding communication). Every reasoning step generates 50 tokens at this decode rate (52,777.7 ms per step), so the latency and energy costs accumulate in decode.


3. CoT Sweep: K=1 to K=16

The next cell sweeps reasoning depth \(K \in \{1, 4, 8, 16\}\) with the InferenceScalingModel. Each step generates 50 tokens of intermediate reasoning, and the cost multiplier grows with \(K\).

from mlsysim.solvers import InferenceScalingModel

cot_solver = InferenceScalingModel()
K_values = [1, 4, 8, 16]

baseline_time = None
results = {}
rows = []

for K in K_values:
    result = cot_solver.solve(
        model=model, hardware=hardware,
        reasoning_steps=K, context_length=2048, precision="fp16"
    )
    total_ms = result.total_reasoning_time.to("ms").magnitude
    energy_j = result.energy_per_query.to("J").magnitude

    if baseline_time is None:
        baseline_time = total_ms

    multiplier = total_ms / baseline_time
    results[K] = result

    rows.append([K, f"{total_ms:.1f}ms", result.tokens_generated, f"{energy_j:.1f} J", f"{multiplier:.1f}x"])

table(["K", "Total Time", "Tokens", "Energy (J)", "Multiplier"], rows)
K   Total Time  Tokens  Energy (J)  Multiplier
──────────────────────────────────────────────
1    55130.3ms      50   38591.2 J        1.0x
4   213463.4ms     200  149424.4 J        3.9x
8   424574.3ms     400  297202.0 J        7.7x
16  846795.9ms     800  592757.1 J       15.4x

Going from \(K=1\) (50 tokens, 55,130.3 ms, 38,591.2 J) to \(K=8\) (400 tokens, 424,574.3 ms, 297,202.0 J) multiplies per-query time and energy by 7.7× (and by 15.4× at \(K=16\) with 800 tokens). The multiplier is slightly below \(K\) because each query pays one fixed TTFT (2,352.6 ms) plus \(K\) decode steps (52,777.7 ms per step).


4. Annualized Fleet Cost

Per-query cost explains the mechanism, while fleet-level cost drives the budget. The cell below computes the annual infrastructure cost of serving 100 queries per second across \(K=1\), \(K=4\), \(K=8\), and \(K=16\).

from mlsysim.solvers import EconomicsModel
from mlsysim.systems.types import Fleet, Node, NetworkFabric
from mlsysim.core.units import Q_

econ = EconomicsModel()
target_qps = 100

fleet_results = {}
fleet_objects = {}
rows = []
for K in K_values:
    r = results[K]
    qt_s = r.total_reasoning_time.to("s").magnitude

    # Each GPU serves one query at a time (batch_size=1)
    qps_per_gpu = 1.0 / qt_s if qt_s > 0 else 0
    gpus_needed = int(target_qps / qps_per_gpu) + 1

    # Build fleet: 8 GPUs per node
    fleet = Fleet(
        name=f"K={K} Serving",
        node=Node(
            name="H100 Node",
            accelerator=hardware,
            accelerators_per_node=8,
            intra_node_bw=Q_("900 GB/s"),
        ),
        count=max((gpus_needed + 7) // 8, 1),
        fabric=NetworkFabric(
            name="IB NDR",
            bandwidth=Q_("400 Gbps").to("GB/s"),
        )
    )

    tco = econ.solve(fleet=fleet, duration_days=365)
    fleet_results[K] = tco
    fleet_objects[K] = fleet

    rows.append([K, f"{qt_s * 1000:.1f}ms", f"{qps_per_gpu:.2f}", fleet.total_accelerators, f"${tco.tco_usd:,.0f}"])

table(["K", "Query (ms)", "QPS/GPU", "GPUs", "Annual TCO ($)"], rows)
K   Query (ms)  QPS/GPU   GPUs  Annual TCO ($)
──────────────────────────────────────────────
1    55130.3ms     0.02   5520     $57,449,257
4   213463.4ms     0.00  21352    $222,220,388
8   424574.3ms     0.00  42464    $441,942,982
16  846795.9ms     0.00  84680    $881,304,910

At 100 QPS, moving from \(K=1\) to \(K=8\) expands the required fleet from 5,520 GPUs ($57.4M annual TCO) to 42,464 GPUs ($441.9M annual TCO), and to 84,680 GPUs ($881.3M annual TCO) at \(K=16\). That jump propagates through the entire infrastructure stack: more GPUs, more power, more cooling, more network fabric, and more capital expenditure.

ImportantKey Insight

A seemingly algorithmic decision (“add more reasoning steps”) is actually an infrastructure spending decision. \(K=8\) chain-of-thought reasoning multiplies per-query latency by 7.7×, so maintaining 100 QPS scales the fleet from 5,520 to 42,464 GPUs and increases annual TCO from $57.4M to $441.9M. The decision to add CoT reasoning is not only a model architecture choice; it is a capital expenditure decision that belongs in infrastructure budget planning.


5. The Routing Argument

The $441.9M annual TCO at \(K=8\) reframes the conversation from model architecture to capital planning. It also raises the question of whether every query must pay the full reasoning cost.

In production, not every query does, and the optimization that avoids it is routing. A router sends easy queries to a smaller, faster model (Llama-3.1-70B at \(K=1\), 2,713.4 ms per query) and routes only hard queries to the full GPT-4 \(K=8\) reasoning pipeline (424,574.3 ms per query). The cell below models a 70/30 split.

# Scenario: 70% of queries go to Llama-3 70B (no reasoning, K=1)
# 30% go to GPT-4 with K=8 reasoning
model_cheap = Models.Language.Llama3_70B

# Cheap path: Llama-3 70B, K=1
r_cheap = cot_solver.solve(
    model=model_cheap, hardware=hardware,
    reasoning_steps=1, context_length=2048, precision="fp16"
)

# Expensive path: GPT-4, K=8 (already computed)
r_expensive = results[8]

# Weighted average query time
qt_cheap = r_cheap.total_reasoning_time.to("s").magnitude
qt_expensive = r_expensive.total_reasoning_time.to("s").magnitude
qt_blended = 0.70 * qt_cheap + 0.30 * qt_expensive

# Compare: all queries to GPT-4 K=8 vs. routed
qps_blended = 1.0 / qt_blended if qt_blended > 0 else 0
gpus_blended = int(target_qps / qps_blended) + 1

fleet_routed = Fleet(
    name="Routed Serving",
    node=Node(name="H100", accelerator=hardware,
              accelerators_per_node=8, intra_node_bw=Q_("900 GB/s")),
    count=max((gpus_blended + 7) // 8, 1),
    fabric=NetworkFabric(name="IB", bandwidth=Q_("400 Gbps").to("GB/s")),
)

tco_routed = econ.solve(fleet=fleet_routed, duration_days=365)
tco_all_k8 = fleet_results[8]

savings = tco_all_k8.tco_usd - tco_routed.tco_usd
pct_savings = savings / tco_all_k8.tco_usd * 100 if tco_all_k8.tco_usd > 0 else 0

table(
    ["Strategy", "GPUs", "Annual TCO ($)"],
    [
        ["All queries -> GPT-4 K=8", fleet_objects[8].total_accelerators, f"${tco_all_k8.tco_usd:,.0f}"],
        ["70/30 routed", fleet_routed.total_accelerators, f"${tco_routed.tco_usd:,.0f}"],
    ]
)
info(Savings=f"${savings:,.0f} ({pct_savings:.0f}%)")
Strategy                   GPUs  Annual TCO ($)
───────────────────────────────────────────────
All queries -> GPT-4 K=8  42464    $441,942,982
70/30 routed              12928    $134,547,826
Savings:  $307,395,156 (70%)

Routing 70% of traffic to Llama-3.1-70B (\(K=1\)) reduces the fleet from 42,464 GPUs to 12,928 GPUs and cuts annual TCO from $441.9M to $134.5M, saving $307.4M (70%). The 30% of queries that still need full reasoning continue to require dedicated GPU capacity, and the routing classifier itself introduces latency and operational complexity. Routing contains the cost multiplier, while capital planning remains essential.


Where This Clicks in the Textbook

Vol II · Ch 2Fleet TCO

Breaks down amortized CapEx, facility power OpEx, and utilization break-even between cloud and on-prem.

Vol II · Ch 10Serving Cost

Shows why lifetime serving fleet CapEx/OpEx dominates one-time training cost at production QPS.

Vol III · Ch 3Reasoning Scale

Quantifies how Chain-of-Thought length and best-of-N deliberation multiply token budgets per query.

Vol III · Ch 19Task Economics

Models total cost per accepted task when retries, tool calls, and verification loops compound.

Next Steps

Back to top