, ,

What is an LLM, and how does it work?

A large language model predicts the next piece of text, over and over. Tokens, parameters and layers, how it picks each word with temperature and top-p, how it learns, and what decides the hardware it needs.

Probability bars for the next token after a prompt

AI Infrastructure series · Part 9 of 24

The first eight parts of this series were about hardware. This part turns to what runs on it. A large language model (LLM), the technology behind ChatGPT, Claude and Gemini, does one surprisingly simple thing: it predicts the next piece of text, over and over. This post follows that one step all the way through, with real numbers: how text becomes tokens, how a token becomes a row of numbers, how the model scores every possible next token and picks one, how it learns to do that, and which parts of the process decide how much GPU memory, bandwidth and compute you need.

Try it: Next-Word Lab

See real tokenizers cut text into tokens, train a tiny BPE vocabulary merge by merge, step through the generation loop with the KV cache growing, and compare temperature and top-p settings for factual answers, creative writing and code.

Open the demo →

What does an LLM actually do?

Given some text, an LLM works out how likely every possible next piece of text is. It then picks one piece, adds it to the text, and does the same again with the slightly longer text. A whole answer, a poem or a program is just that one step repeated a few hundred or a few thousand times, until the model picks a special “stop” token or reaches a length limit.

That sounds too simple to produce anything useful. The trick is that predicting well needs a great deal of knowledge. To continue “The capital of France is” the model has to have absorbed geography. To continue a half-written function it has to have absorbed programming. Prediction at this scale behaves like understanding, even though the mechanism underneath is scoring and picking.

What does one prediction look like? A worked example

Take the prompt “The capital of France is”. The model does not output a word. It outputs a score, called a logit, for every token in its vocabulary: 128,256 of them for Llama 3.1. Most scores are very low. Here are six of the highest, with made-up but realistic values (illustrative), and how they turn into a choice:

1

Scores from the model. ” Paris” 8.0, ” a” 5.0, ” the” 4.5, ” located” 4.0, ” Lyon” 3.0, ” home” 2.5. Scores can be any number, positive or negative; only the gaps between them matter.

2

Make them positive with escore. e8.0 = 2,981, e5.0 = 148.4, e4.5 = 90.0, e4.0 = 54.6, e3.0 = 20.1, e2.5 = 12.2. The total is 3,306.3. A gap of 3 in score becomes a factor of 20 here, which is why the top token pulls so far ahead.

3

Divide by the total to get probabilities. ” Paris” 2,981 ÷ 3,306.3 = 90.2%, ” a” 4.5%, ” the” 2.7%, ” located” 1.7%, ” Lyon” 0.6%, ” home” 0.4%. They add up to 100%. Steps 2 and 3 together are called softmax.

4

Draw a random number between 0 and 1. Lay the probabilities end to end: ” Paris” covers 0 to 0.902, ” a” 0.902 to 0.947, and so on, with ” Lyon” covering 0.991 to 0.997. A draw of 0.42 picks ” Paris”. A draw of 0.993 picks ” Lyon”: the model then states, fluently, that the capital of France is Lyon. At these odds that happens in about 1 answer in 165.

5

Append and repeat. The chosen token joins the text and the whole calculation runs again for the next position, now with ” Paris” in the context.

Every LLM answer is made this way, one draw at a time. The settings that change these odds (temperature, top-k, top-p) come later in this post, and you can watch the draws happen in the demo.

How is text turned into tokens?

Models do not read letters or whole words. Text is first cut into tokens by a tokenizer, and each token is replaced by its number in the model’s vocabulary. Here is a real example, cut by the tokenizer GPT-4o uses (called o200k_base), with each token’s id underneath:

The976 capital9029 of328 France10128 is382 Paris12650,11 and326 it480 is382 known5542 for395 the290 Eiffel155511 Tower37994.13

Fourteen words became 16 tokens. Notice three things. The space belongs to the start of the next token, so ” Paris” and “Paris” are different tokens. Punctuation gets its own token. And ” is” has the same id, 382, both times: the model sees the same number wherever the token appears. A rarer word is split into pieces: “Hyperconverged” becomes “Hyper”, “con”, “ver”, “ged”. Numbers are split too: “3.35” becomes “3”, “.”, “35”, which is one reason models are clumsy at arithmetic.

