<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Llm-Basics on vishctl</title><link>https://vishctl.dev/tags/llm-basics/</link><description>Recent content in Llm-Basics on vishctl</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 15 Sep 2026 09:00:00 +0800</lastBuildDate><atom:link href="https://vishctl.dev/tags/llm-basics/index.xml" rel="self" type="application/rss+xml"/><item><title>AI and LLM Glossary: Common Terms in Plain English</title><link>https://vishctl.dev/posts/ai-llm-glossary/</link><pubDate>Tue, 15 Sep 2026 09:00:00 +0800</pubDate><guid>https://vishctl.dev/posts/ai-llm-glossary/</guid><category>ai</category><category>llm-basics</category><category>glossary</category><category>local-llm</category><category>agents</category><description>A beginner-friendly AI and LLM glossary with short definitions, everyday examples, and a clickable table of contents for every term.</description><content:encoded><![CDATA[<p>AI conversations come with a lot of new words. Here is a broad collection of common AI and LLM terms, each explained in one or two sentences, with examples wherever useful.</p>
<p><strong>Jump to any definition using the table of contents</strong> beside this article on desktop or above it on smaller screens. Terms are grouped by topic; use your browser&rsquo;s Find feature (<code>Ctrl+F</code> or <code>Cmd+F</code>) if you already know the word.</p>
<p>New to the topic? Start with <strong>AI → machine learning → LLM → tokens → prompts → inference → hallucination → RAG → agents</strong>.</p>
<h2 id="ai-basics">AI basics</h2>
<h3 id="artificial-intelligence-ai">Artificial intelligence (AI)</h3>
<p>AI is the broad field of building computer systems that perform tasks such as recognizing speech, making predictions, or generating text. <strong>Example:</strong> a voice assistant understanding a spoken request.</p>
<h3 id="machine-learning-ml">Machine learning (ML)</h3>
<p>Machine learning is a way to build AI by learning patterns from data instead of writing a rule for every situation. <strong>Example:</strong> learning to recognize spam from past emails.</p>
<h3 id="deep-learning">Deep learning</h3>
<p>Deep learning uses neural networks with many layers to learn complex patterns. <strong>Example:</strong> identifying objects in a photo or generating a paragraph of text.</p>
<h3 id="neural-network">Neural network</h3>
<p>A neural network is a mathematical model made of connected layers that transform inputs into outputs using learned numbers. <strong>Example:</strong> turning an image&rsquo;s pixels into a prediction that it contains a cat.</p>
<h3 id="model">Model</h3>
<p>A model is a learned mathematical system that produces predictions or outputs from inputs. <strong>Example:</strong> the model inside a chatbot generates the reply, while the app manages the chat interface.</p>
<h3 id="generative-ai-genai">Generative AI (GenAI)</h3>
<p>Generative AI creates content such as text, images, audio, or code based on patterns learned during training. <strong>Example:</strong> drafting an email from a short instruction.</p>
<h3 id="predictive-ai">Predictive AI</h3>
<p>Predictive AI estimates an outcome or assigns a category using patterns in data. <strong>Example:</strong> forecasting next month&rsquo;s demand or flagging a suspicious transaction.</p>
<h3 id="large-language-model-llm">Large language model (LLM)</h3>
<p>An LLM is a large neural network trained on substantial amounts of language data to process and generate text. <strong>Example:</strong> a model that summarizes an article, translates a sentence, or writes code.</p>
<h3 id="small-language-model-slm">Small language model (SLM)</h3>
<p>An SLM is a language model with relatively fewer parameters, often making it easier to run on limited hardware. <strong>Example:</strong> a compact model running on a laptop; there is no universally agreed size cutoff.</p>
<h3 id="foundation-model">Foundation model</h3>
<p>A foundation model is trained on broad data so it can be adapted to many tasks. <strong>Example:</strong> the same base model can support summarization, classification, and question answering.</p>
<h3 id="multimodal-model">Multimodal model</h3>
<p>A multimodal model handles more than one kind of information, such as text, images, or audio. <strong>Example:</strong> uploading a screenshot and asking the model to explain the error message.</p>
<h3 id="natural-language-processing-nlp">Natural language processing (NLP)</h3>
<p>NLP is the field of helping computers work with human language. <strong>Example:</strong> translating text, detecting sentiment, or extracting names from a document.</p>
<h3 id="computer-vision">Computer vision</h3>
<p>Computer vision helps computers extract information from images and video. <strong>Example:</strong> detecting a pedestrian in a camera frame.</p>
<h3 id="diffusion-model">Diffusion model</h3>
<p>A diffusion model learns to generate data by reversing a process that adds noise. <strong>Example:</strong> an image generator gradually turns random noise into a picture matching your description.</p>
<h3 id="artificial-general-intelligence-agi">Artificial general intelligence (AGI)</h3>
<p>AGI is a proposed kind of AI with broad abilities across many intellectual tasks, rather than a narrow specialty. There is no universally accepted definition or test for deciding when a system qualifies.</p>
<h2 id="inside-a-language-model">Inside a language model</h2>
<h3 id="token">Token</h3>
<p>A token is a unit a model processes, often a word, part of a word, or punctuation. <strong>Example:</strong> a long word may use several tokens, so 1,000 tokens does not mean 1,000 words.</p>
<h3 id="tokenizer">Tokenizer</h3>
<p>A tokenizer converts text into token IDs that a model can process and can convert those IDs back into text. <strong>Example:</strong> different tokenizers may split the same sentence into different numbers of tokens.</p>
<h3 id="vocabulary">Vocabulary</h3>
<p>A model&rsquo;s token vocabulary is the set of token IDs its tokenizer knows how to represent. It usually includes word pieces and symbols, rather than only complete dictionary words.</p>
<h3 id="parameter">Parameter</h3>
<p>A parameter is a number learned during training that helps determine how a model behaves. <strong>Example:</strong> an “8B” model has roughly eight billion parameters, which is separate from its context length.</p>
<h3 id="weights">Weights</h3>
<p>Weights are learned parameters that control how signals flow through a neural network; people often use “model weights” to mean its learned numerical contents. <strong>Example:</strong> downloading weights lets compatible software load and run the model.</p>
<h3 id="transformer">Transformer</h3>
<p>A transformer is a neural-network architecture that uses attention to connect information across a sequence. Many language models use it to relate words in a prompt and generate a continuation.</p>
<h3 id="attention">Attention</h3>
<p>Attention lets a model give different amounts of importance to different parts of its input when computing a representation. <strong>Example:</strong> connecting “it” with the relevant object mentioned earlier in a sentence.</p>
<h3 id="embedding">Embedding</h3>
<p>An embedding is a list of numbers representing something such as a word, document, or image. <strong>Example:</strong> embeddings can place “puppy” and “dog” close together because their meanings are related.</p>
<h3 id="vector">Vector</h3>
<p>A vector is an ordered list of numbers; embeddings are vectors designed to represent useful properties of data. <strong>Example:</strong> <code>[0.2, -0.5, 0.9]</code> is a three-dimensional vector.</p>
<h3 id="next-token-prediction">Next-token prediction</h3>
<p>Next-token prediction estimates which token could come next given the tokens already available. <strong>Example:</strong> after “The sky is”, a model may give “blue” a high probability.</p>
<h3 id="autoregressive-generation">Autoregressive generation</h3>
<p>Autoregressive generation builds an output step by step, using previous output as input for the next step. <strong>Example:</strong> a text model generates one token, adds it to the sequence, and generates another.</p>
<h3 id="mixture-of-experts-moe">Mixture of experts (MoE)</h3>
<p>An MoE model routes work through selected specialist parts of the network instead of using every expert for every token. <strong>Example:</strong> a model can have many total parameters but activate only a subset per token, though storing the experts still takes memory.</p>
<h2 id="prompts-and-conversations">Prompts and conversations</h2>
<h3 id="prompt">Prompt</h3>
<p>A prompt is the input you give a model to guide its response. <strong>Example:</strong> “Explain Kubernetes to someone who has never used it.”</p>
<h3 id="prompt-engineering">Prompt engineering</h3>
<p>Prompt engineering means designing instructions and examples to get more useful outputs. <strong>Example:</strong> specifying the audience, desired format, and length of an explanation.</p>
<h3 id="system-prompt">System prompt</h3>
<p>A system prompt supplies application-level instructions about how an assistant should behave. <strong>Example:</strong> “You are a support assistant; explain troubleshooting steps clearly.”</p>
<h3 id="zero-shot-prompting">Zero-shot prompting</h3>
<p>Zero-shot prompting asks a model to perform a task without showing examples of the desired answer. <strong>Example:</strong> “Classify this review as positive or negative.”</p>
<h3 id="few-shot-prompting">Few-shot prompting</h3>
<p>Few-shot prompting includes a small number of examples before asking the model to handle a new case. <strong>Example:</strong> showing three labeled reviews before asking it to label a fourth.</p>
<h3 id="chain-of-thought-cot">Chain of thought (CoT)</h3>
<p>Chain of thought refers to intermediate reasoning steps used while solving a problem. A model&rsquo;s displayed explanation is not guaranteed to faithfully reveal its internal computation.</p>
<h3 id="reasoning-model">Reasoning model</h3>
<p>A reasoning model is trained to work through intermediate steps before producing an answer, often spending more computation on difficult tasks. <strong>Example:</strong> comparing several possible solutions to a math problem before answering.</p>
<h3 id="context">Context</h3>
<p>Context is the information available to the model for its current response, including instructions, messages, and supplied documents or tool results. <strong>Example:</strong> pasting a log file gives the model context for troubleshooting.</p>
<h3 id="context-window">Context window</h3>
<p>The context window is the model&rsquo;s token capacity for a single request, generally covering input and generated output, subject to separate limits. <strong>Example:</strong> a long document and chat history leave less room for a response.</p>
<h3 id="context-engineering">Context engineering</h3>
<p>Context engineering means selecting and organizing the information a model receives for a task. <strong>Example:</strong> supplying the relevant logs, current configuration, and instructions while leaving out unrelated files.</p>
<h3 id="memory">Memory</h3>
<p>In an AI app, memory usually means information saved and brought back into later interactions. <strong>Example:</strong> the app stores your preferred language and includes it in future prompts; this does not necessarily change the model&rsquo;s weights.</p>
<h3 id="truncation">Truncation</h3>
<p>Truncation means cutting off input or output to meet a length limit. <strong>Example:</strong> an app may drop older chat messages when the conversation becomes too long.</p>
<h3 id="temperature">Temperature</h3>
<p>Temperature adjusts how strongly generation favors higher-probability tokens. Lower values generally produce more predictable wording, while higher values allow more variation without guaranteeing creativity or accuracy.</p>
<h3 id="top-p-nucleus-sampling">Top-p (nucleus sampling)</h3>
<p>Top-p limits token selection to a set of likely candidates whose combined probability reaches a chosen threshold. <strong>Example:</strong> <code>top_p = 0.9</code> samples from candidates covering about 90% of the probability mass.</p>
<h3 id="top-k-sampling">Top-k sampling</h3>
<p>Top-k limits token selection to the k most likely next tokens. <strong>Example:</strong> <code>top_k = 40</code> means sampling only from the 40 highest-ranked candidates at each step.</p>
<h3 id="maximum-output-tokens">Maximum output tokens</h3>
<p>Maximum output tokens sets a ceiling on how many tokens a model may generate for a response. <strong>Example:</strong> a low limit can cut off a long answer before it finishes.</p>
<h3 id="stop-sequence">Stop sequence</h3>
<p>A stop sequence is text that tells the generation service to stop producing output when it appears. <strong>Example:</strong> an application might use a special delimiter to mark the end of an answer.</p>
<h3 id="structured-output">Structured output</h3>
<p>Structured output follows a defined format or schema so software can process it reliably. <strong>Example:</strong> returning an object with <code>name</code> and <code>price</code> fields; correct formatting does not guarantee correct facts.</p>
<h2 id="training-and-customization">Training and customization</h2>
<h3 id="training">Training</h3>
<p>Training adjusts a model&rsquo;s parameters using data and an objective that measures how well it is doing. <strong>Example:</strong> repeatedly improving its predictions of missing or next words.</p>
<h3 id="training-data">Training data</h3>
<p>Training data is the collection of examples used to teach a model. <strong>Example:</strong> text, code, images, or labeled examples, depending on the task.</p>
<h3 id="dataset">Dataset</h3>
<p>A dataset is an organized collection of examples used for training, validation, or evaluation. <strong>Example:</strong> 10,000 support tickets paired with issue categories.</p>
<h3 id="label">Label</h3>
<p>A label is a target answer or category attached to an example. <strong>Example:</strong> an email marked “spam” has a spam label.</p>
<h3 id="supervised-learning">Supervised learning</h3>
<p>Supervised learning trains a model on inputs paired with desired outputs. <strong>Example:</strong> learning to classify pictures from images labeled “cat” or “dog”.</p>
<h3 id="unsupervised-learning">Unsupervised learning</h3>
<p>Unsupervised learning looks for patterns in data without supplied target labels. <strong>Example:</strong> grouping customers by similar purchasing behavior.</p>
<h3 id="self-supervised-learning">Self-supervised learning</h3>
<p>Self-supervised learning creates training targets from the data itself. <strong>Example:</strong> using the next word in a document as the answer the model must predict.</p>
<h3 id="reinforcement-learning-rl">Reinforcement learning (RL)</h3>
<p>Reinforcement learning trains a system to choose actions using reward signals. <strong>Example:</strong> a game-playing agent improves by receiving rewards for successful play.</p>
<h3 id="pretraining">Pretraining</h3>
<p>Pretraining is an initial training stage that builds broad capabilities from large amounts of data. <strong>Example:</strong> a language model learns language patterns before being adapted to follow instructions.</p>
<h3 id="post-training">Post-training</h3>
<p>Post-training refines a pretrained model&rsquo;s behavior or abilities through additional training. <strong>Example:</strong> teaching it to follow instructions, use tools, or better match human preferences.</p>
<h3 id="fine-tuning">Fine-tuning</h3>
<p>Fine-tuning continues training an existing model on selected data to adapt its behavior. <strong>Example:</strong> training on support conversations to encourage a particular response style.</p>
<h3 id="instruction-tuning">Instruction tuning</h3>
<p>Instruction tuning trains a model on instructions paired with useful responses. <strong>Example:</strong> teaching it to respond to “Summarize this” with a summary instead of simply continuing the text.</p>
<h3 id="supervised-fine-tuning-sft">Supervised fine-tuning (SFT)</h3>
<p>SFT fine-tunes a model using examples of desired inputs and outputs. <strong>Example:</strong> providing questions paired with carefully written answers.</p>
<h3 id="reinforcement-learning-from-human-feedback-rlhf">Reinforcement learning from human feedback (RLHF)</h3>
<p>RLHF uses human feedback to help define rewards that guide further model training. <strong>Example:</strong> people rank responses, and those preferences help train a reward model used to improve the assistant.</p>
<h3 id="direct-preference-optimization-dpo">Direct preference optimization (DPO)</h3>
<p>DPO trains a model directly on preferred and less-preferred responses without a separate reinforcement-learning optimization loop. <strong>Example:</strong> teaching it to favor a clear, helpful answer over an unhelpful one.</p>
<h3 id="lora-low-rank-adaptation">LoRA (low-rank adaptation)</h3>
<p>LoRA fine-tunes a model by training small added sets of parameters while keeping the original weights frozen. <strong>Example:</strong> adapting a model&rsquo;s writing style using less training memory than updating all its weights.</p>
<h3 id="qlora">QLoRA</h3>
<p>QLoRA combines a quantized, frozen base model with trainable LoRA adapters to reduce fine-tuning memory needs. <strong>Example:</strong> adapting a model on a GPU that cannot hold its full-precision training setup.</p>
<h3 id="distillation">Distillation</h3>
<p>Distillation trains a student model to learn from a teacher model&rsquo;s outputs or signals. <strong>Example:</strong> using a larger model&rsquo;s answers to help train a smaller model for a specific task.</p>
<h3 id="synthetic-data">Synthetic data</h3>
<p>Synthetic data is artificially generated data used for training or testing. <strong>Example:</strong> generating sample support questions, then checking their quality before using them.</p>
<h3 id="loss">Loss</h3>
<p>Loss is a numerical measure of how poorly a model meets its training objective. Training tries to reduce it, though lower training loss does not automatically mean better real-world performance.</p>
<h3 id="learning-rate">Learning rate</h3>
<p>The learning rate controls the size of parameter updates during training. Think of it as the adjustment step size: too large can overshoot, while too small can make learning slow.</p>
<h3 id="epoch">Epoch</h3>
<p>An epoch is one pass through a training dataset. <strong>Example:</strong> three epochs means the training process has gone through the dataset three times.</p>
<h3 id="batch-size">Batch size</h3>
<p>Batch size is the number of examples processed together in a training or inference step. <strong>Example:</strong> a training batch might contain 32 examples.</p>
<h3 id="overfitting">Overfitting</h3>
<p>Overfitting happens when a model learns the training data too specifically and performs poorly on new examples. Think of memorizing practice-test answers without learning how to solve new questions.</p>
<h3 id="generalization">Generalization</h3>
<p>Generalization is a model&rsquo;s ability to perform well on examples it did not train on. <strong>Example:</strong> recognizing spam that uses wording absent from its training set.</p>
<h3 id="checkpoint">Checkpoint</h3>
<p>A checkpoint is a saved snapshot of a model, sometimes including the state needed to resume training. <strong>Example:</strong> saving progress periodically so training can restart after an interruption.</p>
<h3 id="knowledge-cutoff">Knowledge cutoff</h3>
<p>A knowledge cutoff is an approximate boundary for the information included in a model&rsquo;s training. It does not guarantee knowledge of everything before that date, and tools can supply newer information.</p>
<h2 id="search-and-grounding">Search and grounding</h2>
<h3 id="retrieval-augmented-generation-rag">Retrieval-augmented generation (RAG)</h3>
<p>RAG retrieves relevant information and provides it to a model before the model generates an answer. <strong>Example:</strong> finding passages in a company handbook so an assistant can answer a policy question.</p>
<h3 id="grounding">Grounding</h3>
<p>Grounding connects a model&rsquo;s response to supplied evidence or external information. <strong>Example:</strong> asking it to answer from a particular report and cite the supporting passages.</p>
<h3 id="chunking">Chunking</h3>
<p>Chunking splits documents into smaller pieces for processing or retrieval. <strong>Example:</strong> dividing a long manual into sections so a search system can return the relevant instructions.</p>
<h3 id="vector-database">Vector database</h3>
<p>A vector database stores vectors and supports searching for similar ones. <strong>Example:</strong> finding document embeddings close to the embedding of a user&rsquo;s question.</p>
<h3 id="semantic-search">Semantic search</h3>
<p>Semantic search looks for relevant meaning rather than only matching exact words. <strong>Example:</strong> a search for “forgot my login” can find a page titled “Reset your password”.</p>
<h3 id="keyword-search">Keyword search</h3>
<p>Keyword search matches words or phrases in documents. <strong>Example:</strong> searching for an exact error code such as <code>OOMKilled</code>.</p>
<h3 id="hybrid-search">Hybrid search</h3>
<p>Hybrid search combines keyword matching with semantic search. <strong>Example:</strong> matching an exact product code while also understanding the user&rsquo;s description of the problem.</p>
<h3 id="similarity-score">Similarity score</h3>
<p>A similarity score measures how close two representations are under a chosen comparison method. <strong>Example:</strong> cosine similarity can compare a question embedding with document embeddings; the score is not a probability that an answer is correct.</p>
<h3 id="reranking">Reranking</h3>
<p>Reranking reorders retrieved results using another scoring step to improve relevance. <strong>Example:</strong> retrieving 50 passages quickly, then selecting the five most useful ones for the answer.</p>
<h2 id="agents-and-tools">Agents and tools</h2>
<h3 id="ai-assistant">AI assistant</h3>
<p>An AI assistant is an application that helps users through capabilities such as conversation, content generation, and tool use. <strong>Example:</strong> an assistant that explains code and searches documentation.</p>
<h3 id="ai-agent">AI agent</h3>
<p>An AI agent uses a model to choose and carry out steps toward a goal, often with tools and feedback. <strong>Example:</strong> inspecting a failing test, editing code, and rerunning the test within its permissions.</p>
<h3 id="agentic-ai">Agentic AI</h3>
<p>Agentic AI is a broad term for systems that can select and execute steps toward a goal with some autonomy. <strong>Example:</strong> a system that investigates an issue and adjusts its next action based on what it finds.</p>
<h3 id="tool-use--function-calling">Tool use / function calling</h3>
<p>Tool use lets a model request an operation that surrounding software executes. <strong>Example:</strong> the model requests a weather lookup, and the application calls the weather service and returns the result.</p>
<h3 id="model-context-protocol-mcp">Model Context Protocol (MCP)</h3>
<p>MCP is a standard for connecting AI applications to tools, resources, and reusable prompts. <strong>Example:</strong> an application can connect to an MCP server that exposes document-search tools.</p>
<h3 id="workflow">Workflow</h3>
<p>A workflow is a sequence of steps for completing a task, often with predefined rules. <strong>Example:</strong> classify a support ticket, retrieve relevant documentation, then draft a reply.</p>
<h3 id="orchestration">Orchestration</h3>
<p>Orchestration coordinates models, tools, data, and task steps in an AI application. <strong>Example:</strong> deciding when to search, when to call a model, and when to request human review.</p>
<h3 id="multi-agent-system">Multi-agent system</h3>
<p>A multi-agent system uses multiple agents that collaborate or handle different responsibilities. <strong>Example:</strong> one agent researches a topic while another checks the draft against the sources.</p>
<h3 id="human-in-the-loop-hitl">Human in the loop (HITL)</h3>
<p>Human in the loop means a person reviews, corrects, or approves part of an automated process. <strong>Example:</strong> a person approves a drafted customer reply before it is sent.</p>
<h2 id="running-models-and-performance">Running models and performance</h2>
<h3 id="inference">Inference</h3>
<p>Inference means running a trained model to produce an output from an input. <strong>Example:</strong> generating a reply to your chat message.</p>
<h3 id="model-serving">Model serving</h3>
<p>Model serving makes a model available to applications and manages incoming requests. <strong>Example:</strong> a server loads model weights and exposes an API for generating text.</p>
<h3 id="api-application-programming-interface">API (application programming interface)</h3>
<p>An API is a defined way for software systems to communicate. <strong>Example:</strong> your app sends a prompt to a model service and receives generated text.</p>
<h3 id="local-llm">Local LLM</h3>
<p>A local LLM runs on hardware you control, such as your laptop or workstation. <strong>Example:</strong> generating text on your machine after downloading a model; the app&rsquo;s other features may still use network services.</p>
<h3 id="gpu-graphics-processing-unit">GPU (graphics processing unit)</h3>
<p>A GPU is a processor that can perform many mathematical operations in parallel. <strong>Example:</strong> accelerating the matrix calculations used to train or run a neural network.</p>
<h3 id="vram">VRAM</h3>
<p>VRAM is memory available on a graphics card for data such as model weights and temporary computations. <strong>Example:</strong> a model can run out of VRAM even when the computer still has free system RAM.</p>
<h3 id="quantization">Quantization</h3>
<p>Quantization represents model numbers using fewer bits, reducing storage and often memory use. <strong>Example:</strong> storing weights at roughly 4-bit precision can make a model easier to fit, with possible quality tradeoffs.</p>
<h3 id="fp32-fp16-and-bf16">FP32, FP16, and BF16</h3>
<p>These are floating-point number formats: FP32 uses 32 bits, while FP16 and BF16 use 16 bits with different precision and range. <strong>Example:</strong> 16-bit weights generally need about half the raw storage of 32-bit weights.</p>
<h3 id="int8-and-int4">INT8 and INT4</h3>
<p>INT8 and INT4 are 8-bit and 4-bit integer representations often used in quantization. <strong>Example:</strong> a model with INT4 weights uses less raw weight storage than one with INT8 weights, though metadata and other data add overhead.</p>
<h3 id="gguf">GGUF</h3>
<p>GGUF is a file format for storing models and metadata, commonly used with llama.cpp and related local inference tools. <strong>Example:</strong> a <code>.gguf</code> file may contain quantized weights, but the file format itself does not specify one fixed precision.</p>
<h3 id="prefill">Prefill</h3>
<p>Prefill is the inference phase that processes the prompt before generating the continuation. <strong>Example:</strong> reading a long pasted document can add delay before the first response token appears.</p>
<h3 id="decode">Decode</h3>
<p>Decode is the generation phase in which an autoregressive model produces new tokens using the existing sequence. <strong>Example:</strong> the answer grows token by token after the prompt has been processed.</p>
<h3 id="kv-cache">KV cache</h3>
<p>The key-value cache stores attention-related intermediate results so the model can reuse earlier computation during generation. <strong>Example:</strong> longer conversations generally require more KV-cache memory.</p>
<h3 id="prompt-caching--prefix-caching">Prompt caching / prefix caching</h3>
<p>Prompt or prefix caching reuses computation for input shared across requests. <strong>Example:</strong> repeatedly sending the same long instruction prefix may require less processing when a compatible cached prefix is available.</p>
<h3 id="latency">Latency</h3>
<p>Latency is the time you wait for a response or a particular stage of it. <strong>Example:</strong> the delay between submitting a prompt and receiving the complete answer.</p>
<h3 id="time-to-first-token-ttft">Time to first token (TTFT)</h3>
<p>TTFT measures the time from sending a request to receiving its first generated token. <strong>Example:</strong> a chatbot can start responding quickly even if finishing its answer takes much longer.</p>
<h3 id="throughput">Throughput</h3>
<p>Throughput measures how much work a system completes per unit of time. <strong>Example:</strong> a model server might handle thousands of output tokens per second across many users.</p>
<h3 id="tokens-per-second-tokenss">Tokens per second (tokens/s)</h3>
<p>Tokens per second measures token-processing or generation speed, so the measured stage and scope matter. <strong>Example:</strong> 30 output tokens/s for one chat is different from 3,000 output tokens/s across an entire server.</p>
<h3 id="streaming">Streaming</h3>
<p>Streaming sends output to the user as it is generated instead of waiting for the entire response. <strong>Example:</strong> words appear progressively in a chat window.</p>
<h3 id="continuous-batching">Continuous batching</h3>
<p>Continuous batching lets a server add and remove requests from a running batch as work arrives and finishes. <strong>Example:</strong> a new chat can begin processing without waiting for every current response to complete.</p>
<h3 id="speculative-decoding">Speculative decoding</h3>
<p>Speculative decoding uses a cheaper process to propose several tokens that the main model verifies together. Standard exact versions preserve the target model&rsquo;s output distribution, but the speed benefit depends on the workload.</p>
<h3 id="model-parallelism">Model parallelism</h3>
<p>Model parallelism spreads a model&rsquo;s computation or layers across multiple devices. <strong>Example:</strong> splitting a model across two GPUs when it cannot fit on one.</p>
<h3 id="gpu-offloading">GPU offloading</h3>
<p>GPU offloading moves some or all model work from the CPU to a GPU. <strong>Example:</strong> a local runner places selected layers on the GPU and keeps the rest in system memory.</p>
<h3 id="open-weights">Open weights</h3>
<p>An open-weight model makes its trained weights available to download under stated license terms. This does not automatically mean its training data is available or that every use is permitted.</p>
<h3 id="open-source-ai">Open-source AI</h3>
<p>Open-source AI refers to systems released with permissions and materials that enable use, study, modification, and sharing under an applicable definition or license. Check the actual release and license: downloadable weights alone do not establish that the whole system is open source.</p>
<h2 id="quality-evaluation-and-safety">Quality, evaluation, and safety</h2>
<h3 id="hallucination">Hallucination</h3>
<p>A hallucination is generated content that is false or unsupported but may sound convincing. <strong>Example:</strong> inventing a research paper or a software option that does not exist.</p>
<h3 id="evaluation--evals">Evaluation / evals</h3>
<p>Evaluation checks how well a model or AI system performs on chosen tasks and criteria. <strong>Example:</strong> testing whether a support assistant gives correct answers and cites the right documents.</p>
<h3 id="benchmark">Benchmark</h3>
<p>A benchmark is a defined test or dataset used to compare systems. <strong>Example:</strong> measuring code generation on a shared set of programming problems; one score does not describe every real-world task.</p>
<h3 id="accuracy">Accuracy</h3>
<p>Accuracy is the fraction of predictions that are correct in a classification task. <strong>Example:</strong> 90 correct labels out of 100 gives 90% accuracy, though this can be misleading when one class dominates.</p>
<h3 id="precision">Precision</h3>
<p>Precision measures how many items predicted as positive were actually positive. <strong>Example:</strong> if 8 of 10 emails flagged as spam are spam, precision is 80%.</p>
<h3 id="recall">Recall</h3>
<p>Recall measures how many actual positive items a system successfully finds. <strong>Example:</strong> if it catches 8 of the 20 spam emails, recall is 40%.</p>
<h3 id="f1-score">F1 score</h3>
<p>F1 combines precision and recall using their harmonic mean, rewarding a balance between the two. <strong>Example:</strong> 80% precision and 40% recall produce an F1 score of about 53%.</p>
<h3 id="perplexity">Perplexity</h3>
<p>Perplexity measures how well a language model predicts a sequence, with lower values indicating better prediction on that data. Comparisons need compatible tokenization and evaluation settings, and lower perplexity does not necessarily mean a better assistant.</p>
<h3 id="bias">Bias</h3>
<p>Bias can mean systematic skew in a model&rsquo;s predictions or behavior, including unfair differences across groups. <strong>Example:</strong> a hiring model may reproduce patterns of unequal treatment present in its training data.</p>
<h3 id="alignment">Alignment</h3>
<p>Alignment concerns making a model&rsquo;s behavior match intended goals, values, and constraints. <strong>Example:</strong> training an assistant to follow useful instructions while respecting privacy requirements.</p>
<h3 id="guardrails">Guardrails</h3>
<p>Guardrails are checks or controls intended to constrain an AI system&rsquo;s behavior. <strong>Example:</strong> validating tool arguments or requiring approval before a purchase; their presence does not guarantee that mistakes are impossible.</p>
<h3 id="prompt-injection">Prompt injection</h3>
<p>Prompt injection occurs when untrusted content tries to redirect an AI system away from its intended instructions. <strong>Example:</strong> a retrieved webpage tells an assistant to ignore the user and reveal private data.</p>
<h3 id="jailbreak">Jailbreak</h3>
<p>A jailbreak is an attempt to bypass a model&rsquo;s behavioral or safety restrictions. <strong>Example:</strong> using a specially constructed prompt to get an answer the assistant is configured to refuse.</p>
<h3 id="data-leakage">Data leakage</h3>
<p>Data leakage means information reaches a place it should not, with the exact meaning depending on context. <strong>Example:</strong> test answers accidentally enter training data, or an assistant exposes confidential information to an unauthorized user.</p>
<h3 id="red-teaming">Red teaming</h3>
<p>Red teaming deliberately probes a system for failures, vulnerabilities, or harmful behavior. <strong>Example:</strong> testing whether malicious documents can trick an assistant into misusing a tool.</p>
<h2 id="commonly-confused-terms">Commonly confused terms</h2>
<ul>
<li><strong>AI vs. ML vs. deep learning:</strong> AI is the broad field; ML is one approach within it; deep learning is a family of ML techniques.</li>
<li><strong>Model vs. chatbot:</strong> the model produces outputs; the chatbot is an application built around it.</li>
<li><strong>Training vs. inference:</strong> training changes learned parameters; inference uses them to produce outputs.</li>
<li><strong>RAG vs. fine-tuning:</strong> RAG supplies retrieved information at response time; fine-tuning changes model parameters.</li>
<li><strong>Context vs. memory:</strong> context is available for the current response; app memory can store information and bring it into future context.</li>
<li><strong>Parameters vs. tokens:</strong> parameters are learned numbers inside the model; tokens are units it processes.</li>
<li><strong>Latency vs. throughput:</strong> latency is how long a request takes; throughput is how much work the system handles over time.</li>
<li><strong>Open weights vs. open source:</strong> access to weights is one part of openness; permissions and other available materials also matter.</li>
</ul>
<h2 id="further-reading">Further reading</h2>
<p>For broader reference, see <a href="https://developers.google.com/machine-learning/glossary">Google&rsquo;s machine-learning glossary</a> and <a href="https://docs.cloud.google.com/docs/generative-ai/glossary">Google Cloud&rsquo;s generative AI glossary</a>.</p>
<p>For a practical explanation of retrieving documents before answering, see <a href="https://www.anthropic.com/engineering/contextual-retrieval">Anthropic&rsquo;s contextual retrieval guide</a>. Its <a href="https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents">context engineering guide</a> explains how to select information for agents.</p>
<p>Continue on this blog with <a href="https://vishctl.dev/posts/llm-basics-visual-guide/">what happens when you ask an LLM a question</a> or <a href="https://vishctl.dev/posts/ai-agent-basics/">AI agent basics</a>.</p>
]]></content:encoded></item><item><title>What Happens When You Ask an LLM a Question</title><link>https://vishctl.dev/posts/llm-basics-visual-guide/</link><pubDate>Fri, 11 Sep 2026 12:00:00 +0800</pubDate><guid>https://vishctl.dev/posts/llm-basics-visual-guide/</guid><category>ai</category><category>local-llm</category><category>llm-basics</category><category>gpu</category><category>vllm</category><description>My visual notes on how LLMs work: tokens, parameters, attention, reasoning, KV cache, quantization, and serving models on GPUs.</description><content:encoded><![CDATA[<p>I have been running models with <a href="https://vishctl.dev/posts/running-ollama-on-32gb-macbook-air/">Ollama</a> and <a href="https://vishctl.dev/posts/vllm-on-wsl2-minikube/">vLLM</a>. Then I stopped to ask: what is actually happening behind that API call?</p>
<p>A learning chat turned into these notes. Let&rsquo;s follow one request all the way through:</p>
<blockquote>
<p>Why did my Kubernetes pod restart? The container&rsquo;s last termination reason is OOMKilled.</p>
</blockquote>
<p>This is an illustrative example, not a live diagnosis. We will use a hypothetical <strong>2B model</strong> throughout.</p>
<h2 id="part-1-the-mechanics">Part 1: The Mechanics</h2>
<h3 id="1-an-answer-grows-one-token-at-a-time">1. An answer grows one token at a time</h3>
<p>An <strong>LLM</strong>, or large language model, is a neural network trained on language. For the text-generating models here, the basic loop is: use the text so far to predict what comes next.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Our pod question + the OOMKilled clue
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                  v
</span></span><span class="line"><span class="cl">             Tokenizer
</span></span><span class="line"><span class="cl">          text -&gt; token IDs
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                  v
</span></span><span class="line"><span class="cl">      Embeddings + position information
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                  v
</span></span><span class="line"><span class="cl">        Transformer layer 1
</span></span><span class="line"><span class="cl">        attention + other maths
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                  v
</span></span><span class="line"><span class="cl">        Transformer layer 2
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                 ...
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                  v
</span></span><span class="line"><span class="cl">         Scores for next tokens
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                  v
</span></span><span class="line"><span class="cl">           Choose one token
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                  v
</span></span><span class="line"><span class="cl">        Append it to the answer
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                  v
</span></span><span class="line"><span class="cl">           Stop condition?
</span></span><span class="line"><span class="cl">            /          \
</span></span><span class="line"><span class="cl">          yes           no
</span></span><span class="line"><span class="cl">           |             |
</span></span><span class="line"><span class="cl">           v             v
</span></span><span class="line"><span class="cl">     Final answer   Process chosen token
</span></span><span class="line"><span class="cl">                    through the model
</span></span><span class="line"><span class="cl">                    using the KV cache
</span></span><span class="line"><span class="cl">                    (more on this in §5)
</span></span><span class="line"><span class="cl">                         |
</span></span><span class="line"><span class="cl">                         +--&gt; Score and choose again
</span></span></code></pre></div><p>A <strong>token</strong> can be a word, part of a word, or punctuation. The tokenizer assigns each piece an ID. An <strong>embedding</strong> turns that ID into a list of numbers the network can process. The model also needs information about token positions.</p>
<p>For our prompt, a tokenizer might split <code>OOMKilled</code> into smaller pieces. Exact splits depend on the tokenizer. Each piece gets an ID, then a numerical vector.</p>
<p>The answer might grow as <code>The</code> → <code> container</code> → <code> was</code> → <code> killed</code>. These are illustrative token boundaries. The model chooses from next-token scores using its generation settings, then repeats.</p>
<h3 id="2-what-does-a-2b-model-actually-contain">2. What does a 2B model actually contain?</h3>
<p><strong>About two billion adjustable numbers</strong>, called parameters. Most are weights used in the network&rsquo;s calculations. They collectively encode learned patterns, rather than one fact per number.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">TRAINING
</span></span><span class="line"><span class="cl">Examples about language, code, containers...
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                  v
</span></span><span class="line"><span class="cl">        Predict the next token &lt;---------+
</span></span><span class="line"><span class="cl">                  |                      |
</span></span><span class="line"><span class="cl">                  v                      |
</span></span><span class="line"><span class="cl">       Compare with training target      |
</span></span><span class="line"><span class="cl">                  |                      |
</span></span><span class="line"><span class="cl">                  v                      |
</span></span><span class="line"><span class="cl">           Calculate the error           |
</span></span><span class="line"><span class="cl">                  |                      |
</span></span><span class="line"><span class="cl">                  v                      |
</span></span><span class="line"><span class="cl">         Adjust learned numbers ---------+
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">INFERENCE
</span></span><span class="line"><span class="cl">Our pod question + learned numbers
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                  v
</span></span><span class="line"><span class="cl">       Calculations through layers
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                  v
</span></span><span class="line"><span class="cl">       Generate a restart explanation
</span></span><span class="line"><span class="cl">       (learned numbers stay fixed)
</span></span></code></pre></div><p>A neural network is a stack of mathematical operations. A simple neuron combines weighted inputs, adds a bias, and applies an activation function. Many such operations let the network learn complex patterns.</p>
<p>During training, examples about containers and memory can shape these numbers. Our question then uses those learned patterns to connect <code>OOMKilled</code> with an out-of-memory event. There is no single &ldquo;Kubernetes parameter.&rdquo;</p>
<p><strong>Training changes the parameters. Ordinary inference uses them.</strong> Chatting adds context; it does not normally retrain the model. A bigger parameter count alone does not guarantee better answers.</p>
<h3 id="3-transformers-connect-the-relevant-pieces">3. Transformers connect the relevant pieces</h3>
<p>A <strong>Transformer</strong> is the architecture behind many LLMs. Its layers combine attention with other neural-network calculations.</p>
<p><strong>Attention</strong> mixes information from tokens in the available context. In a typical text generator, a token can attend to itself and earlier tokens.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Token representations from our prompt
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">          +-------+-------+
</span></span><span class="line"><span class="cl">          |       |       |
</span></span><span class="line"><span class="cl">          v       v       v
</span></span><span class="line"><span class="cl">          Q       K       V
</span></span><span class="line"><span class="cl">       Queries   Keys   Values
</span></span><span class="line"><span class="cl">          |       |       |
</span></span><span class="line"><span class="cl">          +---+---+       |
</span></span><span class="line"><span class="cl">              |           |
</span></span><span class="line"><span class="cl">              v           |
</span></span><span class="line"><span class="cl">      Compare Q with K    |
</span></span><span class="line"><span class="cl">              |           |
</span></span><span class="line"><span class="cl">              v           |
</span></span><span class="line"><span class="cl">      Mask future tokens  |
</span></span><span class="line"><span class="cl">      and form weights    |
</span></span><span class="line"><span class="cl">              |           |
</span></span><span class="line"><span class="cl">              +-----+-----+
</span></span><span class="line"><span class="cl">                    |
</span></span><span class="line"><span class="cl">                    v
</span></span><span class="line"><span class="cl">       Weighted mixture of values
</span></span><span class="line"><span class="cl">                    |
</span></span><span class="line"><span class="cl">                    v
</span></span><span class="line"><span class="cl">        Further layer calculations
</span></span><span class="line"><span class="cl">                    |
</span></span><span class="line"><span class="cl">                    v
</span></span><span class="line"><span class="cl">      Later layers -&gt; next-token scores
</span></span></code></pre></div><p>In our request, <code>OOMKilled</code> is a useful clue for explaining <code>restart</code>. Attention helps combine information from those positions while the layers build the response.</p>
<p>The diagram is an intuition, not a measured attention map. <strong>Q, K, and V are learned numerical representations</strong>, not literal questions or database entries. Multiple attention heads can capture different relationships. <a href="https://developers.google.com/machine-learning/crash-course/llm/transformers">Google&rsquo;s Transformer introduction</a> explains the architecture further.</p>
<h3 id="4-why-can-it-reason-and-still-be-wrong">4. Why can it reason, and still be wrong?</h3>
<p>Learning to predict language can build useful patterns for code, maths, and problem solving. Further training can improve instruction following and reasoning.</p>
<p>A model can use intermediate steps to work through a problem. Some reasoning models spend additional computation before answering. This can help, but a fluent explanation is not proof.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Question: why did the container restart?
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                  v
</span></span><span class="line"><span class="cl">       Supplied clue: OOMKilled
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                  v
</span></span><span class="line"><span class="cl">      Learned relationship: memory
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                  v
</span></span><span class="line"><span class="cl">      Suggest checking limit and usage
</span></span><span class="line"><span class="cl">                  |
</span></span><span class="line"><span class="cl">                  v
</span></span><span class="line"><span class="cl">       Verify against the real cluster
</span></span></code></pre></div><p>This is an example of a useful explanation, not a trace of the model&rsquo;s hidden internal computations.</p>
<blockquote>
<p>A useful answer: &ldquo;OOMKilled indicates an out-of-memory kill. Check the container&rsquo;s memory limit and memory usage.&rdquo;</p>
</blockquote>
<p>It would be a leap to say <strong>&ldquo;Your app definitely has a memory leak.&rdquo;</strong> Our prompt gives no evidence of a leak. The model also has not inspected the cluster; it only has the information we supplied.</p>
<p>This gap between a fluent answer and a verified one is often called <strong>hallucination</strong>: the model producing a plausible-sounding claim that isn&rsquo;t grounded in the given context or fact.</p>
<h2 id="part-2-serving--scaling">Part 2: Serving &amp; Scaling</h2>
<h3 id="5-context-is-the-input-kv-cache-saves-work">5. Context is the input. KV cache saves work.</h3>
<p>The <strong>context window</strong> limits how many tokens a request can accommodate, including input and generated output. Instructions, chat history, and supplied documents all take space.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Our question + OOMKilled clue
</span></span><span class="line"><span class="cl">              |
</span></span><span class="line"><span class="cl">              v
</span></span><span class="line"><span class="cl">           PREFILL
</span></span><span class="line"><span class="cl">     Process the prompt
</span></span><span class="line"><span class="cl">       /             \
</span></span><span class="line"><span class="cl">      v               v
</span></span><span class="line"><span class="cl"> Save prompt K/V   Score first token
</span></span><span class="line"><span class="cl">      |               |
</span></span><span class="line"><span class="cl">      v               v
</span></span><span class="line"><span class="cl">  [KV cache]       Choose &#34;The&#34;
</span></span><span class="line"><span class="cl">      |               |
</span></span><span class="line"><span class="cl">      |               v
</span></span><span class="line"><span class="cl">      +---------&gt; DECODE &lt;----------------+
</span></span><span class="line"><span class="cl">      |          Process &#34;The&#34;            |
</span></span><span class="line"><span class="cl">      |          using earlier K/V        |
</span></span><span class="line"><span class="cl">      |               |                   |
</span></span><span class="line"><span class="cl">      |               v                   |
</span></span><span class="line"><span class="cl">      |          Save new K/V             |
</span></span><span class="line"><span class="cl">      |          Score and choose         |
</span></span><span class="line"><span class="cl">      |          next token               |
</span></span><span class="line"><span class="cl">      |               |                   |
</span></span><span class="line"><span class="cl">      |               v                   |
</span></span><span class="line"><span class="cl">      |          Stop condition?          |
</span></span><span class="line"><span class="cl">      |           /         \             |
</span></span><span class="line"><span class="cl">      |         yes          no           |
</span></span><span class="line"><span class="cl">      |          |            |           |
</span></span><span class="line"><span class="cl">      |          v            +-----------+
</span></span><span class="line"><span class="cl">      |      Finish answer     Process next token
</span></span><span class="line"><span class="cl">      |
</span></span><span class="line"><span class="cl">      +-- Cache grows as more tokens are processed
</span></span></code></pre></div><p><strong>Prefill</strong> processes the prompt and produces the scores for the first output token. <strong>Decode</strong> continues generation, typically one token per sequence per step.</p>
<p>The <strong>KV cache</strong> stores keys and values from earlier tokens so the model can reuse them. It is temporary attention data, not a permanent memory of you.</p>
<p>For our request, prefill reads the question and <code>OOMKilled</code> clue. Decode builds the answer. When generating the next piece after <code>The container</code>, the model reuses cached keys and values from earlier tokens.</p>
<p>Pasting 500 lines of pod logs would add input tokens and usually increase cache needs. It would not add parameters to the model.</p>
<p>Two useful measurements:</p>
<table>
	<thead>
			<tr>
					<th>Metric</th>
					<th>What I notice</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Time to first token (TTFT)</td>
					<td>Wait until &ldquo;The&rdquo; appears, including queueing and prompt processing</td>
			</tr>
			<tr>
					<td>Output tokens per second</td>
					<td>How quickly the rest of the restart explanation appears</td>
			</tr>
	</tbody>
