Lesson 17 Open Source Models
Theme:
Lesson 17 · Slide 1

Open Source Models

The open-source LLM ecosystem has exploded. This lesson covers the major model families, how to run them locally, quantization techniques, and when to choose open-source over proprietary APIs.

Learning Objectives

Lesson 17 · Slide 2

The Open-Source LLM Landscape

Since Meta released Llama in early 2023, the open-source ecosystem has grown rapidly. Today there are dozens of competitive model families.

ModelCreatorSizesLicence
Llama 3.1Meta8B, 70B, 405BLlama 3.1 Community
Mistral / MixtralMistral AI7B, 8x7B, 8x22BApache 2.0
FalconTII (UAE)7B, 40B, 180BApache 2.0 / TII
MPTMosaicML7B, 30BApache 2.0
Phi-3Microsoft3.8B, 7B, 14BMIT

Key trend: Smaller models are catching up. Phi-3-mini (3.8B) and Llama 3.1 8B rival GPT-3.5 on many benchmarks while running on a single consumer GPU.

Lesson 17 · Slide 3

The Llama Family

Meta’s Llama models are the most widely adopted open-source LLMs, forming the backbone of the ecosystem.

Why Llama matters: Its open weights created an entire ecosystem of fine-tuned models, tooling, and research. Most open-source LLM infrastructure was built around Llama first.

Note: “Open source” vs “open weights” — most models release weights but not training data or full training code. Llama’s licence restricts use for apps with 700M+ monthly users.
Lesson 17 · Slide 4

Mistral, Falcon, MPT & Phi

Mistral / Mixtral

  • Mistral 7B: Punches above its weight with sliding-window attention and GQA
  • Mixtral 8x7B: Mixture-of-Experts — 46.7B total params but only 12.9B active per token
  • True Apache 2.0 licence — no usage restrictions

Falcon

  • From the Technology Innovation Institute (UAE)
  • Trained on the RefinedWeb dataset (high-quality filtered web data)
  • Falcon 180B was the largest open model before Llama 3.1 405B

MPT (MosaicML)

  • Built with the Composer training framework
  • ALiBi positional encoding for length generalisation
  • Commercially permissive Apache 2.0 licence

Phi (Microsoft)

  • Focused on “small but capable” — trained on high-quality textbook-style data
  • Phi-3 mini (3.8B) matches Llama 3 8B on several benchmarks
  • Ideal for edge and mobile deployment
Lesson 17 · Slide 5

HuggingFace Ecosystem

HuggingFace Hub is the central repository for open-source models, datasets, and spaces. The Transformers library is the standard interface for loading and running models.

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

model_id = "meta-llama/Meta-Llama-3.1-8B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id, torch_dtype=torch.bfloat16, device_map="auto"
)

messages = [{"role": "user", "content": "Explain transformers in 3 sentences."}]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
outputs = model.generate(inputs, max_new_tokens=256)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))

HuggingFace Hub Key Features

Model cards: documentation, benchmarks, licence info. Spaces: hosted demos. Datasets: training and evaluation data. Leaderboards: standardised benchmarks (Open LLM Leaderboard).

Lesson 17 · Slide 6

Running Models Locally: Ollama & llama.cpp

You do not need a cloud GPU to run open-source models. Quantized versions of 7B–13B models run well on modern laptops.

Ollama

  • One-line install, Docker-like UX
  • ollama pull llama3.1
  • ollama run llama3.1
  • OpenAI-compatible REST API on port 11434
  • Automatic model management and quantization

llama.cpp

  • Pure C/C++ inference engine — no Python needed
  • Supports GGUF format (quantized models)
  • Metal (Mac), CUDA (NVIDIA), Vulkan support
  • Powers many tools: Ollama, LM Studio, text-generation-webui
# Using Ollama's OpenAI-compatible API
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")

response = client.chat.completions.create(
    model="llama3.1",
    messages=[{"role": "user", "content": "What is quantization?"}],
)
print(response.choices[0].message.content)
Lesson 17 · Slide 7

Quantization Overview

Quantization reduces model precision from 16-bit to 8-bit, 4-bit, or lower — shrinking memory requirements and speeding up inference with minimal quality loss.

FormatBitsToolUse Case
GGUF2–8 bitllama.cppCPU / Apple Silicon inference
GPTQ4 bitAutoGPTQGPU inference (CUDA)
AWQ4 bitAutoAWQGPU inference, faster than GPTQ
bitsandbytes4/8 bitHuggingFaceTraining and inference via Transformers

Memory Rule of Thumb

A model with N billion parameters in FP16 needs roughly 2N GB of VRAM. At 4-bit quantization, that drops to roughly 0.5N GB. So a 7B model needs ~14 GB at FP16 but only ~3.5 GB at Q4, fitting easily on a laptop.

Note: GGUF naming convention: Q4_K_M = 4-bit quantization, K-quant method, Medium quality. Higher numbers = better quality but more memory.
Lesson 17 · Slide 8

Lab & Homework

Lab Exercises

  1. Install Ollama — pull and run a model locally, explore the CLI
  2. Local vs Cloud — compare Ollama output with Claude API on the same prompts
  3. HuggingFace Hub — explore model cards, understand quantization variants

Homework Tasks

  1. Open vs Closed model comparison matrix
  2. Quantization deep-dive research
  3. Use-case decision framework

No GPU required: Ollama handles quantization automatically. A modern laptop with 8 GB+ RAM can run 7B models comfortably.

1 / ?