How does a tokenizer decide where to cut? BPE step by step

Most tokenizers are built with byte pair encoding (BPE). Start with every text split into single characters (modern tokenizers start from raw bytes). Count every pair of neighbouring symbols across a large training text. Merge the most common pair into a new symbol, add it to the vocabulary, and count again. Stop when the vocabulary reaches the size you want. The diagram runs this on a tiny corpus, the classic example from the BPE paper for machine translation.

Training text: low ×5, lower ×2, newest ×6, widest ×3 (_ marks the end of a word) Step Merge this pair Times seen “newest” is now “lower” is now 1e + s → es9n|e|w|es|t|_l|o|w|e|r|_ 2es + t → est9n|e|w|est|_l|o|w|e|r|_ 3est + _ → est_9n|e|w|est_l|o|w|e|r|_ 4l + o → lo7n|e|w|est_lo|w|e|r|_ 5lo + w → low7n|e|w|est_low|e|r|_ 6n + e → ne6ne|w|est_low|e|r|_ 7ne + w → new6new|est_low|e|r|_ 8new + est_ → newest_6newest_ (1 token)low|e|r|_ A word it never saw: “lowest_” starts as l|o|w|e|s|t|_ and the 8 merges, applied in order, give low|est_ Real tokenizers run the same loop over a huge text sample until the vocabulary holds 50,000 to 250,000 tokens.

Byte pair encoding on a four-word corpus, computed merge by merge; rows highlight in order. Frequent words end up as one token, rare ones are built from pieces, and nothing is ever unknown because single characters (or bytes) are always in the vocabulary.

Two consequences matter for infrastructure. First, the vocabulary is fixed when the tokenizer is built, before the model is trained, and every model has its own. The same text costs a different number of tokens on different models, so token counts, prices and context limits are only comparable within one tokenizer. Second, the merges reflect whatever text dominated the tokenizer’s training sample. Text that looks like that sample is cut into few, long tokens. Text that does not is cut into many short ones.

ModelTokenizerVocabulary sizeWhat it means
GPT-2byte-level BPE50,257Mostly English merges; other scripts fall back to bytes
Llama 2SentencePiece BPE32,000Small table, more tokens per sentence
GPT-4cl100k_base100,277Better coverage of code and European languages
Llama 3, 3.1tiktoken-style BPE128,256Four times Llama 2’s table, fewer tokens for the same text
GPT-4oo200k_base200,019Many more merges for non-Latin scripts
GemmaSentencePiece256,000Large multilingual table

Why do other languages use more tokens?

I ran the same sentence, “The capital of France is Paris, and it is known for the Eiffel Tower”, in six languages through three real tokenizers. The counts below are exact for those tokenizers.

LanguageWordsGPT-2 (50K)GPT-4 (100K)GPT-4o (200K)GPT-4o vs English
English141818161.0×
French121818140.9×
German92417150.9×
Chinese19 characters4226150.9×
Hindi149868251.6×
Tamil818692291.8×
EnglishGPT-2 tokenizer
18
GermanGPT-2 tokenizer
24
ChineseGPT-2 tokenizer
42
HindiGPT-2 tokenizer
98
TamilGPT-2 tokenizer
186

Tokens for the same sentence with GPT-2’s tokenizer, counted with OpenAI’s tiktoken library.

The reason is in how BPE starts. Byte-level tokenizers begin from the bytes of UTF-8 text. An English letter is one byte. A Devanagari or Tamil letter is three. If the tokenizer’s training text had little Hindi, few Hindi merges were learned, and the text falls back to pieces of bytes: the Hindi word for France, six characters and 18 bytes, is 11 tokens for GPT-2. A larger vocabulary trained on more languages fixes most of this, which is why GPT-4o’s tokenizer cuts the Hindi count from 98 to 25. The gap has not gone, and it has real costs: more tokens means a higher bill for the same meaning, a context window that fills sooner, and an answer that takes longer to stream.

