Skip to main content

Inside the Black Box: What Actually Happens When You Send a Prompt to an LLM

Inside the Black Box: What Actually Happens When You Send a Prompt to an LLMPhoto: N43 and Hermes AI
N43 DESK
POLICY . 7983
AI SYSTEMS

Between your keystroke and the model's reply sits a five-stage pipeline - tokenizer, embeddings, attention layers, sampler, detokenizer. Knowing what each stage does changes how you write prompts and what you expect from answers.

Source video: How Do LLMs Work? · Techquickie · approximately 330,646 views observed as of September 26, 2026. The video framed this piece; the research and prose below are independent N43 and Hermes AI work.

Inference latency breakdown by pipeline stage Illustrative percentage shares of time-to-first-token: tokenization 3 percent, embedding lookup 4 percent, prefill attention pass 85 percent, sampling 4 percent, detokenization 4 percent. In steady-state generation, decode dominates wall-clock time instead. Tokenization 3% Embedding lookup 4% Prefill attention pass 85% Sampling 4% Detokenization 4% Share of time-to-first-token (percent, illustrative)
Units: percent of time-to-first-token per pipeline stage. Illustrative shares synthesized from published LLM serving literature (ORCA/vLLM-style prefill-decode analyses); in steady-state generation the decode phase dominates wall-clock time instead.

01 From keystroke to context: tokenization and why models count in tokens

Before a single weight fires, your text is chopped up. A tokenizer runs a learned vocabulary — commonly 32,000 to 256,000 pieces called tokens — over the prompt, splitting words into frequent chunks, subwords, or single characters. A common word may survive whole; rarer strings shatter into several pieces. Numbers, code, and non-English text are notorious for consuming more tokens than their apparent length suggests, because training vocabularies skew toward frequent English.

Three consequences follow. First, context limits are denominated in tokens, not words: a 128,000-token window holds far less prose than a naive character count implies. Second, pricing is denominated in tokens, so an invoice reflects the tokenizer's view of your text, not yours. Third, spelling is fragile: a model asked to count the letters in a word sees a token ID, not a letter sequence, which is why such tricks trip otherwise capable systems. Everything downstream — embeddings, attention, sampling — operates on this token stream, so the tokenizer quietly defines the granularity of everything the model can reason about.

02 Embeddings and the forward pass: how a prompt becomes geometry

Each token ID indexes a lookup table and comes back as a vector — a point in a space with thousands of dimensions. Directions in that space encode meaning: the same geometry that places queen near king minus man plus woman is what lets a model generalize from a handful of examples. Positional information is added so the network can tell where each piece sat in the sequence.

The forward pass then carries these vectors through dozens of stacked blocks. A 7B-class model typically has around 32 such blocks, each containing an attention operation and a feed-forward network that holds most of the parameters. After the final block, the vector at the last position is projected onto the vocabulary to produce one score per possible token: the logits. Nothing in this pass is mysterious in isolation. The apparent magic is what billions of fitted parameters do to geometry after training on trillions of words — compression so aggressive that statistical regularities start to look like reasoning.

03 Attention layers: the context window as working memory

Attention is the mechanism that lets each token consult every other token in the context. For each position the model computes queries, keys, and values; dot products between a query and every key produce weights, and the weighted mixture of values becomes the new representation. Early layers tend to pick up local patterns such as syntax and adjacent-word relations, while later layers assemble longer-range structure: topic, coreference, discourse.

This is why the context window behaves like working memory. Everything the model can use about your instructions must fit inside the window, and relevance is recomputed at every layer rather than stored once. Long prompts therefore do not accumulate understanding linearly: material buried in the middle competes for attention with everything else, and recall of mid-context facts is often weaker than at the edges. When a model seems to forget a constraint stated twenty paragraphs earlier, the honest description is not amnesia but attention that distributed its weight elsewhere. The window is not a recording; it is a rehearsal that must be continuously re-earned.

04 Sampling: why the same prompt never gives the same answer twice

The forward pass ends with logits — a score for every token in the vocabulary. A deterministic argmax would always pick the top one, and identical prompts would get identical answers. Instead, the sampler converts scores into a probability distribution and draws from it. Temperature rescales the logits before the softmax: low values sharpen differences toward predictability, high values inflate the tails toward surprise. Truncation rules such as top-p and top-k cut the tail so genuinely implausible tokens stay excluded even at high temperature.

That draw is why the same prompt never gives the same answer twice, and it is a feature rather than noise. Sampling is where diverse phrasings, brainstorm alternatives, and code variants come from. It is also where instability comes from: a long chain of individually reasonable draws can wander into confident nonsense, and two samplings of one question can disagree. Temperature near zero recovers near-determinism for extraction tasks; creative work usually wants the variance left in.

05 Prefill versus decode: the two very different phases of inference

Inference runs in two phases with very different economics. Prefill processes your entire prompt at once: all tokens are known, so the work is a large batch of matrix multiplications that saturates accelerator compute. It happens once per request and produces the first token — so time-to-first-token scales roughly with prompt length. A ten-word question feels instant; a twenty-page document stuffed into context makes the user wait before a single word appears.

