AI Model Wiki

    Skip to main content
    6 min read
    Lesson 5 of 5

    Training, Fine-Tuning & Inference

    From the course Introduction to AI: Core Concepts

    Understanding the lifecycle of an AI model — from training to deployment — helps you understand why different models behave differently and what's possible.

    Pre-Training: Learning the World

    The first stage is pre-training, where the model learns general knowledge from massive datasets:

    • Data: Trillions of tokens from the internet — books, websites, code, Wikipedia, forums
    • Objective: Predict the next word (for language models) or reconstruct masked words
    • Cost: $10-100+ million in compute for frontier models
    • Time: Weeks to months on thousands of GPUs
    • Result: A "foundation model" with broad knowledge but no specific task training

    This is like a student reading the entire library — they know a lot, but haven't been taught how to have a conversation or follow instructions.

    Fine-Tuning: Specialization

    After pre-training, models are fine-tuned for specific tasks:

    • Instruction tuning — Training on examples of following instructions (Q&A pairs, task completions). This turns GPT into "ChatGPT."
    • RLHF (Reinforcement Learning from Human Feedback) — Human raters rank different model outputs, and the model learns to prefer higher-ranked responses. This improves helpfulness, safety, and quality.
    • Domain fine-tuning — Training on specialized data for specific industries (legal, medical, financial).
    • LoRA/QLoRA — Efficient fine-tuning techniques that modify only a small subset of parameters, making it affordable to customize large models.

    Inference: Using the Model

    Inference is when you actually use the model — sending a prompt and getting a response. Key concepts:

    • Tokens — AI models process text as tokens (roughly ¾ of a word). "Hello, world!" = 4 tokens.
    • Context window — The maximum number of tokens the model can consider at once (128K for GPT-4o, 1M+ for Gemini).
    • Temperature — Controls randomness. Low temperature (0.1) = predictable, focused answers. High temperature (0.9) = creative, varied answers.
    • Top-p (nucleus sampling) — Another way to control output diversity by limiting which tokens the model considers.

    Latency & Cost

    • Larger models = higher quality but slower and more expensive
    • Smaller models = faster and cheaper but less capable
    • This is why companies offer model tiers (GPT-4o vs GPT-4o mini)

    Open Source vs. Closed Source

    • Closed source (GPT-4, Claude, Gemini) — You access via API. Can't see the architecture, weights, or training data. The company controls everything.
    • Open source (Llama, Mistral, Gemma) — Weights are publicly available. You can download, modify, fine-tune, and run locally. More freedom but requires technical expertise.

    The open-source community is closing the gap rapidly, with models like Llama 3 matching or exceeding some closed-source models on benchmarks.

    Key Takeaways

    • •Pre-training creates foundation models from massive datasets at huge compute cost
    • •Fine-tuning specializes models for tasks — instruction following, safety, domain expertise
    • •RLHF trains models to prefer human-approved responses
    • •Temperature and top-p control how creative vs. deterministic model outputs are
    • •Open-source models are closing the gap with closed-source, offering more customization
    0 of 5 lessons marked complete

    Progress is kept in this browser only.