Tokens are the unit for everything that follows in this series. Prices are per million tokens (my token cost post works through the maths), speed is tokens per second, the KV cache grows per token, and the context window is measured in tokens. Counting them takes three lines:

import tiktoken
enc = tiktoken.get_encoding("o200k_base")
print(enc.encode("The capital of France is Paris."))
# [976, 9029, 328, 10128, 382, 12650, 13]  -> 7 tokens

What does the model do with a token id?

A token id is just a row number. The first thing inside the model is the embedding table: a matrix with one row per token in the vocabulary and one column per dimension of the model’s internal vector, its hidden size. Looking up row 12,650 gives a list of a few thousand numbers that stand for that token. Nothing is calculated at this point; it is a memory read.

For Llama 3.1 8B the sizes are exact. The vocabulary has 128,256 tokens and the hidden size is 4,096, so the table holds 128,256 × 4,096 = 525,336,576 numbers. At 2 bytes each in 16-bit precision that is about 1.05 GB, just for the lookup table. At the other end of the model sits the output head, a matrix of the same shape, 4,096 × 128,256, that turns the final vector into one score per vocabulary token. Llama 3.1 8B stores it separately (its config sets tie_word_embeddings to false), so the two ends of the model together take another 1.05 billion parameters. This is the hidden cost of a large vocabulary: each extra 1,000 tokens adds 8.2 million parameters to an 8B model.

token id 12,650 Embedding table 128,256 rows × 4,096 525.3M numbers, 1.05 GB 4,096 numbers 32 transformer layers attention mixes in the tokens before it, the MLP transforms each vector; the vector stays 4,096 numbers long last token’s final vector Output head 4,096 × 128,256, another 525.3M 128,256 scores one per vocabulary token; softmax turns them into odds

Llama 3.1 8B shapes. The token id is only a row number; the embedding lookup is a memory read, the layers are where the arithmetic happens, and the output head produces the scores used in the worked example above.

The numbers in each row start random and are adjusted during training until tokens used in similar ways end up with similar vectors. Inside the layers, each token’s vector is updated using the vectors of the tokens before it. That is the attention mechanism, and it is how ” bank” comes to mean something different after “river” than after “loan”. Part 11 follows a vector through one layer in detail.

What are parameters, and where do they live?

Parameters, also called weights, are every number the model learned in training. “8B” means 8 billion of them. They are grouped into matrices, and every matrix has a fixed job. Llama 3.1 8B’s published shapes let you count them exactly:

PartShapeParametersShare16-bit size
Embedding table128,256 × 4,096525.3M6.5%1.05 GB
Attention, 32 layersQ and O 4,096 × 4,096; K and V 4,096 × 1,0241,342.2M16.7%2.68 GB
MLP, 32 layersthree matrices of 4,096 × 14,3365,637.1M70.2%11.27 GB
Normsvectors of 4,0960.27M0.003%under 1 MB
Output head4,096 × 128,256525.3M6.5%1.05 GB
Total8,030.3M100%16.06 GB
embattentionMLP (feed-forward)head
Embedding and output head 13%Attention 17%MLP 70%

K and V are smaller than Q because Llama 3.1 uses grouped-query attention: 32 query heads share 8 key and value heads, each 128 numbers wide. That choice also shrinks the KV cache, as we will see. The 70% in the MLP is typical of dense models, and it is the part that mixture-of-experts models split into many smaller experts (part 12).

Where they live matters more than what they are called. When the model is served, every parameter sits in GPU memory, and every one is read for every token generated, because each new token passes through every layer. That is why 16.06 GB of weights sets both the minimum memory for this model and the time floor for each token (part 7 works out memory for other sizes and precisions).

How does the model write a whole answer?

The generation loop has two phases. In prefill, the whole prompt goes through the model in one pass. While it does, each layer works out a key and a value vector for every prompt token and stores them in GPU memory: the KV cache. Prefill ends with the first set of scores and the first new token. Then decode begins: each step feeds only the newest token through the layers. Its attention needs the keys and values of every earlier token, and reads them from the cache instead of recomputing them. One step produces one token and adds one entry to the cache.