Decode then generates one token at a time. Each new token must attend over the whole prefix, so every step reads the full model state from memory — yet each step is a small matrix operation that cannot use compute efficiently. Output speed is bounded not by floating-point throughput but by memory bandwidth, which is why tokens per second stays roughly flat no matter how long the answer grows. Serving stacks such as those described in the ORCA and vLLM papers exist largely to keep both phases busy at once, batching prefills from one request against decodes from others.

06 Why speed varies: memory bandwidth, KV cache, and batch effects

Three hardware-level factors explain most of the variance in response speed. First, memory bandwidth: decoding reads every weight and the accumulated cache on each step, so token production tracks how fast bytes move, not how fast the chips multiply. Second, the KV cache: to avoid recomputing attention over the whole prefix, systems store keys and values for every layer and every past token. A 7B-class model with 32 layers reserves roughly half a mebibyte per token in fp16 precision, so a 32,000-token context parks about 16 GiB on the accelerator before a word is emitted — charted below. Third, batching: servers juggle many requests per accelerator, and your latency depends on how much company you have. Heavy load stretches queue time and time-to-first-token; a long shared context inflates memory pressure and can slow everyone. This is also why long conversations feel progressively slower: the cache grows with every turn, and each new token pays a slightly larger tax.

KV-cache memory growth versus context length, 7B-class model Standard formula-based values in GiB: about half a GiB per thousand tokens for a 32-layer fp16 configuration; 2 GiB at 4,000 tokens, 4 GiB at 8,000, 8 GiB at 16,000, and 16 GiB at 32,000. 0 4 8 12 16 GiB 0 4k 8k 16k 32k Context length (thousands of tokens)
Units: GiB of accelerator memory consumed by the KV cache versus context length in thousands of tokens. Standard formula-based values (2 x layers x hidden size x 2 bytes per token, fp16) for a 32-layer, 4,096-hidden 7B-class configuration.

07 What the pipeline explains: prompt length, cost curves, and hallucination pressure

The pipeline is not trivia; it predicts behavior. Prompt length maps to prefill cost, so context dumps raise latency and price in near-linear proportion — charted above — and trimming redundancy is the cheapest optimization available. Because billing counts tokens, formatting and examples are not free: a verbose template pays on every call. Because context is working memory rather than storage, instructions stated once and buried get out-attended by recent text, which is why restating critical constraints at the end of a long prompt works so reliably.

Hallucination pressure also has a mechanical reading. Sampling guarantees fluent output even when the next-token distribution is spread thin over genuinely unknown territory; the model will still emit a confident-looking draw. Nothing in the detokenizer checks facts — its only job is turning token IDs back into text. Treat fluency as a property of the pipeline, not evidence of verification, and spend effort where leverage sits: short, specific prompts; constraints restated near the end; temperature matched to the task; and skepticism calibrated to how far an answer sits from anything the context could have grounded.

Key takeaway: an LLM reply is manufactured in five discrete stages, and each stage leaves fingerprints you can act on — tokens set the cost, prefill sets the wait, decode sets the pace, sampling sets the variance, and none of the stages fact-checks anything.

References

  1. Wikipedia: Large language model — overview of LLM architecture, training, and applications (consulted via Wikipedia REST API, September 26, 2026)
  2. Vaswani et al., Attention Is All You Need — the paper defining the transformer attention mechanism underlying the pipeline described here
  3. Source video: How Do LLMs Work? (Techquickie, ~330,646 views, observed September 26, 2026)
N43 DESK

N43 and Hermes AI · Independent Analysis

By N43 and Hermes AI for DutyStation News.

📰 Related Stories

The Upgrade Decision Is Now an Economic Calculation, Not a Camera Comparison
📰 technology

The Upgrade Decision Is Now an Economic Calculation, Not a Camera Comparison

N43 and Hermes AI1h ago
The 'Wait for the Next One' Trap: How Pre-Announcements Rewired the Phone Market
📰 technology

The 'Wait for the Next One' Trap: How Pre-Announcements Rewired the Phone Market

N43 and Hermes AI1h ago
What Makes an AI Release 'the Best'? Inside the Evaluation Mess Behind the Superlatives
📰 technology

What Makes an AI Release 'the Best'? Inside the Evaluation Mess Behind the Superlatives

N43 and Hermes AI1h ago
The GPT-7 Rumor Cycle: How Pre-Announcement Became Product Strategy
📰 technology

The GPT-7 Rumor Cycle: How Pre-Announcement Became Product Strategy

N43 and Hermes AI9h ago
The Scaling Wall Is Really a Data Bill: What Happens When Text Runs Out
📰 technology

The Scaling Wall Is Really a Data Bill: What Happens When Text Runs Out

N43 and Hermes AI9h ago
The Good-Enough Phone: How the Midrange Ate the Upgrade Cycle
📰 technology

The Good-Enough Phone: How the Midrange Ate the Upgrade Cycle

N43 and Hermes AI9h ago
← Back to News