Kabelo Dike / AI Stack Mental Model

The Foundation Models Layer

Now that we have explored how the Application Layer wraps around and orchestrates execution, let’s step down to Layer 4: Foundation Models.

If the Application Layer is the body, the Foundation Model is the raw computational engine. A foundation model is not a database containing stored records, nor is it an active software daemon with live threads running in the background. Mechanically, it is a static, frozen artifact composed of billions of mathematical weights. When invoked by the orchestrator, it performs massive matrix operations to solve a single statistical problem: predicting the most probable next sequence of tokens given an input context.

What a model actually is (the artifact)

  • Frozen numerical weights: When an engineering team “downloads” or loads an open model, they are not loading an executable binary. They are reading a multi-gigabyte data file of frozen numerical matrices (parameters). During inference, these numbers never change; the model never learns, writes to disk, or updates itself from your conversation.
  • Tokenization: Neural networks do not understand characters, words, or code directly. An input string is first sliced by a tokenizer into discrete integer IDs called tokens (typically chunks of roughly 3 to 4 characters). The model computes strictly over these numerical vectors.
  • Next-token prediction: At the core of transformer architectures is a next-token predictor. Given an input sequence of tokens, the network passes the vectors through dozens of attention layers to compute a probability distribution across its fixed vocabulary, then samples the next token. Repeating this loop token by token produces the output sequence.

Systems primer: neurons, weights, and networks

A neuron is just a linear equation
It is not a biological brain cell. It is a mathematical node that calculates a dot product: Σ (inputᵢ × weightᵢ) + bias passed through a non-linear activation function (like ReLU or GELU). It takes numbers in, scales them, and emits a single number out.
Weights are tuning knobs
A weight is simply a floating-point number (e.g., 0.4281 or -1.1904). It determines how much importance to give to a specific input signal. Training a model is nothing more than running calculus (backpropagation) across billions of examples to calculate the optimal values for these numbers. Once training stops, the weights are frozen.
A neural network is layered matrix multiplication
Billions of these numerical nodes are organized into stacked layers. Output values from Layer 1 become the inputs to Layer 2, and so forth. Passing data forward through these layers is just massive parallel matrix multiplication that transforms a vector of input tokens into a probability distribution over the next token.

The training pipeline: from raw text to assistant

A model does not come out of the factory ready to answer questions or follow technical instructions. It goes through three distinct stages:

  • Pre-training (the base model): The model processes trillions of tokens of text scraped from the internet, books, and code repositories to learn grammar, syntax, facts, and reasoning patterns. However, a raw base model is not an assistant; if you prompt it with “What is the capital of France?”, it might just complete the sentence with “and what is the capital of Germany?” because it is simply completing text documents.
  • Supervised fine-tuning (SFT / post-training): Engineers train the base model on curated question-and-answer datasets structured in a conversational format (User: / Assistant:). This teaches the model to adopt an instructional persona and recognize when it is supposed to respond rather than continue generating a prompt.
  • Preference alignment (RLHF / DPO): Reinforcement Learning from Human Feedback and Direct Preference Optimization score multiple model responses to tune its outputs toward human intent. This step instills safety boundaries, eliminates toxic patterns, and refines the tone to be helpful and concise.

Inference architecture and modern trade-offs

When selecting models for production workloads, there is a direct trade-off between latency, memory footprint, and compute cost:

  • Dense models vs. Mixture of Experts (MoE):
    • In a Dense model, every single parameter in the network is activated for every generated token, requiring heavy compute and high memory bandwidth.
    • In a Mixture of Experts (MoE) architecture, the model contains specialized sub-networks (experts). A lightweight routing mechanism directs each token to only a subset of these experts, drastically reducing operational compute costs while preserving broad reasoning capacity.
  • Context windows and attention: The context window is the finite token buffer the model can evaluate at once. Standard transformer attention scales quadratically (O(N²)) in compute with input length, meaning larger context windows demand significantly more memory and compute during the initial processing phase.
  • Reasoning models (inference-time compute): Traditional models generate output tokens immediately. Newer reasoning models generate hidden “thinking” tokens before emitting the final answer. This trades higher latency and token cost for deeper logical analysis on complex math, architecture, and coding tasks.

Adapting models: fine-tuning vs. in-context retrieval

A common architectural question is whether to train a custom model or use an off-the-shelf foundation model:

  • In-context learning (RAG & tool use): Injecting private data directly into the prompt at runtime. This is ideal for fast-moving business data, costs far less to maintain, provides source citations, and requires zero model retraining.
  • Domain fine-tuning: Updating the actual weights of an existing model using specialized datasets. This does not reliably teach a model new facts, but it is effective for altering style, teaching rare code syntax, or training small, cheap models to output rigid structured formats with high consistency.

The architectural boundary The foundation model knows nothing about your internal production infrastructure, live ticket queues, or databases. It provides the generalized reasoning capacity; the Application Layer above it is responsible for retrieving and injecting domain context at runtime.