Contextids so far Embedid → vector 32 layersattention, MLP Logits128,256 scores Sampletemp, top-p Appendadd to context repeat once per new token, until a stop token or max_tokens Context (prompt in black, generated tokens in red) The capital of France is Paris , and it step 1 → 4: one token each KV cache in GPU memory: keys and values for every token, in every layer free memory, up to the window after prefill: 5 tokens × 128 KB = 640 KB after 4 decode steps: 9 tokens = 1.1 MB (Llama 3.1 8B) Step 0, prefill All 5 prompt tokens go through the layers together. Their keys and values are written to the cache. Lots of maths per weight read: compute-bound. Steps 1 to 4, decode Only the newest token goes through the layers. It reads every weight once, plus the whole cache. Little maths per byte read: bandwidth-bound.

One prefill pass and four decode steps, animated: the stage boxes light up in order and one red token and one cache entry appear per step. KV size per token is Llama 3.1 8B’s 128 KB in 16-bit; token ids and the chosen words are illustrative.

Here is the cache arithmetic for Llama 3.1 8B. Each layer stores a key and a value for each of its 8 KV heads, 128 numbers each, at 2 bytes: 2 × 8 × 128 × 2 = 4,096 bytes per layer. Across 32 layers that is 131,072 bytes, 128 KB per token. A 1,000-token conversation holds about 131 MB of cache. The weights do not change during generation; the cache is the only thing that grows. Without it, step 500 would have to recompute keys and values for all 499 earlier tokens, so total work would grow with the square of the answer length.

The two phases stress different parts of a GPU. Prefill does many calculations per weight read and is limited by compute; it sets the wait for the first token. Decode does about 2 operations per parameter per token, 16 billion for this model, while reading all 16 GB of weights: on an H100 SXM with 3.35 TB/s that is at least 4.8 ms per step, so one user can get at most about 208 tokens per second. Part 13 covers the two phases and part 14 the cache in depth.

How do temperature, top-k and top-p change the pick?

Between the scores and the draw sit a few settings you pass with every request. Temperature divides every score before softmax. Below 1 it widens the gaps, so the top token takes more of the probability. Above 1 it narrows them, so unlikely tokens get picked more often. Temperature 0 is treated as “always take the top token”, called greedy decoding. Top-k keeps only the k highest-scoring tokens and shares the probability among them. Top-p, also called nucleus sampling, keeps the smallest set of top tokens whose probabilities add up to at least p, and drops the rest. Both cut off the long tail of the 128,256 tokens, where the nonsense lives.

Here is what each setting does to the same six scores from the worked example:

SettingParisathelocatedLyonhome
Temperature 0 (greedy)100%00000
Temperature 0.599.6%0.2%0.1%<0.1%<0.1%<0.1%
Temperature 1.090.2%4.5%2.7%1.7%0.6%0.4%
Temperature 1.573.4%9.9%7.1%5.1%2.6%1.9%
Temperature 2.059.6%13.3%10.4%8.1%4.9%3.8%
Temp 1.0, top-k 392.6%4.6%2.8%cutcutcut
Temp 1.0, top-p 0.9100%cutcutcutcutcut
Temp 1.5, top-p 0.981.1%11.0%7.9%cutcutcut

Two rows deserve a closer look. At temperature 1.0, ” Paris” alone holds 90.2%, which already reaches p = 0.9, so top-p keeps only ” Paris”: a confident distribution is left alone, and a flat one keeps more choices. That adaptiveness is why top-p is more popular than top-k. And at temperature 2.0, ” Lyon” climbs from 0.6% to 4.9%, eight times as likely, without the model’s knowledge changing at all. Settings change how often the wrong answer is drawn, not whether the model knows the right one.

UseTypical starting pointWhy
Factual answers, extractiontemperature 0 to 0.3One right answer; variety only adds risk
Codetemperature 0 to 0.3, top-p 0.95A single wrong token can break the program
Chat assistanttemperature 0.6 to 1.0, top-p 0.9 to 0.95Natural wording that does not repeat itself
Creative writing, brainstormingtemperature 0.9 to 1.2, top-p 0.95Less likely words are the point

