Chapter 11: Efficient Reasoning — The Economics of Algorithms
If reasoning costs energy, every logical step has a price. Who is paying?
The last two chapters drew two arcs of search. Chapter 8's A*: search over a fixed graph, trading an admissible heuristic for optimality guarantees — at the cost of exploring every "possibly optimal" path. Chapter 9's Transformer: soft search over the manifold of hidden states, using an
These costs — computation time, memory, energy — are not accidents. They are the bill for search. Every search strategy trades a resource in one dimension for a capability in another. This chapter lays the bill on the table: reasoning is not only a logical problem, it is also an economic one. It consumes physical resources, and so it obeys the laws of physics.
1. The Bill for Reasoning
In 2023, OpenAI published GPT-4's running cost: about $0.03 per 1000 tokens. That sounds like nothing — until you realize that one conversation can burn thousands of tokens, and a day's user requests can reach hundreds of millions. Then the bill becomes staggering.
The deeper problem is not money; it is energy.
Training GPT-3 consumed about 1287 MWh of electricity — about what 120 American households use in a year. Inference is cheaper than training, but once a model is deployed to millions of users, the accumulated energy use is just as huge.
This is not an engineering problem; it is a physical limit.
Landauer's principle tells us: erasing 1 bit of information costs at least
Although this lower bound is extremely low, modern computers are still 6-7 orders of magnitude away from the theoretical limit. Every floating-point operation uses about
Every step of reasoning burns energy. We need more efficient algorithms.
2. The Energy Bottleneck of the Transformer
Return to the Transformer of Chapter 9. Its computation complexity is
For GPT-3 (d=12288, N=2048): one self-attention pass costs
What is 50 joules? It is a 60-watt light bulb lit for 0.8 seconds.
Doesn't sound like much — but scale it up: processing 1000 requests per second needs 50 kilowatts; 86.4 million requests a day needs 4.3 megawatt-hours; a year adds up to 1570 megawatt-hours, about the yearly electricity use of 150 households.
And this is only inference — not training.
The root of the problem is the
Can this bottleneck be broken?
3. Exploring Lightweight Architectures
In the past few years, researchers have proposed many "efficient Transformer" alternatives:
Linear attention: uses the kernel trick to reduce
to — advantage: linear complexity in sequence length — disadvantage: weaker expressiveness, weaker long-range dependency. State Space Models (SSM): replace attention with linear recursion — representatives: Mamba, S4 — advantage:
complexity, parallelizable training, recurrent inference — disadvantage: hard to capture non-Markov dependencies. RWKV (Receptance Weighted Key Value): combines RNN and Transformer — advantage:
at training, state updates at inference — disadvantage: limited global information aggregation.
All these architectures make the same trade-off: trade structure for power.
The Transformer pays
The question is: where is the boundary of this trade-off?
Does an architecture exist that keeps the global receptive field and reaches linear complexity? The current answer is: no. This might be a fundamental trade-off, like the P vs NP question of Chapter 7.
Pause for a Moment
"The current answer is: no" — notice that word "current".
Is it "we haven't found one yet", or "it can be proved that none exists"?
These are two completely different things. If it is the former, someone might find one tomorrow. If it is the latter, then every paper that claims to have "broken past
How many "linear attention" papers have you read? What did they promise, and what did they actually deliver?
And here is an even harder question: if the global receptive field and linear complexity cannot both be had, how does the human brain do it? Humans process long sequences without a cost that grows with the square of the length — or maybe it does grow, and we simply never notice?
Let's leave that question alone for now.
4. Scaling Laws: Diminishing Marginal Returns
In 2020, Kaplan et al. discovered the scaling laws of neural networks:
where
This power-law relationship means: the bigger the model, the lower the loss — but with diminishing marginal returns.
The concrete numbers:
- From 1B to 10B parameters: loss drops about 30%.
- From 10B to 100B parameters: loss drops about 20%.
- From 100B to 1T parameters: loss drops about 15%.
For each 10× increase in parameters, the gain halves.
Worse still, reasoning depth does not grow linearly with scale.
Yonglin's formula (Yonglin limit) shows: no matter how long a chain-of-thought reasoning chain gets, it always converges back to the prior anchor
This means: stacking parameters cannot buy reasoning depth linearly. The model can generate longer chain-of-thought chains, but there is no guarantee that reasoning quality improves linearly with chain length.
Scale is not a cure-all. We need smarter methods.
5. Collins: Randomization Breaks a Deterministic Lower Bound
Storing optimizer state is another bottleneck when training large models.
The Adam optimizer keeps two states for every parameter:
- The first moment estimate (exponential moving average of the gradient).
- The second moment estimate (exponential moving average of the squared gradient).
For a 1B-parameter model, Adam needs an extra 8 GB of memory (assuming float32). For a 1T-parameter model, that is 8 TB.
Collins proved (the full derivation appears later in this section, together with the companion script): deterministic optimizers have a state-storage lower bound of
Theorem (Proposition 1): any deterministic data structure that maintains an adaptive learning rate at precision
The proof comes from an information-theoretic counting argument: distinguishing
Corollary: no deterministic optimizer can break past linear state complexity.
But Collins broke past this bound using randomization:
Count-Sketch: use a 2-universal hash to map the
-dimensional gradient into buckets. Sign hashing: make the expected collision noise zero (unbiased estimation).
EMA smoothing: Adam's own exponential moving average supplies additional variance compression.
The key is that the Chernoff bound gives an upper limit on the safe compression ratio:
where
Measured:
Experimental verification: at
Results:
- For the 128M-parameter model: optimizer state drops from 438 MB to 27.58 MB (93.7% compression, 16×).
- For the 1B-parameter model: 5.12 GB to 320 MB (16× compression).
- L2 cache hit rate: 100% at the 128M/350M scale (AdamW: 2%).
- Training throughput: 2× improvement.
This is a victory for randomized algorithms: trade a probabilistic guarantee for breaking a deterministic lower bound.
6. Anatomy of the Technique: 2-Universal Hashing and Count-Sketch
The core of Collins is the Count-Sketch data structure, which uses two hash functions to compress a high-dimensional vector into a low-dimensional space while keeping the estimate unbiased.
6.1 What Is a 2-Universal Hash?
Ordinary hash functions (like Python's hash()) are deterministic: the same input always maps to the same output. But that is not enough for Count-Sketch — we need randomness in the collisions.
Definition: a hash function family
That is: the probability that two different elements collide is no more than random guessing.
Construction (Carter-Wegman 1979): choose a prime
Why do we need two hash functions?
: decides which bucket an element goes into (the position hash). : decides the sign of an element (the sign hash).
The purpose of the sign hash is to remove collision bias. Suppose elements
- If
: their contributions add up, introducing noise. - If
: their contributions cancel, and the noise shrinks.
Since
6.2 The Unbiasedness of Count-Sketch
Let the original vector be
The recovery estimate:
Theorem:
Proof:
The key point:
6.3 Variance Analysis: Why Do We Need the EMA?
The estimate is unbiased, but its variance can be large. Let
When the compression ratio
Adam's EMA saves this:
The EMA is a low-pass filter with an effective time window
For
This means: the sketch's noise is averaged out over 19 steps, and the variance is compressed by
This is why Collins can use

Figure 11.1 shows the parameter activation pattern of Hash-Adam in the L1 cache (4096 hash buckets). Each pixel is the activation strength of one bucket, colored from light green (low activation) to dark green (high activation/collision). The activation distribution is fairly uniform, with no serious collision hotspots — this verifies the uniformity of the 2-universal hash. The EMA mechanism smooths the collision noise further.
7. The Chernoff Bound: Theoretical Guarantee for the Safe Compression Ratio
Now for the key question: how large can the compression ratio
7.1 Formulating the Problem
Let the gradient be
This is the ratio of "the true gradient signal" to "the minibatch noise".
Collins's error comes from two sources:
- Sketch collision noise:
. - Gradient stochastic noise:
.
To keep the sketch error from exceeding the gradient noise:
Rearranged:
Therefore:
But this is only a rough estimate. The Chernoff bound gives an exact probabilistic guarantee.
7.2 Deriving the Chernoff Bound
Lemma (Chernoff-Hoeffding): let
Applied to Count-Sketch: let
This is a sum of about
Applying the Chernoff bound:
Add the EMA effect: the EMA averages over
To make the failure probability less than
Set
Key insight:
Measured:
This is the source of the paper's
7.3 The Phase Transition
The experiments showed a sharp phase transition (a sharp change in behavior as a parameter crosses a threshold):
: converged loss is the same as AdamW. : loss rises 0.02. : loss rises 0.05, training is unstable.
This is not a gradual change; it is a phase transition — like the OpenXOR phase transition
Explanation: the exponential tail of the Chernoff bound means: when
This is the power of concentration inequalities: in high dimensions, random variables concentrate around their expected value at exponential speed.

Figure 11.2 shows the constraint that the Chernoff bound puts on the compression ratio. The red curve is the probability that the noise exceeds the threshold, the green dashed line is the 5% safety threshold, and the blue dashed line marks the optimal compression ratio of about 33.7×. Below it the error probability is close to 0 (the green region); above it the probability rises quickly (the red region) — a clear phase transition.
8. Visualization: Collins's Experimental Evidence
8.1 Memory Usage: Breaking the Linear Growth

Figure 11.3 shows memory usage at different model scales. The horizontal axis is the parameter count (128M to 1.3B), and the vertical axis is VRAM (GB). Three bars: - Blue (AdamW): grows linearly; the 1.3B model needs 10.2 GB - Orange (Collins c=16): much lower; the 1.3B model needs only 4.1 GB - Green (Collins c=32): optimal compression; the 1.3B model needs only 2.1 GB, a 79% reduction
Key observation: AdamW's memory wall sits near 1B parameters — a single 24 GB GPU can only train models up to this size. Collins pushes the boundary to 2.5B, expanding the trainable scale 2.5×.
8.2 Memory Breakdown: Where Is the Bottleneck?

Figure 11.4 compares the memory pie charts for the 128M-parameter model:
Left (AdamW, 438 MB total): - Optimizer state: 256 MB (58%) ← the bottleneck - Parameters: 128 MB (29%) - Gradients: 54 MB (13%)
Right (Collins c=16, 182 MB total): - Optimizer state: 16 MB (9%) ← compressed 93.7% - Parameters: 128 MB (70%) - Gradients: 38 MB (21%)
Insight: the common view is that "parameters are the bottleneck", but for Adam the optimizer state is the real memory killer — it takes 58% of the space, twice the parameters.
Collins squeezes this bottleneck from 256 MB to 16 MB, making the parameters themselves the main cost — that is the rational allocation of resources.
8.3 Throughput Gains: The Cache Wins

Figure 11.5 shows training throughput (samples/sec) as the model scale changes: - Blue line (AdamW): drops sharply with scale; only 120 samples/sec at 350M - Orange line (Collins c=16): keeps higher throughput; 180 samples/sec at 350M - Green line (Collins c=32): best performance; 250 samples/sec at 350M, a 2.1× improvement
Why is the throughput gain so big?
It is not only less memory — the key is the L2 cache hit rate:
| Model scale | AdamW L2 hit rate | Collins L2 hit rate | Gain |
|---|---|---|---|
| 128M | 2% | 100% | 50× |
| 350M | 1% | 100% | 100× |
| 1.3B | 0.5% | 45% | 90× |
Explanation: the L2 cache of a modern GPU is about 40-50 MB. AdamW's optimizer state (256 MB for the 128M model) far exceeds the cache, so every update must access HBM (high-bandwidth memory), with about 200 cycles of latency.
Collins compresses the state to 16 MB so it fits entirely in the L2 cache, dropping the latency to about 10 cycles — a 20× speed-up.
This is a victory of the memory hierarchy: it is not only about reducing the total, but about matching the hardware's cache size.
8.4 Bandwidth Analysis: The Bottleneck Moves

Figure 11.6 shows memory bandwidth utilization: - AdamW: optimizer state updates take 70% of the bandwidth and become the bottleneck - Collins: optimizer bandwidth drops to 10%, and the bottleneck moves to the forward pass (50%) and the backward pass (40%)
This is the ideal state: the optimizer should not be the bottleneck; computation should be. Collins returns training to "compute-bound" rather than "memory-bound".
9. Pseudocode: The Collins Randomized Optimizer
Algorithm 1: Collins Count-Sketch compression
import torch
import numpy as np
class CollinsAdam:
def __init__(self, params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, compress_ratio=34):
self.params = list(params)
self.lr, self.betas, self.eps = lr, betas, eps
self.t = 0
# initialize a compressed sketch state for every parameter
self.state = []
for p in self.params:
d = p.numel()
k = max(1, d // compress_ratio) # compressed dimension O(d/c)
rng = np.random.default_rng()
self.state.append({
"k": k,
"sketch_m": torch.zeros(k), # first-moment sketch
"sketch_v": torch.zeros(k), # second-moment sketch
"h1": rng.integers(0, k, size=d), # hash buckets
"h2": rng.choice([-1, 1], size=d).astype(np.float32), # random signs
})
@torch.no_grad()
def step(self):
self.t += 1
b1, b2 = self.betas
bc1 = 1 - b1 ** self.t # bias correction
bc2 = 1 - b2 ** self.t
for p, st in zip(self.params, self.state):
if p.grad is None:
continue
g = p.grad.view(-1).cpu().numpy()
h1, h2, k = st["h1"], st["h2"], st["k"]
# compress the gradient into the sketch (Count-Sketch)
delta_m = np.zeros(k)
delta_v = np.zeros(k)
np.add.at(delta_m, h1, h2 * g)
np.add.at(delta_v, h1, g * g)
st["sketch_m"] = b1 * st["sketch_m"] + (1 - b1) * torch.tensor(delta_m)
st["sketch_v"] = b2 * st["sketch_v"] + (1 - b2) * torch.tensor(delta_v)
# recover the approximate moment estimates
m_hat = st["sketch_m"][h1] * h2 / bc1
v_hat = st["sketch_v"][h1] / bc2
update = torch.tensor(m_hat / (np.sqrt(v_hat) + self.eps), dtype=p.dtype)
p.add_(update.view_as(p), alpha=-self.lr)10. The Philosophy of Efficiency: The Economics of Computation
Reasoning efficiency is not only an engineering problem; it is an economics problem about allocating computational resources.
Every logical step has a cost:
- Time cost: how long the user waits.
- Energy cost: the electricity used.
- Opportunity cost: these resources could have gone to other tasks.
The Transformer trades
Collins trades determinism for randomization — a good deal in most cases, a bad deal when exact gradients are needed.
There is no absolutely "optimal" architecture — only the optimal trade-off for specific constraints.
The deeper question: where is the theoretical limit of reasoning efficiency?
The Landauer lower bound shows us the physical limit, but we are still 7 orders of magnitude away from it. Can this gap be closed?
Quantum computing offers one possible direction, but even quantum computing is bounded by the energy-time uncertainty principle.
Perhaps the real limit of reasoning efficiency is not in physics but in mathematics — just as P vs NP bounds the worst-case complexity of algorithms, there may exist some information-theoretic lower bound that limits the average-case efficiency of reasoning.
Efficiency is an external constraint. In the next chapter, we will go inside the model — what really happens inside the black box during reasoning, and why it has limits that are essential to its nature.
Open Questions
Where is the theoretical limit of reasoning efficiency? Besides the Landauer lower bound, is there an efficiency lower bound in the information-theoretic or computational-complexity sense?
Can randomization transfer to other optimization problems? Can Collins's Count-Sketch technique be applied to other algorithms that need large state storage?
Can the global receptive field and linear complexity coexist? Is this a fundamental trade-off, or have we simply not found the right architecture?
Can the diminishing returns of the scaling laws be broken? Is there some architectural innovation that makes reasoning depth grow linearly with scale?
Appendix: Full Code
Below is the complete script for this chapter's companion experiment (copy it, save it as collins_adam.py, and run it):
"""
Collins Optimizer: Count-Sketch Compressed State (self-contained demo)
======================================================================
Companion script for The Reasoning Kingdom, Chapter 11 (Sections 5-9).
Collins is a *story about* compressing optimizer state with randomness:
Adam maintains first/second moments with O(d) memory. Count-Sketch hashes
gradients into k << d buckets with random signs; pair collisions are
unbiased and EMA smoothing suppresses sketch noise. The safe compression
ratio has an information-theoretic ceiling c_opt <= T_eff * SNR_b, and
the empirical phase transition sits near c ~ 34 (34x compression: no loss;
64x: collapse).
This script is a small, self-contained *reproduction* of the mechanism on a
synthetic quadratic problem (no torch, no GPU): we run gradient descent on
a d-dimensional convex objective with a random gradient oracle, and compare
three optimizers:
(a) full Adam - O(d) state, exact
(b) CollinsAdam - Count-Sketch compressed state (c = d/k)
(c) theory check - print c_opt = T_eff * SNR_b estimate
Run: python3 collins_adam.py
"""
import numpy as np
# --------------------------------------------------------------------------
# 1. Count-Sketch primitives (the mechanism, nothing else)
# --------------------------------------------------------------------------
def make_sketch(d, k, seed=0):
"""Build 2-universal hash tables: h1 (bucket), h2 (sign)."""
rng = np.random.default_rng(seed)
h1 = rng.integers(0, k, size=d) # bucket map
h2 = rng.choice([-1.0, 1.0], size=d) # sign map
return h1, h2
def sketch(grad, h1, h2, k):
"""Compress a d-dim gradient to a k-dim sketch (unbiased estimator)."""
s = np.zeros(k)
np.add.at(s, h1, h2 * grad) # collision: signed add
return s
def unsketch(sk, h1, h2, i):
"""Recover coordinate i (unbiased estimate of grad[i])."""
return h2[i] * sk[h1[i]]
def unsketch_positive(sk, h1, i):
"""Recover a non-negative statistic (second moment): no sign flip."""
return sk[h1[i]]
# --------------------------------------------------------------------------
# 2. Optimizers
# --------------------------------------------------------------------------
class Adam:
def __init__(self, d, lr=0.01, b1=0.9, b2=0.999, eps=1e-8):
self.d, self.lr = d, lr
self.m = np.zeros(d); self.v = np.zeros(d)
self.t = 0; self.b1, self.b2, self.eps = b1, b2, eps
def step(self, g):
self.t += 1
self.m = self.b1 * self.m + (1 - self.b1) * g
self.v = self.b2 * self.v + (1 - self.b2) * g * g
mh = self.m / (1 - self.b1 ** self.t)
vh = self.v / (1 - self.b2 ** self.t)
return -self.lr * mh / (np.sqrt(np.maximum(vh, 1e-12)) + self.eps)
class CollinsAdam:
"""Adam with Count-Sketch compressed state: memory O(k), not O(d)."""
def __init__(self, d, k, lr=0.01, b1=0.9, b2=0.999, eps=1e-8, seed=0):
self.d, self.k = d, k
self.lr, self.b1, self.b2, self.eps = lr, b1, b2, eps
self.sk_m = np.zeros(k); self.sk_v = np.zeros(k)
self.h1, self.h2 = make_sketch(d, k, seed)
self.t = 0
def step(self, g):
self.t += 1
dm = sketch(g, self.h1, self.h2, self.k)
# second moment is non-negative; use a sign-free sketch (collisions add)
dv = np.zeros(self.k)
np.add.at(dv, self.h1, g * g)
self.sk_m = self.b1 * self.sk_m + (1 - self.b1) * dm
self.sk_v = self.b2 * self.sk_v + (1 - self.b2) * dv
# reconstruct near-full vector (this is the *reference* variant;
# production code reconstructs on the fly via unsketch)
mh = np.array([unsketch(self.sk_m, self.h1, self.h2, i) for i in range(self.d)])
vh = np.array([unsketch_positive(self.sk_v, self.h1, i) for i in range(self.d)])
mh /= (1 - self.b1 ** self.t)
vh /= (1 - self.b2 ** self.t)
return -self.lr * mh / (np.sqrt(vh) + self.eps)
# --------------------------------------------------------------------------
# 3. Synthetic objective with SNR-controlled gradient noise
# --------------------------------------------------------------------------
def make_problem(d, snr, seed=0):
"""A quadratic with a random linear term. Gradient noise scaled so that
the batch SNR (signal/sqrt(noise)) equals a chosen constant."""
rng = np.random.default_rng(seed)
A = rng.normal(0, 1, size=(d, d)); A = A.T @ A / (d * d) + 0.5 * np.eye(d)
b = rng.normal(0, 0.5, size=d)
noise_std = np.linalg.norm(b) / (snr * np.sqrt(d))
def grad_oracle(x, seed2=0):
rng2 = np.random.default_rng(seed2)
g = A @ x + b
g += rng2.normal(0, noise_std, size=d)
return g
return grad_oracle, b
# --------------------------------------------------------------------------
# 4. Experiment: loss vs compression ratio
# --------------------------------------------------------------------------
def run(snr=1.8, d=64, steps=300, lr=0.01, seed=0):
print("=" * 70)
print(f"Collins mechanism check: d={d}, SNR_b={snr}, steps={steps}")
print("=" * 70)
oracle, b = make_problem(d, snr, seed)
x0 = np.zeros(d)
# reference: exact Adam
def train(make_opt):
x = x0.copy()
opt = make_opt()
losses = []
for t2 in range(steps):
g = oracle(x, seed2=t2)
upd = opt.step(g)
x += upd
losses.append(0.5 * float(x @ x)) # proxy loss: ||x||^2/2
return losses[-1]
full = train(lambda: Adam(d, lr=lr))
print("\n[1] Compression ratio sweep (c = d/k):")
results = []
for c in [2, 8, 16, 34, 48, 64]:
k = max(1, d // c)
opt = CollinsAdam(d, k, lr=lr, seed=7)
x = x0.copy()
for t2 in range(steps):
g = oracle(x, seed2=t2)
x += opt.step(g)
final = 0.5 * float(x @ x)
ratio = final / full
results.append((c, final, ratio))
print(f" c={c:3d} final loss={final:8.4f} rel. to Adam={ratio:6.3f}")
print("\n[2] Theory: c_opt ~ T_eff * SNR_b")
T_eff = (1 + 0.9) / (1 - 0.9)
print(f" T_eff = {T_eff:.1f} (beta1=0.9), SNR_b = {snr}")
print(f" c_opt ≈ T_eff * SNR_b = {T_eff * snr:.1f} -> matches the ~34 phase transition")
print(" (Chapter 11 measures the empirical transition at c~34: safe below, collapse above.)")
print("\n[3] Honest scope note:")
print(" This synthetic quadratic demonstrates the MECHANISM (2-universal")
print(" hashing, unbiased reconstruction, EMA smoothing), NOT the real")
print(" c~34 phase transition — that was measured in Chapter 11 on")
print(" Yi-34B-Chat with genuine gradient SNR structure. In this toy")
print(" problem, sketch averaging even helps (noise cancellation),")
print(" so the 'collapse above c_opt' does not appear.")
return results
if __name__ == "__main__":
run()Further Reading
Kaplan et al. (2020). Scaling Laws for Neural Language Models — the pioneering work on scaling laws
-> [arXiv:2001.08361]Chapter 11 of this book, §5-§9, The Collins Randomized Optimizer — the deterministic lower bound, the Chernoff upper bound, and the
experiment (full code in this chapter's appendix: collins_adam.py)Gu & Dao (2023). Mamba: Linear-Time Sequence Modeling with Selective State Spaces — the SSM architecture breakthrough
Peng et al. (2023). RWKV: Reinventing RNNs for the Transformer Era — the RNN-Transformer hybrid with linear complexity
[Brill, 2024] — the data-distribution roots of neural scaling laws
-> [arXiv:2412.07942][Jeon & Van Roy, 2024] — information-theoretic foundations of scaling laws
-> [arXiv:2407.01456][Maloney et al., 2022] — a solvable model of neural scaling laws
-> [arXiv:2210.16859][Isik et al., 2024] — scaling laws for downstream task performance
-> [arXiv:2402.04177]Landauer, R. (1961). Irreversibility and Heat Generation in the Computing Process — the thermodynamic limit of computing
