LLM Architecture: From Transformer Block to Production
Ask about LLM architecture and you get two different answers: how the model works inside, and how the system around it is built. Both matter, but only some of the internals change a decision you will actually make. Here is the whole stack, layer by layer.

On this page

LLM architecture means two different things, and almost every argument about it comes from people using the term in both senses at once. The first sense is the model itself: tokenizer, embeddings, a stack of transformer blocks, and a decoding step that picks the next token. The second sense is the system around the model: context assembly, retrieval, tools, memory, orchestration, evaluation, observability. You only get to design the second one.
If you are shipping a product, the second sense of LLM architecture is where your quarter goes. The model arrives as a fixed artifact with a price per token and a context limit, and you build a system around it. That system is where latency, cost, accuracy and failure behavior get decided.
That said, the internals aren't decoration. Five of them change decisions you'll make about serving, cost and context budget. The rest won't change your design. What follows is LLM architecture explained at both levels: enough of the transformer to know which internals matter, then the application architecture in full, with the trade-off attached to every choice. It sits under our broader AI software development guide.
The short version
- LLM architecture splits into model architecture (fixed when you pick a model) and application architecture (everything you control). Say which one you mean before the meeting starts.
- Inside the model, the internals that change your decisions are the context window, the KV cache, the attention variant, mixture-of-experts sparsity, and the tokenizer. The rest is background.
- An LLM application has eight components: model, context assembly, retrieval, tools, memory, orchestration, evaluation, observability. Skipping the last two is a common architectural failure, and an expensive one.
- Capability sits in one of four layers: prompting, retrieval, fine-tuning, continued pre-training. Climb only on evidence, because each rung costs roughly an order of magnitude more than the one below.
- Use retrieval when the model lacks knowledge. Use fine-tuning when it lacks behavior. Most teams who say they need fine-tuning have a retrieval problem.
- Routing between a cheap model and a strong one is usually the biggest single cost lever. Published research puts the saving between two-fold and near-total.
- The architecture that survives a prototype is not the architecture that survives production traffic. Caching, streaming, fallbacks and concurrency limits have to be designed in.
What LLM architecture means at two levels
LLM model architecture is the shape of the network: how many layers, how attention is computed, how positions are encoded, how the vocabulary maps to vectors. It is decided by whoever trained the model, and you change it only by training. When a paper says "architecture", this is what it means.
Application architecture is the shape of the system: what goes into the context window on each call, what the model is allowed to invoke, how many times it runs before answering, what happens when it returns nonsense. You decide it, it changes weekly, and it's what a production incident is usually about.
The two levels connect at three points:
- The context window is the interface between them. Model architecture sets its size and its cost per token; application architecture decides what goes in it.
- The serving profile is set by model internals (parameter count, attention variant, sparsity) and consumed by your architecture as latency and dollars per request.
- The output contract is a probability distribution over tokens on the model side and a parsed, validated object on yours.
Everything else is separable, so you can swap the model without redesigning the system. Teams often do exactly that when a better or cheaper model ships.
Inside the model: the transformer architecture in brief
A transformer is a stack of attention and feed-forward blocks that turns token IDs into next-token probabilities. Every current large language model descends from one 2017 paper, in which Vaswani and colleagues proposed an architecture "based solely on attention mechanisms, dispensing with recurrence and convolutions entirely" (Vaswani et al., 2017). Nearly a decade later the core loop is unchanged; what moved is efficiency, scale and the tricks around attention.
Here is the path a request takes through the model, and what each stage means for your bill and your context budget.
Tokens and embeddings: how text enters the model
A tokenizer splits text into subword pieces. This is worth one minute of your attention because it decides your bill: the same paragraph can cost noticeably more tokens in one model's vocabulary than another's, and non-English text, code and long identifiers fragment much harder than plain English prose. Any cost model built on word counts rather than token counts will be wrong.
Each token ID becomes a dense vector, and position information is added so the model knows word order, since attention on its own is order-blind. Modern models mostly use rotary position embeddings, which encode position by rotating query and key vectors rather than adding a fixed signal (Su et al., 2021). The practical consequence is that position handling is now the thing being modified whenever a lab extends a context window, which is why long-context variants appear as separate releases.
Attention and the LLM architecture variants that cut serving cost
Attention lets every token look at every other token and decide what is relevant. Multi-head attention runs several of these comparisons in parallel over different learned subspaces. That's the part of the architecture that made the transformer work, and it's also the part that makes it expensive, because attention cost grows quadratically with sequence length.
What is a KV cache and why it caps concurrency
A KV cache stores the key and value tensors a model has already computed for earlier tokens, so each new token reuses them. Without it, producing token 501 would mean recomputing attention over the previous 500. The cache grows with context length and with concurrent users, and on long conversations it can consume more GPU memory than the weights. So the KV cache, more than the parameter count, sets how many users fit on one GPU.
Two attention variants you'll meet in model cards exist to shrink it:
- Grouped-query attention (GQA) gives several query heads a shared set of key-value heads. The paper reports that "uptrained GQA achieves quality close to multi-head attention with comparable speed to" multi-query attention, and that uptraining an existing checkpoint takes "5% of original pre-training compute" (Ainslie et al., 2023).
- Multi-head latent attention (MLA) goes further and compresses the cache into a latent vector. DeepSeek-V2, which pairs MLA with a mixture-of-experts design, reports that against DeepSeek 67B it "reduces the KV cache by 93.3%" and "boosts the maximum generation throughput to 5.76 times" (DeepSeek-AI, 2024).
If you never self-host, this is trivia. If you do, it's your capacity plan.
Feed-forward layers, normalization and depth
After attention mixes information across positions, a feed-forward network transforms each position independently. This is where most of a dense model's parameters live. Normalization and residual connections wrap both sublayers so that gradients survive a deep stack. That plumbing is what let models scale past a few dozen layers.
Stack that block dozens of times and you have the model. Depth and width are the two dials, and their product is roughly what you pay to serve it.
Mixture of experts breaks that relationship, which is why so many recent open releases use it. Instead of every parameter running on every token, a router activates a small subset. DeepSeek-V3 has "671B total parameters with 37B activated for each token" (DeepSeek-AI, 2024). The architectural consequence is a model with the knowledge capacity of something enormous and the per-token compute of something mid-sized, at the price of needing all 671 billion parameters resident in memory. For a hosted API you see this only as unusually good quality per dollar. For self-hosting it changes what hardware you need.
Decoding: how the next token is chosen
The final layer produces a score for every token in the vocabulary. Softmax turns those into probabilities, then a sampling strategy picks one: greedy selection takes the highest, temperature flattens or sharpens the distribution, top-k and top-p restrict the candidate pool.
Sampling is the one internal you control directly through the API, and it often gets left alone. Teams building extraction or classification pipelines leave temperature at a creative default and then file bug reports about inconsistency. Set it low for anything with a schema and higher for anything with a voice. Either way, choose it on purpose.
Types of LLM architecture: decoder-only, encoder-decoder and encoder-only
LLM architectures come in three families: encoder-only, encoder-decoder and decoder-only. A decoder-only transformer generates text one token at a time, and each position sees only the tokens before it. The original transformer had both halves, an encoder and a decoder, and the field split them apart. What separates the families is which tokens each position is allowed to see.
Decoder-only won the general-purpose slot because of how it trains. Its training objective is next-token prediction, so any text at all is usable training data with no paired examples required, which makes pre-training data effectively unlimited. The same design also absorbs classification, extraction and summarization once you phrase them as generation, so one model replaces a shelf of task-specific ones.
Encoder-only models didn't disappear. Many retrieval layers in production run one to produce embeddings and often a second to rerank results. A typical LLM architecture therefore often contains two model families, which is easy to miss because only one of them produces text a user reads.
Which model internals actually change an architecture decision
Of everything above, five internals reach your design. The rest belongs to the people training models.
Everything else (normalization placement, activation functions, the exact positional scheme, expert routing strategy) you can't change, and it doesn't change what you build.
One more item belongs on the list, although it's a property of behavior and the network diagram won't show it: models don't use long contexts evenly. Liu and colleagues found that "performance is often highest when relevant information occurs at the beginning or end of the input context, and significantly degrades when models must access relevant information in the middle of long contexts, even for explicitly long-context models" (Liu et al., 2023). For your design, that means a bigger context window is no substitute for good retrieval, and where you place retrieved passages in the prompt has measurable consequences.
A larger context window doesn't fix bad retrieval. The failure moves to the middle of the prompt, where it's harder to see.
The components of an LLM application architecture
An LLM application architecture is the system built around the model: the code that assembles context, retrieves documents, calls tools, keeps memory, sequences calls and measures the result. This is the level you design. Eight components show up in most production systems, whether or not the team has named them.
Context assembly, memory and orchestration need more than a table row.
Context assembly is the real prompt engineering. By the time a request reaches the model, several sources have competed for room: system instructions, conversation history, retrieved passages, tool definitions, output schema. Something has to decide the budget and the order. Teams that leave this implicit find that adding a feature quietly pushed the instructions out of the window, and the symptom looks like the model getting dumber for no reason.
Memory has to be designed. Short-term memory is the conversation you replay each turn, and replaying it in full means every turn costs more than the last. Long-term memory is what survives the session, which means storage, retrieval and a policy on what to forget. Both are cheap to bolt on and expensive to bolt on badly.
Orchestration is where complexity gets added for free and paid for later. Agent frameworks make elaborate multi-step loops tempting on day one. Anthropic's guidance draws the line clearly: "Workflows are systems where LLMs and tools are orchestrated through predefined code paths. Agents, on the other hand, are systems where LLMs dynamically direct their own processes and tool usage", and the recommendation is to find "the simplest solution possible, and only increasing complexity when needed" (Anthropic, 2024). A fixed sequence can be tested, reasoned about and bounded in cost. Reach for autonomy only where the task branches in ways you can't enumerate (our guide to AI agents for business covers where that pays back), and treat every tool call as a privileged action: validate arguments, scope permissions, log what happened, keep a human in the loop for anything irreversible.
Where to put capability in your LLM architecture
The architecture question with the biggest consequences is which layer holds the thing that makes your system yours. Framework and vector database come later. There are four candidates, and each costs roughly an order of magnitude more than the one before.
The timelines are typical for our projects, not industry statistics.
Climb only when you have evidence the layer below can't do the job, and by evidence we mean a failing eval set. A team that skips layers can spend a quarter learning that its fine-tune can't recall a policy document because the policy changed after training.
Layer one: prompting and context engineering
The first instinct is to treat prompting as copywriting. Pick better words, get better output. That works until the inputs vary, and then it doesn't. Real prompt design is closer to interface design: you are defining a contract that states the role, the constraints, the shape of the answer, and what to do when the answer is not available. Wording matters less than structure.
Three things hold up in production. Be explicit about failure, because a line like "if the contract is not in the provided context, say you cannot find it" prevents a whole class of confident wrong answers. Constrain the output format, and validate it, since free text that usually parses will eventually break a Friday deploy. Use examples sparingly, because two well-chosen ones anchor format and tone better than ten generic ones and cost far less context.
For internal tooling and well-scoped tasks, a sharp prompt over a strong base model is the entire architecture. Reaching past it is premature optimization.
Layer two: retrieval, when the custom part is your data
Retrieval-augmented generation is where most LLM architectures should stop. It exists for one reason: the model lacks knowledge. Your policies, your product docs, last quarter's numbers, a customer's ticket history. None of it sits in the weights, and it changes too fast to bake in.
RAG fetches the relevant pieces at query time and places them in context, so the knowledge updates when you edit a document rather than when you retrain. That property alone explains why retrieval beats fine-tuning for most enterprise work: an answer that has to be current cannot live in weights frozen last March. It also keeps the system auditable, because you can show which passage produced which sentence.
Most of the quality comes from data work. Chunking sets your ceiling before you write a line of prompt. Embedding choice and reranking decide whether the right passage reaches the model at all. Citation plumbing decides whether anyone trusts the output. We go deeper on all of it in our guide to building RAG systems on LLMs, and benchmark dedicated vector engines against PostgreSQL pgvector in our Pinecone vs Qdrant vs Weaviate guide.
One test tells you whether you are on this layer: write down a failing answer, then ask whether a human expert could have answered correctly given only a folder of your documents. If yes, you have a retrieval problem, and no amount of weight adjustment will fix it.
Layer three: fine-tuning on your own examples
Fine-tuning is for when the model lacks behavior. It knows the facts but will not reliably produce the format, tone or classification pattern you need. Fine-tuning adjusts weights on your examples so that behavior becomes the default instead of a paragraph of instructions you pay for on every call.
Two techniques made this layer affordable. LoRA freezes the base model and trains small low-rank matrices instead, which the original paper reports can "reduce the number of trainable parameters by 10,000 times and the GPU memory requirement by 3 times" relative to fine-tuning GPT-3 175B with Adam (Hu et al., 2021). QLoRA adds 4-bit quantization of the frozen base and gets far enough that a 65B parameter model fits "on a single 48GB GPU while preserving full 16-bit finetuning task performance" (Dettmers et al., 2023).
The data floor is lower than most teams assume. OpenAI's fine-tuning documentation puts the minimum at 10 examples and recommends "starting with 50 well-crafted demonstrations and evaluating the results" (OpenAI). Consistency across that training data matters far more than volume. A small, clean, uniform set usually beats a much larger contradictory one, and a contradictory dataset produces a model that is confidently inconsistent, which is worse than the base model you started with. Before any of it goes into a training run, check that you hold the rights to use it: customer text collected under a processing agreement written for support tickets rarely covers baking that text into weights you then serve to other customers.
One platform change affects any plan built on hosted tuning. OpenAI is winding down its fine-tuning platform: the documentation states it "is no longer accessible to new users, but existing users of the fine-tuning platform will be able to create training jobs for the coming months" (OpenAI). The deprecations page gives the dates: closed since May 7, 2026 to organizations that had never fine-tuned, with self-serve job creation for existing users ending January 6, 2027. If your architecture assumes tuning on a hosted API, check the API still offers it before the roadmap depends on it. Open-weight models don't carry that risk. Our practical walkthrough of fine-tuning an LLM covers the mechanics.
Layer four: continued pre-training
Continued pre-training, sometimes called domain-adaptive pre-training, keeps training an existing base model on a large corpus of domain text before any instruction tuning. This is the first layer where the model's underlying sense of a domain shifts, not just its surface behavior.
The canonical worked example is BloombergGPT, a 50 billion parameter model trained on "a 363 billion token dataset based on Bloomberg's extensive data sources" combined with "345 billion tokens from general purpose datasets" (Wu et al., 2023). Note the shape of that: roughly half the corpus is proprietary financial text Bloomberg had accumulated over decades, and it still needed the general half to remain a usable language model.
That ratio is the entry test. You need a domain corpus measured in hundreds of billions of tokens, and it has to be text open models have not already absorbed. Public regulatory filings do not qualify, because every frontier model has read them. Forty years of proprietary trading commentary does. If you can't name a corpus of that scale that is yours, you aren't on this layer, and no vendor proposal should put you there.
BloombergGPT was published in 2023, and the frontier has moved since. General models now perform strongly on many finance benchmarks without domain pre-training. In 2024, Andreessen Horowitz reported that among the enterprises it surveyed "most are opting not to train their own LLM from scratch and instead use retrieval-augmented generation (RAG) or fine-tune an open source model for their specific needs" (a16z, 2024), and the firm has since published a 2025 edition of that survey. This layer narrows every year.
Why almost nobody should pre-train from scratch
Pre-training a foundation model is a fifth option in a different budget category. Two published figures make the scale concrete.
Meta's Llama 3.1 405B was pre-trained on 15.6 trillion tokens using up to 16,000 H100 GPUs (Dubey et al., 2024), and Meta's model card puts the 405B run at 30.84 million H100-80GB GPU-hours, out of 39.3 million cumulative across the whole Llama 3.1 herd (Meta). DeepSeek-V3, a deliberately efficiency-focused effort, required 2.788 million H800 GPU-hours for full training on 14.8 trillion tokens, which the team priced at $5.576 million assuming $2 per GPU-hour (DeepSeek-AI, 2024).
The DeepSeek number is the one people quote as proof that pre-training got cheap. Read the paper's own caveat first: "the aforementioned costs include only the official training of DeepSeek-V3, excluding the costs associated with prior research and ablation experiments on architectures, algorithms, or data." The headline figure is the cost of the final run once a research team already knows exactly what to run.
The real exceptions are few: a proprietary corpus at pre-training scale that you have the legal right to train on; a non-text modality such as protein sequences, chip layouts or telemetry, where general language pre-training gives you little; a sovereignty requirement that forces you to account for every token in the training set; or a business where the model itself is the product and its weights are your differentiator. "Our industry is very specialised" is answered by fine-tuning, and "our data is very sensitive" is answered by where you deploy.
Single model versus routing in an LLM architecture
Almost every system starts with one model behind one endpoint, and almost every system that reaches real traffic ends up with more than one. It's one of the biggest cost decisions in an LLM architecture, and it often gets made by accident.
Requests aren't uniform. Some are trivial classification, some need real reasoning, and paying frontier prices for both means subsidising the easy ones. A router sends each request to the cheapest model that can handle it, with the strong model as fallback.
Published research puts real numbers on the gain. FrugalGPT, which cascades from cheap models to expensive ones and stops when an answer is good enough, reports that it "can match the performance of the best individual LLM (e.g. GPT-4) with up to 98% cost reduction or improve the accuracy over GPT-4 by 4% with the same cost" (Chen et al., 2023). RouteLLM, which learns to route from preference data, "significantly reduces costs by over 2 times in certain cases without compromising the quality of responses" and keeps working "even when the strong and weak models are changed at test time" (Ong et al., 2024).
Treat the 98 percent figure as a ceiling from a favourable benchmark rather than a forecast. The two-fold saving is the number to plan against, and at scale that's still a lot of money.
Routing carries a cost of its own, and that is what makes it an architecture decision instead of an optimization. You now have two quality bars to maintain, a classifier that can itself be wrong, and a debugging story that starts with "which model answered this". Three rules keep it manageable:
- Route on evidence, not intuition. Build the eval set first, run it against both models, and route the categories where the cheap model measurably holds up.
- Make the routing decision observable. Every trace records which model ran and why, or you will never diagnose a quality regression.
- Keep the escape hatch. A confidence threshold or a validation failure should escalate to the strong model rather than returning a bad answer.
Route on evals. If you can't show the cheap model holds up on a category of requests, it doesn't get that category.
Small models also keep getting more capable. A distilled model in the 3B to 8B range, fine-tuned on one narrow job, can often handle work that used to go to a frontier model, at a fraction of the serving cost and inside a boundary you control. That makes the cheap branch viable for more of your traffic.
Choosing a base model for your LLM architecture
Once you know which layer holds your capability, the base model follows from two questions rather than from a leaderboard: where the model has to run, and how much of the licence you can live with.
Data residency usually settles this before quality does. A clinical or defence workload that cannot send text to a third-party cloud has already chosen open weights, whatever the benchmarks say. Everyone else should start on a hosted API and move only when a measured reason appears: an eval the API fails, a latency budget it misses, or an inference bill a smaller tuned model would halve.
The internals from earlier come back here. If you are self-hosting, the attention variant and the sparsity pattern decide whether a model fits your hardware at your concurrency, and two models with identical benchmark scores can differ several-fold in what they cost you to serve. Our AI development team runs this comparison on serving cost at target concurrency rather than on leaderboard position, because that is the number that shows up in the invoice, and we break down the 36-month H100 math across per-second serverless GPUs, dedicated TensorRT-LLM endpoints, and owned vLLM clusters in Modal vs Baseten.
Evaluation and observability belong in the architecture
Most LLM architecture diagrams stop at the model and the data stores. That omission is why so many systems ship and then quietly degrade: the components that tell you whether the thing works are treated as tooling rather than as architecture.
Evaluation is what makes a system safe to change. The model is non-deterministic, the inputs are open-ended, and "correct" is often a judgment call, so you cannot test it like a normal function and "it looked good when I tried it" is not a test. Teams that ship reliable systems keep a real eval set of a few dozen to a few hundred representative inputs with known-good answers, grade outputs with a mix of exact checks and model-as-judge rubrics, and treat that set as a versioned asset. It's also the only reliable way to measure hallucination on a domain-specific task, since a general benchmark tells you nothing about whether the model invents clauses in your contracts.
Observability is the production half of the same job. An LLM call is a distributed-systems span with unusual attributes: which model, how many input and output tokens, how long, which tools fired, what came back. OpenTelemetry now maintains dedicated conventions for exactly this, covering "spans, metrics, and events for GenAI clients, MCP (Model Context Protocol), and provider-specific conventions" (OpenTelemetry). Adopting a standard schema early costs an afternoon and means your traces survive a change of vendor, whether you route spans into ClickHouse-backed open-source collectors or managed SaaS platforms as evaluated in Langfuse vs LangSmith.
If you can't measure whether a change made the system better, you're guessing.
The pairing matters more than either half. Offline evals catch the problems you already know about; production traces show you the ones users found first. A healthy loop moves failures from the second into the first, so every incident permanently enlarges the eval set.
How an LLM architecture changes from prototype to production traffic
The LLM architecture that gets a demo applauded isn't the one that survives a Monday. Four things change, and each one has to be designed for.
Caching stops being optional. Long system prompts and stable retrieved context get re-sent on every call, and providers now bill that differently. Anthropic's documentation states that "cache read tokens are 0.1 times the base input tokens price", with 5-minute cache writes at 1.25 times and 1-hour writes at 2 times (Anthropic). OpenAI caches prompt prefixes automatically, with a minimum cacheable prefix of 1,024 tokens on its current models and a minimum that varies with request settings on older ones (OpenAI). Both point the same way: put the stable parts of your prompt first and the variable parts last, or you'll pay full price for content that never changed. Prompt layout is now a cost decision.
Latency becomes a structure problem. A multi-step chain that takes ten seconds feels broken regardless of answer quality. Streaming the first token early, running independent retrieval and tool calls concurrently rather than in sequence, and routing easy queries to a faster model are all architectural responses. Adding a spinner is not.
Failure modes multiply. Provider APIs rate-limit, time out and have incidents. Production architecture needs timeouts, retries with backoff, a circuit breaker, and ideally a fallback model on a different provider. The last one is only cheap if you built the model layer as an interface rather than as a hard-coded client, which is a decision made on day one and regretted in month six. For hot-path SSE failover, token-budget holds, and proxy latency trade-offs, see our Portkey vs LiteLLM gateway teardown.
Concurrency exposes the internals. If you self-host, the KV cache from earlier is now your capacity ceiling, and it grows with both context length and simultaneous users. Teams that sized hardware from a single-user benchmark discover this in the worst possible week. Cap conversation history, summarize instead of replaying, and measure memory at your target concurrency before you commit to a GPU count.
Under all four sits one habit: know your unit economics per request before traffic arrives. Token costs are small per call and large in aggregate, and the difference between a healthy margin and a bad one is usually a cache hit rate and a routing rule.
What each layer of an LLM architecture costs
Cost in an LLM architecture tracks the layer, and the shape of the spend changes as you climb. On the lower layers almost all of it is engineering time. On the upper ones compute takes over, and by continued pre-training the compute line dwarfs everything else.
Published prices give you an anchor for fine-tuning. OpenAI's last published price list shows supervised fine-tuning at $25 per million training tokens on gpt-4.1 and $5 on gpt-4.1-mini, both on models now marked deprecated (OpenAI), so a dataset of a few thousand demonstrations is a rounding error against a single engineer-week. Self-hosted LoRA runs land in the same territory once you price GPU time near the $2 per hour DeepSeek assumed for H800s. The training run is rarely the expensive part.
Watch for two cost traps. The first is treating that run as the project: a LoRA run on a mid-size open model is cheap, but the eval set that tells you whether it worked is not, and it usually takes longer to build than the model takes to train. The second is forgetting that custom weights are an asset you maintain. A fine-tuned model needs hosting, monitoring and periodic retraining as the world moves; a prompt does not. That ongoing line is what turns a one-quarter project into a permanent team commitment, and it belongs in the business case from day one. For the wider picture, our breakdown of what AI development actually costs puts these numbers alongside the rest of a build.
What you own at each layer of the architecture
Ownership usually gets asked about last. Ask first, because it doesn't scale with spend.
Prompting and retrieval are cleanly yours. Prompts, chunking logic, embeddings, the retrieval index and the evaluation set are all your artifacts, and they port between model providers with little rework. A team that stays at the retrieval layer can change providers without rewriting anything of substance.
Fine-tuning depends entirely on the base licence. A LoRA adapter you trained over an open-weight model is yours to host, but the base model's terms travel with it. Take the Llama 3.1 Community Licence, which covers a widely used model and carries real conditions. Distribute a model derived from it and you "shall also include 'Llama' at the beginning of any such AI model name", and you must "prominently display 'Built with Llama' on a related website, user interface, blogpost, about page, or product documentation". There is a scale clause too: cross 700 million monthly active users on the release date and you must request a separate licence from Meta (Meta). Apache-2.0 models carry none of this, which is a reason to check the licence before the benchmark.
A fine-tune on a hosted API is something you rent. You cannot export the weights, the provider controls the lifecycle, and as OpenAI's wind-down shows, the platform can close to new users while a competitor's open-weight adapter keeps running on hardware they rent by the hour.
Continued pre-training can make you a regulated provider. Under the European Commission's guidelines for general-purpose AI models, non-binding guidance published in July 2025, a downstream modifier becomes the provider of the modified model when "the training compute used for the modification is greater than a third of the training compute of the original model". Where the original figure is unknown, the threshold falls back to a third of 10^23 FLOP for an ordinary GPAI model, or a third of 10^25 FLOP for one with systemic risk (European Commission, 2025). Cross that line and the transparency and documentation obligations of a model provider attach to you, not to the lab whose weights you started from. Put that on the slide when you price a continued pre-training run.
How to design your LLM architecture: a decision sequence
Run this in order and stop at the first answer.
- Write twenty failing cases. Real inputs where a strong base model with a decent prompt gets it wrong. If you can't produce twenty, you don't yet have evidence to justify any architecture beyond an API call.
- Sort each failure into facts or behavior. Was the model missing something it never knew, or refusing to do something the way you need? Two piles, no third.
- If the facts pile is larger, build retrieval. Nothing you do to the weights will help, because weights cannot contain something that changes weekly.
- If the behavior pile is larger, try harder at prompting first. A serious pass with explicit failure handling and a constrained output schema resolves a large share of cases that started as "we need to fine-tune".
- If prompting plus retrieval still fails on behavior, fine-tune. You now have a labeling target that is specific and defensible: the cases that survived steps three and four.
- Only consider continued pre-training if you can name the corpus. Hundreds of billions of tokens, proprietary, legally yours, in one sentence. If you can't, the answer is no.
- Decide the model layer separately. Single model or router, hosted or self-hosted, based on the eval results and the serving cost at your target concurrency.
- Build evaluation and observability alongside, not afterwards. Every step above produces test cases. Keep them.
The one shortcut past this sequence is latency and unit cost. If a small fine-tuned model can do at 8B parameters what you currently pay a frontier model to do, the fine-tune pays for itself in inference savings regardless of quality gain. That's a finance decision, and it belongs in a spreadsheet before it reaches a roadmap.
Don't pick a framework first. Start with one narrow, valuable task you can describe precisely, and write twenty examples of good output for it. That's your first eval set, and it tells you more about feasibility than any LLM architecture diagram, including the ones above. Then get a prompt working, add retrieval when the model needs facts it doesn't have, add orchestration when one call isn't enough, and measure at every step.
If you're weighing whether to build your LLM architecture in-house or partner on it, that decision is mostly about people. Our generative AI development team designs and ships these systems, and our guide to AI staffing covers the roles this work needs, what they cost in the US market, and when bringing in a team that has already shipped one beats a six-month search.