Common starting values, not rules; model makers often publish their own recommended settings, and these should come first.

In practice the settings travel with each request to a model server. This is the OpenAI-compatible API that vLLM and most other servers expose (part 16):

curl http://localhost:8000/v1/completions -H "Content-Type: application/json" -d '{
  "model": "meta-llama/Llama-3.1-8B-Instruct",
  "prompt": "The capital of France is",
  "max_tokens": 20, "temperature": 0.2, "top_p": 0.9, "logprobs": 5 }'
# "logprobs": 5 returns the top five candidates and their log-probabilities
# for each generated token; "usage" in the reply counts prompt and completion tokens

Why are models confidently wrong?

Look again at the draw. The model produces the most likely continuation given its training, not a checked fact. There is no step where it looks something up or asks itself whether it is sure. Fluency comes from the same process as accuracy, so a wrong token is written in exactly the same confident style as a right one. When a fact was rare in the training text, such as a minor court case, a specific part number or a quote, the right answer may score little higher than several plausible wrong ones, and the model picks one of them. This is what people call hallucination. Lower temperature helps when the right answer is clearly on top; it cannot help when it is not. Grounding the answer in retrieved documents, as RAG systems do, puts the right text into the context so it scores highest. That reduces wrong answers but does not remove them.

What is a context window, and what happens when it fills?

The context window is the most tokens the model can consider in one request: prompt plus answer. Llama 3.1 supports 128K (131,072) tokens. Everything the model knows about your conversation has to fit in it: the system prompt, tool definitions, retrieved documents, the earlier turns, the new question and room for the answer.

One request in a 128K-token window (illustrative mix) retrieved documents 40K chat history 60K answer room 24.5K system prompt 2K, tool definitions 4K at the left; the question (500 tokens) is the thin line before the answer room KV cache if the window is full, Llama 3.1 8B: 131,072 × 128 KB = 16 GiB for one request KV cache, 1 full request: 17.2 GB model weights in 16-bit: 16.1 GB When the conversation no longer fits Server rejects it prompt plus max_tokens over the limit returns an error App drops old turns oldest messages are cut; the model simply never sees them App summarises old turns replaced by a short summary; detail is lost

Segment sizes are an illustrative mix for a RAG chat app. The KV figure uses Llama 3.1 8B’s published shapes in 16-bit: one full-length request needs about as much memory as the model itself.

The model itself never sees anything outside the window, and it does not choose what to drop: the server or the application decides. A model server such as vLLM refuses a request that cannot fit inside its configured maximum length. Chat applications quietly cut or summarise the oldest turns, which is why a long chat can “forget” something you said at the start. The cost of a long window is mostly memory, not weights: each token of context is 128 KB of KV cache for every concurrent request, and every decode step reads all of it. That is why a server is usually configured with a maximum length far below what the model supports.

How does a model learn?

Training adjusts the parameters so that the scores in the worked example come out right. The model reads a passage, predicts each next token, and the training code measures how much probability it gave to the token that really came next. Back-propagation then nudges every parameter a tiny amount in the direction that would have raised that probability. Repeated over trillions of tokens, the nudges add up to grammar, facts, style and reasoning habits. It happens in stages, and the stages differ in size by orders of magnitude.

1 Pre-training predict the next token on raw web, books, code trillions of tokens → base model 2 Instruction tuning prompts with written good answers (SFT) 10Ks to millions → instruct model 3 Preference tuning pairs of answers ranked better and worse 10Ks to 1M+ pairs → chat model 4 Reasoning RL reward answers that can be checked: maths, code optional stage → reasoning model Same prompt to each kind of model: “What is the capital of France?” (illustrative replies) Base model “What is the capital of Germany? What is the capital of Spain? …” continues the text; it looks like a quiz, so it adds questions Instruct model “The capital of France is Paris.” answers the question, in the format it was tuned on Reasoning model [thinking: a simple fact; France’s capital is Paris] “Paris.” writes hidden working first; those tokens are still decoded

