Key takeaway
- How to build an LLM or foundation model: data, transformer pretraining, LoRA fine-tuning, evaluation and governance, and when to adapt, not train.
How do you build an LLM or foundation model, and should you?
A foundation model is, in the words of the Stanford authors who named the term, a model "trained on broad data at scale and adaptable to a wide range of downstream tasks". A large language model (LLM) is a foundation model trained on text. Building one means five things in order: assemble and clean data, choose a transformer architecture, pretrain at scale, adapt it to your tasks, and evaluate and govern it before anyone depends on it.
For most enterprises the first decision is not how to train, but whether to. Pretraining from scratch is a programme for a handful of organisations. Adapting an existing model with your own data, retrieval and policy usually delivers the business result at a fraction of the effort. This guide covers both paths so that CTOs, CIOs and architects can choose with evidence. For the wider context, see our overview of artificial intelligence and the top generative AI use cases.
Should you build, adapt or buy a model?
| Path | What you do | When it fits | Main trade-off |
|---|---|---|---|
| Use a hosted model | Call a vendor model through an API and add retrieval and guardrails | Fast start, general tasks, low data sensitivity | Less control over model behaviour and data residency |
| Adapt an open or licensed model | Fine-tune or add adapters, host it yourself | Domain language, private data, predictable running cost | You own serving, evaluation and updates |
| Pretrain from scratch | Collect data, train all weights, run the full pipeline | Unusual language or modality, or model creation is your business | Largest compute, data and talent commitment, plus provider obligations under the EU AI Act |
Our own experience points the same way. In an internal code-scanning pipeline built on open-source coding models hosted on our own small machines, throughput in tokens per second set the pace: scanning one repository took 10 to 12 hours, so the team paused the job to rework the serving approach. The lesson for any self-hosted model is to measure serving speed against the real workload before committing.
What are the steps to build an LLM?
1. Collect and select data
Gather a broad corpus that covers the language, domains and formats the model must handle: books, articles, web text, code and your own documents where you hold the rights. Record the source, licence and date of every dataset. Breadth helps the model generalise, but the data must also represent your target domain.