CTO and Co-founder at Idealogic. Directing engineering, systems architecture, security, and full-stack delivery across web, mobile, and blockchain.
Frequently asked questions
LLM architecture describes two different things depending on who is asking. Model architecture is the internal design of the network itself: tokenization, embeddings, stacked transformer blocks with attention and feed-forward layers, and a decoding step that picks the next token. Application architecture is the system built around that model: context assembly, retrieval, tools, memory, orchestration, evaluation and observability. Engineers building a product spend almost all of their time on the second one.
Inside the model: a tokenizer, an embedding layer with positional information, a stack of transformer blocks each containing attention and a feed-forward network with normalization and residual connections, and an output layer that turns hidden states into token probabilities. Around the model, a production system adds context assembly, a retrieval layer, a tool layer, memory, an orchestration layer that sequences calls, guardrails, an evaluation harness, and observability. The model itself is the smaller part of the engineering.
Model architecture is fixed the moment you choose a model, and you change it only by training. LLM application architecture is everything you control: what goes into the context window, what the model can call, how many times it runs, and what happens when it is wrong. Most published diagrams labelled LLM architecture show one or the other without saying which. Confusing the two is why teams try to solve a retrieval problem by switching models.
Three families come out of the original transformer. Encoder-only models such as BERT read the whole input at once and suit classification, embedding and retrieval. Encoder-decoder models such as T5 map one sequence to another and suit translation and summarization. Decoder-only models generate one token at a time conditioned on everything before it, which is the design behind GPT, Llama, Mistral and Qwen. A fourth variant, mixture of experts, changes how many parameters run per token rather than how information flows.
A decoder-only stack trains on a single objective, predicting the next token, which means any text at all is training data with no paired inputs and outputs required. That makes pre-training data effectively unlimited, and it scales cleanly. The same design also handles classification, extraction and summarization when you phrase them as generation, so one model covers work that used to need three. Encoder-only models still win on embedding and reranking, which is why retrieval stacks usually run both.
Generating each new token requires attention over every previous token, so models cache the key and value tensors instead of recomputing them. That cache grows with the conversation and with concurrent users, and on long contexts it can dominate GPU memory. It's the reason attention variants exist: DeepSeek-V2, which uses Multi-head Latent Attention, reports a 93.3 percent smaller KV cache than DeepSeek 67B and 5.76 times its maximum generation throughput. If you self-host, the KV cache sets how many users fit on a GPU.
Retrieval-augmented generation is the layer that fetches relevant documents at query time and places them in the context window, so the model reasons over facts you supplied rather than only what it absorbed in training. It is the right answer whenever the knowledge changes faster than you can retrain, and it keeps answers auditable because you can point at the source. In practice the quality comes from chunking, embedding choice, reranking and citation plumbing, not from the model.
Almost never. Custom LLM development normally means placing capability in one of four layers: prompting and context engineering, retrieval over your own data, fine-tuning on your own examples, or continued pre-training on a domain corpus. Training a foundation model from scratch is a fifth option with a different budget: Meta's Llama 3.1 405B run took 30.84 million H100 GPU-hours. Unless you hold a corpus no open model has seen, you start from open or hosted weights.
More from the journal

Langfuse vs LangSmith in 2026: OTel, Evals & AI TCO
Engineering and 36-month TCO teardown of Langfuse vs LangSmith in 2026 alongside Arize Phoenix and Braintrust: ClickHouse OpenTelemetry ingestion, seat vs unit pricing, PII redaction, and MIT self-hosting.

Algolia vs Typesense vs Meilisearch: 2026 Search & TCO
Algolia vs Typesense vs Meilisearch in 2026, compared on engineering and 36-month TCO: Algolia pricing per 1,000 autocomplete requests vs in-RAM Raft clusters, Rust LMDB disk trade-offs, and blue/green reindexing.

Pinecone vs Qdrant vs Weaviate: 2026 RAG & TCO Guide
Engineering and 36-month TCO benchmark of Pinecone vs Qdrant vs Weaviate and PostgreSQL pgvector in 2026: filterable HNSW recall, hybrid BM25/RRF search, multi-tenant isolation, HIPAA BYOC, and RAG build costs.