liveBook · Manning

Chapter 9: Creating an LLM project: Reimplementing Llama 3

What you will learn in chapter 9 of LLMs in Production

The chapter introduces a hands-on project that brings earlier LLM lessons together by implementing and training a Llama-inspired model, improving it, and deploying it.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces a hands-on project that brings earlier LLM lessons together by implementing and training a Llama-inspired model, improving it, and deploying it.

Key terms: Meta’s Llama3, pretraining, from scratch, quantization, low-rank adaptation (LoRA), production endpoint

9.1 Implementing Meta’s Llama

This section explains why Llama 3 is a useful model to study and sets expectations for building and productionizing a smaller reimplementation.

Key terms: Llama 3, availability, open source software community, clean data, real model, data, GPUs, productionize

9.1.1 Tokenization and configuration

This section sets up the tokenizer and master configuration for a from-scratch Llama project and explains how those choices affect training and inference.

Key terms: Llama 3 tokenizer, SentencePiece, tiktoken, pretrained weights, padding token, <PAD>, vocab, encoding, decoding, batch processing

9.1.2 Dataset, data loading, evaluation, and generation

This section sets up memory-conscious data preparation, next-token training batches, validation loss, and text generation for a small Llama project.

Key terms: TinyStories, streaming, tokenization, attention masks, train and val splits, data leaks, get_batches, self-supervised learning, context window, expected output

9.1.3 Network architecture

The section builds and trains a small feed-forward language model as a baseline, explains its loss and padding choices, and uses its results to set up the move toward Llama.

Key terms: two-layer feed-forward network, linear model, ReLU, Llama 3, cross entropy, perplexity, <PAD>, ignore_index, pad_token_id, training loop

9.2 Simple Llama

The section builds a resource-conscious Llama-like model, explains how it differs from the earlier feed-forward network, and assesses what its training results show.

Key terms: Simple Llama, Llama 3, Kaggle, Colab, LlamaBlocks, n_layers, RMSNormalization, RoPEMaskedMultiheadAttention, SwiGLU, ReLU

9.3 Making it better

This section uses a model that passes internal tests but fails production checks to shift attention toward deployability, model size, and the systems surrounding the model.

Key terms: internal benchmarks, production environment, efficacy tests, size, systems we engineer around models, data, pretraining, deploy

9.3.1 Quantization

Shows how post-training INT8 quantization can shrink the Llama model for deployment while warning that compression can make its output less reliable.

Key terms: quantization, INT8, PyTorch, compression, perplexity, compress weights, prompt engineering

9.3.2 LoRA

This section uses LoRA to adapt Simple Llama for a new task without retraining it from scratch, then explains how to save and use the adaptation for inference.

Key terms: LoRA, data drift, finetune, LoRALayer, SimpleLlama, instruct dataset, get_batches, state dicts, rank, state dict

9.3.3 Fully sharded data parallel–quantized LoRA

This section combines QLoRA with PyTorch’s fully sharded data parallel training to fine-tune large models across GPUs, then explains how to prepare the resulting model for upload.

Key terms: QLoRA, quantized model, frozen, LoRA, fully sharded data parallel, FSDP, data parallelism, model parameter parallelism, sharding, fsdp_qlora

9.4 Deploy to a Hugging Face Hub Space

This section shows how to prepare a trained Llama model for Hugging Face, set up a Space to host an app, and account for the compute its model needs.

Key terms: Hugging Face Spaces, Gradio, Streamlit, FastAPI, weights, Hugging Face Hub, model.push_to_hub(), simple Llama LoRA, Space, Git

9.5 Summary

The section recaps the model-design, adaptation, and deployment choices involved in building a Llama project.

Where this is used later

Concepts explained in this chapter

← Chapter 8: Applications and Agents: Building an interactive experience Chapter 10: Creating a coding copilot project: Integrating an LLM service into VS Code with RAG →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.