2. Preprocess and tokenise
Remove noise and duplicates, standardise formats, handle special characters and filter personal or restricted data. Then tokenise the text into the units the model will read. Data quality at this stage sets a ceiling on everything downstream.
3. Choose the architecture
Modern LLMs use the transformer, introduced in "Attention Is All You Need" (Vaswani et al., 2017) as a network "based solely on attention mechanisms". Architectural choices include the number of layers, the attention design and the model size. Unless you have a research reason, start from a published open architecture rather than designing your own.
4. Pretrain at scale
Pretraining exposes the model to the corpus so that it learns statistical patterns of language, usually by predicting the next token. It is the most compute-intensive stage and can run for days or weeks even on large clusters. The DeepMind study "Training Compute-Optimal Large Language Models" (Hoffmann et al., 2022) concluded that model size and the number of training tokens should be scaled equally, so a bigger model alone is not the efficient answer without more data.
5. Adapt, align and evaluate
After pretraining, the model is adapted to tasks. Full fine-tuning updates every weight. Parameter-efficient methods such as LoRA freeze the base model and train small adapters: the LoRA paper reports up to 10,000 times fewer trainable parameters and 3 times lower GPU memory than fine-tuning GPT-3 175B with Adam. Alignment with human feedback can matter more than raw size: in the InstructGPT study, human raters preferred outputs from a 1.3 billion parameter tuned model over those of the 175 billion parameter GPT-3. Our glossary entry on language-model embeddings explains the representation layer that underpins these steps. Where the tuned model needs high-quality instruction data, AgentInstruct creates, validates and curates instruction data for a given use case, according to its own page.
What has changed since the first LLM wave?
| Area | Earlier practice | Current practice |
|---|---|---|
| Adaptation | Full fine-tuning of every weight | Adapters such as LoRA, plus retrieval, on a base model you did not pretrain |
| Alignment | Pretrained model used as is | Instruction tuning and human feedback before release |
| Regulation | Voluntary principles | Binding duties for general-purpose AI model providers in the EU |
| Use | Chat and text generation | Models acting inside agentic workflows with tools and policy limits |
What do governance, security and cost require?
Training data can carry bias, personal data and false content, and the model can repeat all three. Curate and document data, test outputs for bias across the groups you serve, and apply privacy controls such as anonymisation and access limits before training. Add review and fact-checking where output reaches customers or decisions.
Two official frameworks give a common language. The NIST AI Risk Management Framework (released 26 January 2023, voluntary) and its Generative AI Profile, NIST AI 600-1 (released 26 July 2024), help teams identify and manage risks specific to generative AI. In the EU, the Commission states that the obligations for general-purpose AI model providers entered into application on 2 August 2025, that its enforcement powers start on 2 August 2026, and that models placed on the market before 2 August 2025 must comply by 2 August 2027. If you pretrain a model and offer it in the EU, you are in scope; check the Commission guidance with your legal team.
Cost has three parts: training compute, serving cost per token, and the people who evaluate and maintain the model. Training energy use is also a sustainability matter, so track compute and prefer efficient methods. Because agents now call models to act, the model is only one layer. ElixirData Context OS provides governed context and decision traces above the agents that use your model, and AgentEvaluation scores and benchmarks AI agents before and after they go live, as its own page describes.
In what order should an enterprise adopt LLMs?
- Pick one workflow with a measurable outcome and a named owner.
- Start with a hosted or open model plus retrieval over your own documents.
- Build an evaluation set from real cases before you tune anything.
- Adapt with adapters or instruction tuning only where evaluation shows a gap.
- Add policy, logging and human review before agents act on model output.
- Consider pretraining only if the earlier steps cannot meet a clear business need.
When not to build: if your data is small, your task is general, or you cannot staff evaluation and serving, an adapted existing model is safer and cheaper. Our generative AI and agentic AI services support this adoption path.
To map one decision your agents should make with this model, and the context and policy it depends on, book a Context Workshop. See what happens in the workshop.
Frequently asked questions
What is the difference between an LLM and a foundation model?
A foundation model is trained on broad data at scale and can be adapted to many tasks. An LLM is a foundation model trained mainly on text.
Do we need to train an LLM from scratch?
Usually not. Adapting an existing model with fine-tuning, adapters and retrieval meets most enterprise needs. Pretraining suits organisations whose language, modality or business is model creation.
What does LoRA change in fine-tuning?
LoRA freezes the base weights and trains small adapters. Its authors report up to 10,000 times fewer trainable parameters and 3 times lower GPU memory than full fine-tuning of GPT-3 175B with Adam.
How much data does a larger model need?
DeepMind's 2022 compute-optimal study concluded that model size and training tokens should be scaled equally, so more parameters need more data.
Which rules apply to model providers in the EU?
General-purpose AI model provider obligations entered into application on 2 August 2025, with Commission enforcement powers from 2 August 2026 and a 2 August 2027 deadline for earlier models.
How should we evaluate a model before use?
Build a test set from real workflow cases, compare runs over time, and review bias, privacy and accuracy before agents act on its output.
Follow XenonStack on LinkedIn: XenonStack on LinkedIn for new guides on agentic AI, data and platform engineering.
Ready to put AI agents to work? Explore ElixirClaw, the agentic OS platform to build, orchestrate and govern AI agents.
Explore the XenonStack platform family: ElixirData · ElixirClaw · ElixirHub · NexaStack · MetaSecure · Neural AI · AgentGRC · AgentSRE · AgentAnalyst · AgentInstruct · AgentRAI · AgentScrum · AgentSearch · AgentForce · AI Aviator · SAIF Aviator · CohortIQ · XenonStack AI · XenonStack UAE