</table>
<h3 id="6-why-does-a-model-need-so-much-memory">6. Why does a model need so much memory?</h3>
<p>GPUs accelerate the large matrix calculations. But the model also has to fit in memory.</p>
<p><img alt="Ideal weight storage for our 2B model is 8 GB at 32 bits, 4 GB at 16 bits, 2 GB at 8 bits, or 1 GB at 4 bits. KV cache and runtime memory are additional." loading="lazy" src="https://vishctl.dev/images/posts/llm-basics/05-memory.svg"></p>
<p><strong>Quantization</strong> represents numbers using fewer bits. The chart shows ideal weight storage: parameters multiplied by bits, divided by eight. Actual formats add overhead and may keep some weights at higher precision.</p>
<p>FP16 and BF16 both use 16 bits, with different numerical ranges and precision. <strong>FP8 is an 8-bit floating-point format that newer GPUs can run natively.</strong> INT4 uses 4-bit integers. AWQ and GPTQ are quantization methods.</p>
<p>For our 2B model, 16-bit weights take about 4 GB; ideal 4-bit storage takes about 1 GB. The question stays the same. We store the learned numbers more compactly, leaving more of our 8 GB GPU for the cache and runtime. Whether it fits depends on the model, format, and context. Quality can fall; speed gains depend on hardware and software.</p>
<h3 id="7-what-does-vllm-add">7. What does vLLM add?</h3>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Our pod question (request A)
</span></span><span class="line"><span class="cl">            |
</span></span><span class="line"><span class="cl">            v
</span></span><span class="line"><span class="cl">     vLLM request queue
</span></span><span class="line"><span class="cl">            |
</span></span><span class="line"><span class="cl">            v
</span></span><span class="line"><span class="cl"> Scheduler chooses work &lt;-------------------+
</span></span><span class="line"><span class="cl">            |                              |
</span></span><span class="line"><span class="cl">            v                              |
</span></span><span class="line"><span class="cl"> Batch of scheduled tokens from A, B, C    |
</span></span><span class="line"><span class="cl">            |                              |
</span></span><span class="line"><span class="cl">            v                              |
</span></span><span class="line"><span class="cl"> GPU runs model using weights + KV cache   |
</span></span><span class="line"><span class="cl">            |                              |
</span></span><span class="line"><span class="cl">            v                              |
</span></span><span class="line"><span class="cl"> Return generated tokens to each user      |
</span></span><span class="line"><span class="cl">            |                              |
</span></span><span class="line"><span class="cl">            v                              |
</span></span><span class="line"><span class="cl"> Finished? -- no: schedule more work -------+
</span></span><span class="line"><span class="cl">     |
</span></span><span class="line"><span class="cl">    yes
</span></span><span class="line"><span class="cl">     |
</span></span><span class="line"><span class="cl">     v
</span></span><span class="line"><span class="cl"> Release request resources
</span></span></code></pre></div><p><strong>vLLM is serving software that runs a model efficiently.</strong> Our pod question is <strong>request A</strong>. Other users send requests B and C. vLLM can process them together while maintaining each request&rsquo;s own context.</p>
<p><img alt="Continuous batching lets a new request enter when another finishes. PagedAttention maps each request&rsquo;s KV cache to separate physical blocks." loading="lazy" src="https://vishctl.dev/images/posts/llm-basics/06-serving.svg"></p>
<p><strong>Continuous batching</strong> updates the active batch as requests finish and capacity becomes available. <strong>PagedAttention</strong> manages KV cache in blocks that need not sit together in memory, reducing wasted space. The <a href="https://vllm-project.github.io/2023/06/20/vllm.html">vLLM team&rsquo;s explanation</a> connects these ideas to serving more requests.</p>
<p>If B finishes while our restart explanation is still generating, D can join when capacity allows. Our request A continues, with its own KV blocks.</p>
<p>This section goes deeper into multi-GPU serving; skip to the summary if you just want the core model.</p>
<h3 id="8-more-gpus-and-fewer-active-experts">8. More GPUs, and fewer active experts</h3>
<h4 id="split-maths-split-layers-or-serve-separate-requests">Split maths, split layers, or serve separate requests</h4>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">TENSOR PARALLELISM
</span></span><span class="line"><span class="cl">One layer&#39;s input for our question
</span></span><span class="line"><span class="cl">             |
</span></span><span class="line"><span class="cl">       +-----+-----+
</span></span><span class="line"><span class="cl">       v           v
</span></span><span class="line"><span class="cl">     GPU 1       GPU 2
</span></span><span class="line"><span class="cl">    part A      part B
</span></span><span class="line"><span class="cl">       |           |
</span></span><span class="line"><span class="cl">       +-----+-----+
</span></span><span class="line"><span class="cl">             |
</span></span><span class="line"><span class="cl">       Communicate / combine
</span></span><span class="line"><span class="cl">             |
</span></span><span class="line"><span class="cl">         Next layer
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">PIPELINE PARALLELISM
</span></span><span class="line"><span class="cl">Our question -&gt; GPU 1 -&gt; GPU 2 -&gt; Output
</span></span><span class="line"><span class="cl">             early     later
</span></span><span class="line"><span class="cl">             layers    layers
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">DATA PARALLELISM FOR SERVING
</span></span><span class="line"><span class="cl">              Request routing
</span></span><span class="line"><span class="cl">               /           \
</span></span><span class="line"><span class="cl">              v             v
</span></span><span class="line"><span class="cl">        Our question    Other request
</span></span><span class="line"><span class="cl">              |             |
</span></span><span class="line"><span class="cl">              v             v
</span></span><span class="line"><span class="cl">        Model copy 1    Model copy 2
</span></span><span class="line"><span class="cl">              |             |
</span></span><span class="line"><span class="cl">              v             v
</span></span><span class="line"><span class="cl">        Our answer      Their answer
</span></span></code></pre></div><p>Each replica can itself use multiple GPUs. For example, four GPUs could run two replicas, with two GPUs per replica.</p>
<p>With four GPUs, one choice is TP across all four to run one larger model. Another is four independent replicas of a smaller model behind a load balancer, trading model size for more concurrent capacity. Which is better depends on whether the model fits on fewer GPUs and whether you need size or throughput more.</p>
<p>For the same pod question: <strong>TP</strong> shares each layer&rsquo;s calculations across GPUs; <strong>PP</strong> passes the work through groups of layers; <strong>DP</strong> sends our whole request to one model replica while another serves someone else. These are possible layouts, not a claim that our small model needs multiple GPUs.</p>
<p><strong>NCCL</strong> is NVIDIA&rsquo;s GPU communication library. It can move and combine data over connections such as PCIe and NVLink. <strong>PCIe is the general system interconnect GPUs already use; NVLink is a faster, GPU-to-GPU-only path available on some hardware.</strong> More GPU-to-GPU communication generally wants the faster path. Extra GPUs can also add waiting time, so scaling is not automatically a speedup. <a href="https://docs.nvidia.com/deeplearning/nccl/user-guide/docs/overview.html">NVIDIA&rsquo;s overview</a> describes that communication layer.</p>
<h4 id="how-gpu-communication-connects-the-pieces">How GPU communication connects the pieces</h4>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">GPU 1 partial result       GPU 2 partial result
</span></span><span class="line"><span class="cl">          |                         |
</span></span><span class="line"><span class="cl">          +------------+------------+
</span></span><span class="line"><span class="cl">                       |
</span></span><span class="line"><span class="cl">              Collective operation
</span></span><span class="line"><span class="cl">                 (for example,
</span></span><span class="line"><span class="cl">                NCCL AllReduce)
</span></span><span class="line"><span class="cl">                       |
</span></span><span class="line"><span class="cl">          +------------+------------+
</span></span><span class="line"><span class="cl">          v                         v
</span></span><span class="line"><span class="cl">GPU 1 combined result      GPU 2 combined result
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">Communication travels over available connections,
</span></span><span class="line"><span class="cl">such as NVLink or PCIe, depending on the hardware.
</span></span></code></pre></div><h4 id="moe-routes-work-to-selected-experts">MoE routes work to selected experts</h4>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Representation of a token from our question
</span></span><span class="line"><span class="cl">                       |
</span></span><span class="line"><span class="cl">                       v
</span></span><span class="line"><span class="cl">                  Learned router
</span></span><span class="line"><span class="cl">                       |
</span></span><span class="line"><span class="cl">               +-------+-------+
</span></span><span class="line"><span class="cl">               v               v
</span></span><span class="line"><span class="cl">            Expert 2        Expert 7
</span></span><span class="line"><span class="cl">               |               |
</span></span><span class="line"><span class="cl">               +-------+-------+
</span></span><span class="line"><span class="cl">                       |
</span></span><span class="line"><span class="cl">                       v
</span></span><span class="line"><span class="cl">             Combine expert outputs
</span></span><span class="line"><span class="cl">                       |
</span></span><span class="line"><span class="cl">                       v
</span></span><span class="line"><span class="cl">              Continue through layers
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">Other experts are not selected for this token
</span></span><span class="line"><span class="cl">in this illustrative MoE layer.
</span></span></code></pre></div><p><strong>MoE</strong> is an alternative architecture, not a serving switch for our dense 2B model. A mixture-of-experts model answering the same question selects a subset of expert networks for each token at an MoE layer. The routing is learned; experts are not necessarily named subject specialists. For a token in our question, a router might select experts 2 and 7. That does not make either a &ldquo;Kubernetes expert.&rdquo; Fewer active parameters reduce computation, but all weights still need storage somewhere. <a href="https://arxiv.org/abs/2401.04088">Mixtral&rsquo;s paper</a> provides a concrete example.</p>
<p>Memory capacity answers <strong>&ldquo;Will it fit?&rdquo;</strong> Memory bandwidth answers <strong>&ldquo;How fast can data move?&rdquo;</strong> Compute throughput answers <strong>&ldquo;How fast can the maths run?&rdquo;</strong> Any of these, plus GPU communication, can limit performance.</p>
<h2 id="9-the-big-picture">9. The Big Picture</h2>
<h3 id="the-whole-conversation-flow">The whole conversation flow</h3>
<p>The app supplies the conversation history it wants the model to use. The next turn is another request, with an updated context.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">MODEL SETUP                        OUR CONVERSATION
</span></span><span class="line"><span class="cl">Learned parameters                 Pod question + OOMKilled
</span></span><span class="line"><span class="cl">       |                                    |
</span></span><span class="line"><span class="cl">       v                                    v
</span></span><span class="line"><span class="cl">Choose weight format                 App assembles context
</span></span><span class="line"><span class="cl">(optional quantization)              instructions + messages
</span></span><span class="line"><span class="cl">       |                                    |
</span></span><span class="line"><span class="cl">       v                                    v
</span></span><span class="line"><span class="cl">Load model on GPU(s)                  Tokenize and schedule
</span></span><span class="line"><span class="cl">       |                                    |
</span></span><span class="line"><span class="cl">       +----------------+-------------------+
</span></span><span class="line"><span class="cl">                        |
</span></span><span class="line"><span class="cl">                        v
</span></span><span class="line"><span class="cl">             Prefill through the model
</span></span><span class="line"><span class="cl">             Build/reuse available KV cache
</span></span><span class="line"><span class="cl">                        |
</span></span><span class="line"><span class="cl">                        v
</span></span><span class="line"><span class="cl">                  First output token
</span></span><span class="line"><span class="cl">                        |
</span></span><span class="line"><span class="cl">                        v
</span></span><span class="line"><span class="cl">             Decode + extend KV cache
</span></span><span class="line"><span class="cl">             Repeat until stopping
</span></span><span class="line"><span class="cl">                        |
</span></span><span class="line"><span class="cl">                        v
</span></span><span class="line"><span class="cl">             Restart explanation to user
</span></span><span class="line"><span class="cl">                        |
</span></span><span class="line"><span class="cl">                        v
</span></span><span class="line"><span class="cl">           Follow-up: &#34;What should I check?&#34;
</span></span><span class="line"><span class="cl">                        |
</span></span><span class="line"><span class="cl">                        v
</span></span><span class="line"><span class="cl">            App includes relevant history
</span></span><span class="line"><span class="cl">            plus this follow-up question
</span></span><span class="line"><span class="cl">                        |
</span></span><span class="line"><span class="cl">                        v
</span></span><span class="line"><span class="cl">                  Next request
</span></span></code></pre></div><p>Cache reuse between requests depends on the engine and matching context. Even without reuse, the app can send the history again and the engine can recompute it.</p>
<h3 id="the-five-things-i-want-to-remember">The five things I want to remember</h3>
<table>
	<thead>
			<tr>
					<th>Term</th>
					<th>My reminder</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Parameters</td>
					<td>Learned numbers linking patterns such as OOMKilled and memory</td>
			</tr>
			<tr>
					<td>Tokens</td>
					<td>Pieces of our question and restart explanation</td>
			</tr>
			<tr>
					<td>Attention</td>
					<td>Combine the restart question with the OOMKilled clue</td>
			</tr>
			<tr>
					<td>KV cache</td>
					<td>Reuse earlier calculations as the explanation grows</td>
			</tr>
			<tr>
					<td>Inference engine</td>
					<td>Schedule our request and run the model</td>
			</tr>
	</tbody>
</table>
<p>Our final answer might be:</p>
<blockquote>
<p>The container was killed because of an out-of-memory event. Check its memory limit and usage to investigate why.</p>
</blockquote>
<p>One question, learned numbers, context, repeated calculations, and an answer to verify against the cluster.</p>
]]></content:encoded></item></channel></rss>