Data sizes are the published ranges in the table below; the replies are illustrative. Each stage starts from the previous stage’s weights, so later stages shape behaviour rather than add much knowledge.

StageDataPublished examplesHardware
Pre-trainingRaw text and code, next-token predictionGPT-3: 300B tokens. Llama 2: 2T tokens. Llama 3: over 15T tokensThousands of GPUs for weeks or months; Llama 3.1 405B used up to 16,000 H100s
Instruction tuning (SFT)Prompts with written model answersInstructGPT: about 13K prompts. Llama 2: 27,540 annotated examplesTens to hundreds of GPUs, hours to days
Preference tuning (RLHF, DPO)Pairs of answers ranked by people or modelsInstructGPT reward model: 33K prompts. Llama 2: over 1 million comparisonsSimilar to SFT; RLHF also runs a reward model and generates answers during training
Reasoning RL (optional)Problems whose answers can be checked automaticallyVaries; few makers publish sizesHeavy on inference: the model writes long attempts to be scored
Your fine-tuningYour own examples, often a few thousandLoRA trains well under 1% of the parametersOne GPU to a few servers (part 19)

Pre-training is where knowledge comes from, and it is the stage almost nobody repeats. A useful rule from the Chinchilla paper (Hoffmann et al., 2022) is that compute is best spent on about 20 training tokens per parameter. Modern small models go far past that on purpose: Llama 3 8B saw over 15 trillion tokens, nearly 1,900 per parameter, because a small model that is cheap to serve is worth extra training. Training compute is about 6 × parameters × tokens, so for that model: 6 × 8.03 billion × 15 trillion ≈ 7.2 × 1023 operations, which Meta’s model card puts at 1.46 million H100 GPU hours for Llama 3.1 8B.

What is the difference between base, instruct and reasoning models?

KindStages appliedBehaviourTypical useInfrastructure effect
BasePre-training onlyContinues any text; does not follow instructions reliablyStarting point for your own fine-tuningSame size and speed as the instruct version
Instruct or chatPlus SFT and preference tuningAnswers questions, follows a chat template, refuses some requestsAssistants, RAG, most applicationsSame weights shape; usually what you serve
ReasoningPlus reinforcement learning on checkable problemsWrites a chain of working before the answerMaths, code, multi-step planning, agentsMany more output tokens per answer: more decode time, more KV cache, higher cost

On a model hub these usually appear as separate files with the same architecture, such as Llama-3.1-8B and Llama-3.1-8B-Instruct. The memory needed to serve them is identical. A reasoning model can be the same size too; what changes is that it may decode hundreds or thousands of hidden thinking tokens before the visible answer, and every one of them costs a decode step and a KV cache entry.

What does an LLM need from hardware at each stage?

Put the pieces together for one model, Llama 3.1 8B, and the hardware needs line up with the earlier parts of the series:

StageMemoryBottleneckWorked numberRead more
Pre-trainingAbout 16 bytes per parameter (weights, gradients, optimizer state): 128 GB before activationsCompute and the network between GPUs7.2 × 1023 operations, 1.46M H100 GPU hourspart 15
Full fine-tuningSame 16 bytes per parameter: more than one 80 GB GPUMemory128 GB, so shard across 2 or more GPUspart 19
LoRA fine-tuning16 GB frozen weights plus a small adapterMemoryRank 16 on all 7 matrices: 41.9M parameters, about 84 MBpart 19
Inference, prefill16 GB weights plus KV for the promptCompute2 × 8.03B = 16 GFLOPs per prompt tokenpart 13
Inference, decode16 GB weights plus 128 KB per token per requestMemory bandwidth16 GB ÷ 3.35 TB/s = 4.8 ms a step, at most about 208 tokens/s for one user on an H100part 4, part 14
16.06 GBweights to hold and to read for every token (8.03B × 2 bytes, part 7)
128 KBKV cache per token of context, per request
~208 tok/ssingle-user ceiling on one H100 SXM, before any batching (illustrative ideal)

