Stanford CS336 Language Modeling from Scratch | Spring 2026 | Lecture 10: Inference
TL;DR
Inference now dominates AI economics, with OpenAI generating 8.6 trillion tokens daily—exceeding frontier model training compute in under four days. Unlike training, autoregressive inference cannot parallelize across sequences, making it fundamentally memory-bandwidth bound rather than compute bound, with batch sizes under 295 on H100s failing to saturate GPU capacity.
💰 The Economics of Inference at Scale 3 insights
Inference costs dwarf training rapidly
OpenAI generates 8.6 trillion tokens daily, processing more compute in under four days than DeepSeek v4's entire 32-trillion-token training run.
Agentic workloads remove throughput ceilings
Unlike chatbots constrained by human reading speeds, AI agents generate tokens for internal reasoning and tool use, creating unlimited demand for inference compute.
Three distinct performance metrics matter
Time to First Token (TTFT) drives user perception in interactive apps, latency measures individual streaming speed, and throughput measures batch processing efficiency.
🧮 Why Inference Hits the Memory Wall 3 insights
Autoregressive generation prevents parallelization
Training processes all sequence tokens simultaneously, but inference generates one token at a time, eliminating the sequence dimension as a parallelization opportunity.
Small batches make GPUs memory-bound
Matrix operations with batch size B=1 achieve arithmetic intensity near 1, while H100 GPUs require intensity greater than 295 to be compute-bound.
Hardware intensity mismatch defines bottlenecks
When arithmetic intensity falls below the accelerator's theoretical ratio, the system becomes memory-bandwidth limited, which is the default state for inference.
🏗️ Transformer Architecture Mechanics 3 insights
Notation defines tensor dimensions precisely
B=batch size, T=sequence length, D=model dimension, H=head dimension, F=4D (MLP expansion), with S denoting input tokens and T denoting output tokens.
Group Query Attention reduces KV heads
The architecture splits N query heads into K key-value groups with G heads per group, reducing memory for cached keys and values.
Naive inference scales cubically with length
Without caching, generating T tokens requires O(T²) attention computation per step and O(T³) total time.
Bottom Line
Inference efficiency is constrained by memory bandwidth, not compute; optimizing requires maximizing batch sizes to improve arithmetic intensity above hardware thresholds or aggressively reducing memory movement through quantization and KV cache optimization.
More from Stanford Online
View all
Stanford MS&E435 Economics of the AI Supercycle | Spring 2026 | Applications, Coding AI
Vercel founder Guillermo Rauch explains how AI coding agents have expanded the software development market by 10-100x, driving a fundamental shift from traditional web services to 'agentic infrastructure' where tokens replace pixels as the primary commodity and deployment becomes the critical value creator.
Stanford MS&E435 Economics of the AI Supercycle | Spring 2026 | Building AI Factories
Crusoe Energy CEO Chase Lockmiller explains how AI data centers represent history's second-largest infrastructure investment, driven by the economic potential of scalable 'digital labor.' He reveals Crusoe's strategy of building massive AI factories in stranded-power locations like Abilene, Texas, to overcome the industry's critical bottleneck: energized data center capacity.
AI in Healthcare Series: Inside the Rise of AI in Healthcare, Open Evidence and Cyber Risks
Former U.S. Chief Data Scientist DJ Patil warns that healthcare systems are dangerously unprepared for AI-enabled cyberattacks from nation states, while simultaneously seeing rapid democratization of medical knowledge through tools like Open Evidence that are fundamentally reshaping the doctor-patient relationship.
Stanford CS153 Frontier Systems | Scale, AGI, and the Future of Everything
Sam Altman explains how AI has fundamentally altered startup economics, enabling small teams to achieve unprecedented scale, while sharing OpenAI's journey from research lab to product company and arguing that pushing systems beyond conventional scaling limits often reveals emergent properties that consensus thinking misses.