From attention to KV cache to serving: a HungerSync learning path
Connect Transformer attention, KV caching, and inference serving through a HungerSync case, without treating Ollama to vLLM as a mandatory upgrade.
A working local model server can be the right place to stay. Building a useful application does not require replacing it just because another engine exposes more controls.
For the HungerSync learning path, the strongest addition is attention → KV cache → serving behavior. It connects the model code in Sebastian Raschka’s LLMs-from-scratch to the practical work of explaining memory use, waiting requests, and an operator’s experience. Raschka’s attention chapter and KV-cache implementation provide the code-level starting points.[7][8]
Keep engine comparison optional. Learning how vLLM works can be worthwhile even when the application continues to use Ollama. Choosing a model, its representation, and the server that runs it are separate decisions.
The HungerSync case: the workbench makes operators wait
Section titled “The HungerSync case: the workbench makes operators wait”HungerSync is a fictional airport food-delivery platform used here as a teaching case. During a flight disruption, a passenger reports:
My gate moved to A07. Please do not send my meal to B12.
The delivery-exception workbench brings together the passenger’s report, the kitchen’s order state, operational guidance, and a proposed next action. It is an incident-processing application rather than a general chat interface.
In this extension, the platform engineer needs a local inference service to support several kinds of work:
| Workload | HungerSync example | What matters |
|---|---|---|
| Short interactive requests | Interpret a passenger’s gate correction and propose an incident update | Useful output, responsiveness, reliable structure |
| Longer contextual requests | Consult operational guidance and explain how to handle a delivery exception | Relevant context, reasoning quality, prompt-processing time |
| Background processing | Summarize completed incidents or prepare documents for retrieval | Completion rate, resource use, recoverability |
| Development work | Run evaluation examples while improving the application | Repeatability without disrupting operators |
The engineer needs to choose a combination of model, serving configuration, and workload organization that supports these needs without unnecessary complexity. Possible answers include keeping Ollama, changing how the application schedules work, separating interactive and background jobs, or using vLLM for a particular workload.
This is a curriculum proposal, not a report of a deployed HungerSync service or a matched performance benchmark.
Start with attention, then follow the cache into serving
Section titled “Start with attention, then follow the cache into serving”An inference-server option becomes easier to reason about after tracing the computation it controls. The priority path begins inside the small Transformer, not with a server installation.
Attention: what does the next token need?
Section titled “Attention: what does the next token need?”Use the attention implementation to reason through queries, keys, values, attention scores, the causal mask, and the weighted output. Raschka’s Chapter 3 is specifically about coding attention mechanisms.[8]
For the gate-correction example, distinguish the input text from the model’s intermediate tensors. Understanding attention does not establish that a tiny model will resolve an incident correctly. It explains how that model processes context.
KV cache: what can generation reuse?
Section titled “KV cache: what can generation reuse?”Raschka’s walkthrough shows why previously computed keys and values for an unchanged prefix can be reused as generation adds tokens. The cached generation path processes the prompt, then feeds newly generated tokens through the model while retaining earlier keys and values.[7]
That reuse changes the implementation. Cache buffers, position tracking, and reset behavior become part of the generation path. The cache also consumes memory; avoiding repeated computation does not make the retained tensors free.[7]
A useful hands-on choice is to annotate the changes between the uncached and cached GPT files, sketch the tensor shapes, or implement a small portion of the cache yourself. These are alternatives, not a prescribed benchmark. You do not need to train a domain foundation model to study the mechanism.
Serving behavior: who uses the available memory and computation?
Section titled “Serving behavior: who uses the available memory and computation?”Now connect that cache to the workbench. A long contextual request and several short interactive requests compete for finite resources. Ollama’s documentation explains that parallel requests and configured context length affect memory requirements together.[2]
The server adds scheduling and resource management around the model. vLLM’s serving controls make the tradeoffs between prompt processing, decoding, concurrency, and cache capacity explicit.[4]
This gives the latency notebook a concrete line of inquiry: determine whether an operator is waiting for application work, a place in the server’s queue, prompt processing, or token generation. A tokens-per-second figure alone cannot explain the whole incident path.
Keep these meanings of memory separate:
- Model weights are the parameters used by the model.
- A KV cache retains intermediate attention computations during inference.[7]
- Prefix caching can reuse compatible cached computation for a shared prompt beginning across requests.[3]
- Application memory stores the incident history or other records the application chooses to retain.
- Retrieval selects external information to include in a request.
A KV cache is neither the passenger’s durable history nor a database of current order facts. Prefix caching is also different from saving a complete generated answer and returning it later.
Ollama already supports substantial applications
Section titled “Ollama already supports substantial applications”Ollama is a model server with an HTTP API, not merely a chat application. Its OpenAI-compatible interface supports a subset of that API, including streaming, tools, embeddings, and structured-output controls; the selected model and interface still matter.[1]
Ollama also supports concurrent processing. With sufficient memory, it can keep multiple models loaded and process requests in parallel for a model. Its queue and parallelism settings are documented serving controls.[2]
Neither “Ollama is single-user” nor “vLLM is the model-server step” is a useful distinction. A HungerSync developer can build API integrations, structured incident proposals, and tool-driven workflows without making an engine migration part of the exercise.
The notebook should leave room for a simple conclusion:
Ollama meets this application’s needs.
Where vLLM becomes useful learning material
Section titled “Where vLLM becomes useful learning material”vLLM offers mechanisms worth studying when they answer a workload question: continuous batching for overlapping requests, PagedAttention for KV-cache memory management, chunked prefill for processing long prompts in portions, and prefix caching for reusing a shared prompt beginning.[3][4]
These mechanisms are not promises that vLLM will be faster for the chosen model on the chosen machine. Prefix caching primarily reduces repeated prefill work; it does not generally shorten the decoding of each new answer token.[3]
For HungerSync, stable operational instructions or a shared document prefix might offer reuse. Changing order facts still need to reach the request. Prompt layout therefore belongs alongside retrieval and application-memory design, rather than being treated only as wording advice.
vLLM’s metrics provide another reason to learn it. The server reports waiting requests, time to first token, inter-token latency, end-to-end request latency, and KV-cache utilization.[6]
Those measurements support different questions. A configuration might improve aggregate throughput while making an operator’s interactive request less responsive. Client timing, application traces, and server metrics help explain that tradeoff from different parts of the system.
Weave serving into the existing notebook ideas
Section titled “Weave serving into the existing notebook ideas”The numbers below refer to the HungerSync engineering starter sequence. They identify related topics, not a required order or a claim that the proposed extensions have already been implemented.
| Notebook extension | Where it fits | Alternatives and questions to explore |
|---|---|---|
| From attention to inference memory: highest priority | 03–04: LLM internals; 20: Latency | Connect the from-scratch Transformer to prefill, token-by-token decoding, and KV caching. Separate model-weight memory, inference-cache memory, and the agent’s persistent records. |
| A model server is not a chat interface | 02: APIs; 12: Real tools | Call Ollama’s native API, use an OpenAI-compatible client, or introduce a small application adapter. Which interface exposes the capabilities the application needs? |
| API compatibility is not feature equivalence | 06: Tool calling; 07: Structured outputs; 13: Fallbacks | Compare request formats, streaming events, tool responses, and schema support. What can the application share across backends, and what needs engine-specific handling? |
| Interactive work versus background work | 10: Agent; 16: Evals; 20: Latency | Compare concurrent execution, an application queue, scheduled background jobs, or separate services. Would workload organization solve the problem before changing engines? |
| Prompt layout as a serving decision | 09: RAG; 11: Memory; 20: Latency | Explore stable instructions and document prefixes versus changing incident facts. Distinguish prefix caching from answer caching and document retrieval. |
| A checkpoint is part of a deployment configuration | 05: Model adaptation; 18: Deployment | Compare model revisions, precision, quantization, templates, parsers, and hardware support. Fitting in memory does not establish complete deployment compatibility. |
| Explain the wait, not just the total duration | 15: Observability; 21: Logs; 22: User failures | Distinguish application work, queueing, prompt processing, and generation. Compare client timing, application traces, and server metrics. |
| Choose an operating model, not a winner | 18: Deployment; 19: Costs; 23: README | Compare one service, an optional comparison environment, split workloads, or selected hosted inference. Include output quality and maintenance effort, not just tokens per second. |
The attention-and-cache extension should receive the most development effort. It provides the explanation that the API, observability, and serving notebooks can refer back to. An engine comparison can remain a side investigation.
Make comparisons answer different questions
Section titled “Make comparisons answer different questions”If an engine comparison is useful, first decide what it should explain.
| Comparison | What it could help you understand |
|---|---|
| Closely matched models and settings across engines | Serving-engine differences, subject to remaining implementation and configuration differences |
| Different checkpoints or quantization formats across engines | Tradeoffs between complete deployment configurations, rather than an isolated engine comparison |
| One interactive request versus overlapping workloads | Whether aggregate throughput and operator responsiveness move together or conflict |
| One service versus separated workloads | Whether architecture and scheduling matter more than changing the inference engine |
Model revision, tokenizer, precision, chat template, context length, output length, caching, and concurrency can all complicate interpretation. Where those choices differ, describe the comparison accordingly. Do not turn a result about two complete deployments into a universal ranking of their serving engines.
For DGX Spark exploration, use NVIDIA’s recipe selector instead of inventing a generic launch configuration. NVIDIA explicitly treats model and precision, container architecture, vLLM version, parsers, and parallel configuration as compatibility requirements.[5]
A documented recipe is a reason to explore that configuration. It is not evidence that Ollama is generally unsuitable for the machine.
Copyable prompts for hands-on learning
Section titled “Copyable prompts for hands-on learning”Use a prompt to request the amount of help you want. If you are driving the keyboard, name the function or section you are studying and ask for a hint or one question rather than a complete implementation.
Connect the book to serving
Section titled “Connect the book to serving”Use the small GPT implementation from LLMs-from-scratch to explain prefill,decoding, and KV caching. Start with concepts I already understand. Thenexplain what an inference server adds around the model. Distinguish KV caching,prefix caching, application memory, and retrieval. Ask me one question at a time.Analyze alternatives
Section titled “Analyze alternatives”HungerSync needs short incident-processing requests alongside longer contextualand background jobs. Help me compare Ollama, vLLM, and application-levelworkload scheduling. Ask about quality, hardware, privacy, responsiveness,and maintenance effort. Recommend techniques conditionally; do not assumechanging servers is necessary.Understand comparison limits
Section titled “Understand comparison limits”Help me distinguish a serving-engine comparison from a complete deploymentcomparison. Explain how checkpoint revision, quantization, tokenizer, chattemplate, context length, output length, caching, and concurrency can affectinterpretation. Offer approaches I could choose, not a prescribed benchmark.Research failure patterns
Section titled “Research failure patterns”Research common failures in local LLM serving: overload, memory pressure,model loading, streaming interruptions, tool parsing, schema support, andhardware incompatibility. Prefer primary documentation and engineering issuereports. Explain symptoms, prevention, and recovery, and distinguishapplication problems from model or server problems.What to build and write about first
Section titled “What to build and write about first”Start with the connection between an attention operation, the state generation retains, and the behavior an operator notices. Choose whether to begin with a code-reading note, a tensor sketch, or an unfinished cache implementation. Explain what you understand and which design choices you want to explore next.
That work can become a notebook, a short explanation, or a work-in-progress article. It does not need a server migration or a completed benchmark to be worth sharing.
The useful outcome is an application design you can explain. Keeping Ollama, changing workload scheduling, or studying vLLM without adopting it permanently are all possible outcomes of that work.
Sources
Section titled “Sources”[1] https://docs.ollama.com/api/openai-compatibility — Ollama: OpenAI compatibility [2] https://docs.ollama.com/faq — Ollama FAQ: concurrency and memory [3] https://docs.vllm.ai/en/latest/features/automatic_prefix_caching.html — vLLM: automatic prefix caching [4] https://docs.vllm.ai/en/latest/configuration/optimization.html — vLLM: serving optimization [5] https://build.nvidia.com/spark/vllm/choose-recipe — NVIDIA DGX Spark: choose a vLLM recipe [6] https://docs.vllm.ai/en/latest/usage/metrics — vLLM: production metrics [7] https://raw.githubusercontent.com/rasbt/LLMs-from-scratch/main/ch04/03_kv-cache/README.md — Raschka: adding a KV cache to GPT [8] https://raw.githubusercontent.com/rasbt/LLMs-from-scratch/main/ch03/README.md — Raschka: coding attention mechanisms