Serving many users changes the picture again, because one read of the weights can serve a whole batch of requests at once. That is the subject of the serving parts, from part 16 onwards.

What do people get wrong about LLMs?

  • “It looks things up.” A model on its own has no database and no internet. Everything it knows is spread across its weights, as of its training cut-off. When a product does search the web or your documents, a separate system fetches text and places it in the context window, and the model reads it there.
  • “It remembers me.” Weights do not change when you chat; inference only reads them. Each request starts from nothing except what is in its context. Chat “memory” features work by saving notes and inserting them into later prompts, which costs tokens like any other text.
  • “Bigger is always better.” Training data and tuning matter as much as size. The Chinchilla paper’s 70B model beat the 280B Gopher model by training on more than four times the data. A well-trained 8B model that fits one GPU often serves a narrow task as well as a much larger one, at a fraction of the cost.
  • “Temperature 0 gives the same answer every time.” It removes the random draw, but tiny floating-point differences from batching on GPUs can still flip a close call between two tokens, and one different token changes everything after it. Expect near-identical, not guaranteed identical.
  • “A token is a word.” In English a token averages about three quarters of a word, and in many other languages a word can be several tokens. Size budgets and price estimates in tokens, never in words.
  • “A longer context window is free.” The window is a limit, not a cost. The cost is the KV cache for the tokens you actually send, multiplied by the number of users at once.

Short answers to common questions

Does an LLM understand what it writes?

It builds internal representations good enough to predict text across almost any subject, which behaves like understanding for many tasks. It has no separate step that checks facts, so treat its output as a strong draft, not a source.

Why does the same question get different answers?

Because each token is a random draw from a distribution. With temperature above 0, a different early token sends the rest of the answer down a different path.

How many tokens is a page of text?

About 500 words of English is roughly 650 to 700 tokens on a modern tokenizer. The same page in Hindi or Tamil can be one and a half to two times that, and several times more on older tokenizers.

Can I change what a model knows without retraining it?

For facts that change, put them in the prompt with retrieval (RAG). For behaviour, format or a narrow skill, fine-tune with LoRA. Pre-training again is almost never the answer.

What decides the hardware an LLM needs
  • Number of parameters, times bytes per parameter: the memory for weights (part 7).
  • Context length and number of users: the size of the KV cache.
  • Prompt length: prefill time, which is compute-bound.
  • Answer length, including any hidden reasoning tokens: decode time, which is memory-bandwidth-bound.
  • Your tokenizer and language: the same text can cost very different token counts.
  • Whether you only run the model, or also fine-tune or train it.

Token ids and counts were produced with OpenAI’s tiktoken library (gpt2, cl100k_base and o200k_base encodings). The BPE example follows Sennrich et al. (2016) and was computed merge by merge. Llama 3.1 8B shapes and vocabulary are from its published model config; GPU hours and training tokens are from Meta’s Llama 3 paper and model card. Llama 2 data sizes are from the Llama 2 paper (Touvron et al., 2023), InstructGPT sizes from Ouyang et al. (2022), GPT-3 tokens from Brown et al. (2020), the 20 tokens per parameter rule and the Gopher comparison from Hoffmann et al. (2022). Gemma’s vocabulary is from Google’s Gemma documentation. Logit scores, context mixes, sampling presets and example replies are illustrative; bandwidth figures are ideal ceilings.

About The Author


Discover more from Journal of Intelligent Infrastructure

Subscribe to get the latest posts sent to your email.

Leave a Reply

Your email address will not be published. Required fields are marked *

Architect’s Toolkit

About the Author

Dr. Pranay Jha is a Cloud and AI Consultant with 18+ years of experience in hybrid cloud, virtualization, and enterprise infrastructure transformation. He specializes in VMware technologies, multi-cloud strategy, and Generative AI solutions. He holds a PhD in Computer Applications with research focused on Cloud and AI, has published multiple research papers, and has been a VMware vExpert since 2016 and a VMUG Community Leader.

Discover more from Journal of Intelligent Infrastructure

Subscribe now to keep reading and get access to the full archive.

Continue reading