Lompat ke konten

Tutorial Llama

Llama tutorial: Meta open-weight models, licenses and model choice, running Llama locally, prompt formats, quantization, retrieval, fine-tuning and serving.

Getting Started

  1. 1 What Is Llama? Meta's Open-Weight Models Learn what Llama is, what open weights means, who this tutorial is for, what you need, which examples run in your browser and how the course is organized.
  2. 2 How Llama Generates Text: Tokens, Weights and Sampling Understand tokens, parameters, base and instruct models, context windows and sampling settings, so the later Llama lessons on running and tuning make sense.

Models and Licenses

  1. 3 The Llama Model Family A map of Llama generations and sizes, from Llama 2 to Llama 4 Scout and Maverick, with context lengths, text and vision models and how to read model names.
  2. 4 Llama Licenses and Acceptable Use Learn the main conditions in Meta's Llama community licenses: attribution, naming, the large-company threshold, EU limits on multimodal models and use rules.
  3. 5 Choosing a Llama Model Pick a Llama model by task, hardware, language, license and quality. Build a small test set and score candidates instead of guessing from model size.

Running Llama Locally

  1. 6 Run Llama Locally with Ollama Install Ollama, download and chat with a small Llama model, use key commands, customize behavior with a Modelfile and keep the local server private.
  2. 7 Run Llama with llama.cpp Use llama.cpp to run GGUF Llama models from the command line, set context size and GPU layers, and start a local server with an OpenAI-compatible API.
  3. 8 Run Llama with Hugging Face Transformers Request access to gated Llama weights, log in with the hf command, download files safely and generate replies in Python with the Transformers library.
  4. 9 Call a Local Llama Server from Python Send chat requests to a local Llama server with Python, read replies and token counts, keep conversation history, stream output and handle errors.

Prompting and Chat Formats

  1. 10 Llama Chat Templates and Special Tokens See how role messages become one token stream in Llama 3 and Llama 4, what end-of-turn tokens do and why you should use the official chat template.
  2. 11 Prompting Llama and Getting Structured Output Write clear prompts for Llama, use system messages and examples, ask for JSON, constrain output with schemas, then validate and repair replies in code.

Memory, Speed and Quantization

  1. 12 Llama Memory Requirements: Weights and KV Cache Estimate how much RAM or GPU memory a Llama model needs: weight size by number format, the KV cache that grows with context and runtime overhead.
  2. 13 Llama Quantization and GGUF Learn what quantization does, how to read GGUF names such as Q4_K_M and Q8_0, how to convert and quantize with llama.cpp and how to test quality loss.
  3. 14 Llama Speed and Context Settings Understand time to first token and tokens per second, then improve local Llama speed with GPU offload, context limits, prompt reuse and fair benchmarks.

Retrieval and Tools

  1. 15 Retrieval with Llama: Answer from Your Documents Build retrieval for Llama: split documents into chunks, embed them with an embedding model, find the closest passages and ask for answers with citations.
  2. 16 Tool Calling with Llama Learn how Llama asks to call functions, Meta's output formats, how Ollama, llama.cpp and vLLM support tools and how to build a safe, validated tool loop.

Fine-tuning

  1. 17 When to Fine-tune Llama and How to Prepare Data Decide between prompting, retrieval and fine-tuning, then prepare clean conversational training data, split it correctly and check for leaks and private data.
  2. 18 Fine-tune Llama with LoRA and QLoRA Learn how LoRA adapters work, see real TRL and PEFT code for a Llama fine-tune with QLoRA, choose settings and avoid common training failures.
  3. 19 Evaluate and Ship a Fine-tuned Llama Compare a fine-tune with its baseline, check regressions and safety, then merge or load a LoRA adapter, convert it for local runtimes and release it safely.

Serving and Safety

  1. 20 Serving Llama to Real Users Choose a serving stack for Llama, run vLLM, protect the API, plan for concurrency and context, add limits, queues, monitoring and safe fallbacks.
  2. 21 Safety: Llama Guard and Prompt Guard Add layered safety around Llama with Llama Guard content classification, Prompt Guard injection detection, output checks, permissions and human review.

Projects and Reference

  1. 22 Project: A Local Llama Chat Assistant Build a command-line assistant with history trimming, commands, error handling and a swappable backend, testing it with a stand-in before using local Llama.
  2. 23 Project: Private Document Q&A with Llama Build a document question-answering app with chunking, search, access rules, grounded prompts, citation checks and an evaluation set you can run locally.
  3. 24 Llama Glossary and Cheat Sheet A quick reference for Llama terms, model facts, local commands, prompt tokens, memory formulas and a launch checklist, checked as of December 2026.